Skip to content

Commit 20f5752

Browse files
committed
Add -distributor.enable-type-and-unit-labels per tenant flag
Signed-off-by: SungJin1212 <[email protected]>
1 parent 23f8337 commit 20f5752

File tree

9 files changed

+24
-37
lines changed

9 files changed

+24
-37
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## master / unreleased
44

55
* [FEATURE] StoreGateway: Introduces a new parquet mode. #7046
6+
* [FEATURE] Distributor: Add a per-tenant flag `-distributor.enable-type-and-unit-labels` which enables to add `__unit__` and `__type__` labels for remote write v2 and OTLP requests. #7077
67
* [ENHANCEMENT] Ingester: Add `enable_matcher_optimization` config to apply low selectivity matchers lazily. #7063
78
* [ENHANCEMENT] Distributor: Add a label references validation for remote write v2 request. #7074
89
* [ENHANCEMENT] Distributor: Add count, spans, and buckets validations for native histogram. #7072
@@ -36,7 +37,6 @@
3637
* [FEATURE] Querier: Support for configuring query optimizers and enabling XFunctions in the Thanos engine. #6873
3738
* [FEATURE] Query Frontend: Add support /api/v1/format_query API for formatting queries. #6893
3839
* [FEATURE] Query Frontend: Add support for /api/v1/parse_query API (experimental) to parse a PromQL expression and return it as a JSON-formatted AST (abstract syntax tree). #6978
39-
* [FEATURE] Distributor: Add a per-tenant flag `-distributor.rw2-enable-type-and-unit-labels` which enables to add `__unit__` and `__type__` labels for remote write v2 requests. #7077
4040
* [ENHANCEMENT] Upgrade the Prometheus version to 3.6.0 and add a `-name-validation-scheme` flag to support UTF-8. #7040 #7056
4141
* [ENHANCEMENT] Distributor: Emit an error with a 400 status code when empty labels are found before the relabelling or label dropping process. #7052
4242
* [ENHANCEMENT] Parquet Storage: Add support for additional sort columns during Parquet file generation #7003

