Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metrics: add component-base/metrics.Options #696

Merged
merged 1 commit into from
Aug 30, 2024
Merged
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: 6 additions & 0 deletions cmd/apiserver/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -37,6 +38,7 @@ type ClusterPediaServerOptions struct {
CoreAPI *genericoptions.CoreAPIOptions
FeatureGate featuregate.FeatureGate
Traces *genericoptions.TracingOptions
Metrics *metrics.Options

Storage *storageoptions.StorageOptions
}
Expand Down Expand Up @@ -66,6 +68,7 @@ func NewServerOptions() *ClusterPediaServerOptions {
CoreAPI: genericoptions.NewCoreAPIOptions(),
FeatureGate: feature.DefaultFeatureGate,
Traces: genericoptions.NewTracingOptions(),
Metrics: metrics.NewOptions(),

Storage: storageoptions.NewStorageOptions(),
}
Expand All @@ -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)
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion pkg/metrics/server/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strconv"

"github.com/spf13/pflag"
"k8s.io/component-base/metrics"
)

type Options struct {
Expand All @@ -13,18 +14,22 @@ type Options struct {

TLSConfig string
DisableGZIPEncoding bool

Metrics *metrics.Options
}

func NewOptions() *Options {
return &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) {
Expand All @@ -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,
Expand Down
Loading