github.com/aclisp/heapster@v0.19.2-0.20160613100040-51756f899a96/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 (
    20  	"fmt"
    21  	"runtime"
    22  
    23  	"github.com/prometheus/client_golang/prometheus"
    24  )
    25  
    26  // Info contains versioning information.
    27  // TODO: Add []string of api versions supported? It's still unclear
    28  // how we'll want to distribute that information.
    29  type Info struct {
    30  	Major        string `json:"major"`
    31  	Minor        string `json:"minor"`
    32  	GitVersion   string `json:"gitVersion"`
    33  	GitCommit    string `json:"gitCommit"`
    34  	GitTreeState string `json:"gitTreeState"`
    35  	BuildDate    string `json:"buildDate"`
    36  	GoVersion    string `json:"goVersion"`
    37  	Compiler     string `json:"compiler"`
    38  	Platform     string `json:"platform"`
    39  }
    40  
    41  // Get returns the overall codebase version. It's for detecting
    42  // what code a binary was built from.
    43  func Get() Info {
    44  	// These variables typically come from -ldflags settings and in
    45  	// their absence fallback to the settings in pkg/version/base.go
    46  	return Info{
    47  		Major:        gitMajor,
    48  		Minor:        gitMinor,
    49  		GitVersion:   gitVersion,
    50  		GitCommit:    gitCommit,
    51  		GitTreeState: gitTreeState,
    52  		BuildDate:    buildDate,
    53  		GoVersion:    runtime.Version(),
    54  		Compiler:     runtime.Compiler,
    55  		Platform:     fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
    56  	}
    57  }
    58  
    59  // String returns info as a human-friendly version string.
    60  func (info Info) String() string {
    61  	return info.GitVersion
    62  }
    63  
    64  func init() {
    65  	buildInfo := prometheus.NewGaugeVec(
    66  		prometheus.GaugeOpts{
    67  			Name: "kubernetes_build_info",
    68  			Help: "A metric with a constant '1' value labeled by major, minor, git version, git commit, git tree state, build date, Go version, and compiler from which Kubernetes was built, and platform on which it is running.",
    69  		},
    70  		[]string{"major", "minor", "gitVersion", "gitCommit", "gitTreeState", "buildDate", "goVersion", "compiler", "platform"},
    71  	)
    72  	info := Get()
    73  	buildInfo.WithLabelValues(info.Major, info.Minor, info.GitVersion, info.GitCommit, info.GitTreeState, info.BuildDate, info.GoVersion, info.Compiler, info.Platform).Set(1)
    74  
    75  	prometheus.MustRegister(buildInfo)
    76  }