docs/configuration/config-file-reference.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3274,11 +3274,6 @@ otlp:
32743274
# EXPERIMENTAL: If true, delta temporality otlp metrics to be ingested.
32753275
# CLI flag: -distributor.otlp.allow-delta-temporality
32763276
[allow_delta_temporality: <boolean> | default = false]
3277-
3278-
# EXPERIMENTAL: If true, the '__type__' and '__unit__' labels are added for
3279-
# the OTLP metrics.
3280-
# CLI flag: -distributor.otlp.enable-type-and-unit-labels
3281-
[enable_type_and_unit_labels: <boolean> | default = false]
32823277
```
32833278

32843279
### `etcd_config`
@@ -3999,9 +3994,9 @@ The `limits_config` configures default and per-tenant limits imposed by Cortex s
39993994
[promote_resource_attributes: <list of string> | default = ]
40003995
40013996
# EXPERIMENTAL: If true, the __type__ and __unit__ labels are added to metrics.
4002-
# This only applies to remote write v2 requests.
4003-
# CLI flag: -distributor.rw2-enable-type-and-unit-labels
4004-
[rw_2_enable_type_and_unit_labels: <boolean> | default = false]
3997+
# This applies to remote write v2 and OTLP requests.
3998+
# CLI flag: -distributor.enable-type-and-unit-labels
3999+
[enable_type_and_unit_labels: <boolean> | default = false]
40054000
40064001
# The maximum number of active series per user, per ingester. 0 to disable.
40074002
# CLI flag: -ingester.max-series-per-user

integration/remote_write_v2_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,9 @@ func TestIngest_EnableTypeAndUnitLabels(t *testing.T) {
234234
"-ring.store": "consul",
235235
"-consul.hostname": consul.NetworkHTTPEndpoint(),
236236
// Distributor.
237-
"-distributor.replication-factor": "1",
238-
"-distributor.remote-writev2-enabled": "true",
239-
"-distributor.rw2-enable-type-and-unit-labels": "true",
237+
"-distributor.replication-factor": "1",
238+
"-distributor.remote-writev2-enabled": "true",
239+
"-distributor.enable-type-and-unit-labels": "true",
240240
// Store-gateway.
241241
"-store-gateway.sharding-enabled": "false",
242242
// alert manager

pkg/distributor/distributor.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,9 @@ type InstanceLimits struct {
197197
}
198198

199199
type OTLPConfig struct {
200-
ConvertAllAttributes bool `yaml:"convert_all_attributes"`
201-
DisableTargetInfo bool `yaml:"disable_target_info"`
202-
AllowDeltaTemporality bool `yaml:"allow_delta_temporality"`
203-
EnableTypeAndUnitLabels bool `yaml:"enable_type_and_unit_labels"`
200+
ConvertAllAttributes bool `yaml:"convert_all_attributes"`
201+
DisableTargetInfo bool `yaml:"disable_target_info"`
202+
AllowDeltaTemporality bool `yaml:"allow_delta_temporality"`
204203
}
205204

206205
// RegisterFlags adds the flags required to config this to the given FlagSet
@@ -229,7 +228,6 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
229228
f.BoolVar(&cfg.OTLPConfig.ConvertAllAttributes, "distributor.otlp.convert-all-attributes", false, "If true, all resource attributes are converted to labels.")
230229
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)")
231230
f.BoolVar(&cfg.OTLPConfig.AllowDeltaTemporality, "distributor.otlp.allow-delta-temporality", false, "EXPERIMENTAL: If true, delta temporality otlp metrics to be ingested.")
232-
f.BoolVar(&cfg.OTLPConfig.EnableTypeAndUnitLabels, "distributor.otlp.enable-type-and-unit-labels", false, "EXPERIMENTAL: If true, the '__type__' and '__unit__' labels are added for the OTLP metrics.")
233231
}
234232

235233
// Validate config and returns error on failure

pkg/util/push/otlp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func convertToPromTS(ctx context.Context, pmetrics pmetric.Metrics, cfg distribu
181181
AddMetricSuffixes: true,
182182
DisableTargetInfo: cfg.DisableTargetInfo,
183183
AllowDeltaTemporality: cfg.AllowDeltaTemporality,
184-
EnableTypeAndUnitLabels: cfg.EnableTypeAndUnitLabels,
184+
EnableTypeAndUnitLabels: overrides.EnableTypeAndUnitLabels(userID),
185185
}
186186

187187
var annots annotations.Annotations

pkg/util/push/otlp_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ func TestOTLP_EnableTypeAndUnitLabels(t *testing.T) {
8080
for _, test := range tests {
8181
t.Run(test.description, func(t *testing.T) {
8282
cfg := distributor.OTLPConfig{
83-
EnableTypeAndUnitLabels: test.enableTypeAndUnitLabels,
84-
AllowDeltaTemporality: test.allowDeltaTemporality,
83+
AllowDeltaTemporality: test.allowDeltaTemporality,
8584
}
8685
metrics := pmetric.NewMetrics()
8786
rm := metrics.ResourceMetrics().AppendEmpty()
@@ -90,6 +89,7 @@ func TestOTLP_EnableTypeAndUnitLabels(t *testing.T) {
9089
test.otlpSeries.CopyTo(sm.Metrics().AppendEmpty())
9190

9291
limits := validation.Limits{}
92+
limits.EnableTypeAndUnitLabels = test.enableTypeAndUnitLabels
9393
overrides := validation.NewOverrides(limits, nil)
9494
promSeries, metadata, err := convertToPromTS(ctx, metrics, cfg, overrides, "user-1", logger)
9595
require.NoError(t, err)

pkg/util/push/push.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func Handler(remoteWrite2Enabled bool, maxRecvMsgSize int, overrides *validation
9999
req.Source = cortexpb.API
100100
}
101101

102-
v1Req, err := convertV2RequestToV1(&req, overrides.RW2EnableTypeAndUnitLabels(userID))
102+
v1Req, err := convertV2RequestToV1(&req, overrides.EnableTypeAndUnitLabels(userID))
103103
if err != nil {
104104
level.Error(logger).Log("err", err.Error())
105105
http.Error(w, err.Error(), http.StatusBadRequest)

pkg/util/validation/limits.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ type Limits struct {
152152
MetricRelabelConfigs []*relabel.Config `yaml:"metric_relabel_configs,omitempty" json:"metric_relabel_configs,omitempty" doc:"nocli|description=List of metric relabel configurations. Note that in most situations, it is more effective to use metrics relabeling directly in the Prometheus server, e.g. remote_write.write_relabel_configs."`
153153
MaxNativeHistogramBuckets int `yaml:"max_native_histogram_buckets" json:"max_native_histogram_buckets"`
154154
PromoteResourceAttributes []string `yaml:"promote_resource_attributes" json:"promote_resource_attributes"`
155-
RW2EnableTypeAndUnitLabels bool `yaml:"rw_2_enable_type_and_unit_labels" json:"rw_2_enable_type_and_unit_labels"`
155+
EnableTypeAndUnitLabels bool `yaml:"enable_type_and_unit_labels" json:"enable_type_and_unit_labels"`
156156

157157
// Ingester enforced limits.
158158
// Series
@@ -265,7 +265,7 @@ func (l *Limits) RegisterFlags(f *flag.FlagSet) {
265265
f.IntVar(&l.HAMaxClusters, "distributor.ha-tracker.max-clusters", 0, "Maximum number of clusters that HA tracker will keep track of for single user. 0 to disable the limit.")
266266
f.Var((*flagext.StringSliceCSV)(&l.PromoteResourceAttributes), "distributor.promote-resource-attributes", "Comma separated list of resource attributes that should be converted to labels.")
267267
f.Var(&l.DropLabels, "distributor.drop-label", "This flag can be used to specify label names that to drop during sample ingestion within the distributor and can be repeated in order to drop multiple labels.")
268-
f.BoolVar(&l.RW2EnableTypeAndUnitLabels, "distributor.rw2-enable-type-and-unit-labels", false, "EXPERIMENTAL: If true, the __type__ and __unit__ labels are added to metrics. This only applies to remote write v2 requests.")
268+
f.BoolVar(&l.EnableTypeAndUnitLabels, "distributor.enable-type-and-unit-labels", false, "EXPERIMENTAL: If true, the __type__ and __unit__ labels are added to metrics. This applies to remote write v2 and OTLP requests.")
269269
f.IntVar(&l.MaxLabelNameLength, "validation.max-length-label-name", 1024, "Maximum length accepted for label names")
270270
f.IntVar(&l.MaxLabelValueLength, "validation.max-length-label-value", 2048, "Maximum length accepted for label value. This setting also applies to the metric name")
271271
f.IntVar(&l.MaxLabelNamesPerSeries, "validation.max-label-names-per-series", 30, "Maximum number of label names per series.")
@@ -1094,8 +1094,8 @@ func (o *Overrides) AlertmanagerMaxSilenceSizeBytes(userID string) int {
10941094
return o.GetOverridesForUser(userID).AlertmanagerMaxSilencesSizeBytes
10951095
}
10961096

1097-
func (o *Overrides) RW2EnableTypeAndUnitLabels(userID string) bool {
1098-
return o.GetOverridesForUser(userID).RW2EnableTypeAndUnitLabels
1097+
func (o *Overrides) EnableTypeAndUnitLabels(userID string) bool {
1098+
return o.GetOverridesForUser(userID).EnableTypeAndUnitLabels
10991099
}
11001100

11011101
func (o *Overrides) DisabledRuleGroups(userID string) DisabledRuleGroups {

schemas/cortex-config-schema.json

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3822,12 +3822,6 @@
38223822
"description": "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)",
38233823
"type": "boolean",
38243824
"x-cli-flag": "distributor.otlp.disable-target-info"
3825-
},
3826-
"enable_type_and_unit_labels": {
3827-
"default": false,
3828-
"description": "EXPERIMENTAL: If true, the '__type__' and '__unit__' labels are added for the OTLP metrics.",
3829-
"type": "boolean",
3830-
"x-cli-flag": "distributor.otlp.enable-type-and-unit-labels"
38313825
}
38323826
},
38333827
"type": "object"
@@ -4946,6 +4940,12 @@
49464940
"type": "boolean",
49474941
"x-cli-flag": "blocks-storage.tsdb.enable-native-histograms"
49484942
},
4943+
"enable_type_and_unit_labels": {
4944+
"default": false,
4945+
"description": "EXPERIMENTAL: If true, the __type__ and __unit__ labels are added to metrics. This applies to remote write v2 and OTLP requests.",
4946+
"type": "boolean",
4947+
"x-cli-flag": "distributor.enable-type-and-unit-labels"
4948+
},
49494949
"enforce_metadata_metric_name": {
49504950
"default": true,
49514951
"description": "Enforce every metadata has a metric name.",
@@ -5375,12 +5375,6 @@
53755375
"description": "Enable to allow rules to be evaluated with data from a single zone, if other zones are not available.",
53765376
"type": "boolean"
53775377
},
5378-
"rw_2_enable_type_and_unit_labels": {
5379-
"default": false,
5380-
"description": "EXPERIMENTAL: If true, the __type__ and __unit__ labels are added to metrics. This only applies to remote write v2 requests.",
5381-
"type": "boolean",
5382-
"x-cli-flag": "distributor.rw2-enable-type-and-unit-labels"
5383-
},
53845378
"s3_sse_kms_encryption_context": {
53855379
"description": "S3 server-side encryption KMS encryption context. If unset and the key ID override is set, the encryption context will not be provided to S3. Ignored if the SSE type override is not set.",
53865380
"type": "string"

0 commit comments

Comments
 (0)