Skip to content

Commit 66373c2

Browse files
committed
Add info metric for client-go version
KSM supports a range of Kubernetes versions which makes it important to keep up with new versions as clusters upgrade. In order to allow for alerting on unsupported cluster versions, this commit adds an info metric for the client-go version used by KSM. This way users can set up alerts if the cluster in which KSM is running is outside of the supported range. Signed-off-by: fpetkovski <[email protected]>
1 parent f421b9a commit 66373c2

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ MULTI_ARCH_IMG = $(IMAGE)-$(ARCH)
2020
USER ?= $(shell id -u -n)
2121
HOST ?= $(shell hostname)
2222
MARKDOWNLINT_CLI2_VERSION = 0.18.1
23+
CLIENT_GO_VERSION = $(shell go list -m -f '{{.Version}}' k8s.io/client-go)
24+
KSM_MODULE = $(shell go list -m)
2325

2426
DOCKER_CLI ?= docker
2527
PROMTOOL_CLI ?= promtool
26-
GOMPLATE_CLI ?= go tool github.com/hairyhenderson/gomplate/v4/cmd/gomplate
28+
GOMPLATE_CLI ?= go tool github.com/hairyhenderson/gomplate/v4/cmd/gomplate
2729
GOJSONTOYAML_CLI ?= go tool github.com/brancz/gojsontoyaml
2830
EMBEDMD_CLI ?= go tool github.com/campoy/embedmd
2931
JSONNET_CLI ?= go tool github.com/google/go-jsonnet/cmd/jsonnet
@@ -69,7 +71,7 @@ doccheck: generate validate-template
6971
@echo OK
7072

7173
build-local:
72-
GOOS=$(OS) GOARCH=$(ARCH) CGO_ENABLED=0 go build -ldflags "-s -w -X ${PKG}/version.Version=${TAG} -X ${PKG}/version.Revision=${GIT_COMMIT} -X ${PKG}/version.Branch=${BRANCH} -X ${PKG}/version.BuildUser=${USER}@${HOST} -X ${PKG}/version.BuildDate=${BUILD_DATE}" -o kube-state-metrics
74+
GOOS=$(OS) GOARCH=$(ARCH) CGO_ENABLED=0 go build -ldflags "-s -w -X ${PKG}/version.Version=${TAG} -X ${PKG}/version.Revision=${GIT_COMMIT} -X ${PKG}/version.Branch=${BRANCH} -X ${PKG}/version.BuildUser=${USER}@${HOST} -X ${PKG}/version.BuildDate=${BUILD_DATE} -X ${PKG}/version.BuildDate=${BUILD_DATE} -X ${KSM_MODULE}/pkg/app.ClientGoVersion=${CLIENT_GO_VERSION}" -o kube-state-metrics
7375

7476
build: kube-state-metrics
7577

pkg/app/server.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ import (
6363
"k8s.io/kube-state-metrics/v2/pkg/util/proc"
6464
)
6565

66+
// ClientGoVersion is the version for the client-go library used by KSM. This
67+
// value is set at build time using go build flags.
68+
var ClientGoVersion = "unknown"
69+
6670
const (
6771
metricsPath = "/metrics"
6872
healthzPath = "/healthz"
@@ -86,6 +90,16 @@ func RunKubeStateMetricsWrapper(ctx context.Context, opts *options.Options) erro
8690
func RunKubeStateMetrics(ctx context.Context, opts *options.Options) error {
8791
ksmMetricsRegistry := prometheus.NewRegistry()
8892
ksmMetricsRegistry.MustRegister(versionCollector.NewCollector("kube_state_metrics"))
93+
94+
clientGoVersion := promauto.With(ksmMetricsRegistry).NewGaugeVec(
95+
prometheus.GaugeOpts{
96+
Name: "kube_state_metrics_client_go_info",
97+
Help: "An info metric for the client-go version used by kube-state-metrics",
98+
},
99+
[]string{"version"},
100+
)
101+
clientGoVersion.WithLabelValues(ClientGoVersion).Set(1)
102+
89103
durationVec := promauto.With(ksmMetricsRegistry).NewHistogramVec(
90104
prometheus.HistogramOpts{
91105
Name: "http_request_duration_seconds",

0 commit comments

Comments
 (0)