From 9e798ce13973d31dd28104c97113a2d1321ed39a Mon Sep 17 00:00:00 2001 From: Christian Schlotter Date: Tue, 27 Aug 2024 17:17:21 +0200 Subject: [PATCH] metrics: make LabelFromKey optional / omitempty --- pkg/metrics/internal/config/config_metrics_types.go | 4 ++-- pkg/metrics/internal/config/doc.go | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/metrics/internal/config/config_metrics_types.go b/pkg/metrics/internal/config/config_metrics_types.go index 9ea6eeffe..c57c8b0e9 100644 --- a/pkg/metrics/internal/config/config_metrics_types.go +++ b/pkg/metrics/internal/config/config_metrics_types.go @@ -32,7 +32,7 @@ type MetricGauge struct { // ValueFrom is the path to a numeric field under Path that will be the metric value. ValueFrom []string `yaml:"valueFrom" json:"valueFrom"` // LabelFromKey adds a label with the given name if Path is an object. The label value will be the object key. - LabelFromKey string `yaml:"labelFromKey" json:"labelFromKey"` + LabelFromKey string `yaml:"labelFromKey,omitempty" json:"labelFromKey,omitempty"` // NilIsZero indicates that if a value is nil it will be treated as zero value. NilIsZero bool `yaml:"nilIsZero" json:"nilIsZero"` } @@ -42,7 +42,7 @@ type MetricGauge struct { type MetricInfo struct { MetricMeta `yaml:",inline" json:",inline"` // LabelFromKey adds a label with the given name if Path is an object. The label value will be the object key. - LabelFromKey string `yaml:"labelFromKey" json:"labelFromKey"` + LabelFromKey string `yaml:"labelFromKey,omitempty" json:"labelFromKey,omitempty"` } // MetricStateSet is a metric which represent a series of related boolean values, also called a bitset. diff --git a/pkg/metrics/internal/config/doc.go b/pkg/metrics/internal/config/doc.go index e839c8e14..5548521dc 100644 --- a/pkg/metrics/internal/config/doc.go +++ b/pkg/metrics/internal/config/doc.go @@ -35,4 +35,6 @@ limitations under the License. // * Rename the package to `config`. // * Add `omitempty` to: // - `MetricMeta.LabelsFromPath +// - `MetricGauge.LabelFromkey` +// - `MetricInfo.LabelFromkey` package config