Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ MULTI_ARCH_IMG = $(IMAGE)-$(ARCH)
USER ?= $(shell id -u -n)
HOST ?= $(shell hostname)
MARKDOWNLINT_CLI2_VERSION = 0.18.1
CLIENT_GO_VERSION = $(shell go list -m -f '{{.Version}}' k8s.io/client-go)
KSM_MODULE = $(shell go list -m)

DOCKER_CLI ?= docker
PROMTOOL_CLI ?= promtool
GOMPLATE_CLI ?= go tool github.com/hairyhenderson/gomplate/v4/cmd/gomplate
GOMPLATE_CLI ?= go tool github.com/hairyhenderson/gomplate/v4/cmd/gomplate
GOJSONTOYAML_CLI ?= go tool github.com/brancz/gojsontoyaml
EMBEDMD_CLI ?= go tool github.com/campoy/embedmd
JSONNET_CLI ?= go tool github.com/google/go-jsonnet/cmd/jsonnet
Expand Down Expand Up @@ -69,7 +71,7 @@ doccheck: generate validate-template
@echo OK

build-local:
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
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

build: kube-state-metrics

Expand Down
14 changes: 14 additions & 0 deletions pkg/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ import (
"k8s.io/kube-state-metrics/v2/pkg/util/proc"
)

// ClientGoVersion is the version for the client-go library used by KSM. This
// value is set at build time using go build flags.
var ClientGoVersion = "unknown"

const (
metricsPath = "/metrics"
healthzPath = "/healthz"
Expand All @@ -86,6 +90,16 @@ func RunKubeStateMetricsWrapper(ctx context.Context, opts *options.Options) erro
func RunKubeStateMetrics(ctx context.Context, opts *options.Options) error {
ksmMetricsRegistry := prometheus.NewRegistry()
ksmMetricsRegistry.MustRegister(versionCollector.NewCollector("kube_state_metrics"))

clientGoVersion := promauto.With(ksmMetricsRegistry).NewGaugeVec(
prometheus.GaugeOpts{
Name: "kube_state_metrics_client_go_info",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can make this part of the kube_state_metrics_build_info metrics, but then on the other hand we don't have that many metrics in this metric path.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding the label to kube_state_metrics_build_info makes sense. Does this metric exist though? I wasn't able to find it on port 8081.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prometheus/client_golang#1860 PR is here to add support.

Help: "An info metric for the client-go version used by kube-state-metrics",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we mark it as experimental?

},
[]string{"version"},
)
clientGoVersion.WithLabelValues(ClientGoVersion).Set(1)

durationVec := promauto.With(ksmMetricsRegistry).NewHistogramVec(
prometheus.HistogramOpts{
Name: "http_request_duration_seconds",
Expand Down