This commit is contained in:
Junang Li 2024-09-14 11:01:07 -04:00
parent ad20b23cf1
commit b1096fe71b
4 changed files with 42 additions and 42 deletions

View file

@ -234,7 +234,7 @@ func StreamChunkedReadResponses(
for ss.Next() { for ss.Next() {
series := ss.At() series := ss.At()
iter = series.Iterator(iter) iter = series.Iterator(iter)
lbls = MergeLabels(prompb.FromLabels(series.Labels(), lbls), sortedExternalLabels) lbls = MergeLabels(prompb.FromLabels(series.Labels(), lbls), sortedExternalLabels)
maxDataLength := maxBytesInFrame maxDataLength := maxBytesInFrame
for _, lbl := range lbls { for _, lbl := range lbls {

View file

@ -20,12 +20,12 @@ import (
"context" "context"
"testing" "testing"
"time" "time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"
"go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/pdata/pmetric"
"github.com/stretchr/testify/assert" "google.golang.org/protobuf/proto"
"github.com/prometheus/common/model" "github.com/prometheus/common/model"

View file

@ -448,9 +448,9 @@ func TestExponentialToNativeHistogram(t *testing.T) {
Schema: 1, Schema: 1,
ZeroThreshold: defaultZeroThreshold, ZeroThreshold: defaultZeroThreshold,
ZeroCount: &prompb.Histogram_ZeroCountInt{ZeroCountInt: 1}, ZeroCount: &prompb.Histogram_ZeroCountInt{ZeroCountInt: 1},
NegativeSpans: []prompb.BucketSpan{{Offset: 2, Length: 2}}, NegativeSpans: []*prompb.BucketSpan{{Offset: 2, Length: 2}},
NegativeDeltas: []int64{1, 0}, NegativeDeltas: []int64{1, 0},
PositiveSpans: []prompb.BucketSpan{{Offset: 2, Length: 2}}, PositiveSpans: []*prompb.BucketSpan{{Offset: 2, Length: 2}},
PositiveDeltas: []int64{1, 0}, PositiveDeltas: []int64{1, 0},
Timestamp: 500, Timestamp: 500,
} }
@ -481,9 +481,9 @@ func TestExponentialToNativeHistogram(t *testing.T) {
Schema: 1, Schema: 1,
ZeroThreshold: defaultZeroThreshold, ZeroThreshold: defaultZeroThreshold,
ZeroCount: &prompb.Histogram_ZeroCountInt{ZeroCountInt: 1}, ZeroCount: &prompb.Histogram_ZeroCountInt{ZeroCountInt: 1},
NegativeSpans: []prompb.BucketSpan{{Offset: 2, Length: 2}}, NegativeSpans: []*prompb.BucketSpan{{Offset: 2, Length: 2}},
NegativeDeltas: []int64{1, 0}, NegativeDeltas: []int64{1, 0},
PositiveSpans: []prompb.BucketSpan{{Offset: 2, Length: 2}}, PositiveSpans: []*prompb.BucketSpan{{Offset: 2, Length: 2}},
PositiveDeltas: []int64{1, 0}, PositiveDeltas: []int64{1, 0},
Timestamp: 500, Timestamp: 500,
} }
@ -523,9 +523,9 @@ func TestExponentialToNativeHistogram(t *testing.T) {
Schema: 8, Schema: 8,
ZeroThreshold: defaultZeroThreshold, ZeroThreshold: defaultZeroThreshold,
ZeroCount: &prompb.Histogram_ZeroCountInt{ZeroCountInt: 1}, ZeroCount: &prompb.Histogram_ZeroCountInt{ZeroCountInt: 1},
PositiveSpans: []prompb.BucketSpan{{Offset: 2, Length: 3}}, PositiveSpans: []*prompb.BucketSpan{{Offset: 2, Length: 3}},
PositiveDeltas: []int64{1, 0, 0}, // 1, 1, 1 PositiveDeltas: []int64{1, 0, 0}, // 1, 1, 1
NegativeSpans: []prompb.BucketSpan{{Offset: 3, Length: 3}}, NegativeSpans: []*prompb.BucketSpan{{Offset: 3, Length: 3}},
NegativeDeltas: []int64{1, 0, 0}, // 1, 1, 1 NegativeDeltas: []int64{1, 0, 0}, // 1, 1, 1
Timestamp: 500, Timestamp: 500,
} }
@ -555,9 +555,9 @@ func TestExponentialToNativeHistogram(t *testing.T) {
Schema: 8, Schema: 8,
ZeroThreshold: defaultZeroThreshold, ZeroThreshold: defaultZeroThreshold,
ZeroCount: &prompb.Histogram_ZeroCountInt{ZeroCountInt: 1}, ZeroCount: &prompb.Histogram_ZeroCountInt{ZeroCountInt: 1},
PositiveSpans: []prompb.BucketSpan{{Offset: 1, Length: 2}}, PositiveSpans: []*prompb.BucketSpan{{Offset: 1, Length: 2}},
PositiveDeltas: []int64{1, 1}, // 0+1, 1+1 = 1, 2 PositiveDeltas: []int64{1, 1}, // 0+1, 1+1 = 1, 2
NegativeSpans: []prompb.BucketSpan{{Offset: 2, Length: 2}}, NegativeSpans: []*prompb.BucketSpan{{Offset: 2, Length: 2}},
NegativeDeltas: []int64{2, -1}, // 1+1, 1+0 = 2, 1 NegativeDeltas: []int64{2, -1}, // 1+1, 1+0 = 2, 1
Timestamp: 500, Timestamp: 500,
} }
@ -575,8 +575,8 @@ func TestExponentialToNativeHistogram(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.Empty(t, annots) require.Empty(t, annots)
assert.Equal(t, tt.wantNativeHist(), got) assert.Equal(t, tt.wantNativeHist(), *got)
validateNativeHistogramCount(t, got) validateNativeHistogramCount(t, *got)
}) })
} }
} }
@ -644,20 +644,20 @@ func TestPrometheusConverter_addExponentialHistogramDataPoints(t *testing.T) {
return metric return metric
}, },
wantSeries: func() map[uint64]*prompb.TimeSeries { wantSeries: func() map[uint64]*prompb.TimeSeries {
labels := []prompb.Label{ labels := []*prompb.Label{
{Name: model.MetricNameLabel, Value: "test_hist"}, {Name: model.MetricNameLabel, Value: "test_hist"},
{Name: "attr", Value: "test_attr"}, {Name: "attr", Value: "test_attr"},
} }
return map[uint64]*prompb.TimeSeries{ return map[uint64]*prompb.TimeSeries{
timeSeriesSignature(labels): { timeSeriesSignature(labels): {
Labels: labels, Labels: labels,
Histograms: []prompb.Histogram{ Histograms: []*prompb.Histogram{
{ {
Count: &prompb.Histogram_CountInt{CountInt: 7}, Count: &prompb.Histogram_CountInt{CountInt: 7},
Schema: 1, Schema: 1,
ZeroThreshold: defaultZeroThreshold, ZeroThreshold: defaultZeroThreshold,
ZeroCount: &prompb.Histogram_ZeroCountInt{ZeroCountInt: 0}, ZeroCount: &prompb.Histogram_ZeroCountInt{ZeroCountInt: 0},
PositiveSpans: []prompb.BucketSpan{{Offset: 0, Length: 2}}, PositiveSpans: []*prompb.BucketSpan{{Offset: 0, Length: 2}},
PositiveDeltas: []int64{4, -2}, PositiveDeltas: []int64{4, -2},
}, },
{ {
@ -665,11 +665,11 @@ func TestPrometheusConverter_addExponentialHistogramDataPoints(t *testing.T) {
Schema: 1, Schema: 1,
ZeroThreshold: defaultZeroThreshold, ZeroThreshold: defaultZeroThreshold,
ZeroCount: &prompb.Histogram_ZeroCountInt{ZeroCountInt: 0}, ZeroCount: &prompb.Histogram_ZeroCountInt{ZeroCountInt: 0},
PositiveSpans: []prompb.BucketSpan{{Offset: 0, Length: 3}}, PositiveSpans: []*prompb.BucketSpan{{Offset: 0, Length: 3}},
PositiveDeltas: []int64{4, -2, -1}, PositiveDeltas: []int64{4, -2, -1},
}, },
}, },
Exemplars: []prompb.Exemplar{ Exemplars: []*prompb.Exemplar{
{Value: 1}, {Value: 1},
{Value: 2}, {Value: 2},
}, },
@ -703,11 +703,11 @@ func TestPrometheusConverter_addExponentialHistogramDataPoints(t *testing.T) {
return metric return metric
}, },
wantSeries: func() map[uint64]*prompb.TimeSeries { wantSeries: func() map[uint64]*prompb.TimeSeries {
labels := []prompb.Label{ labels := []*prompb.Label{
{Name: model.MetricNameLabel, Value: "test_hist"}, {Name: model.MetricNameLabel, Value: "test_hist"},
{Name: "attr", Value: "test_attr"}, {Name: "attr", Value: "test_attr"},
} }
labelsAnother := []prompb.Label{ labelsAnother := []*prompb.Label{
{Name: model.MetricNameLabel, Value: "test_hist"}, {Name: model.MetricNameLabel, Value: "test_hist"},
{Name: "attr", Value: "test_attr_two"}, {Name: "attr", Value: "test_attr_two"},
} }
@ -715,33 +715,33 @@ func TestPrometheusConverter_addExponentialHistogramDataPoints(t *testing.T) {
return map[uint64]*prompb.TimeSeries{ return map[uint64]*prompb.TimeSeries{
timeSeriesSignature(labels): { timeSeriesSignature(labels): {
Labels: labels, Labels: labels,
Histograms: []prompb.Histogram{ Histograms: []*prompb.Histogram{
{ {
Count: &prompb.Histogram_CountInt{CountInt: 7}, Count: &prompb.Histogram_CountInt{CountInt: 7},
Schema: 1, Schema: 1,
ZeroThreshold: defaultZeroThreshold, ZeroThreshold: defaultZeroThreshold,
ZeroCount: &prompb.Histogram_ZeroCountInt{ZeroCountInt: 0}, ZeroCount: &prompb.Histogram_ZeroCountInt{ZeroCountInt: 0},
PositiveSpans: []prompb.BucketSpan{{Offset: 0, Length: 2}}, PositiveSpans: []*prompb.BucketSpan{{Offset: 0, Length: 2}},
PositiveDeltas: []int64{4, -2}, PositiveDeltas: []int64{4, -2},
}, },
}, },
Exemplars: []prompb.Exemplar{ Exemplars: []*prompb.Exemplar{
{Value: 1}, {Value: 1},
}, },
}, },
timeSeriesSignature(labelsAnother): { timeSeriesSignature(labelsAnother): {
Labels: labelsAnother, Labels: labelsAnother,
Histograms: []prompb.Histogram{ Histograms: []*prompb.Histogram{
{ {
Count: &prompb.Histogram_CountInt{CountInt: 4}, Count: &prompb.Histogram_CountInt{CountInt: 4},
Schema: 1, Schema: 1,
ZeroThreshold: defaultZeroThreshold, ZeroThreshold: defaultZeroThreshold,
ZeroCount: &prompb.Histogram_ZeroCountInt{ZeroCountInt: 0}, ZeroCount: &prompb.Histogram_ZeroCountInt{ZeroCountInt: 0},
NegativeSpans: []prompb.BucketSpan{{Offset: 0, Length: 3}}, NegativeSpans: []*prompb.BucketSpan{{Offset: 0, Length: 3}},
NegativeDeltas: []int64{4, -2, -1}, NegativeDeltas: []int64{4, -2, -1},
}, },
}, },
Exemplars: []prompb.Exemplar{ Exemplars: []*prompb.Exemplar{
{Value: 2}, {Value: 2},
}, },
}, },

View file

@ -45,13 +45,13 @@ func TestPrometheusConverter_addGaugeNumberDataPoints(t *testing.T) {
) )
}, },
want: func() map[uint64]*prompb.TimeSeries { want: func() map[uint64]*prompb.TimeSeries {
labels := []prompb.Label{ labels := []*prompb.Label{
{Name: model.MetricNameLabel, Value: "test"}, {Name: model.MetricNameLabel, Value: "test"},
} }
return map[uint64]*prompb.TimeSeries{ return map[uint64]*prompb.TimeSeries{
timeSeriesSignature(labels): { timeSeriesSignature(labels): {
Labels: labels, Labels: labels,
Samples: []prompb.Sample{ Samples: []*prompb.Sample{
{ {
Value: 1, Value: 1,
Timestamp: convertTimeStamp(pcommon.Timestamp(ts)), Timestamp: convertTimeStamp(pcommon.Timestamp(ts)),
@ -100,13 +100,13 @@ func TestPrometheusConverter_addSumNumberDataPoints(t *testing.T) {
) )
}, },
want: func() map[uint64]*prompb.TimeSeries { want: func() map[uint64]*prompb.TimeSeries {
labels := []prompb.Label{ labels := []*prompb.Label{
{Name: model.MetricNameLabel, Value: "test"}, {Name: model.MetricNameLabel, Value: "test"},
} }
return map[uint64]*prompb.TimeSeries{ return map[uint64]*prompb.TimeSeries{
timeSeriesSignature(labels): { timeSeriesSignature(labels): {
Labels: labels, Labels: labels,
Samples: []prompb.Sample{ Samples: []*prompb.Sample{
{ {
Value: 1, Value: 1,
Timestamp: convertTimeStamp(ts), Timestamp: convertTimeStamp(ts),
@ -128,17 +128,17 @@ func TestPrometheusConverter_addSumNumberDataPoints(t *testing.T) {
return m return m
}, },
want: func() map[uint64]*prompb.TimeSeries { want: func() map[uint64]*prompb.TimeSeries {
labels := []prompb.Label{ labels := []*prompb.Label{
{Name: model.MetricNameLabel, Value: "test"}, {Name: model.MetricNameLabel, Value: "test"},
} }
return map[uint64]*prompb.TimeSeries{ return map[uint64]*prompb.TimeSeries{
timeSeriesSignature(labels): { timeSeriesSignature(labels): {
Labels: labels, Labels: labels,
Samples: []prompb.Sample{{ Samples: []*prompb.Sample{{
Value: 1, Value: 1,
Timestamp: convertTimeStamp(ts), Timestamp: convertTimeStamp(ts),
}}, }},
Exemplars: []prompb.Exemplar{ Exemplars: []*prompb.Exemplar{
{Value: 2}, {Value: 2},
}, },
}, },
@ -161,22 +161,22 @@ func TestPrometheusConverter_addSumNumberDataPoints(t *testing.T) {
return metric return metric
}, },
want: func() map[uint64]*prompb.TimeSeries { want: func() map[uint64]*prompb.TimeSeries {
labels := []prompb.Label{ labels := []*prompb.Label{
{Name: model.MetricNameLabel, Value: "test_sum"}, {Name: model.MetricNameLabel, Value: "test_sum"},
} }
createdLabels := []prompb.Label{ createdLabels := []*prompb.Label{
{Name: model.MetricNameLabel, Value: "test_sum" + createdSuffix}, {Name: model.MetricNameLabel, Value: "test_sum" + createdSuffix},
} }
return map[uint64]*prompb.TimeSeries{ return map[uint64]*prompb.TimeSeries{
timeSeriesSignature(labels): { timeSeriesSignature(labels): {
Labels: labels, Labels: labels,
Samples: []prompb.Sample{ Samples: []*prompb.Sample{
{Value: 1, Timestamp: convertTimeStamp(ts)}, {Value: 1, Timestamp: convertTimeStamp(ts)},
}, },
}, },
timeSeriesSignature(createdLabels): { timeSeriesSignature(createdLabels): {
Labels: createdLabels, Labels: createdLabels,
Samples: []prompb.Sample{ Samples: []*prompb.Sample{
{Value: float64(convertTimeStamp(ts)), Timestamp: convertTimeStamp(ts)}, {Value: float64(convertTimeStamp(ts)), Timestamp: convertTimeStamp(ts)},
}, },
}, },
@ -197,13 +197,13 @@ func TestPrometheusConverter_addSumNumberDataPoints(t *testing.T) {
return metric return metric
}, },
want: func() map[uint64]*prompb.TimeSeries { want: func() map[uint64]*prompb.TimeSeries {
labels := []prompb.Label{ labels := []*prompb.Label{
{Name: model.MetricNameLabel, Value: "test_sum"}, {Name: model.MetricNameLabel, Value: "test_sum"},
} }
return map[uint64]*prompb.TimeSeries{ return map[uint64]*prompb.TimeSeries{
timeSeriesSignature(labels): { timeSeriesSignature(labels): {
Labels: labels, Labels: labels,
Samples: []prompb.Sample{ Samples: []*prompb.Sample{
{Value: 0, Timestamp: convertTimeStamp(ts)}, {Value: 0, Timestamp: convertTimeStamp(ts)},
}, },
}, },
@ -224,13 +224,13 @@ func TestPrometheusConverter_addSumNumberDataPoints(t *testing.T) {
return metric return metric
}, },
want: func() map[uint64]*prompb.TimeSeries { want: func() map[uint64]*prompb.TimeSeries {
labels := []prompb.Label{ labels := []*prompb.Label{
{Name: model.MetricNameLabel, Value: "test_sum"}, {Name: model.MetricNameLabel, Value: "test_sum"},
} }
return map[uint64]*prompb.TimeSeries{ return map[uint64]*prompb.TimeSeries{
timeSeriesSignature(labels): { timeSeriesSignature(labels): {
Labels: labels, Labels: labels,
Samples: []prompb.Sample{ Samples: []*prompb.Sample{
{Value: 0, Timestamp: convertTimeStamp(ts)}, {Value: 0, Timestamp: convertTimeStamp(ts)},
}, },
}, },