github.com/timstclair/heapster@v0.20.0-alpha1/Godeps/_workspace/src/k8s.io/kubernetes/pkg/version/version.go (about)

     1  /*
     2  Copyright 2014 The Kubernetes Authors All rights reserved.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package version
    18  
    19  import "github.com/prometheus/client_golang/prometheus"
    20  
    21  // Info contains versioning information.
    22  // TODO: Add []string of api versions supported? It's still unclear
    23  // how we'll want to distribute that information.
    24  type Info struct {
    25  	Major        string `json:"major"`
    26  	Minor        string `json:"minor"`
    27  	GitVersion   string `json:"gitVersion"`
    28  	GitCommit    string `json:"gitCommit"`
    29  	GitTreeState string `json:"gitTreeState"`
    30  }
    31  
    32  // Get returns the overall codebase version. It's for detecting
    33  // what code a binary was built from.
    34  func Get() Info {
    35  	// These variables typically come from -ldflags settings and in
    36  	// their absence fallback to the settings in pkg/version/base.go
    37  	return Info{
    38  		Major:        gitMajor,
    39  		Minor:        gitMinor,
    40  		GitVersion:   gitVersion,
    41  		GitCommit:    gitCommit,
    42  		GitTreeState: gitTreeState,
    43  	}
    44  }
    45  
    46  // String returns info as a human-friendly version string.
    47  func (info Info) String() string {
    48  	return info.GitVersion
    49  }
    50  
    51  func init() {
    52  	buildInfo := prometheus.NewGaugeVec(
    53  		prometheus.GaugeOpts{
    54  			Name: "kubernetes_build_info",
    55  			Help: "A metric with a constant '1' value labeled by major, minor, git version, git commit and git tree state from which Kubernetes was built.",
    56  		},
    57  		[]string{"major", "minor", "gitVersion", "gitCommit", "gitTreeState"},
    58  	)
    59  	info := Get()
    60  	buildInfo.WithLabelValues(info.Major, info.Minor, info.GitVersion, info.GitCommit, info.GitTreeState).Set(1)
    61  
    62  	prometheus.MustRegister(buildInfo)
    63  }