Skip to content

Commit

Permalink
metrics: register clusterpedia and kubernetes build info
Browse files Browse the repository at this point in the history
Signed-off-by: Iceber Gu <[email protected]>
  • Loading branch information
Iceber committed Aug 29, 2024
1 parent b570837 commit 764d1a5
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 67 deletions.
1 change: 1 addition & 0 deletions cmd/apiserver/app/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"k8s.io/component-base/term"

"github.com/clusterpedia-io/clusterpedia/cmd/apiserver/app/options"
_ "github.com/clusterpedia-io/clusterpedia/pkg/metrics"
"github.com/clusterpedia-io/clusterpedia/pkg/storage"
"github.com/clusterpedia-io/clusterpedia/pkg/version/verflag"
)
Expand Down
4 changes: 2 additions & 2 deletions pkg/kube_state_metrics/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"k8s.io/component-base/metrics/legacyregistry"
"k8s.io/klog/v2"

"github.com/clusterpedia-io/clusterpedia/pkg/metrics"
"github.com/clusterpedia-io/clusterpedia/pkg/metrics/logger"
"github.com/clusterpedia-io/clusterpedia/pkg/version"
)

Expand Down Expand Up @@ -49,7 +49,7 @@ func RunServer(config ServerConfig, getter ClusterMetricsWriterListGetter) {

klog.Info("Kube State Metrics Server is running...")
// TODO(iceber): handle error
_ = web.ListenAndServe(server, flags, metrics.Logger)
_ = web.ListenAndServe(server, flags, logger.Logger)
}

func buildMetricsServer(config ServerConfig, getter ClusterMetricsWriterListGetter, durationObserver prometheus.ObserverVec) *mux.Router {
Expand Down
2 changes: 1 addition & 1 deletion pkg/metrics/logger.go → pkg/metrics/logger/logger.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package metrics
package logger

import "k8s.io/klog/v2"

Expand Down
12 changes: 0 additions & 12 deletions pkg/metrics/metrics.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/metrics/options.go → pkg/metrics/server/options.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package metrics
package server

import (
"net"
Expand Down
8 changes: 5 additions & 3 deletions pkg/metrics/server.go → pkg/metrics/server/server.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package metrics
package server

import (
"net/http"
Expand All @@ -9,6 +9,8 @@ import (
"k8s.io/component-base/metrics/legacyregistry"
"k8s.io/klog/v2"

_ "github.com/clusterpedia-io/clusterpedia/pkg/metrics"
"github.com/clusterpedia-io/clusterpedia/pkg/metrics/logger"
"github.com/clusterpedia-io/clusterpedia/pkg/pprof"
"github.com/clusterpedia-io/clusterpedia/pkg/version"
)
Expand All @@ -33,15 +35,15 @@ func RunServer(config Config) {
}

klog.Info("Metrics Server is running...")
_ = web.ListenAndServe(server, flags, Logger)
_ = web.ListenAndServe(server, flags, logger.Logger)
}

func buildMetricsServer(config Config) *http.ServeMux {
mux := http.NewServeMux()
mux.Handle("/metrics", metrics.HandlerWithReset(
legacyregistry.DefaultGatherer.(metrics.KubeRegistry),
metrics.HandlerOpts{
ErrorLog: Logger,
ErrorLog: logger.Logger,
DisableCompression: config.DisableGZIPEncoding,
}),
)
Expand Down
22 changes: 22 additions & 0 deletions pkg/metrics/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package metrics

import (
"k8s.io/component-base/metrics"
"k8s.io/component-base/metrics/legacyregistry"

"github.com/clusterpedia-io/clusterpedia/pkg/version"
)

var buildInfo = metrics.NewGaugeVec(
&metrics.GaugeOpts{
Name: "clusterpedia_build_info",
Help: "A metric with a constant '1' value labeled by 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.",
},
[]string{"git_version", "git_commit", "git_tree_state", "build_date", "go_ve rsion", "compiler", "platform"},
)

func init() {
info := version.Get()
legacyregistry.MustRegister(buildInfo)
buildInfo.WithLabelValues(info.GitVersion, info.GitCommit, info.GitTreeState, info.BuildDate, info.GoVersion, info.Compiler, info.Platform).Set(1)
}

This file was deleted.

41 changes: 41 additions & 0 deletions vendor/k8s.io/component-base/metrics/prometheus/version/metrics.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ github.com/pmezard/go-difflib/difflib
## explicit; go 1.20
github.com/prometheus/client_golang/prometheus
github.com/prometheus/client_golang/prometheus/collectors
github.com/prometheus/client_golang/prometheus/collectors/version
github.com/prometheus/client_golang/prometheus/internal
github.com/prometheus/client_golang/prometheus/promauto
github.com/prometheus/client_golang/prometheus/promhttp
Expand Down Expand Up @@ -1372,6 +1371,7 @@ k8s.io/component-base/metrics/features
k8s.io/component-base/metrics/legacyregistry
k8s.io/component-base/metrics/prometheus/feature
k8s.io/component-base/metrics/prometheus/slis
k8s.io/component-base/metrics/prometheus/version
k8s.io/component-base/metrics/prometheus/workqueue
k8s.io/component-base/metrics/prometheusextension
k8s.io/component-base/metrics/testutil
Expand Down

0 comments on commit 764d1a5

Please sign in to comment.