From 9c44bb1e95988baca3dcbce57c040bf94cc61dd3 Mon Sep 17 00:00:00 2001 From: Siddharth Ahuja Date: Fri, 20 Feb 2026 16:02:22 +0530 Subject: [PATCH 1/2] Make add-metric-suffixes configurable --- pkg/distributor/distributor.go | 2 ++ pkg/util/push/otlp.go | 2 +- pkg/util/push/otlp_test.go | 10 ++++++++++ schemas/cortex-config-schema.json | 6 ++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/pkg/distributor/distributor.go b/pkg/distributor/distributor.go index 188e6df98d..b9e2ee574c 100644 --- a/pkg/distributor/distributor.go +++ b/pkg/distributor/distributor.go @@ -202,6 +202,7 @@ type OTLPConfig struct { DisableTargetInfo bool `yaml:"disable_target_info"` AllowDeltaTemporality bool `yaml:"allow_delta_temporality"` EnableTypeAndUnitLabels bool `yaml:"enable_type_and_unit_labels"` + AddMetricSuffixes bool `yaml:"add_metric_suffixes"` } // RegisterFlags adds the flags required to config this to the given FlagSet @@ -231,6 +232,7 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) { f.BoolVar(&cfg.OTLPConfig.DisableTargetInfo, "distributor.otlp.disable-target-info", false, "If true, a target_info metric is not ingested. (refer to: https://github.com/prometheus/OpenMetrics/blob/main/specification/OpenMetrics.md#supporting-target-metadata-in-both-push-based-and-pull-based-systems)") f.BoolVar(&cfg.OTLPConfig.AllowDeltaTemporality, "distributor.otlp.allow-delta-temporality", false, "EXPERIMENTAL: If true, delta temporality otlp metrics to be ingested.") f.BoolVar(&cfg.OTLPConfig.EnableTypeAndUnitLabels, "distributor.otlp.enable-type-and-unit-labels", false, "Deprecated: Use `-distributor.enable-type-and-unit-labels` flag instead.") + f.BoolVar(&cfg.OTLPConfig.AddMetricSuffixes, "distributor.otlp.add-metric-suffixes", true, "If true, suffixes will be added to all metrics.") } // Validate config and returns error on failure diff --git a/pkg/util/push/otlp.go b/pkg/util/push/otlp.go index d2f5f402d3..0a77bbee52 100644 --- a/pkg/util/push/otlp.go +++ b/pkg/util/push/otlp.go @@ -184,7 +184,7 @@ func convertToPromTS(ctx context.Context, pmetrics pmetric.Metrics, cfg distribu collector := newCollectingAppender() promConverter := prometheusremotewrite.NewPrometheusConverter(collector) settings := prometheusremotewrite.Settings{ - AddMetricSuffixes: true, + AddMetricSuffixes: cfg.AddMetricSuffixes, DisableTargetInfo: cfg.DisableTargetInfo, AllowDeltaTemporality: cfg.AllowDeltaTemporality, EnableTypeAndUnitLabels: overrides.EnableTypeAndUnitLabels(userID), diff --git a/pkg/util/push/otlp_test.go b/pkg/util/push/otlp_test.go index 5a8b19d6ae..2658dc12ab 100644 --- a/pkg/util/push/otlp_test.go +++ b/pkg/util/push/otlp_test.go @@ -39,6 +39,7 @@ func TestOTLP_EnableTypeAndUnitLabels(t *testing.T) { description string enableTypeAndUnitLabels bool allowDeltaTemporality bool + addMetricSuffixes bool otlpSeries pmetric.Metric expectedLabels labels.Labels expectedMetadata prompb.MetricMetadata @@ -46,6 +47,7 @@ func TestOTLP_EnableTypeAndUnitLabels(t *testing.T) { { description: "[enableTypeAndUnitLabels: true], the '__type__' label should be attached when the type is the gauge", enableTypeAndUnitLabels: true, + addMetricSuffixes: true, otlpSeries: createOtelSum("test", "seconds", pmetric.AggregationTemporalityCumulative, ts), expectedLabels: labels.FromMap(map[string]string{ "__name__": "test_seconds", @@ -59,6 +61,7 @@ func TestOTLP_EnableTypeAndUnitLabels(t *testing.T) { description: "[enableTypeAndUnitLabels: true], the '__type__' label should not be attached when the type is unknown", enableTypeAndUnitLabels: true, allowDeltaTemporality: true, + addMetricSuffixes: true, otlpSeries: createOtelSum("test", "seconds", pmetric.AggregationTemporalityDelta, ts), expectedLabels: labels.FromMap(map[string]string{ "__name__": "test_seconds", @@ -70,6 +73,7 @@ func TestOTLP_EnableTypeAndUnitLabels(t *testing.T) { { description: "[enableTypeAndUnitLabels: false]", enableTypeAndUnitLabels: false, + addMetricSuffixes: true, otlpSeries: createOtelSum("test", "seconds", pmetric.AggregationTemporalityCumulative, ts), expectedLabels: labels.FromMap(map[string]string{ "__name__": "test_seconds", @@ -83,6 +87,7 @@ func TestOTLP_EnableTypeAndUnitLabels(t *testing.T) { t.Run(test.description, func(t *testing.T) { cfg := distributor.OTLPConfig{ AllowDeltaTemporality: test.allowDeltaTemporality, + AddMetricSuffixes: test.addMetricSuffixes, } metrics := pmetric.NewMetrics() rm := metrics.ResourceMetrics().AppendEmpty() @@ -388,6 +393,7 @@ func TestOTLPConvertToPromTS(t *testing.T) { cfg: distributor.OTLPConfig{ ConvertAllAttributes: false, DisableTargetInfo: false, + AddMetricSuffixes: true, }, expectedLabels: []prompb.Label{ { @@ -410,6 +416,7 @@ func TestOTLPConvertToPromTS(t *testing.T) { cfg: distributor.OTLPConfig{ ConvertAllAttributes: false, DisableTargetInfo: true, + AddMetricSuffixes: true, }, expectedLabels: []prompb.Label{ { @@ -432,6 +439,7 @@ func TestOTLPConvertToPromTS(t *testing.T) { cfg: distributor.OTLPConfig{ ConvertAllAttributes: false, DisableTargetInfo: true, + AddMetricSuffixes: true, }, expectedLabels: []prompb.Label{ { @@ -450,6 +458,7 @@ func TestOTLPConvertToPromTS(t *testing.T) { cfg: distributor.OTLPConfig{ ConvertAllAttributes: true, DisableTargetInfo: true, + AddMetricSuffixes: true, }, expectedLabels: []prompb.Label{ { @@ -484,6 +493,7 @@ func TestOTLPConvertToPromTS(t *testing.T) { cfg: distributor.OTLPConfig{ ConvertAllAttributes: true, DisableTargetInfo: true, + AddMetricSuffixes: true, }, expectedLabels: []prompb.Label{ { diff --git a/schemas/cortex-config-schema.json b/schemas/cortex-config-schema.json index dfbd85f685..d2f57c2191 100644 --- a/schemas/cortex-config-schema.json +++ b/schemas/cortex-config-schema.json @@ -3906,6 +3906,12 @@ "description": "Deprecated: Use `-distributor.enable-type-and-unit-labels` flag instead.", "type": "boolean", "x-cli-flag": "distributor.otlp.enable-type-and-unit-labels" + }, + "add_metric_suffixes": { + "default": true, + "description": "If true, suffixes will be added to all metrics.", + "type": "boolean", + "x-cli-flag": "distributor.otlp.add-metric-suffixes" } }, "type": "object" From 6fdace05908135af1bba2a9374094cea95b7d9ec Mon Sep 17 00:00:00 2001 From: Siddharth Ahuja Date: Sun, 22 Feb 2026 20:16:49 +0530 Subject: [PATCH 2/2] Documentation updates --- CHANGELOG.md | 1 + docs/configuration/config-file-reference.md | 4 ++++ docs/guides/open-telemetry-collector.md | 6 ++++++ schemas/cortex-config-schema.json | 2 +- 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 75425534bf..b3243fc8f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ * Metrics: Renamed `cortex_parquet_queryable_cache_*` to `cortex_parquet_cache_*`. * Flags: Renamed `-querier.parquet-queryable-shard-cache-size` to `-querier.parquet-shard-cache-size` and `-querier.parquet-queryable-shard-cache-ttl` to `-querier.parquet-shard-cache-ttl`. * Config: Renamed `parquet_queryable_shard_cache_size` to `parquet_shard_cache_size` and `parquet_queryable_shard_cache_ttl` to `parquet_shard_cache_ttl`. +* [FEATURE] Distrubutor: Add `-distributor.otlp.add-metric-suffixes` flag. If true, suffixes will be added to the metrics. #7286 * [FEATURE] StoreGateway: Introduces a new parquet mode. #7046 * [FEATURE] StoreGateway: Add a parquet shard cache to parquet mode. #7166 * [FEATURE] Distributor: Add a per-tenant flag `-distributor.enable-type-and-unit-labels` that enables adding `__unit__` and `__type__` labels for remote write v2 and OTLP requests. This is a breaking change; the `-distributor.otlp.enable-type-and-unit-labels` flag is now deprecated, operates as a no-op, and has been consolidated into this new flag. #7077 diff --git a/docs/configuration/config-file-reference.md b/docs/configuration/config-file-reference.md index 81b85fb018..4f60d9050e 100644 --- a/docs/configuration/config-file-reference.md +++ b/docs/configuration/config-file-reference.md @@ -3337,6 +3337,10 @@ otlp: # Deprecated: Use `-distributor.enable-type-and-unit-labels` flag instead. # CLI flag: -distributor.otlp.enable-type-and-unit-labels [enable_type_and_unit_labels: | default = false] + + # If true, suffixes will be added to the metrics. + # CLI flag: -distributor.otlp.add-metric-suffixes + [add_metric_suffixes: | default = true] ``` ### `etcd_config` diff --git a/docs/guides/open-telemetry-collector.md b/docs/guides/open-telemetry-collector.md index cd0e9bd7ad..3c92a8fcc7 100644 --- a/docs/guides/open-telemetry-collector.md +++ b/docs/guides/open-telemetry-collector.md @@ -77,6 +77,7 @@ distributor: disable_target_info: allow_delta_temporality: enable_type_and_unit_labels: + add_metric_suffixes: // pending more here ``` ### Ingest `target_info` metric @@ -156,3 +157,8 @@ overrides: promote_resource_attributes: ["attr1", "attr2"] ` ``` + +### Configure adding suffixes to metrics + +The flag `add_metric_suffixes` allows control to add suffixes to metrics for normalization. +This flag is enabled by default. diff --git a/schemas/cortex-config-schema.json b/schemas/cortex-config-schema.json index d2f57c2191..16a498a4d4 100644 --- a/schemas/cortex-config-schema.json +++ b/schemas/cortex-config-schema.json @@ -3909,7 +3909,7 @@ }, "add_metric_suffixes": { "default": true, - "description": "If true, suffixes will be added to all metrics.", + "description": "If true, suffixes will be added to the metrics.", "type": "boolean", "x-cli-flag": "distributor.otlp.add-metric-suffixes" }