Skip to content

Commit 8b825d1

Browse files
committed
Add show-hidden-metrics-for-version to scheduler
1 parent 7fe64cc commit 8b825d1

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

cmd/kube-scheduler/app/options/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ go_library(
4242
"//staging/src/k8s.io/component-base/cli/flag:go_default_library",
4343
"//staging/src/k8s.io/component-base/codec:go_default_library",
4444
"//staging/src/k8s.io/component-base/config:go_default_library",
45+
"//staging/src/k8s.io/component-base/metrics:go_default_library",
4546
"//staging/src/k8s.io/kube-scheduler/config/v1alpha2:go_default_library",
4647
"//vendor/github.com/spf13/pflag:go_default_library",
4748
"//vendor/k8s.io/klog:go_default_library",

cmd/kube-scheduler/app/options/options.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
"k8s.io/client-go/tools/record"
4040
cliflag "k8s.io/component-base/cli/flag"
4141
componentbaseconfig "k8s.io/component-base/config"
42+
"k8s.io/component-base/metrics"
4243
"k8s.io/klog"
4344
kubeschedulerconfigv1alpha2 "k8s.io/kube-scheduler/config/v1alpha2"
4445
schedulerappconfig "k8s.io/kubernetes/cmd/kube-scheduler/app/config"
@@ -68,6 +69,8 @@ type Options struct {
6869
WriteConfigTo string
6970

7071
Master string
72+
73+
ShowHiddenMetricsForVersion string
7174
}
7275

7376
// NewOptions returns default scheduler app options.
@@ -154,6 +157,15 @@ func (o *Options) Flags() (nfs cliflag.NamedFlagSets) {
154157
leaderelectionconfig.BindFlags(&o.ComponentConfig.LeaderElection.LeaderElectionConfiguration, nfs.FlagSet("leader election"))
155158
utilfeature.DefaultMutableFeatureGate.AddFlag(nfs.FlagSet("feature gate"))
156159

160+
// TODO(RainbowMango): move it to genericoptions before next flag comes.
161+
mfs := nfs.FlagSet("metrics")
162+
mfs.StringVar(&o.ShowHiddenMetricsForVersion, "show-hidden-metrics-for-version", o.ShowHiddenMetricsForVersion,
163+
"The previous version for which you want to show hidden metrics. "+
164+
"Only the previous minor version is meaningful, other values will not be allowed. "+
165+
"Accepted format of version is <major>.<minor>, e.g.: '1.16'. "+
166+
"The purpose of this format is make sure you have the opportunity to notice if the next release hides additional metrics, "+
167+
"rather than being surprised when they are permanently removed in the release after that.")
168+
157169
return nfs
158170
}
159171

@@ -199,6 +211,9 @@ func (o *Options) ApplyTo(c *schedulerappconfig.Config) error {
199211
return err
200212
}
201213
}
214+
if len(o.ShowHiddenMetricsForVersion) > 0 {
215+
metrics.SetShowHidden()
216+
}
202217

203218
return nil
204219
}
@@ -215,6 +230,7 @@ func (o *Options) Validate() []error {
215230
errs = append(errs, o.Authentication.Validate()...)
216231
errs = append(errs, o.Authorization.Validate()...)
217232
errs = append(errs, o.Deprecated.Validate()...)
233+
errs = append(errs, metrics.ValidateShowHiddenMetricsVersion(o.ShowHiddenMetricsForVersion)...)
218234

219235
return errs
220236
}

0 commit comments

Comments
 (0)