From b9572adb7186aa121b26a6edda366eaf1c4c6e87 Mon Sep 17 00:00:00 2001 From: Pranshu Srivastava Date: Sat, 26 Jul 2025 14:25:25 +0530 Subject: [PATCH] component-base: introduce metrics api Introduce metrics API for configuring options. Signed-off-by: Pranshu Srivastava --- .../component-base/metrics/api/v1/doc.go | 29 +++++++++++ .../component-base/metrics/api/v1/types.go | 26 ++++++++++ .../metrics/api/v1/zz_generated.deepcopy.go | 39 +++++++++++++++ .../k8s.io/component-base/metrics/options.go | 19 +++++-- .../metrics/zz_generated.deepcopy.go | 50 +++++++++++++++++++ 5 files changed, 159 insertions(+), 4 deletions(-) create mode 100644 staging/src/k8s.io/component-base/metrics/api/v1/doc.go create mode 100644 staging/src/k8s.io/component-base/metrics/api/v1/types.go create mode 100644 staging/src/k8s.io/component-base/metrics/api/v1/zz_generated.deepcopy.go create mode 100644 staging/src/k8s.io/component-base/metrics/zz_generated.deepcopy.go diff --git a/staging/src/k8s.io/component-base/metrics/api/v1/doc.go b/staging/src/k8s.io/component-base/metrics/api/v1/doc.go new file mode 100644 index 0000000000000..fce4ed3b489e7 --- /dev/null +++ b/staging/src/k8s.io/component-base/metrics/api/v1/doc.go @@ -0,0 +1,29 @@ +/* +Copyright 2024 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// +k8s:deepcopy-gen=package + +// Package v1 contains the configuration API for metrics. +// +// The intention is to only have a single version of this API, potentially with +// new fields added over time in a backwards-compatible manner. Fields for +// alpha or beta features are allowed as long as they are defined so that not +// changing the defaults leaves those features disabled. +// +// The "v1" package name is just a reminder that API compatibility rules apply, +// not an indication of the stability of all features covered by it. + +package v1 // import "k8s.io/component-base/metrics/api/v1" diff --git a/staging/src/k8s.io/component-base/metrics/api/v1/types.go b/staging/src/k8s.io/component-base/metrics/api/v1/types.go new file mode 100644 index 0000000000000..308a87a30debb --- /dev/null +++ b/staging/src/k8s.io/component-base/metrics/api/v1/types.go @@ -0,0 +1,26 @@ +/* +Copyright 2024 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1 + +import ( + "k8s.io/component-base/metrics" +) + +// MetricsConfiguration contains metrics options. +type MetricsConfiguration struct { + metrics.Options `json:",inline"` +} diff --git a/staging/src/k8s.io/component-base/metrics/api/v1/zz_generated.deepcopy.go b/staging/src/k8s.io/component-base/metrics/api/v1/zz_generated.deepcopy.go new file mode 100644 index 0000000000000..7b232613ff11c --- /dev/null +++ b/staging/src/k8s.io/component-base/metrics/api/v1/zz_generated.deepcopy.go @@ -0,0 +1,39 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by deepcopy-gen. DO NOT EDIT. + +package v1 + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MetricsConfiguration) DeepCopyInto(out *MetricsConfiguration) { + *out = *in + in.Options.DeepCopyInto(&out.Options) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MetricsConfiguration. +func (in *MetricsConfiguration) DeepCopy() *MetricsConfiguration { + if in == nil { + return nil + } + out := new(MetricsConfiguration) + in.DeepCopyInto(out) + return out +} diff --git a/staging/src/k8s.io/component-base/metrics/options.go b/staging/src/k8s.io/component-base/metrics/options.go index 17f44ef2a3f81..bd098b954c8a7 100644 --- a/staging/src/k8s.io/component-base/metrics/options.go +++ b/staging/src/k8s.io/component-base/metrics/options.go @@ -27,11 +27,22 @@ import ( ) // Options has all parameters needed for exposing metrics from components +// +k8s:deepcopy-gen=true type Options struct { - ShowHiddenMetricsForVersion string - DisabledMetrics []string - AllowListMapping map[string]string - AllowListMappingManifest string + // ShowHiddenMetricsForVersion is the previous version for which you want to show hidden metrics. + // Only the previous minor version is meaningful, other values will not be allowed. + // The format is ., e.g.: '1.16'. + // The purpose of this format is make sure you have the opportunity to notice if the next release hides additional metrics, + // rather than being surprised when they are permanently removed in the release after that. + ShowHiddenMetricsForVersion string `json:"showHiddenMetricsForVersion,omitempty"` + // DisabledMetrics is a list of fully qualified metric names that should be disabled. + // Disabling metrics is higher in precedence than showing hidden metrics. + DisabledMetrics []string `json:"disabledMetrics,omitempty"` + // AllowListMapping is the map from metric-label to value allow-list of this label. + // The key's format is ,, while its value is a list of allowed values for that label of that metric. For e.g., "metric1,label1": "v1,v2,v3". + AllowListMapping map[string]string `json:"allowListMapping,omitempty"` + // The path to the manifest file that contains the allow-list mapping. Provided for convenience over AllowListMapping. + AllowListMappingManifest string `json:"allowListMappingManifest,omitempty"` } // NewOptions returns default metrics options diff --git a/staging/src/k8s.io/component-base/metrics/zz_generated.deepcopy.go b/staging/src/k8s.io/component-base/metrics/zz_generated.deepcopy.go new file mode 100644 index 0000000000000..3b7ed2464be99 --- /dev/null +++ b/staging/src/k8s.io/component-base/metrics/zz_generated.deepcopy.go @@ -0,0 +1,50 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by deepcopy-gen. DO NOT EDIT. + +package metrics + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Options) DeepCopyInto(out *Options) { + *out = *in + if in.DisabledMetrics != nil { + in, out := &in.DisabledMetrics, &out.DisabledMetrics + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.AllowListMapping != nil { + in, out := &in.AllowListMapping, &out.AllowListMapping + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Options. +func (in *Options) DeepCopy() *Options { + if in == nil { + return nil + } + out := new(Options) + in.DeepCopyInto(out) + return out +}