Skip to content

Commit 975f3e9

Browse files
committed
Add -distributor.enable-type-and-unit-labels per tenant flag
Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>
1 parent b90cf60 commit 975f3e9

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
@@ -2,6 +2,7 @@
22

33
## master / unreleased
44

5+
* [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
56
* [ENHANCEMENT] Ingester: Add `enable_matcher_optimization` config to apply low selectivity matchers lazily. #7063
67
* [ENHANCEMENT] Distributor: Add a label references validation for remote write v2 request. #7074
78
* [BUGFIX] Compactor: Avoid race condition which allow a grouper to not compact all partitions. #7082
@@ -31,7 +32,6 @@
3132
* [FEATURE] Querier: Support for configuring query optimizers and enabling XFunctions in the Thanos engine. #6873
3233
* [FEATURE] Query Frontend: Add support /api/v1/format_query API for formatting queries. #6893
3334
* [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
34-
* [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
3535
* [ENHANCEMENT] Upgrade the Prometheus version to 3.6.0 and add a `-name-validation-scheme` flag to support UTF-8. #7040 #7056
3636
* [ENHANCEMENT] Distributor: Emit an error with a 400 status code when empty labels are found before the relabelling or label dropping process. #7052
3737
* [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
@@ -3270,11 +3270,6 @@ otlp:
32703270
# EXPERIMENTAL: If true, delta temporality otlp metrics to be ingested.
32713271
# CLI flag: -distributor.otlp.allow-delta-temporality
32723272
[allow_delta_temporality: <boolean> | default = false]
3273-
3274-
# EXPERIMENTAL: If true, the '__type__' and '__unit__' labels are added for
3275-
# the OTLP metrics.
3276-
# CLI flag: -distributor.otlp.enable-type-and-unit-labels
3277-
[enable_type_and_unit_labels: <boolean> | default = false]
32783273
```
32793274

32803275
### `etcd_config`
@@ -3995,9 +3990,9 @@ The `limits_config` configures default and per-tenant limits imposed by Cortex s
39953990
[promote_resource_attributes: <list of string> | default = ]
39963991
39973992
# EXPERIMENTAL: If true, the __type__ and __unit__ labels are added to metrics.
3998-
# This only applies to remote write v2 requests.
3999-
# CLI flag: -distributor.rw2-enable-type-and-unit-labels
4000-
[rw_2_enable_type_and_unit_labels: <boolean> | default = false]
3993+
# This applies to remote write v2 and OTLP requests.
3994+
# CLI flag: -distributor.enable-type-and-unit-labels
3995+
[enable_type_and_unit_labels: <boolean> | default = false]
40013996
40023997
# The maximum number of active series per user, per ingester. 0 to disable.
40033998
# 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
@@ -3816,12 +3816,6 @@
38163816
"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)",
38173817
"type": "boolean",
38183818
"x-cli-flag": "distributor.otlp.disable-target-info"
3819-
},
3820-
"enable_type_and_unit_labels": {
3821-
"default": false,
3822-
"description": "EXPERIMENTAL: If true, the '__type__' and '__unit__' labels are added for the OTLP metrics.",
3823-
"type": "boolean",
3824-
"x-cli-flag": "distributor.otlp.enable-type-and-unit-labels"
38253819
}
38263820
},
38273821
"type": "object"
@@ -4940,6 +4934,12 @@
49404934
"type": "boolean",
49414935
"x-cli-flag": "blocks-storage.tsdb.enable-native-histograms"
49424936
},
4937+
"enable_type_and_unit_labels": {
4938+
"default": false,
4939+
"description": "EXPERIMENTAL: If true, the __type__ and __unit__ labels are added to metrics. This applies to remote write v2 and OTLP requests.",
4940+
"type": "boolean",
4941+
"x-cli-flag": "distributor.enable-type-and-unit-labels"
4942+
},
49434943
"enforce_metadata_metric_name": {
49444944
"default": true,
49454945
"description": "Enforce every metadata has a metric name.",
@@ -5369,12 +5369,6 @@
53695369
"description": "Enable to allow rules to be evaluated with data from a single zone, if other zones are not available.",
53705370
"type": "boolean"
53715371
},
5372-
"rw_2_enable_type_and_unit_labels": {
5373-
"default": false,
5374-
"description": "EXPERIMENTAL: If true, the __type__ and __unit__ labels are added to metrics. This only applies to remote write v2 requests.",
5375-
"type": "boolean",
5376-
"x-cli-flag": "distributor.rw2-enable-type-and-unit-labels"
5377-
},
53785372
"s3_sse_kms_encryption_context": {
53795373
"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.",
53805374
"type": "string"

0 commit comments

Comments
 (0)