Skip to content

Commit

Permalink
Merge pull request #696 from scydas/metrics_options
Browse files Browse the repository at this point in the history
metrics: add component-base/metrics.Options
  • Loading branch information
Iceber authored Aug 30, 2024
2 parents 5afaf71 + 358a263 commit 602ce91
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
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

0 comments on commit 602ce91

Please sign in to comment.