1/*
2Copyright 2019 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package version
18
19import (
20	"k8s.io/component-base/metrics"
21	"k8s.io/component-base/metrics/legacyregistry"
22	"k8s.io/component-base/version"
23)
24
25var (
26	buildInfo = metrics.NewGaugeVec(
27		&metrics.GaugeOpts{
28			Name:           "kubernetes_build_info",
29			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.",
30			StabilityLevel: metrics.ALPHA,
31		},
32		[]string{"major", "minor", "git_version", "git_commit", "git_tree_state", "build_date", "go_version", "compiler", "platform"},
33	)
34)
35
36// RegisterBuildInfo registers the build and version info in a metadata metric in prometheus
37func init() {
38	info := version.Get()
39	legacyregistry.MustRegister(buildInfo)
40	buildInfo.WithLabelValues(info.Major, info.Minor, info.GitVersion, info.GitCommit, info.GitTreeState, info.BuildDate, info.GoVersion, info.Compiler, info.Platform).Set(1)
41}
42