Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* [FEATURE] StoreGateway: Introduces a new parquet mode. #7046
* [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
* [ENHANCEMENT] Distributor: Skip attaching `__unit__` and `__type__` labels when `-distributor.enable-type-and-unit-labels` is enabled, as these are appended from metadata. #7145
* [ENHANCEMENT] StoreGateway: Add tracings to parquet mode. #7125
* [ENHANCEMENT] Alertmanager: Upgrade alertmanger to 0.29.0 and add a new incidentIO integration. #7092
* [ENHANCEMENT] Querier: Add a `-querier.parquet-queryable-shard-cache-ttl` flag to add TTL to parquet shard cache. #7098
Expand Down
7 changes: 6 additions & 1 deletion pkg/util/push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/exp/api/remote"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/schema"
"github.com/prometheus/prometheus/util/compression"
Expand Down Expand Up @@ -202,7 +203,11 @@ func convertV2RequestToV1(req *cortexpb.PreallocWriteRequestV2, enableTypeAndUni
if shouldAttachTypeAndUnitLabels {
slb := labels.NewScratchBuilder(lbs.Len() + 2) // for __type__ and __unit__
lbs.Range(func(l labels.Label) {
slb.Add(l.Name, l.Value)
// Skip __type__ and __unit__ labels to prevent duplication,
// We append these labels from metadata.
if l.Name != model.MetricTypeLabel && l.Name != model.MetricUnitLabel {
slb.Add(l.Name, l.Value)
}
})
schema.Metadata{Type: cortexpb.MetadataV2MetricTypeToMetricType(metricType), Unit: unit}.AddToLabels(&slb)
slb.Sort()
Expand Down
48 changes: 47 additions & 1 deletion pkg/util/push/push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func Benchmark_convertV2RequestToV1(b *testing.B) {
}

func Test_convertV2RequestToV1_WithEnableTypeAndUnitLabels(t *testing.T) {
symbols := []string{"", "__name__", "test_metric1", "b", "c", "baz", "qux", "d", "e", "foo", "bar", "f", "g", "h", "i", "Test gauge for test purposes", "Maybe op/sec who knows (:", "Test counter for test purposes"}
symbols := []string{"", "__name__", "test_metric1", "b", "c", "baz", "qux", "d", "e", "foo", "bar", "f", "g", "h", "i", "Test gauge for test purposes", "Maybe op/sec who knows (:", "Test counter for test purposes", "__type__", "exist type", "__unit__", "exist unit"}
samples := []cortexpb.Sample{
{
Value: 123,
Expand Down Expand Up @@ -233,6 +233,52 @@ func Test_convertV2RequestToV1_WithEnableTypeAndUnitLabels(t *testing.T) {
},
enableTypeAndUnitLabels: true,
},
{
desc: "should be added from metadata when __type__ and __unit__ labels already exist.",
v2Req: &cortexpb.PreallocWriteRequestV2{
WriteRequestV2: cortexpb.WriteRequestV2{
Symbols: symbols,
Timeseries: []cortexpb.PreallocTimeseriesV2{
{
TimeSeriesV2: &cortexpb.TimeSeriesV2{
LabelsRefs: []uint32{1, 2, 3, 4, 18, 19, 20, 21},
Samples: samples,
Metadata: cortexpb.MetadataV2{Type: cortexpb.METRIC_TYPE_COUNTER, HelpRef: 15, UnitRef: 16},
Exemplars: []cortexpb.ExemplarV2{{LabelsRefs: []uint32{11, 12}, Value: 1, Timestamp: 1}},
},
},
},
},
},
expectedV1Req: cortexpb.PreallocWriteRequest{
WriteRequest: cortexpb.WriteRequest{
Timeseries: []cortexpb.PreallocTimeseries{
{
TimeSeries: &cortexpb.TimeSeries{
Labels: cortexpb.FromLabelsToLabelAdapters(labels.FromStrings("__name__", "test_metric1", "__type__", "counter", "__unit__", "Maybe op/sec who knows (:", "b", "c")),
Samples: samples,
Exemplars: []cortexpb.Exemplar{
{
Labels: cortexpb.FromLabelsToLabelAdapters(labels.FromStrings("f", "g")),
Value: 1,
TimestampMs: 1,
},
},
},
},
},
Metadata: []*cortexpb.MetricMetadata{
{
Type: cortexpb.COUNTER,
MetricFamilyName: "test_metric1",
Help: "Test gauge for test purposes",
Unit: "Maybe op/sec who knows (:",
},
},
},
},
enableTypeAndUnitLabels: true,
},
{
desc: "should not attach unit and type labels when the enableTypeAndUnitLabels is false",
v2Req: &cortexpb.PreallocWriteRequestV2{
Expand Down
Loading