Skip to content

Commit a07e79f

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.
1 parent f421b9a commit a07e79f

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ import (
6363
"k8s.io/kube-state-metrics/v2/pkg/util/proc"
6464
)
6565

66+
var ClientGoVersion = "unknown"
67+
6668
const (
6769
metricsPath = "/metrics"
6870
healthzPath = "/healthz"
@@ -86,6 +88,16 @@ func RunKubeStateMetricsWrapper(ctx context.Context, opts *options.Options) erro
8688
func RunKubeStateMetrics(ctx context.Context, opts *options.Options) error {
8789
ksmMetricsRegistry := prometheus.NewRegistry()
8890
ksmMetricsRegistry.MustRegister(versionCollector.NewCollector("kube_state_metrics"))
91+
92+
clientGoVersion := promauto.With(ksmMetricsRegistry).NewGaugeVec(
93+
prometheus.GaugeOpts{
94+
Name: "kube_state_metrics_client_go_info",
95+
Help: "An info metric for the client-go version used by kube-state-metrics",
96+
},
97+
[]string{"version"},
98+
)
99+
clientGoVersion.WithLabelValues(ClientGoVersion).Set(1)
100+
89101
durationVec := promauto.With(ksmMetricsRegistry).NewHistogramVec(
90102
prometheus.HistogramOpts{
91103
Name: "http_request_duration_seconds",

0 commit comments

Comments
 (0)