Skip to content

Commit ee25599

Browse files
committed
component-base: introduce metrics api
Introduce metrics API for configuring options in a non-breaking manner.
1 parent 8aa1d33 commit ee25599

File tree

5 files changed

+160
-7
lines changed

5 files changed

+160
-7
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// +k8s:deepcopy-gen=package
18+
19+
// Package v1 contains the configuration API for metrics.
20+
//
21+
// The intention is to only have a single version of this API, potentially with
22+
// new fields added over time in a backwards-compatible manner. Fields for
23+
// alpha or beta features are allowed as long as they are defined so that not
24+
// changing the defaults leaves those features disabled.
25+
//
26+
// The "v1" package name is just a reminder that API compatibility rules apply,
27+
// not an indication of the stability of all features covered by it.
28+
29+
package v1 // import "k8s.io/component-base/metrics/api/v1"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1
18+
19+
import (
20+
"k8s.io/component-base/metrics"
21+
)
22+
23+
// MetricsConfiguration contains metrics options.
24+
type MetricsConfiguration struct {
25+
metrics.Options `json:",inline"`
26+
}

staging/src/k8s.io/component-base/metrics/api/v1/zz_generated.deepcopy.go

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/component-base/metrics/options.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,21 @@ import (
2727
)
2828

2929
// Options has all parameters needed for exposing metrics from components
30+
// +k8s:deepcopy-gen=true
3031
type Options struct {
31-
ShowHiddenMetricsForVersion string
32-
DisabledMetrics []string
33-
AllowListMapping map[string]string
34-
AllowListMappingManifest string
32+
// ShowHiddenMetricsForVersion is the previous version for which you want to show hidden metrics.
33+
// Metrics deprecated in 1.(x-1)th version are hidden by default in the 1.xth version.
34+
// Only the previous minor version is meaningful, other values will not be allowed.
35+
// The format is <major>.<minor>, e.g.: '1.16'.
36+
ShowHiddenMetricsForVersion string `json:"showHiddenMetricsForVersion,omitempty"`
37+
// DisabledMetrics is a list of fully qualified metric names that should be disabled.
38+
// Disabling metrics is higher in precedence than showing hidden metrics.
39+
DisabledMetrics []string `json:"disabledMetrics,omitempty"`
40+
// AllowListMapping is the map from metric-label to value allow-list of this label.
41+
// The key's format is <MetricName>,<LabelName>, while its value is a list of allowed values for that label of that metric. For e.g., "metric1,label1": "v1,v2,v3".
42+
AllowListMapping map[string]string `json:"allowListMapping,omitempty"`
43+
// The path to the manifest file that contains the allow-list mapping. Provided for convenience over AllowListMapping.
44+
AllowListMappingManifest string `json:"allowListMappingManifest,omitempty"`
3545
}
3646

3747
// NewOptions returns default metrics options
@@ -68,10 +78,9 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) {
6878
}
6979
fs.StringVar(&o.ShowHiddenMetricsForVersion, "show-hidden-metrics-for-version", o.ShowHiddenMetricsForVersion,
7080
"The previous version for which you want to show hidden metrics. "+
81+
"Metrics deprecated in 1.(x-1)th version are hidden by default in the 1.xth version. "+
7182
"Only the previous minor version is meaningful, other values will not be allowed. "+
72-
"The format is <major>.<minor>, e.g.: '1.16'. "+
73-
"The purpose of this format is make sure you have the opportunity to notice if the next release hides additional metrics, "+
74-
"rather than being surprised when they are permanently removed in the release after that.")
83+
"The format is <major>.<minor>, e.g.: '1.16'. ")
7584
fs.StringSliceVar(&o.DisabledMetrics,
7685
"disabled-metrics",
7786
o.DisabledMetrics,

staging/src/k8s.io/component-base/metrics/zz_generated.deepcopy.go

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)