diff --git a/cmd/apiserver/app/options/options.go b/cmd/apiserver/app/options/options.go index 389b19ff9..d3f0b6ac6 100644 --- a/cmd/apiserver/app/options/options.go +++ b/cmd/apiserver/app/options/options.go @@ -17,6 +17,7 @@ import ( "k8s.io/component-base/featuregate" "k8s.io/component-base/logs" logsapi "k8s.io/component-base/logs/api/v1" + "k8s.io/component-base/metrics" "github.com/clusterpedia-io/clusterpedia/pkg/apiserver" generatedopenapi "github.com/clusterpedia-io/clusterpedia/pkg/generated/openapi" @@ -37,6 +38,7 @@ type ClusterPediaServerOptions struct { CoreAPI *genericoptions.CoreAPIOptions FeatureGate featuregate.FeatureGate Traces *genericoptions.TracingOptions + Metrics *metrics.Options Storage *storageoptions.StorageOptions } @@ -66,6 +68,7 @@ func NewServerOptions() *ClusterPediaServerOptions { CoreAPI: genericoptions.NewCoreAPIOptions(), FeatureGate: feature.DefaultFeatureGate, Traces: genericoptions.NewTracingOptions(), + Metrics: metrics.NewOptions(), Storage: storageoptions.NewStorageOptions(), } @@ -75,6 +78,7 @@ func (o *ClusterPediaServerOptions) Validate() error { errors := []error{} errors = append(errors, o.validateGenericOptions()...) errors = append(errors, o.Storage.Validate()...) + errors = append(errors, o.Metrics.Validate()...) return utilerrors.NewAggregate(errors) } @@ -83,6 +87,7 @@ func (o *ClusterPediaServerOptions) Config() (*apiserver.Config, error) { if err := o.Validate(); err != nil { return nil, err } + o.Metrics.Apply() storage, err := storage.NewStorageFactory(o.Storage.Name, o.Storage.ConfigPath) if err != nil { @@ -170,6 +175,7 @@ func (o *ClusterPediaServerOptions) Flags() cliflag.NamedFlagSets { o.Features.AddFlags(fss.FlagSet("features")) logsapi.AddFlags(o.Logs, fss.FlagSet("logs")) o.Traces.AddFlags(fss.FlagSet("traces")) + o.Metrics.AddFlags(fss.FlagSet("metrics")) o.Storage.AddFlags(fss.FlagSet("storage")) return fss diff --git a/pkg/metrics/server/options.go b/pkg/metrics/server/options.go index 5ee5d71e8..730316bb1 100644 --- a/pkg/metrics/server/options.go +++ b/pkg/metrics/server/options.go @@ -5,6 +5,7 @@ import ( "strconv" "github.com/spf13/pflag" + "k8s.io/component-base/metrics" ) type Options struct { @@ -13,6 +14,8 @@ type Options struct { TLSConfig string DisableGZIPEncoding bool + + Metrics *metrics.Options } func NewOptions() *Options { @@ -20,11 +23,13 @@ func NewOptions() *Options { Host: "::", Port: 8081, DisableGZIPEncoding: false, + + Metrics: metrics.NewOptions(), } } func (o *Options) Validate() []error { - return nil + return o.Metrics.Validate() } func (o *Options) AddFlags(fs *pflag.FlagSet) { @@ -33,9 +38,12 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) { fs.BoolVar(&o.DisableGZIPEncoding, "metrics-disable-gzip-encoding", o.DisableGZIPEncoding, "Gzip responses when requested by clients via 'Accept-Encoding: gzip' header.") fs.StringVar(&o.TLSConfig, "metrics-tls-config", o.TLSConfig, "Path to the TLS configuration file of metrics") + o.Metrics.AddFlags(fs) } func (o *Options) Config() (config Config) { + o.Metrics.Apply() + return Config{ Endpoint: net.JoinHostPort(o.Host, strconv.Itoa(o.Port)), TLSConfig: o.TLSConfig,