Skip to content

Commit

Permalink
Merge pull request #695 from Iceber/legacyregistry_metrics
Browse files Browse the repository at this point in the history
metrics: register clusterpedia and kubernetes build info
  • Loading branch information
Iceber committed Aug 29, 2024
2 parents 34189ea + 4cdf195 commit 5afaf71
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 76 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 cmd/clustersynchro-manager/app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

crdclientset "github.com/clusterpedia-io/clusterpedia/pkg/generated/clientset/versioned"
kubestatemetrics "github.com/clusterpedia-io/clusterpedia/pkg/kube_state_metrics"
metrics "github.com/clusterpedia-io/clusterpedia/pkg/metrics"
metricsserver "github.com/clusterpedia-io/clusterpedia/pkg/metrics/server"
"github.com/clusterpedia-io/clusterpedia/pkg/storage"
"github.com/clusterpedia-io/clusterpedia/pkg/synchromanager/clustersynchro"
)
Expand All @@ -19,7 +19,7 @@ type Config struct {

WorkerNumber int
ShardingName string
MetricsServerConfig metrics.Config
MetricsServerConfig metricsserver.Config
KubeMetricsServerConfig *kubestatemetrics.ServerConfig
StorageFactory storage.StorageFactory
ClusterSyncConfig clustersynchro.ClusterSyncConfig
Expand Down
6 changes: 3 additions & 3 deletions cmd/clustersynchro-manager/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/clusterpedia-io/clusterpedia/cmd/clustersynchro-manager/app/config"
crdclientset "github.com/clusterpedia-io/clusterpedia/pkg/generated/clientset/versioned"
kubestatemetrics "github.com/clusterpedia-io/clusterpedia/pkg/kube_state_metrics"
"github.com/clusterpedia-io/clusterpedia/pkg/metrics"
metricsserver "github.com/clusterpedia-io/clusterpedia/pkg/metrics/server"
"github.com/clusterpedia-io/clusterpedia/pkg/storage"
storageoptions "github.com/clusterpedia-io/clusterpedia/pkg/storage/options"
"github.com/clusterpedia-io/clusterpedia/pkg/synchromanager/clustersynchro"
Expand All @@ -42,7 +42,7 @@ type Options struct {

Logs *logs.Options
Storage *storageoptions.StorageOptions
Metrics *metrics.Options
Metrics *metricsserver.Options
KubeStateMetrics *kubestatemetrics.Options

WorkerNumber int // WorkerNumber is the number of worker goroutines
Expand Down Expand Up @@ -76,7 +76,7 @@ func NewClusterSynchroManagerOptions() (*Options, error) {

options.Logs = logs.NewOptions()
options.Storage = storageoptions.NewStorageOptions()
options.Metrics = metrics.NewMetricsServerOptions()
options.Metrics = metricsserver.NewOptions()
options.KubeStateMetrics = kubestatemetrics.NewOptions()

options.WorkerNumber = 5
Expand Down
4 changes: 2 additions & 2 deletions cmd/clustersynchro-manager/app/synchro.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/clusterpedia-io/clusterpedia/cmd/clustersynchro-manager/app/config"
"github.com/clusterpedia-io/clusterpedia/cmd/clustersynchro-manager/app/options"
kubestatemetrics "github.com/clusterpedia-io/clusterpedia/pkg/kube_state_metrics"
"github.com/clusterpedia-io/clusterpedia/pkg/metrics"
metricsserver "github.com/clusterpedia-io/clusterpedia/pkg/metrics/server"
"github.com/clusterpedia-io/clusterpedia/pkg/storage"
"github.com/clusterpedia-io/clusterpedia/pkg/synchromanager"
clusterpediafeature "github.com/clusterpedia-io/clusterpedia/pkg/utils/feature"
Expand Down Expand Up @@ -88,7 +88,7 @@ func Run(ctx context.Context, c *config.Config) error {
synchromanager := synchromanager.NewManager(c.CRDClient, c.StorageFactory, c.ClusterSyncConfig, c.ShardingName)

go func() {
metrics.RunServer(c.MetricsServerConfig)
metricsserver.Run(c.MetricsServerConfig)
}()

if c.KubeMetricsServerConfig != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/kube_state_metrics/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/spf13/pflag"
"k8s.io/kube-state-metrics/v2/pkg/options"

"github.com/clusterpedia-io/clusterpedia/pkg/metrics"
metricsserver "github.com/clusterpedia-io/clusterpedia/pkg/metrics/server"
)

var defaultResources = options.ResourceSet{
Expand Down Expand Up @@ -87,7 +87,7 @@ func (o *Options) MetricsStoreBuilderConfig() *MetricsStoreBuilderConfig {
}
}

func (o *Options) ServerConfig(config metrics.Config) *ServerConfig {
func (o *Options) ServerConfig(config metricsserver.Config) *ServerConfig {
if !o.EnableKubeStateMetrics {
return nil
}
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"
metricsserver "github.com/clusterpedia-io/clusterpedia/pkg/metrics/server"
"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, metricsserver.Logger)
}

func buildMetricsServer(config ServerConfig, getter ClusterMetricsWriterListGetter, durationObserver prometheus.ObserverVec) *mux.Router {
Expand Down
12 changes: 0 additions & 12 deletions pkg/metrics/metrics.go

This file was deleted.

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

import "k8s.io/klog/v2"

Expand Down
4 changes: 2 additions & 2 deletions 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 All @@ -15,7 +15,7 @@ type Options struct {
DisableGZIPEncoding bool
}

func NewMetricsServerOptions() *Options {
func NewOptions() *Options {
return &Options{
Host: "::",
Port: 8081,
Expand Down
5 changes: 3 additions & 2 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,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/pprof"
"github.com/clusterpedia-io/clusterpedia/pkg/version"
)
Expand All @@ -20,7 +21,7 @@ type Config struct {
DisableGZIPEncoding bool
}

func RunServer(config Config) {
func Run(config Config) {
server := &http.Server{
Handler: buildMetricsServer(config),
ReadHeaderTimeout: 6 * time.Second,
Expand Down
23 changes: 23 additions & 0 deletions pkg/metrics/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package metrics

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

"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 Clusterpedia was built, and platform on which it is running.",
},
[]string{"git_version", "git_commit", "git_tree_state", "build_date", "go_version", "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 5afaf71

Please sign in to comment.