mirror of
https://github.com/prometheus/prometheus.git
synced 2026-05-28 04:02:21 -04:00
refactor: use Appender mock for otlptranslator tests (#17999)
Signed-off-by: bwplotka <bwplotka@gmail.com>
This commit is contained in:
parent
fe5cb190e6
commit
5e46e77754
5 changed files with 533 additions and 585 deletions
|
|
@ -1,100 +0,0 @@
|
|||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package prometheusremotewrite
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
||||
"github.com/prometheus/prometheus/model/exemplar"
|
||||
"github.com/prometheus/prometheus/model/histogram"
|
||||
"github.com/prometheus/prometheus/model/labels"
|
||||
"github.com/prometheus/prometheus/model/metadata"
|
||||
"github.com/prometheus/prometheus/storage"
|
||||
"github.com/prometheus/prometheus/util/testutil"
|
||||
)
|
||||
|
||||
// TODO(bwplotka): Move to teststorage.Appendable. This require slight refactor of tests and I couldn't do this before
|
||||
// switching to AppenderV2 (I would need to adjust AppenderV1 mock exemplar flow which is pointless since we don't plan
|
||||
// to use it). For now keeping tests diff small for confidence.
|
||||
type mockCombinedAppender struct {
|
||||
pendingSamples []combinedSample
|
||||
pendingHistograms []combinedHistogram
|
||||
|
||||
samples []combinedSample
|
||||
histograms []combinedHistogram
|
||||
}
|
||||
|
||||
type combinedSample struct {
|
||||
metricFamilyName string
|
||||
ls labels.Labels
|
||||
meta metadata.Metadata
|
||||
t int64
|
||||
st int64
|
||||
v float64
|
||||
es []exemplar.Exemplar
|
||||
}
|
||||
|
||||
type combinedHistogram struct {
|
||||
metricFamilyName string
|
||||
ls labels.Labels
|
||||
meta metadata.Metadata
|
||||
t int64
|
||||
st int64
|
||||
h *histogram.Histogram
|
||||
es []exemplar.Exemplar
|
||||
}
|
||||
|
||||
func (m *mockCombinedAppender) Append(_ storage.SeriesRef, ls labels.Labels, st, t int64, v float64, h *histogram.Histogram, _ *histogram.FloatHistogram, opts storage.AOptions) (_ storage.SeriesRef, err error) {
|
||||
if h != nil {
|
||||
m.pendingHistograms = append(m.pendingHistograms, combinedHistogram{
|
||||
metricFamilyName: opts.MetricFamilyName,
|
||||
ls: ls,
|
||||
meta: opts.Metadata,
|
||||
t: t,
|
||||
st: st,
|
||||
h: h,
|
||||
es: opts.Exemplars,
|
||||
})
|
||||
return 0, nil
|
||||
}
|
||||
m.pendingSamples = append(m.pendingSamples, combinedSample{
|
||||
metricFamilyName: opts.MetricFamilyName,
|
||||
ls: ls,
|
||||
meta: opts.Metadata,
|
||||
t: t,
|
||||
st: st,
|
||||
v: v,
|
||||
es: opts.Exemplars,
|
||||
})
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (m *mockCombinedAppender) Commit() error {
|
||||
m.samples = append(m.samples, m.pendingSamples...)
|
||||
m.pendingSamples = m.pendingSamples[:0]
|
||||
m.histograms = append(m.histograms, m.pendingHistograms...)
|
||||
m.pendingHistograms = m.pendingHistograms[:0]
|
||||
return nil
|
||||
}
|
||||
|
||||
func (*mockCombinedAppender) Rollback() error {
|
||||
return errors.New("not implemented")
|
||||
}
|
||||
|
||||
func requireEqual(t testing.TB, expected, actual any, msgAndArgs ...any) {
|
||||
testutil.RequireEqualWithOptions(t, expected, actual, []cmp.Option{cmp.AllowUnexported(combinedSample{}, combinedHistogram{})}, msgAndArgs...)
|
||||
}
|
||||
|
|
@ -34,9 +34,12 @@ import (
|
|||
"github.com/prometheus/prometheus/model/metadata"
|
||||
"github.com/prometheus/prometheus/prompb"
|
||||
"github.com/prometheus/prometheus/storage"
|
||||
"github.com/prometheus/prometheus/util/teststorage"
|
||||
"github.com/prometheus/prometheus/util/testutil"
|
||||
)
|
||||
|
||||
type sample = teststorage.Sample
|
||||
|
||||
func TestPrometheusConverter_createAttributes(t *testing.T) {
|
||||
resourceAttrs := map[string]string{
|
||||
"service.name": "service name",
|
||||
|
|
@ -403,7 +406,7 @@ func TestPrometheusConverter_createAttributes(t *testing.T) {
|
|||
}
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
c := NewPrometheusConverter(&mockCombinedAppender{})
|
||||
c := NewPrometheusConverter(teststorage.NewAppendable().AppenderV2(t.Context()))
|
||||
settings := Settings{
|
||||
PromoteResourceAttributes: NewPromoteResourceAttributes(config.OTLPConfig{
|
||||
PromoteAllResourceAttributes: tc.promoteAllResourceAttributes,
|
||||
|
|
@ -450,8 +453,7 @@ func TestPrometheusConverter_createAttributes(t *testing.T) {
|
|||
attrsWithNameLabel.PutStr("__name__", "wrong_metric_name")
|
||||
attrsWithNameLabel.PutStr("other_attr", "value")
|
||||
|
||||
mockAppender := &mockCombinedAppender{}
|
||||
c := NewPrometheusConverter(mockAppender)
|
||||
c := NewPrometheusConverter(teststorage.NewAppendable().AppenderV2(t.Context()))
|
||||
settings := Settings{}
|
||||
|
||||
require.NoError(t, c.setResourceContext(resource, settings))
|
||||
|
|
@ -496,8 +498,7 @@ func TestPrometheusConverter_createAttributes(t *testing.T) {
|
|||
attrsWithTypeAndUnit.PutStr(model.MetricUnitLabel, "wrong_unit")
|
||||
attrsWithTypeAndUnit.PutStr("other_attr", "value")
|
||||
|
||||
mockAppender := &mockCombinedAppender{}
|
||||
c := NewPrometheusConverter(mockAppender)
|
||||
c := NewPrometheusConverter(teststorage.NewAppendable().AppenderV2(t.Context()))
|
||||
settings := Settings{EnableTypeAndUnitLabels: true}
|
||||
|
||||
require.NoError(t, c.setResourceContext(resource, settings))
|
||||
|
|
@ -577,7 +578,7 @@ func TestPrometheusConverter_AddSummaryDataPoints(t *testing.T) {
|
|||
metric func() pmetric.Metric
|
||||
scope scope
|
||||
promoteScope bool
|
||||
want func() []combinedSample
|
||||
want func() []sample
|
||||
}{
|
||||
{
|
||||
name: "summary with start time and without scope promotion",
|
||||
|
|
@ -594,25 +595,25 @@ func TestPrometheusConverter_AddSummaryDataPoints(t *testing.T) {
|
|||
},
|
||||
scope: defaultScope,
|
||||
promoteScope: false,
|
||||
want: func() []combinedSample {
|
||||
return []combinedSample{
|
||||
want: func() []sample {
|
||||
return []sample{
|
||||
{
|
||||
metricFamilyName: "test_summary",
|
||||
ls: labels.FromStrings(
|
||||
MF: "test_summary",
|
||||
L: labels.FromStrings(
|
||||
model.MetricNameLabel, "test_summary"+sumStr,
|
||||
),
|
||||
t: convertTimeStamp(ts),
|
||||
st: convertTimeStamp(ts),
|
||||
v: 0,
|
||||
T: convertTimeStamp(ts),
|
||||
ST: convertTimeStamp(ts),
|
||||
V: 0,
|
||||
},
|
||||
{
|
||||
metricFamilyName: "test_summary",
|
||||
ls: labels.FromStrings(
|
||||
MF: "test_summary",
|
||||
L: labels.FromStrings(
|
||||
model.MetricNameLabel, "test_summary"+countStr,
|
||||
),
|
||||
t: convertTimeStamp(ts),
|
||||
st: convertTimeStamp(ts),
|
||||
v: 0,
|
||||
T: convertTimeStamp(ts),
|
||||
ST: convertTimeStamp(ts),
|
||||
V: 0,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
|
@ -632,7 +633,7 @@ func TestPrometheusConverter_AddSummaryDataPoints(t *testing.T) {
|
|||
},
|
||||
scope: defaultScope,
|
||||
promoteScope: true,
|
||||
want: func() []combinedSample {
|
||||
want: func() []sample {
|
||||
scopeLabels := []string{
|
||||
"otel_scope_attr1", "value1",
|
||||
"otel_scope_attr2", "value2",
|
||||
|
|
@ -640,22 +641,22 @@ func TestPrometheusConverter_AddSummaryDataPoints(t *testing.T) {
|
|||
"otel_scope_schema_url", defaultScope.schemaURL,
|
||||
"otel_scope_version", defaultScope.version,
|
||||
}
|
||||
return []combinedSample{
|
||||
return []sample{
|
||||
{
|
||||
metricFamilyName: "test_summary",
|
||||
ls: labels.FromStrings(append(scopeLabels,
|
||||
MF: "test_summary",
|
||||
L: labels.FromStrings(append(scopeLabels,
|
||||
model.MetricNameLabel, "test_summary"+sumStr)...),
|
||||
t: convertTimeStamp(ts),
|
||||
st: convertTimeStamp(ts),
|
||||
v: 0,
|
||||
T: convertTimeStamp(ts),
|
||||
ST: convertTimeStamp(ts),
|
||||
V: 0,
|
||||
},
|
||||
{
|
||||
metricFamilyName: "test_summary",
|
||||
ls: labels.FromStrings(append(scopeLabels,
|
||||
MF: "test_summary",
|
||||
L: labels.FromStrings(append(scopeLabels,
|
||||
model.MetricNameLabel, "test_summary"+countStr)...),
|
||||
t: convertTimeStamp(ts),
|
||||
st: convertTimeStamp(ts),
|
||||
v: 0,
|
||||
T: convertTimeStamp(ts),
|
||||
ST: convertTimeStamp(ts),
|
||||
V: 0,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
|
@ -674,23 +675,23 @@ func TestPrometheusConverter_AddSummaryDataPoints(t *testing.T) {
|
|||
},
|
||||
scope: defaultScope,
|
||||
promoteScope: false,
|
||||
want: func() []combinedSample {
|
||||
return []combinedSample{
|
||||
want: func() []sample {
|
||||
return []sample{
|
||||
{
|
||||
metricFamilyName: "test_summary",
|
||||
ls: labels.FromStrings(
|
||||
MF: "test_summary",
|
||||
L: labels.FromStrings(
|
||||
model.MetricNameLabel, "test_summary"+sumStr,
|
||||
),
|
||||
t: convertTimeStamp(ts),
|
||||
v: 0,
|
||||
T: convertTimeStamp(ts),
|
||||
V: 0,
|
||||
},
|
||||
{
|
||||
metricFamilyName: "test_summary",
|
||||
ls: labels.FromStrings(
|
||||
MF: "test_summary",
|
||||
L: labels.FromStrings(
|
||||
model.MetricNameLabel, "test_summary"+countStr,
|
||||
),
|
||||
t: convertTimeStamp(ts),
|
||||
v: 0,
|
||||
T: convertTimeStamp(ts),
|
||||
V: 0,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
|
@ -718,41 +719,41 @@ func TestPrometheusConverter_AddSummaryDataPoints(t *testing.T) {
|
|||
},
|
||||
scope: defaultScope,
|
||||
promoteScope: false,
|
||||
want: func() []combinedSample {
|
||||
return []combinedSample{
|
||||
want: func() []sample {
|
||||
return []sample{
|
||||
{
|
||||
metricFamilyName: "test_summary",
|
||||
ls: labels.FromStrings(
|
||||
MF: "test_summary",
|
||||
L: labels.FromStrings(
|
||||
model.MetricNameLabel, "test_summary"+sumStr,
|
||||
),
|
||||
t: convertTimeStamp(ts),
|
||||
v: 100,
|
||||
T: convertTimeStamp(ts),
|
||||
V: 100,
|
||||
},
|
||||
{
|
||||
metricFamilyName: "test_summary",
|
||||
ls: labels.FromStrings(
|
||||
MF: "test_summary",
|
||||
L: labels.FromStrings(
|
||||
model.MetricNameLabel, "test_summary"+countStr,
|
||||
),
|
||||
t: convertTimeStamp(ts),
|
||||
v: 50,
|
||||
T: convertTimeStamp(ts),
|
||||
V: 50,
|
||||
},
|
||||
{
|
||||
metricFamilyName: "test_summary",
|
||||
ls: labels.FromStrings(
|
||||
MF: "test_summary",
|
||||
L: labels.FromStrings(
|
||||
model.MetricNameLabel, "test_summary",
|
||||
quantileStr, "0.5",
|
||||
),
|
||||
t: convertTimeStamp(ts),
|
||||
v: 30,
|
||||
T: convertTimeStamp(ts),
|
||||
V: 30,
|
||||
},
|
||||
{
|
||||
metricFamilyName: "test_summary",
|
||||
ls: labels.FromStrings(
|
||||
MF: "test_summary",
|
||||
L: labels.FromStrings(
|
||||
model.MetricNameLabel, "test_summary",
|
||||
quantileStr, "0.9",
|
||||
),
|
||||
t: convertTimeStamp(ts),
|
||||
v: 40,
|
||||
T: convertTimeStamp(ts),
|
||||
V: 40,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
|
@ -761,8 +762,9 @@ func TestPrometheusConverter_AddSummaryDataPoints(t *testing.T) {
|
|||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
metric := tt.metric()
|
||||
mockAppender := &mockCombinedAppender{}
|
||||
converter := NewPrometheusConverter(mockAppender)
|
||||
appTest := teststorage.NewAppendable()
|
||||
app := appTest.AppenderV2(t.Context())
|
||||
converter := NewPrometheusConverter(app)
|
||||
settings := Settings{
|
||||
PromoteScopeMetadata: tt.promoteScope,
|
||||
}
|
||||
|
|
@ -772,17 +774,16 @@ func TestPrometheusConverter_AddSummaryDataPoints(t *testing.T) {
|
|||
require.NoError(t, converter.setResourceContext(resource, settings))
|
||||
require.NoError(t, converter.setScopeContext(tt.scope, settings))
|
||||
|
||||
converter.addSummaryDataPoints(
|
||||
require.NoError(t, converter.addSummaryDataPoints(
|
||||
context.Background(),
|
||||
metric.Summary().DataPoints(),
|
||||
settings,
|
||||
storage.AOptions{
|
||||
MetricFamilyName: metric.Name(),
|
||||
},
|
||||
)
|
||||
require.NoError(t, mockAppender.Commit())
|
||||
|
||||
requireEqual(t, tt.want(), mockAppender.samples)
|
||||
))
|
||||
require.NoError(t, app.Commit())
|
||||
teststorage.RequireEqual(t, tt.want(), appTest.ResultSamples())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -805,7 +806,7 @@ func TestPrometheusConverter_AddHistogramDataPoints(t *testing.T) {
|
|||
metric func() pmetric.Metric
|
||||
scope scope
|
||||
promoteScope bool
|
||||
want func() []combinedSample
|
||||
want func() []sample
|
||||
}{
|
||||
{
|
||||
name: "histogram with start time and without scope promotion",
|
||||
|
|
@ -822,26 +823,26 @@ func TestPrometheusConverter_AddHistogramDataPoints(t *testing.T) {
|
|||
},
|
||||
scope: defaultScope,
|
||||
promoteScope: false,
|
||||
want: func() []combinedSample {
|
||||
return []combinedSample{
|
||||
want: func() []sample {
|
||||
return []sample{
|
||||
{
|
||||
metricFamilyName: "test_hist",
|
||||
ls: labels.FromStrings(
|
||||
MF: "test_hist",
|
||||
L: labels.FromStrings(
|
||||
model.MetricNameLabel, "test_hist"+countStr,
|
||||
),
|
||||
t: convertTimeStamp(ts),
|
||||
st: convertTimeStamp(ts),
|
||||
v: 0,
|
||||
T: convertTimeStamp(ts),
|
||||
ST: convertTimeStamp(ts),
|
||||
V: 0,
|
||||
},
|
||||
{
|
||||
metricFamilyName: "test_hist",
|
||||
ls: labels.FromStrings(
|
||||
MF: "test_hist",
|
||||
L: labels.FromStrings(
|
||||
model.MetricNameLabel, "test_hist_bucket",
|
||||
model.BucketLabel, "+Inf",
|
||||
),
|
||||
t: convertTimeStamp(ts),
|
||||
st: convertTimeStamp(ts),
|
||||
v: 0,
|
||||
T: convertTimeStamp(ts),
|
||||
ST: convertTimeStamp(ts),
|
||||
V: 0,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
|
@ -861,7 +862,7 @@ func TestPrometheusConverter_AddHistogramDataPoints(t *testing.T) {
|
|||
},
|
||||
scope: defaultScope,
|
||||
promoteScope: true,
|
||||
want: func() []combinedSample {
|
||||
want: func() []sample {
|
||||
scopeLabels := []string{
|
||||
"otel_scope_attr1", "value1",
|
||||
"otel_scope_attr2", "value2",
|
||||
|
|
@ -869,23 +870,23 @@ func TestPrometheusConverter_AddHistogramDataPoints(t *testing.T) {
|
|||
"otel_scope_schema_url", defaultScope.schemaURL,
|
||||
"otel_scope_version", defaultScope.version,
|
||||
}
|
||||
return []combinedSample{
|
||||
return []sample{
|
||||
{
|
||||
metricFamilyName: "test_hist",
|
||||
ls: labels.FromStrings(append(scopeLabels,
|
||||
MF: "test_hist",
|
||||
L: labels.FromStrings(append(scopeLabels,
|
||||
model.MetricNameLabel, "test_hist"+countStr)...),
|
||||
t: convertTimeStamp(ts),
|
||||
st: convertTimeStamp(ts),
|
||||
v: 0,
|
||||
T: convertTimeStamp(ts),
|
||||
ST: convertTimeStamp(ts),
|
||||
V: 0,
|
||||
},
|
||||
{
|
||||
metricFamilyName: "test_hist",
|
||||
ls: labels.FromStrings(append(scopeLabels,
|
||||
MF: "test_hist",
|
||||
L: labels.FromStrings(append(scopeLabels,
|
||||
model.MetricNameLabel, "test_hist_bucket",
|
||||
model.BucketLabel, "+Inf")...),
|
||||
t: convertTimeStamp(ts),
|
||||
st: convertTimeStamp(ts),
|
||||
v: 0,
|
||||
T: convertTimeStamp(ts),
|
||||
ST: convertTimeStamp(ts),
|
||||
V: 0,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
|
@ -902,24 +903,24 @@ func TestPrometheusConverter_AddHistogramDataPoints(t *testing.T) {
|
|||
|
||||
return metric
|
||||
},
|
||||
want: func() []combinedSample {
|
||||
return []combinedSample{
|
||||
want: func() []sample {
|
||||
return []sample{
|
||||
{
|
||||
metricFamilyName: "test_hist",
|
||||
ls: labels.FromStrings(
|
||||
MF: "test_hist",
|
||||
L: labels.FromStrings(
|
||||
model.MetricNameLabel, "test_hist"+countStr,
|
||||
),
|
||||
t: convertTimeStamp(ts),
|
||||
v: 0,
|
||||
T: convertTimeStamp(ts),
|
||||
V: 0,
|
||||
},
|
||||
{
|
||||
metricFamilyName: "test_hist",
|
||||
ls: labels.FromStrings(
|
||||
MF: "test_hist",
|
||||
L: labels.FromStrings(
|
||||
model.MetricNameLabel, "test_hist_bucket",
|
||||
model.BucketLabel, "+Inf",
|
||||
),
|
||||
t: convertTimeStamp(ts),
|
||||
v: 0,
|
||||
T: convertTimeStamp(ts),
|
||||
V: 0,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
|
@ -928,8 +929,9 @@ func TestPrometheusConverter_AddHistogramDataPoints(t *testing.T) {
|
|||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
metric := tt.metric()
|
||||
mockAppender := &mockCombinedAppender{}
|
||||
converter := NewPrometheusConverter(mockAppender)
|
||||
appTest := teststorage.NewAppendable()
|
||||
app := appTest.AppenderV2(t.Context())
|
||||
converter := NewPrometheusConverter(app)
|
||||
settings := Settings{
|
||||
PromoteScopeMetadata: tt.promoteScope,
|
||||
}
|
||||
|
|
@ -939,24 +941,23 @@ func TestPrometheusConverter_AddHistogramDataPoints(t *testing.T) {
|
|||
require.NoError(t, converter.setResourceContext(resource, settings))
|
||||
require.NoError(t, converter.setScopeContext(tt.scope, settings))
|
||||
|
||||
converter.addHistogramDataPoints(
|
||||
require.NoError(t, converter.addHistogramDataPoints(
|
||||
context.Background(),
|
||||
metric.Histogram().DataPoints(),
|
||||
settings,
|
||||
storage.AOptions{
|
||||
MetricFamilyName: metric.Name(),
|
||||
},
|
||||
)
|
||||
require.NoError(t, mockAppender.Commit())
|
||||
|
||||
requireEqual(t, tt.want(), mockAppender.samples)
|
||||
))
|
||||
require.NoError(t, app.Commit())
|
||||
teststorage.RequireEqual(t, tt.want(), appTest.ResultSamples())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetPromExemplars(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
c := NewPrometheusConverter(&mockCombinedAppender{})
|
||||
c := NewPrometheusConverter(teststorage.NewAppendable().AppenderV2(t.Context()))
|
||||
|
||||
t.Run("Exemplars with int value", func(t *testing.T) {
|
||||
es := pmetric.NewExemplarSlice()
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import (
|
|||
"github.com/prometheus/prometheus/model/labels"
|
||||
"github.com/prometheus/prometheus/model/metadata"
|
||||
"github.com/prometheus/prometheus/storage"
|
||||
"github.com/prometheus/prometheus/util/teststorage"
|
||||
)
|
||||
|
||||
type expectedBucketLayout struct {
|
||||
|
|
@ -383,8 +384,8 @@ func TestConvertBucketsLayout(t *testing.T) {
|
|||
for scaleDown, wantLayout := range tt.wantLayout {
|
||||
t.Run(fmt.Sprintf("%s-scaleby-%d", tt.name, scaleDown), func(t *testing.T) {
|
||||
gotSpans, gotDeltas := convertBucketsLayout(tt.buckets().BucketCounts().AsRaw(), tt.buckets().Offset(), scaleDown, true)
|
||||
requireEqual(t, wantLayout.wantSpans, gotSpans)
|
||||
requireEqual(t, wantLayout.wantDeltas, gotDeltas)
|
||||
require.Equal(t, wantLayout.wantSpans, gotSpans)
|
||||
require.Equal(t, wantLayout.wantDeltas, gotDeltas)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -634,7 +635,7 @@ func TestPrometheusConverter_addExponentialHistogramDataPoints(t *testing.T) {
|
|||
metric func() pmetric.Metric
|
||||
scope scope
|
||||
promoteScope bool
|
||||
wantSeries func() []combinedHistogram
|
||||
wantSeries func() []sample
|
||||
}{
|
||||
{
|
||||
name: "histogram data points with same labels and without scope promotion",
|
||||
|
|
@ -663,19 +664,19 @@ func TestPrometheusConverter_addExponentialHistogramDataPoints(t *testing.T) {
|
|||
},
|
||||
scope: defaultScope,
|
||||
promoteScope: false,
|
||||
wantSeries: func() []combinedHistogram {
|
||||
wantSeries: func() []sample {
|
||||
lbls := labels.FromStrings(
|
||||
model.MetricNameLabel, "test_hist",
|
||||
"attr", "test_attr",
|
||||
)
|
||||
return []combinedHistogram{
|
||||
return []sample{
|
||||
{
|
||||
metricFamilyName: "test_hist",
|
||||
ls: lbls,
|
||||
meta: metadata.Metadata{},
|
||||
t: 0,
|
||||
st: 0,
|
||||
h: &histogram.Histogram{
|
||||
MF: "test_hist",
|
||||
L: lbls,
|
||||
M: metadata.Metadata{},
|
||||
T: 0,
|
||||
ST: 0,
|
||||
H: &histogram.Histogram{
|
||||
Count: 7,
|
||||
Schema: 1,
|
||||
ZeroThreshold: defaultZeroThreshold,
|
||||
|
|
@ -683,15 +684,15 @@ func TestPrometheusConverter_addExponentialHistogramDataPoints(t *testing.T) {
|
|||
PositiveSpans: []histogram.Span{{Offset: 0, Length: 2}},
|
||||
PositiveBuckets: []int64{4, -2},
|
||||
},
|
||||
es: []exemplar.Exemplar{{Value: 1}},
|
||||
ES: []exemplar.Exemplar{{Value: 1}},
|
||||
},
|
||||
{
|
||||
metricFamilyName: "test_hist",
|
||||
ls: lbls,
|
||||
meta: metadata.Metadata{},
|
||||
t: 0,
|
||||
st: 0,
|
||||
h: &histogram.Histogram{
|
||||
MF: "test_hist",
|
||||
L: lbls,
|
||||
M: metadata.Metadata{},
|
||||
T: 0,
|
||||
ST: 0,
|
||||
H: &histogram.Histogram{
|
||||
Count: 4,
|
||||
Schema: 1,
|
||||
ZeroThreshold: defaultZeroThreshold,
|
||||
|
|
@ -699,7 +700,7 @@ func TestPrometheusConverter_addExponentialHistogramDataPoints(t *testing.T) {
|
|||
PositiveSpans: []histogram.Span{{Offset: 0, Length: 3}},
|
||||
PositiveBuckets: []int64{4, -2, -1},
|
||||
},
|
||||
es: []exemplar.Exemplar{{Value: 2}},
|
||||
ES: []exemplar.Exemplar{{Value: 2}},
|
||||
},
|
||||
}
|
||||
},
|
||||
|
|
@ -731,7 +732,7 @@ func TestPrometheusConverter_addExponentialHistogramDataPoints(t *testing.T) {
|
|||
},
|
||||
scope: defaultScope,
|
||||
promoteScope: true,
|
||||
wantSeries: func() []combinedHistogram {
|
||||
wantSeries: func() []sample {
|
||||
lbls := labels.FromStrings(
|
||||
model.MetricNameLabel, "test_hist",
|
||||
"attr", "test_attr",
|
||||
|
|
@ -741,14 +742,14 @@ func TestPrometheusConverter_addExponentialHistogramDataPoints(t *testing.T) {
|
|||
"otel_scope_attr1", "value1",
|
||||
"otel_scope_attr2", "value2",
|
||||
)
|
||||
return []combinedHistogram{
|
||||
return []sample{
|
||||
{
|
||||
metricFamilyName: "test_hist",
|
||||
ls: lbls,
|
||||
meta: metadata.Metadata{},
|
||||
t: 0,
|
||||
st: 0,
|
||||
h: &histogram.Histogram{
|
||||
MF: "test_hist",
|
||||
L: lbls,
|
||||
M: metadata.Metadata{},
|
||||
T: 0,
|
||||
ST: 0,
|
||||
H: &histogram.Histogram{
|
||||
Count: 7,
|
||||
Schema: 1,
|
||||
ZeroThreshold: defaultZeroThreshold,
|
||||
|
|
@ -756,15 +757,15 @@ func TestPrometheusConverter_addExponentialHistogramDataPoints(t *testing.T) {
|
|||
PositiveSpans: []histogram.Span{{Offset: 0, Length: 2}},
|
||||
PositiveBuckets: []int64{4, -2},
|
||||
},
|
||||
es: []exemplar.Exemplar{{Value: 1}},
|
||||
ES: []exemplar.Exemplar{{Value: 1}},
|
||||
},
|
||||
{
|
||||
metricFamilyName: "test_hist",
|
||||
ls: lbls,
|
||||
meta: metadata.Metadata{},
|
||||
t: 0,
|
||||
st: 0,
|
||||
h: &histogram.Histogram{
|
||||
MF: "test_hist",
|
||||
L: lbls,
|
||||
M: metadata.Metadata{},
|
||||
T: 0,
|
||||
ST: 0,
|
||||
H: &histogram.Histogram{
|
||||
Count: 4,
|
||||
Schema: 1,
|
||||
ZeroThreshold: defaultZeroThreshold,
|
||||
|
|
@ -772,7 +773,7 @@ func TestPrometheusConverter_addExponentialHistogramDataPoints(t *testing.T) {
|
|||
PositiveSpans: []histogram.Span{{Offset: 0, Length: 3}},
|
||||
PositiveBuckets: []int64{4, -2, -1},
|
||||
},
|
||||
es: []exemplar.Exemplar{{Value: 2}},
|
||||
ES: []exemplar.Exemplar{{Value: 2}},
|
||||
},
|
||||
}
|
||||
},
|
||||
|
|
@ -804,7 +805,7 @@ func TestPrometheusConverter_addExponentialHistogramDataPoints(t *testing.T) {
|
|||
},
|
||||
scope: defaultScope,
|
||||
promoteScope: false,
|
||||
wantSeries: func() []combinedHistogram {
|
||||
wantSeries: func() []sample {
|
||||
lbls := labels.FromStrings(
|
||||
model.MetricNameLabel, "test_hist",
|
||||
"attr", "test_attr",
|
||||
|
|
@ -814,14 +815,14 @@ func TestPrometheusConverter_addExponentialHistogramDataPoints(t *testing.T) {
|
|||
"attr", "test_attr_two",
|
||||
)
|
||||
|
||||
return []combinedHistogram{
|
||||
return []sample{
|
||||
{
|
||||
metricFamilyName: "test_hist",
|
||||
ls: lbls,
|
||||
meta: metadata.Metadata{},
|
||||
t: 0,
|
||||
st: 0,
|
||||
h: &histogram.Histogram{
|
||||
MF: "test_hist",
|
||||
L: lbls,
|
||||
M: metadata.Metadata{},
|
||||
T: 0,
|
||||
ST: 0,
|
||||
H: &histogram.Histogram{
|
||||
Count: 7,
|
||||
Schema: 1,
|
||||
ZeroThreshold: defaultZeroThreshold,
|
||||
|
|
@ -829,15 +830,15 @@ func TestPrometheusConverter_addExponentialHistogramDataPoints(t *testing.T) {
|
|||
PositiveSpans: []histogram.Span{{Offset: 0, Length: 2}},
|
||||
PositiveBuckets: []int64{4, -2},
|
||||
},
|
||||
es: []exemplar.Exemplar{{Value: 1}},
|
||||
ES: []exemplar.Exemplar{{Value: 1}},
|
||||
},
|
||||
{
|
||||
metricFamilyName: "test_hist",
|
||||
ls: labelsAnother,
|
||||
meta: metadata.Metadata{},
|
||||
t: 0,
|
||||
st: 0,
|
||||
h: &histogram.Histogram{
|
||||
MF: "test_hist",
|
||||
L: labelsAnother,
|
||||
M: metadata.Metadata{},
|
||||
T: 0,
|
||||
ST: 0,
|
||||
H: &histogram.Histogram{
|
||||
Count: 4,
|
||||
Schema: 1,
|
||||
ZeroThreshold: defaultZeroThreshold,
|
||||
|
|
@ -845,7 +846,7 @@ func TestPrometheusConverter_addExponentialHistogramDataPoints(t *testing.T) {
|
|||
NegativeSpans: []histogram.Span{{Offset: 0, Length: 3}},
|
||||
NegativeBuckets: []int64{4, -2, -1},
|
||||
},
|
||||
es: []exemplar.Exemplar{{Value: 2}},
|
||||
ES: []exemplar.Exemplar{{Value: 2}},
|
||||
},
|
||||
}
|
||||
},
|
||||
|
|
@ -855,8 +856,9 @@ func TestPrometheusConverter_addExponentialHistogramDataPoints(t *testing.T) {
|
|||
t.Run(tt.name, func(t *testing.T) {
|
||||
metric := tt.metric()
|
||||
|
||||
mockAppender := &mockCombinedAppender{}
|
||||
converter := NewPrometheusConverter(mockAppender)
|
||||
appTest := teststorage.NewAppendable()
|
||||
app := appTest.AppenderV2(t.Context())
|
||||
converter := NewPrometheusConverter(app)
|
||||
namer := otlptranslator.MetricNamer{
|
||||
WithMetricSuffixes: true,
|
||||
}
|
||||
|
|
@ -883,9 +885,8 @@ func TestPrometheusConverter_addExponentialHistogramDataPoints(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.Empty(t, annots)
|
||||
|
||||
require.NoError(t, mockAppender.Commit())
|
||||
|
||||
requireEqual(t, tt.wantSeries(), mockAppender.histograms)
|
||||
require.NoError(t, app.Commit())
|
||||
teststorage.RequireEqual(t, tt.wantSeries(), appTest.ResultSamples())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -1112,7 +1113,7 @@ func TestPrometheusConverter_addCustomBucketsHistogramDataPoints(t *testing.T) {
|
|||
metric func() pmetric.Metric
|
||||
scope scope
|
||||
promoteScope bool
|
||||
wantSeries func() []combinedHistogram
|
||||
wantSeries func() []sample
|
||||
}{
|
||||
{
|
||||
name: "histogram data points with same labels and without scope promotion",
|
||||
|
|
@ -1141,19 +1142,19 @@ func TestPrometheusConverter_addCustomBucketsHistogramDataPoints(t *testing.T) {
|
|||
},
|
||||
scope: defaultScope,
|
||||
promoteScope: false,
|
||||
wantSeries: func() []combinedHistogram {
|
||||
wantSeries: func() []sample {
|
||||
lbls := labels.FromStrings(
|
||||
model.MetricNameLabel, "test_hist_to_nhcb",
|
||||
"attr", "test_attr",
|
||||
)
|
||||
return []combinedHistogram{
|
||||
return []sample{
|
||||
{
|
||||
metricFamilyName: "test_hist_to_nhcb",
|
||||
ls: lbls,
|
||||
meta: metadata.Metadata{},
|
||||
t: 0,
|
||||
st: 0,
|
||||
h: &histogram.Histogram{
|
||||
MF: "test_hist_to_nhcb",
|
||||
L: lbls,
|
||||
M: metadata.Metadata{},
|
||||
T: 0,
|
||||
ST: 0,
|
||||
H: &histogram.Histogram{
|
||||
Count: 3,
|
||||
Sum: 3,
|
||||
Schema: -53,
|
||||
|
|
@ -1161,15 +1162,15 @@ func TestPrometheusConverter_addCustomBucketsHistogramDataPoints(t *testing.T) {
|
|||
PositiveBuckets: []int64{2, -2, 1},
|
||||
CustomValues: []float64{5, 10},
|
||||
},
|
||||
es: []exemplar.Exemplar{{Value: 1}},
|
||||
ES: []exemplar.Exemplar{{Value: 1}},
|
||||
},
|
||||
{
|
||||
metricFamilyName: "test_hist_to_nhcb",
|
||||
ls: lbls,
|
||||
meta: metadata.Metadata{},
|
||||
t: 0,
|
||||
st: 0,
|
||||
h: &histogram.Histogram{
|
||||
MF: "test_hist_to_nhcb",
|
||||
L: lbls,
|
||||
M: metadata.Metadata{},
|
||||
T: 0,
|
||||
ST: 0,
|
||||
H: &histogram.Histogram{
|
||||
Count: 11,
|
||||
Sum: 5,
|
||||
Schema: -53,
|
||||
|
|
@ -1177,7 +1178,7 @@ func TestPrometheusConverter_addCustomBucketsHistogramDataPoints(t *testing.T) {
|
|||
PositiveBuckets: []int64{3, 5, -8},
|
||||
CustomValues: []float64{0, 1},
|
||||
},
|
||||
es: []exemplar.Exemplar{{Value: 2}},
|
||||
ES: []exemplar.Exemplar{{Value: 2}},
|
||||
},
|
||||
}
|
||||
},
|
||||
|
|
@ -1209,7 +1210,7 @@ func TestPrometheusConverter_addCustomBucketsHistogramDataPoints(t *testing.T) {
|
|||
},
|
||||
scope: defaultScope,
|
||||
promoteScope: true,
|
||||
wantSeries: func() []combinedHistogram {
|
||||
wantSeries: func() []sample {
|
||||
lbls := labels.FromStrings(
|
||||
model.MetricNameLabel, "test_hist_to_nhcb",
|
||||
"attr", "test_attr",
|
||||
|
|
@ -1219,14 +1220,14 @@ func TestPrometheusConverter_addCustomBucketsHistogramDataPoints(t *testing.T) {
|
|||
"otel_scope_attr1", "value1",
|
||||
"otel_scope_attr2", "value2",
|
||||
)
|
||||
return []combinedHistogram{
|
||||
return []sample{
|
||||
{
|
||||
metricFamilyName: "test_hist_to_nhcb",
|
||||
ls: lbls,
|
||||
meta: metadata.Metadata{},
|
||||
t: 0,
|
||||
st: 0,
|
||||
h: &histogram.Histogram{
|
||||
MF: "test_hist_to_nhcb",
|
||||
L: lbls,
|
||||
M: metadata.Metadata{},
|
||||
T: 0,
|
||||
ST: 0,
|
||||
H: &histogram.Histogram{
|
||||
Count: 3,
|
||||
Sum: 3,
|
||||
Schema: -53,
|
||||
|
|
@ -1234,15 +1235,15 @@ func TestPrometheusConverter_addCustomBucketsHistogramDataPoints(t *testing.T) {
|
|||
PositiveBuckets: []int64{2, -2, 1},
|
||||
CustomValues: []float64{5, 10},
|
||||
},
|
||||
es: []exemplar.Exemplar{{Value: 1}},
|
||||
ES: []exemplar.Exemplar{{Value: 1}},
|
||||
},
|
||||
{
|
||||
metricFamilyName: "test_hist_to_nhcb",
|
||||
ls: lbls,
|
||||
meta: metadata.Metadata{},
|
||||
t: 0,
|
||||
st: 0,
|
||||
h: &histogram.Histogram{
|
||||
MF: "test_hist_to_nhcb",
|
||||
L: lbls,
|
||||
M: metadata.Metadata{},
|
||||
T: 0,
|
||||
ST: 0,
|
||||
H: &histogram.Histogram{
|
||||
Count: 11,
|
||||
Sum: 5,
|
||||
Schema: -53,
|
||||
|
|
@ -1250,7 +1251,7 @@ func TestPrometheusConverter_addCustomBucketsHistogramDataPoints(t *testing.T) {
|
|||
PositiveBuckets: []int64{3, 5, -8},
|
||||
CustomValues: []float64{0, 1},
|
||||
},
|
||||
es: []exemplar.Exemplar{{Value: 2}},
|
||||
ES: []exemplar.Exemplar{{Value: 2}},
|
||||
},
|
||||
}
|
||||
},
|
||||
|
|
@ -1282,7 +1283,7 @@ func TestPrometheusConverter_addCustomBucketsHistogramDataPoints(t *testing.T) {
|
|||
},
|
||||
scope: defaultScope,
|
||||
promoteScope: false,
|
||||
wantSeries: func() []combinedHistogram {
|
||||
wantSeries: func() []sample {
|
||||
lbls := labels.FromStrings(
|
||||
model.MetricNameLabel, "test_hist_to_nhcb",
|
||||
"attr", "test_attr",
|
||||
|
|
@ -1292,14 +1293,14 @@ func TestPrometheusConverter_addCustomBucketsHistogramDataPoints(t *testing.T) {
|
|||
"attr", "test_attr_two",
|
||||
)
|
||||
|
||||
return []combinedHistogram{
|
||||
return []sample{
|
||||
{
|
||||
metricFamilyName: "test_hist_to_nhcb",
|
||||
ls: lbls,
|
||||
meta: metadata.Metadata{},
|
||||
t: 0,
|
||||
st: 0,
|
||||
h: &histogram.Histogram{
|
||||
MF: "test_hist_to_nhcb",
|
||||
L: lbls,
|
||||
M: metadata.Metadata{},
|
||||
T: 0,
|
||||
ST: 0,
|
||||
H: &histogram.Histogram{
|
||||
Count: 6,
|
||||
Sum: 3,
|
||||
Schema: -53,
|
||||
|
|
@ -1307,15 +1308,15 @@ func TestPrometheusConverter_addCustomBucketsHistogramDataPoints(t *testing.T) {
|
|||
PositiveBuckets: []int64{4, -2},
|
||||
CustomValues: []float64{0, 1},
|
||||
},
|
||||
es: []exemplar.Exemplar{{Value: 1}},
|
||||
ES: []exemplar.Exemplar{{Value: 1}},
|
||||
},
|
||||
{
|
||||
metricFamilyName: "test_hist_to_nhcb",
|
||||
ls: labelsAnother,
|
||||
meta: metadata.Metadata{},
|
||||
t: 0,
|
||||
st: 0,
|
||||
h: &histogram.Histogram{
|
||||
MF: "test_hist_to_nhcb",
|
||||
L: labelsAnother,
|
||||
M: metadata.Metadata{},
|
||||
T: 0,
|
||||
ST: 0,
|
||||
H: &histogram.Histogram{
|
||||
Count: 11,
|
||||
Sum: 5,
|
||||
Schema: -53,
|
||||
|
|
@ -1323,7 +1324,7 @@ func TestPrometheusConverter_addCustomBucketsHistogramDataPoints(t *testing.T) {
|
|||
PositiveBuckets: []int64{3, 5},
|
||||
CustomValues: []float64{0, 1},
|
||||
},
|
||||
es: []exemplar.Exemplar{{Value: 2}},
|
||||
ES: []exemplar.Exemplar{{Value: 2}},
|
||||
},
|
||||
}
|
||||
},
|
||||
|
|
@ -1333,8 +1334,9 @@ func TestPrometheusConverter_addCustomBucketsHistogramDataPoints(t *testing.T) {
|
|||
t.Run(tt.name, func(t *testing.T) {
|
||||
metric := tt.metric()
|
||||
|
||||
mockAppender := &mockCombinedAppender{}
|
||||
converter := NewPrometheusConverter(mockAppender)
|
||||
appTest := teststorage.NewAppendable()
|
||||
app := appTest.AppenderV2(t.Context())
|
||||
converter := NewPrometheusConverter(app)
|
||||
namer := otlptranslator.MetricNamer{
|
||||
WithMetricSuffixes: true,
|
||||
}
|
||||
|
|
@ -1363,9 +1365,8 @@ func TestPrometheusConverter_addCustomBucketsHistogramDataPoints(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.Empty(t, annots)
|
||||
|
||||
require.NoError(t, mockAppender.Commit())
|
||||
|
||||
requireEqual(t, tt.wantSeries(), mockAppender.histograms)
|
||||
require.NoError(t, app.Commit())
|
||||
teststorage.RequireEqual(t, tt.wantSeries(), appTest.ResultSamples())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import (
|
|||
"github.com/prometheus/prometheus/model/labels"
|
||||
"github.com/prometheus/prometheus/model/metadata"
|
||||
"github.com/prometheus/prometheus/storage"
|
||||
"github.com/prometheus/prometheus/util/teststorage"
|
||||
)
|
||||
|
||||
func TestFromMetrics(t *testing.T) {
|
||||
|
|
@ -79,8 +80,9 @@ func TestFromMetrics(t *testing.T) {
|
|||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
mockAppender := &mockCombinedAppender{}
|
||||
converter := NewPrometheusConverter(mockAppender)
|
||||
appTest := teststorage.NewAppendable()
|
||||
app := appTest.AppenderV2(t.Context())
|
||||
converter := NewPrometheusConverter(app)
|
||||
payload, wantPromMetrics := createExportRequest(5, 128, 128, 2, 0, tc.settings, tc.temporality)
|
||||
seenFamilyNames := map[string]struct{}{}
|
||||
for _, wantMetric := range wantPromMetrics {
|
||||
|
|
@ -102,14 +104,14 @@ func TestFromMetrics(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.Empty(t, annots)
|
||||
|
||||
require.NoError(t, mockAppender.Commit())
|
||||
require.NoError(t, app.Commit())
|
||||
|
||||
ts := mockAppender.samples
|
||||
require.Len(t, ts, 1536+1) // +1 for the target_info.
|
||||
got := appTest.ResultSamples()
|
||||
require.Len(t, got, 1536+1) // +1 for the target_info.
|
||||
|
||||
tgtInfoCount := 0
|
||||
for _, s := range ts {
|
||||
lbls := s.ls
|
||||
for _, s := range got {
|
||||
lbls := s.L
|
||||
if lbls.Get(labels.MetricName) == "target_info" {
|
||||
tgtInfoCount++
|
||||
require.Equal(t, "test-namespace/test-service", lbls.Get("job"))
|
||||
|
|
@ -148,11 +150,14 @@ func TestFromMetrics(t *testing.T) {
|
|||
|
||||
h.SetCount(15)
|
||||
h.SetSum(155)
|
||||
h.BucketCounts().FromRaw([]uint64{3, 11, 0})
|
||||
h.ExplicitBounds().FromRaw([]float64{0.124, 1.123})
|
||||
|
||||
generateAttributes(h.Attributes(), "series", 1)
|
||||
|
||||
mockAppender := &mockCombinedAppender{}
|
||||
converter := NewPrometheusConverter(mockAppender)
|
||||
appTest := teststorage.NewAppendable()
|
||||
app := appTest.AppenderV2(t.Context())
|
||||
converter := NewPrometheusConverter(app)
|
||||
annots, err := converter.FromMetrics(
|
||||
context.Background(),
|
||||
request.Metrics(),
|
||||
|
|
@ -160,21 +165,56 @@ func TestFromMetrics(t *testing.T) {
|
|||
)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, annots)
|
||||
require.NoError(t, mockAppender.Commit())
|
||||
require.NoError(t, app.Commit())
|
||||
|
||||
if convertHistogramsToNHCB {
|
||||
require.Len(t, mockAppender.histograms, 1)
|
||||
require.Empty(t, mockAppender.samples)
|
||||
} else {
|
||||
require.Empty(t, mockAppender.histograms)
|
||||
require.Len(t, mockAppender.samples, 3)
|
||||
expectedSamples := []sample{
|
||||
{
|
||||
MF: "histogram_1", M: metadata.Metadata{Type: model.MetricTypeHistogram},
|
||||
L: labels.FromStrings("__name__", "histogram_1_sum", "series_name_1", "value-1"),
|
||||
T: ts.AsTime().UnixMilli(), V: 155,
|
||||
},
|
||||
{
|
||||
MF: "histogram_1", M: metadata.Metadata{Type: model.MetricTypeHistogram},
|
||||
L: labels.FromStrings("__name__", "histogram_1_count", "series_name_1", "value-1"),
|
||||
T: ts.AsTime().UnixMilli(), V: 15,
|
||||
},
|
||||
{
|
||||
MF: "histogram_1", M: metadata.Metadata{Type: model.MetricTypeHistogram},
|
||||
L: labels.FromStrings("__name__", "histogram_1_bucket", "le", "0.124", "series_name_1", "value-1"),
|
||||
T: ts.AsTime().UnixMilli(), V: 3,
|
||||
},
|
||||
{
|
||||
MF: "histogram_1", M: metadata.Metadata{Type: model.MetricTypeHistogram},
|
||||
L: labels.FromStrings("__name__", "histogram_1_bucket", "le", "1.123", "series_name_1", "value-1"),
|
||||
T: ts.AsTime().UnixMilli(), V: 14,
|
||||
},
|
||||
{
|
||||
MF: "histogram_1", M: metadata.Metadata{Type: model.MetricTypeHistogram},
|
||||
L: labels.FromStrings("__name__", "histogram_1_bucket", "le", "+Inf", "series_name_1", "value-1"),
|
||||
T: ts.AsTime().UnixMilli(), V: 15,
|
||||
},
|
||||
}
|
||||
if convertHistogramsToNHCB {
|
||||
expectedSamples = []sample{
|
||||
{
|
||||
MF: "histogram_1", M: metadata.Metadata{Type: model.MetricTypeHistogram},
|
||||
L: labels.FromStrings("__name__", "histogram_1", "series_name_1", "value-1"),
|
||||
T: ts.AsTime().UnixMilli(), H: &histogram.Histogram{
|
||||
Schema: -53, Count: 15, Sum: 155,
|
||||
PositiveSpans: []histogram.Span{{Offset: 0, Length: 3}},
|
||||
PositiveBuckets: []int64{3, 8, -11},
|
||||
CustomValues: []float64{0.124, 1.123},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
teststorage.RequireEqual(t, expectedSamples, appTest.ResultSamples())
|
||||
})
|
||||
}
|
||||
|
||||
t.Run("context cancellation", func(t *testing.T) {
|
||||
settings := Settings{}
|
||||
converter := NewPrometheusConverter(&mockCombinedAppender{})
|
||||
converter := NewPrometheusConverter(teststorage.NewAppendable().AppenderV2(t.Context()))
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
// Verify that converter.FromMetrics respects cancellation.
|
||||
cancel()
|
||||
|
|
@ -187,7 +227,7 @@ func TestFromMetrics(t *testing.T) {
|
|||
|
||||
t.Run("context timeout", func(t *testing.T) {
|
||||
settings := Settings{}
|
||||
converter := NewPrometheusConverter(&mockCombinedAppender{})
|
||||
converter := NewPrometheusConverter(teststorage.NewAppendable().AppenderV2(t.Context()))
|
||||
// Verify that converter.FromMetrics respects timeout.
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 0)
|
||||
t.Cleanup(cancel)
|
||||
|
|
@ -220,7 +260,7 @@ func TestFromMetrics(t *testing.T) {
|
|||
generateAttributes(h.Attributes(), "series", 10)
|
||||
}
|
||||
|
||||
converter := NewPrometheusConverter(&mockCombinedAppender{})
|
||||
converter := NewPrometheusConverter(teststorage.NewAppendable().AppenderV2(t.Context()))
|
||||
annots, err := converter.FromMetrics(context.Background(), request.Metrics(), Settings{})
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, annots)
|
||||
|
|
@ -253,7 +293,7 @@ func TestFromMetrics(t *testing.T) {
|
|||
generateAttributes(h.Attributes(), "series", 10)
|
||||
}
|
||||
|
||||
converter := NewPrometheusConverter(&mockCombinedAppender{})
|
||||
converter := NewPrometheusConverter(teststorage.NewAppendable().AppenderV2(t.Context()))
|
||||
annots, err := converter.FromMetrics(
|
||||
context.Background(),
|
||||
request.Metrics(),
|
||||
|
|
@ -301,8 +341,9 @@ func TestFromMetrics(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
mockAppender := &mockCombinedAppender{}
|
||||
converter := NewPrometheusConverter(mockAppender)
|
||||
appTest := teststorage.NewAppendable()
|
||||
app := appTest.AppenderV2(t.Context())
|
||||
converter := NewPrometheusConverter(app)
|
||||
annots, err := converter.FromMetrics(
|
||||
context.Background(),
|
||||
request.Metrics(),
|
||||
|
|
@ -312,8 +353,11 @@ func TestFromMetrics(t *testing.T) {
|
|||
)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, annots)
|
||||
require.NoError(t, mockAppender.Commit())
|
||||
require.Len(t, mockAppender.samples, 22)
|
||||
require.NoError(t, app.Commit())
|
||||
|
||||
got := appTest.ResultSamples()
|
||||
require.Len(t, got, 22)
|
||||
|
||||
// There should be a target_info sample at the earliest metric timestamp, then two spaced lookback delta/2 apart,
|
||||
// then one at the latest metric timestamp.
|
||||
targetInfoLabels := labels.FromStrings(
|
||||
|
|
@ -330,36 +374,36 @@ func TestFromMetrics(t *testing.T) {
|
|||
Type: model.MetricTypeGauge,
|
||||
Help: "Target metadata",
|
||||
}
|
||||
requireEqual(t, []combinedSample{
|
||||
teststorage.RequireEqual(t, []sample{
|
||||
{
|
||||
metricFamilyName: "target_info",
|
||||
v: 1,
|
||||
t: ts.AsTime().UnixMilli(),
|
||||
ls: targetInfoLabels,
|
||||
meta: targetInfoMeta,
|
||||
MF: "target_info",
|
||||
V: 1,
|
||||
T: ts.AsTime().UnixMilli(),
|
||||
L: targetInfoLabels,
|
||||
M: targetInfoMeta,
|
||||
},
|
||||
{
|
||||
metricFamilyName: "target_info",
|
||||
v: 1,
|
||||
t: ts.AsTime().Add(defaultLookbackDelta / 2).UnixMilli(),
|
||||
ls: targetInfoLabels,
|
||||
meta: targetInfoMeta,
|
||||
MF: "target_info",
|
||||
V: 1,
|
||||
T: ts.AsTime().Add(defaultLookbackDelta / 2).UnixMilli(),
|
||||
L: targetInfoLabels,
|
||||
M: targetInfoMeta,
|
||||
},
|
||||
{
|
||||
metricFamilyName: "target_info",
|
||||
v: 1,
|
||||
t: ts.AsTime().Add(defaultLookbackDelta).UnixMilli(),
|
||||
ls: targetInfoLabels,
|
||||
meta: targetInfoMeta,
|
||||
MF: "target_info",
|
||||
V: 1,
|
||||
T: ts.AsTime().Add(defaultLookbackDelta).UnixMilli(),
|
||||
L: targetInfoLabels,
|
||||
M: targetInfoMeta,
|
||||
},
|
||||
{
|
||||
metricFamilyName: "target_info",
|
||||
v: 1,
|
||||
t: ts.AsTime().Add(defaultLookbackDelta + defaultLookbackDelta/4).UnixMilli(),
|
||||
ls: targetInfoLabels,
|
||||
meta: targetInfoMeta,
|
||||
MF: "target_info",
|
||||
V: 1,
|
||||
T: ts.AsTime().Add(defaultLookbackDelta + defaultLookbackDelta/4).UnixMilli(),
|
||||
L: targetInfoLabels,
|
||||
M: targetInfoMeta,
|
||||
},
|
||||
}, mockAppender.samples[len(mockAppender.samples)-4:])
|
||||
}, got[len(got)-4:])
|
||||
})
|
||||
|
||||
t.Run("target_info deduplication across multiple resources with same labels", func(t *testing.T) {
|
||||
|
|
@ -401,8 +445,9 @@ func TestFromMetrics(t *testing.T) {
|
|||
generateAttributes(point2.Attributes(), "series", 1)
|
||||
}
|
||||
|
||||
mockAppender := &mockCombinedAppender{}
|
||||
converter := NewPrometheusConverter(mockAppender)
|
||||
appTest := teststorage.NewAppendable()
|
||||
app := appTest.AppenderV2(t.Context())
|
||||
converter := NewPrometheusConverter(app)
|
||||
annots, err := converter.FromMetrics(
|
||||
context.Background(),
|
||||
request.Metrics(),
|
||||
|
|
@ -412,11 +457,11 @@ func TestFromMetrics(t *testing.T) {
|
|||
)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, annots)
|
||||
require.NoError(t, mockAppender.Commit())
|
||||
require.NoError(t, app.Commit())
|
||||
|
||||
var targetInfoSamples []combinedSample
|
||||
for _, s := range mockAppender.samples {
|
||||
if s.ls.Get(labels.MetricName) == "target_info" {
|
||||
var targetInfoSamples []sample
|
||||
for _, s := range appTest.ResultSamples() {
|
||||
if s.L.Get(labels.MetricName) == "target_info" {
|
||||
targetInfoSamples = append(targetInfoSamples, s)
|
||||
}
|
||||
}
|
||||
|
|
@ -437,20 +482,20 @@ func TestFromMetrics(t *testing.T) {
|
|||
Type: model.MetricTypeGauge,
|
||||
Help: "Target metadata",
|
||||
}
|
||||
requireEqual(t, []combinedSample{
|
||||
teststorage.RequireEqual(t, []sample{
|
||||
{
|
||||
metricFamilyName: "target_info",
|
||||
v: 1,
|
||||
t: ts.AsTime().UnixMilli(),
|
||||
ls: targetInfoLabels,
|
||||
meta: targetInfoMeta,
|
||||
MF: "target_info",
|
||||
V: 1,
|
||||
T: ts.AsTime().UnixMilli(),
|
||||
L: targetInfoLabels,
|
||||
M: targetInfoMeta,
|
||||
},
|
||||
{
|
||||
metricFamilyName: "target_info",
|
||||
v: 1,
|
||||
t: ts.AsTime().Add(defaultLookbackDelta / 2).UnixMilli(),
|
||||
ls: targetInfoLabels,
|
||||
meta: targetInfoMeta,
|
||||
MF: "target_info",
|
||||
V: 1,
|
||||
T: ts.AsTime().Add(defaultLookbackDelta / 2).UnixMilli(),
|
||||
L: targetInfoLabels,
|
||||
M: targetInfoMeta,
|
||||
},
|
||||
}, targetInfoSamples)
|
||||
})
|
||||
|
|
@ -483,8 +528,9 @@ func TestFromMetrics(t *testing.T) {
|
|||
point.SetTimestamp(ts)
|
||||
point.SetDoubleValue(1.0)
|
||||
|
||||
mockAppender := &mockCombinedAppender{}
|
||||
converter := NewPrometheusConverter(mockAppender)
|
||||
appTest := teststorage.NewAppendable()
|
||||
app := appTest.AppenderV2(t.Context())
|
||||
converter := NewPrometheusConverter(app)
|
||||
annots, err := converter.FromMetrics(
|
||||
context.Background(),
|
||||
request.Metrics(),
|
||||
|
|
@ -495,12 +541,12 @@ func TestFromMetrics(t *testing.T) {
|
|||
)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, annots)
|
||||
require.NoError(t, mockAppender.Commit())
|
||||
require.NoError(t, app.Commit())
|
||||
|
||||
// Find target_info samples.
|
||||
var targetInfoSamples []combinedSample
|
||||
for _, s := range mockAppender.samples {
|
||||
if s.ls.Get(labels.MetricName) == "target_info" {
|
||||
var targetInfoSamples []sample
|
||||
for _, s := range appTest.ResultSamples() {
|
||||
if s.L.Get(labels.MetricName) == "target_info" {
|
||||
targetInfoSamples = append(targetInfoSamples, s)
|
||||
}
|
||||
}
|
||||
|
|
@ -508,22 +554,23 @@ func TestFromMetrics(t *testing.T) {
|
|||
|
||||
// Verify target_info does NOT have scope labels.
|
||||
for _, s := range targetInfoSamples {
|
||||
require.Empty(t, s.ls.Get("otel_scope_name"), "target_info should not have otel_scope_name")
|
||||
require.Empty(t, s.ls.Get("otel_scope_version"), "target_info should not have otel_scope_version")
|
||||
require.Empty(t, s.ls.Get("otel_scope_schema_url"), "target_info should not have otel_scope_schema_url")
|
||||
require.Empty(t, s.ls.Get("otel_scope_scope_attr"), "target_info should not have scope attributes")
|
||||
require.Empty(t, s.L.Get("otel_scope_name"), "target_info should not have otel_scope_name")
|
||||
require.Empty(t, s.L.Get("otel_scope_version"), "target_info should not have otel_scope_version")
|
||||
require.Empty(t, s.L.Get("otel_scope_schema_url"), "target_info should not have otel_scope_schema_url")
|
||||
require.Empty(t, s.L.Get("otel_scope_scope_attr"), "target_info should not have scope attributes")
|
||||
}
|
||||
|
||||
// Verify the metric itself DOES have scope labels.
|
||||
var metricSamples []combinedSample
|
||||
for _, s := range mockAppender.samples {
|
||||
if s.ls.Get(labels.MetricName) == "test_gauge" {
|
||||
var metricSamples []sample
|
||||
for _, s := range appTest.ResultSamples() {
|
||||
if s.L.Get(labels.MetricName) == "test_gauge" {
|
||||
metricSamples = append(metricSamples, s)
|
||||
}
|
||||
}
|
||||
|
||||
require.NotEmpty(t, metricSamples, "expected metric samples")
|
||||
require.Equal(t, "my-scope", metricSamples[0].ls.Get("otel_scope_name"), "metric should have otel_scope_name")
|
||||
require.Equal(t, "1.0.0", metricSamples[0].ls.Get("otel_scope_version"), "metric should have otel_scope_version")
|
||||
require.Equal(t, "my-scope", metricSamples[0].L.Get("otel_scope_name"), "metric should have otel_scope_name")
|
||||
require.Equal(t, "1.0.0", metricSamples[0].L.Get("otel_scope_version"), "metric should have otel_scope_version")
|
||||
})
|
||||
|
||||
t.Run("target_info should include promoted resource attributes", func(t *testing.T) {
|
||||
|
|
@ -548,8 +595,9 @@ func TestFromMetrics(t *testing.T) {
|
|||
point.SetTimestamp(ts)
|
||||
point.SetDoubleValue(1.0)
|
||||
|
||||
mockAppender := &mockCombinedAppender{}
|
||||
converter := NewPrometheusConverter(mockAppender)
|
||||
appTest := teststorage.NewAppendable()
|
||||
app := appTest.AppenderV2(t.Context())
|
||||
converter := NewPrometheusConverter(app)
|
||||
annots, err := converter.FromMetrics(
|
||||
context.Background(),
|
||||
request.Metrics(),
|
||||
|
|
@ -562,12 +610,12 @@ func TestFromMetrics(t *testing.T) {
|
|||
)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, annots)
|
||||
require.NoError(t, mockAppender.Commit())
|
||||
require.NoError(t, app.Commit())
|
||||
|
||||
// Find target_info samples.
|
||||
var targetInfoSamples []combinedSample
|
||||
for _, s := range mockAppender.samples {
|
||||
if s.ls.Get(labels.MetricName) == "target_info" {
|
||||
var targetInfoSamples []sample
|
||||
for _, s := range appTest.ResultSamples() {
|
||||
if s.L.Get(labels.MetricName) == "target_info" {
|
||||
targetInfoSamples = append(targetInfoSamples, s)
|
||||
}
|
||||
}
|
||||
|
|
@ -575,19 +623,19 @@ func TestFromMetrics(t *testing.T) {
|
|||
|
||||
// Verify target_info has the promoted resource attribute.
|
||||
for _, s := range targetInfoSamples {
|
||||
require.Equal(t, "promoted-value", s.ls.Get("custom_promoted_attr"), "target_info should have promoted resource attributes")
|
||||
require.Equal(t, "another-value", s.ls.Get("another_resource_attr"), "target_info should have non-promoted resource attributes")
|
||||
require.Equal(t, "promoted-value", s.L.Get("custom_promoted_attr"), "target_info should have promoted resource attributes")
|
||||
require.Equal(t, "another-value", s.L.Get("another_resource_attr"), "target_info should have non-promoted resource attributes")
|
||||
}
|
||||
|
||||
// Verify the metric also has the promoted resource attribute.
|
||||
var metricSamples []combinedSample
|
||||
for _, s := range mockAppender.samples {
|
||||
if s.ls.Get(labels.MetricName) == "test_gauge" {
|
||||
var metricSamples []sample
|
||||
for _, s := range appTest.ResultSamples() {
|
||||
if s.L.Get(labels.MetricName) == "test_gauge" {
|
||||
metricSamples = append(metricSamples, s)
|
||||
}
|
||||
}
|
||||
require.NotEmpty(t, metricSamples, "expected metric samples")
|
||||
require.Equal(t, "promoted-value", metricSamples[0].ls.Get("custom_promoted_attr"), "metric should have promoted resource attribute")
|
||||
require.Equal(t, "promoted-value", metricSamples[0].L.Get("custom_promoted_attr"), "metric should have promoted resource attribute")
|
||||
})
|
||||
|
||||
t.Run("target_info should include promoted attributes when KeepIdentifyingResourceAttributes is enabled", func(t *testing.T) {
|
||||
|
|
@ -613,8 +661,9 @@ func TestFromMetrics(t *testing.T) {
|
|||
point.SetTimestamp(ts)
|
||||
point.SetDoubleValue(1.0)
|
||||
|
||||
mockAppender := &mockCombinedAppender{}
|
||||
converter := NewPrometheusConverter(mockAppender)
|
||||
appTest := teststorage.NewAppendable()
|
||||
app := appTest.AppenderV2(t.Context())
|
||||
converter := NewPrometheusConverter(app)
|
||||
annots, err := converter.FromMetrics(
|
||||
context.Background(),
|
||||
request.Metrics(),
|
||||
|
|
@ -628,11 +677,11 @@ func TestFromMetrics(t *testing.T) {
|
|||
)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, annots)
|
||||
require.NoError(t, mockAppender.Commit())
|
||||
require.NoError(t, app.Commit())
|
||||
|
||||
var targetInfoSamples []combinedSample
|
||||
for _, s := range mockAppender.samples {
|
||||
if s.ls.Get(labels.MetricName) == "target_info" {
|
||||
var targetInfoSamples []sample
|
||||
for _, s := range appTest.ResultSamples() {
|
||||
if s.L.Get(labels.MetricName) == "target_info" {
|
||||
targetInfoSamples = append(targetInfoSamples, s)
|
||||
}
|
||||
}
|
||||
|
|
@ -640,24 +689,24 @@ func TestFromMetrics(t *testing.T) {
|
|||
|
||||
// Verify target_info has the promoted resource attribute.
|
||||
for _, s := range targetInfoSamples {
|
||||
require.Equal(t, "promoted-value", s.ls.Get("custom_promoted_attr"), "target_info should have promoted resource attributes")
|
||||
require.Equal(t, "promoted-value", s.L.Get("custom_promoted_attr"), "target_info should have promoted resource attributes")
|
||||
// And it should have the identifying attributes (since KeepIdentifyingResourceAttributes is true).
|
||||
require.Equal(t, "test-service", s.ls.Get("service_name"), "target_info should have service.name when KeepIdentifyingResourceAttributes is true")
|
||||
require.Equal(t, "test-namespace", s.ls.Get("service_namespace"), "target_info should have service.namespace when KeepIdentifyingResourceAttributes is true")
|
||||
require.Equal(t, "instance-1", s.ls.Get("service_instance_id"), "target_info should have service.instance.id when KeepIdentifyingResourceAttributes is true")
|
||||
require.Equal(t, "test-service", s.L.Get("service_name"), "target_info should have service.name when KeepIdentifyingResourceAttributes is true")
|
||||
require.Equal(t, "test-namespace", s.L.Get("service_namespace"), "target_info should have service.namespace when KeepIdentifyingResourceAttributes is true")
|
||||
require.Equal(t, "instance-1", s.L.Get("service_instance_id"), "target_info should have service.instance.id when KeepIdentifyingResourceAttributes is true")
|
||||
// And the non-promoted resource attribute.
|
||||
require.Equal(t, "another-value", s.ls.Get("another_resource_attr"), "target_info should have non-promoted resource attributes")
|
||||
require.Equal(t, "another-value", s.L.Get("another_resource_attr"), "target_info should have non-promoted resource attributes")
|
||||
}
|
||||
|
||||
// Verify the metric also has the promoted resource attribute.
|
||||
var metricSamples []combinedSample
|
||||
for _, s := range mockAppender.samples {
|
||||
if s.ls.Get(labels.MetricName) == "test_gauge" {
|
||||
var metricSamples []sample
|
||||
for _, s := range appTest.ResultSamples() {
|
||||
if s.L.Get(labels.MetricName) == "test_gauge" {
|
||||
metricSamples = append(metricSamples, s)
|
||||
}
|
||||
}
|
||||
require.NotEmpty(t, metricSamples, "expected metric samples")
|
||||
require.Equal(t, "promoted-value", metricSamples[0].ls.Get("custom_promoted_attr"), "metric should have promoted resource attribute")
|
||||
require.Equal(t, "promoted-value", metricSamples[0].L.Get("custom_promoted_attr"), "metric should have promoted resource attribute")
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -665,13 +714,12 @@ func TestTemporality(t *testing.T) {
|
|||
ts := time.Unix(100, 0)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
allowDelta bool
|
||||
convertToNHCB bool
|
||||
inputSeries []pmetric.Metric
|
||||
expectedSamples []combinedSample
|
||||
expectedHistograms []combinedHistogram
|
||||
expectedError string
|
||||
name string
|
||||
allowDelta bool
|
||||
convertToNHCB bool
|
||||
inputSeries []pmetric.Metric
|
||||
expectedSamples []sample
|
||||
expectedError string
|
||||
}{
|
||||
{
|
||||
name: "all cumulative when delta not allowed",
|
||||
|
|
@ -680,7 +728,7 @@ func TestTemporality(t *testing.T) {
|
|||
createOtelSum("test_metric_1", pmetric.AggregationTemporalityCumulative, ts),
|
||||
createOtelSum("test_metric_2", pmetric.AggregationTemporalityCumulative, ts),
|
||||
},
|
||||
expectedSamples: []combinedSample{
|
||||
expectedSamples: []sample{
|
||||
createPromFloatSeries("test_metric_1", ts, model.MetricTypeCounter),
|
||||
createPromFloatSeries("test_metric_2", ts, model.MetricTypeCounter),
|
||||
},
|
||||
|
|
@ -692,7 +740,7 @@ func TestTemporality(t *testing.T) {
|
|||
createOtelSum("test_metric_1", pmetric.AggregationTemporalityDelta, ts),
|
||||
createOtelSum("test_metric_2", pmetric.AggregationTemporalityDelta, ts),
|
||||
},
|
||||
expectedSamples: []combinedSample{
|
||||
expectedSamples: []sample{
|
||||
createPromFloatSeries("test_metric_1", ts, model.MetricTypeUnknown),
|
||||
createPromFloatSeries("test_metric_2", ts, model.MetricTypeUnknown),
|
||||
},
|
||||
|
|
@ -704,7 +752,7 @@ func TestTemporality(t *testing.T) {
|
|||
createOtelSum("test_metric_1", pmetric.AggregationTemporalityDelta, ts),
|
||||
createOtelSum("test_metric_2", pmetric.AggregationTemporalityCumulative, ts),
|
||||
},
|
||||
expectedSamples: []combinedSample{
|
||||
expectedSamples: []sample{
|
||||
createPromFloatSeries("test_metric_1", ts, model.MetricTypeUnknown),
|
||||
createPromFloatSeries("test_metric_2", ts, model.MetricTypeCounter),
|
||||
},
|
||||
|
|
@ -716,7 +764,7 @@ func TestTemporality(t *testing.T) {
|
|||
createOtelSum("test_metric_1", pmetric.AggregationTemporalityCumulative, ts),
|
||||
createOtelSum("test_metric_2", pmetric.AggregationTemporalityDelta, ts),
|
||||
},
|
||||
expectedSamples: []combinedSample{
|
||||
expectedSamples: []sample{
|
||||
createPromFloatSeries("test_metric_1", ts, model.MetricTypeCounter),
|
||||
},
|
||||
expectedError: `invalid temporality and type combination for metric "test_metric_2"`,
|
||||
|
|
@ -728,7 +776,7 @@ func TestTemporality(t *testing.T) {
|
|||
createOtelSum("test_metric_1", pmetric.AggregationTemporalityCumulative, ts),
|
||||
createOtelSum("test_metric_2", pmetric.AggregationTemporalityUnspecified, ts),
|
||||
},
|
||||
expectedSamples: []combinedSample{
|
||||
expectedSamples: []sample{
|
||||
createPromFloatSeries("test_metric_1", ts, model.MetricTypeCounter),
|
||||
},
|
||||
expectedError: `invalid temporality and type combination for metric "test_metric_2"`,
|
||||
|
|
@ -739,7 +787,7 @@ func TestTemporality(t *testing.T) {
|
|||
inputSeries: []pmetric.Metric{
|
||||
createOtelExponentialHistogram("test_histogram", pmetric.AggregationTemporalityCumulative, ts),
|
||||
},
|
||||
expectedHistograms: []combinedHistogram{
|
||||
expectedSamples: []sample{
|
||||
createPromNativeHistogramSeries("test_histogram", histogram.UnknownCounterReset, ts, model.MetricTypeHistogram),
|
||||
},
|
||||
},
|
||||
|
|
@ -750,7 +798,7 @@ func TestTemporality(t *testing.T) {
|
|||
createOtelExponentialHistogram("test_histogram_1", pmetric.AggregationTemporalityDelta, ts),
|
||||
createOtelExponentialHistogram("test_histogram_2", pmetric.AggregationTemporalityCumulative, ts),
|
||||
},
|
||||
expectedHistograms: []combinedHistogram{
|
||||
expectedSamples: []sample{
|
||||
createPromNativeHistogramSeries("test_histogram_1", histogram.GaugeType, ts, model.MetricTypeUnknown),
|
||||
createPromNativeHistogramSeries("test_histogram_2", histogram.UnknownCounterReset, ts, model.MetricTypeHistogram),
|
||||
},
|
||||
|
|
@ -762,7 +810,7 @@ func TestTemporality(t *testing.T) {
|
|||
createOtelExponentialHistogram("test_histogram_1", pmetric.AggregationTemporalityDelta, ts),
|
||||
createOtelExponentialHistogram("test_histogram_2", pmetric.AggregationTemporalityCumulative, ts),
|
||||
},
|
||||
expectedHistograms: []combinedHistogram{
|
||||
expectedSamples: []sample{
|
||||
createPromNativeHistogramSeries("test_histogram_2", histogram.UnknownCounterReset, ts, model.MetricTypeHistogram),
|
||||
},
|
||||
expectedError: `invalid temporality and type combination for metric "test_histogram_1"`,
|
||||
|
|
@ -774,7 +822,7 @@ func TestTemporality(t *testing.T) {
|
|||
inputSeries: []pmetric.Metric{
|
||||
createOtelExplicitHistogram("test_histogram", pmetric.AggregationTemporalityCumulative, ts),
|
||||
},
|
||||
expectedHistograms: []combinedHistogram{
|
||||
expectedSamples: []sample{
|
||||
createPromNHCBSeries("test_histogram", histogram.UnknownCounterReset, ts, model.MetricTypeHistogram),
|
||||
},
|
||||
},
|
||||
|
|
@ -786,7 +834,7 @@ func TestTemporality(t *testing.T) {
|
|||
createOtelExplicitHistogram("test_histogram_1", pmetric.AggregationTemporalityDelta, ts),
|
||||
createOtelExplicitHistogram("test_histogram_2", pmetric.AggregationTemporalityCumulative, ts),
|
||||
},
|
||||
expectedHistograms: []combinedHistogram{
|
||||
expectedSamples: []sample{
|
||||
createPromNHCBSeries("test_histogram_1", histogram.GaugeType, ts, model.MetricTypeUnknown),
|
||||
createPromNHCBSeries("test_histogram_2", histogram.UnknownCounterReset, ts, model.MetricTypeHistogram),
|
||||
},
|
||||
|
|
@ -799,7 +847,7 @@ func TestTemporality(t *testing.T) {
|
|||
createOtelExplicitHistogram("test_histogram_1", pmetric.AggregationTemporalityDelta, ts),
|
||||
createOtelExplicitHistogram("test_histogram_2", pmetric.AggregationTemporalityCumulative, ts),
|
||||
},
|
||||
expectedHistograms: []combinedHistogram{
|
||||
expectedSamples: []sample{
|
||||
createPromNHCBSeries("test_histogram_2", histogram.UnknownCounterReset, ts, model.MetricTypeHistogram),
|
||||
},
|
||||
expectedError: `invalid temporality and type combination for metric "test_histogram_1"`,
|
||||
|
|
@ -840,7 +888,7 @@ func TestTemporality(t *testing.T) {
|
|||
inputSeries: []pmetric.Metric{
|
||||
createOtelGauge("test_gauge_1", ts),
|
||||
},
|
||||
expectedSamples: []combinedSample{
|
||||
expectedSamples: []sample{
|
||||
createPromFloatSeries("test_gauge_1", ts, model.MetricTypeGauge),
|
||||
},
|
||||
},
|
||||
|
|
@ -863,25 +911,22 @@ func TestTemporality(t *testing.T) {
|
|||
s.CopyTo(sm.Metrics().AppendEmpty())
|
||||
}
|
||||
|
||||
mockAppender := &mockCombinedAppender{}
|
||||
c := NewPrometheusConverter(mockAppender)
|
||||
appTest := teststorage.NewAppendable()
|
||||
app := appTest.AppenderV2(t.Context())
|
||||
c := NewPrometheusConverter(app)
|
||||
settings := Settings{
|
||||
AllowDeltaTemporality: tc.allowDelta,
|
||||
ConvertHistogramsToNHCB: tc.convertToNHCB,
|
||||
}
|
||||
|
||||
_, err := c.FromMetrics(context.Background(), metrics, settings)
|
||||
|
||||
if tc.expectedError != "" {
|
||||
require.EqualError(t, err, tc.expectedError)
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
require.NoError(t, mockAppender.Commit())
|
||||
|
||||
// Sort series to make the test deterministic.
|
||||
requireEqual(t, tc.expectedSamples, mockAppender.samples)
|
||||
requireEqual(t, tc.expectedHistograms, mockAppender.histograms)
|
||||
require.NoError(t, app.Commit())
|
||||
teststorage.RequireEqual(t, tc.expectedSamples, appTest.ResultSamples())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -900,13 +945,13 @@ func createOtelSum(name string, temporality pmetric.AggregationTemporality, ts t
|
|||
return m
|
||||
}
|
||||
|
||||
func createPromFloatSeries(name string, ts time.Time, typ model.MetricType) combinedSample {
|
||||
return combinedSample{
|
||||
metricFamilyName: name,
|
||||
ls: labels.FromStrings("__name__", name, "test_label", "test_value"),
|
||||
t: ts.UnixMilli(),
|
||||
v: 5,
|
||||
meta: metadata.Metadata{
|
||||
func createPromFloatSeries(name string, ts time.Time, typ model.MetricType) sample {
|
||||
return sample{
|
||||
MF: name,
|
||||
L: labels.FromStrings("__name__", name, "test_label", "test_value"),
|
||||
T: ts.UnixMilli(),
|
||||
V: 5,
|
||||
M: metadata.Metadata{
|
||||
Type: typ,
|
||||
},
|
||||
}
|
||||
|
|
@ -938,15 +983,15 @@ func createOtelExponentialHistogram(name string, temporality pmetric.Aggregation
|
|||
return m
|
||||
}
|
||||
|
||||
func createPromNativeHistogramSeries(name string, hint histogram.CounterResetHint, ts time.Time, typ model.MetricType) combinedHistogram {
|
||||
return combinedHistogram{
|
||||
metricFamilyName: name,
|
||||
ls: labels.FromStrings("__name__", name, "test_label", "test_value"),
|
||||
t: ts.UnixMilli(),
|
||||
meta: metadata.Metadata{
|
||||
func createPromNativeHistogramSeries(name string, hint histogram.CounterResetHint, ts time.Time, typ model.MetricType) sample {
|
||||
return sample{
|
||||
MF: name,
|
||||
L: labels.FromStrings("__name__", name, "test_label", "test_value"),
|
||||
T: ts.UnixMilli(),
|
||||
M: metadata.Metadata{
|
||||
Type: typ,
|
||||
},
|
||||
h: &histogram.Histogram{
|
||||
H: &histogram.Histogram{
|
||||
Count: 1,
|
||||
Sum: 5,
|
||||
Schema: 0,
|
||||
|
|
@ -973,15 +1018,15 @@ func createOtelExplicitHistogram(name string, temporality pmetric.AggregationTem
|
|||
return m
|
||||
}
|
||||
|
||||
func createPromNHCBSeries(name string, hint histogram.CounterResetHint, ts time.Time, typ model.MetricType) combinedHistogram {
|
||||
return combinedHistogram{
|
||||
metricFamilyName: name,
|
||||
ls: labels.FromStrings("__name__", name, "test_label", "test_value"),
|
||||
meta: metadata.Metadata{
|
||||
func createPromNHCBSeries(name string, hint histogram.CounterResetHint, ts time.Time, typ model.MetricType) sample {
|
||||
return sample{
|
||||
MF: name,
|
||||
L: labels.FromStrings("__name__", name, "test_label", "test_value"),
|
||||
M: metadata.Metadata{
|
||||
Type: typ,
|
||||
},
|
||||
t: ts.UnixMilli(),
|
||||
h: &histogram.Histogram{
|
||||
T: ts.UnixMilli(),
|
||||
H: &histogram.Histogram{
|
||||
Count: 20,
|
||||
Sum: 30,
|
||||
Schema: -53,
|
||||
|
|
@ -998,50 +1043,50 @@ func createPromNHCBSeries(name string, hint histogram.CounterResetHint, ts time.
|
|||
}
|
||||
}
|
||||
|
||||
func createPromClassicHistogramSeries(name string, ts time.Time, typ model.MetricType) []combinedSample {
|
||||
return []combinedSample{
|
||||
func createPromClassicHistogramSeries(name string, ts time.Time, typ model.MetricType) []sample {
|
||||
return []sample{
|
||||
{
|
||||
metricFamilyName: name,
|
||||
ls: labels.FromStrings("__name__", name+"_sum", "test_label", "test_value"),
|
||||
t: ts.UnixMilli(),
|
||||
v: 30,
|
||||
meta: metadata.Metadata{
|
||||
MF: name,
|
||||
L: labels.FromStrings("__name__", name+"_sum", "test_label", "test_value"),
|
||||
T: ts.UnixMilli(),
|
||||
V: 30,
|
||||
M: metadata.Metadata{
|
||||
Type: typ,
|
||||
},
|
||||
},
|
||||
{
|
||||
metricFamilyName: name,
|
||||
ls: labels.FromStrings("__name__", name+"_count", "test_label", "test_value"),
|
||||
t: ts.UnixMilli(),
|
||||
v: 20,
|
||||
meta: metadata.Metadata{
|
||||
MF: name,
|
||||
L: labels.FromStrings("__name__", name+"_count", "test_label", "test_value"),
|
||||
T: ts.UnixMilli(),
|
||||
V: 20,
|
||||
M: metadata.Metadata{
|
||||
Type: typ,
|
||||
},
|
||||
},
|
||||
{
|
||||
metricFamilyName: name,
|
||||
ls: labels.FromStrings("__name__", name+"_bucket", "le", "1", "test_label", "test_value"),
|
||||
t: ts.UnixMilli(),
|
||||
v: 10,
|
||||
meta: metadata.Metadata{
|
||||
MF: name,
|
||||
L: labels.FromStrings("__name__", name+"_bucket", "le", "1", "test_label", "test_value"),
|
||||
T: ts.UnixMilli(),
|
||||
V: 10,
|
||||
M: metadata.Metadata{
|
||||
Type: typ,
|
||||
},
|
||||
},
|
||||
{
|
||||
metricFamilyName: name,
|
||||
ls: labels.FromStrings("__name__", name+"_bucket", "le", "2", "test_label", "test_value"),
|
||||
t: ts.UnixMilli(),
|
||||
v: 20,
|
||||
meta: metadata.Metadata{
|
||||
MF: name,
|
||||
L: labels.FromStrings("__name__", name+"_bucket", "le", "2", "test_label", "test_value"),
|
||||
T: ts.UnixMilli(),
|
||||
V: 20,
|
||||
M: metadata.Metadata{
|
||||
Type: typ,
|
||||
},
|
||||
},
|
||||
{
|
||||
metricFamilyName: name,
|
||||
ls: labels.FromStrings("__name__", name+"_bucket", "le", "+Inf", "test_label", "test_value"),
|
||||
t: ts.UnixMilli(),
|
||||
v: 20,
|
||||
meta: metadata.Metadata{
|
||||
MF: name,
|
||||
L: labels.FromStrings("__name__", name+"_bucket", "le", "+Inf", "test_label", "test_value"),
|
||||
T: ts.UnixMilli(),
|
||||
V: 20,
|
||||
M: metadata.Metadata{
|
||||
Type: typ,
|
||||
},
|
||||
},
|
||||
|
|
@ -1064,32 +1109,32 @@ func createOtelSummary(name string, ts time.Time) pmetric.Metric {
|
|||
return m
|
||||
}
|
||||
|
||||
func createPromSummarySeries(name string, ts time.Time) []combinedSample {
|
||||
return []combinedSample{
|
||||
func createPromSummarySeries(name string, ts time.Time) []sample {
|
||||
return []sample{
|
||||
{
|
||||
metricFamilyName: name,
|
||||
ls: labels.FromStrings("__name__", name+"_sum", "test_label", "test_value"),
|
||||
t: ts.UnixMilli(),
|
||||
v: 18,
|
||||
meta: metadata.Metadata{
|
||||
MF: name,
|
||||
L: labels.FromStrings("__name__", name+"_sum", "test_label", "test_value"),
|
||||
T: ts.UnixMilli(),
|
||||
V: 18,
|
||||
M: metadata.Metadata{
|
||||
Type: model.MetricTypeSummary,
|
||||
},
|
||||
},
|
||||
{
|
||||
metricFamilyName: name,
|
||||
ls: labels.FromStrings("__name__", name+"_count", "test_label", "test_value"),
|
||||
t: ts.UnixMilli(),
|
||||
v: 9,
|
||||
meta: metadata.Metadata{
|
||||
MF: name,
|
||||
L: labels.FromStrings("__name__", name+"_count", "test_label", "test_value"),
|
||||
T: ts.UnixMilli(),
|
||||
V: 9,
|
||||
M: metadata.Metadata{
|
||||
Type: model.MetricTypeSummary,
|
||||
},
|
||||
},
|
||||
{
|
||||
metricFamilyName: name,
|
||||
ls: labels.FromStrings("__name__", name, "quantile", "0.5", "test_label", "test_value"),
|
||||
t: ts.UnixMilli(),
|
||||
v: 2,
|
||||
meta: metadata.Metadata{
|
||||
MF: name,
|
||||
L: labels.FromStrings("__name__", name, "quantile", "0.5", "test_label", "test_value"),
|
||||
T: ts.UnixMilli(),
|
||||
V: 2,
|
||||
M: metadata.Metadata{
|
||||
Type: model.MetricTypeSummary,
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import (
|
|||
"github.com/prometheus/prometheus/model/labels"
|
||||
"github.com/prometheus/prometheus/model/metadata"
|
||||
"github.com/prometheus/prometheus/storage"
|
||||
"github.com/prometheus/prometheus/util/teststorage"
|
||||
)
|
||||
|
||||
func TestPrometheusConverter_addGaugeNumberDataPoints(t *testing.T) {
|
||||
|
|
@ -50,7 +51,7 @@ func TestPrometheusConverter_addGaugeNumberDataPoints(t *testing.T) {
|
|||
metric func() pmetric.Metric
|
||||
scope scope
|
||||
promoteScope bool
|
||||
want func() []combinedSample
|
||||
want func() []sample
|
||||
}{
|
||||
{
|
||||
name: "gauge without scope promotion",
|
||||
|
|
@ -63,17 +64,17 @@ func TestPrometheusConverter_addGaugeNumberDataPoints(t *testing.T) {
|
|||
},
|
||||
scope: defaultScope,
|
||||
promoteScope: false,
|
||||
want: func() []combinedSample {
|
||||
want: func() []sample {
|
||||
lbls := labels.FromStrings(
|
||||
model.MetricNameLabel, "test",
|
||||
)
|
||||
return []combinedSample{
|
||||
return []sample{
|
||||
{
|
||||
metricFamilyName: "test",
|
||||
ls: lbls,
|
||||
meta: metadata.Metadata{},
|
||||
t: convertTimeStamp(pcommon.Timestamp(ts)),
|
||||
v: 1,
|
||||
MF: "test",
|
||||
L: lbls,
|
||||
M: metadata.Metadata{},
|
||||
T: convertTimeStamp(pcommon.Timestamp(ts)),
|
||||
V: 1,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
|
@ -89,7 +90,7 @@ func TestPrometheusConverter_addGaugeNumberDataPoints(t *testing.T) {
|
|||
},
|
||||
scope: defaultScope,
|
||||
promoteScope: true,
|
||||
want: func() []combinedSample {
|
||||
want: func() []sample {
|
||||
lbls := labels.FromStrings(
|
||||
model.MetricNameLabel, "test",
|
||||
"otel_scope_name", defaultScope.name,
|
||||
|
|
@ -98,13 +99,13 @@ func TestPrometheusConverter_addGaugeNumberDataPoints(t *testing.T) {
|
|||
"otel_scope_attr1", "value1",
|
||||
"otel_scope_attr2", "value2",
|
||||
)
|
||||
return []combinedSample{
|
||||
return []sample{
|
||||
{
|
||||
metricFamilyName: "test",
|
||||
ls: lbls,
|
||||
meta: metadata.Metadata{},
|
||||
t: convertTimeStamp(pcommon.Timestamp(ts)),
|
||||
v: 1,
|
||||
MF: "test",
|
||||
L: lbls,
|
||||
M: metadata.Metadata{},
|
||||
T: convertTimeStamp(pcommon.Timestamp(ts)),
|
||||
V: 1,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
|
@ -113,8 +114,9 @@ func TestPrometheusConverter_addGaugeNumberDataPoints(t *testing.T) {
|
|||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
metric := tt.metric()
|
||||
mockAppender := &mockCombinedAppender{}
|
||||
converter := NewPrometheusConverter(mockAppender)
|
||||
appTest := teststorage.NewAppendable()
|
||||
app := appTest.AppenderV2(t.Context())
|
||||
converter := NewPrometheusConverter(app)
|
||||
settings := Settings{
|
||||
PromoteScopeMetadata: tt.promoteScope,
|
||||
}
|
||||
|
|
@ -132,9 +134,8 @@ func TestPrometheusConverter_addGaugeNumberDataPoints(t *testing.T) {
|
|||
MetricFamilyName: metric.Name(),
|
||||
},
|
||||
)
|
||||
require.NoError(t, mockAppender.Commit())
|
||||
|
||||
requireEqual(t, tt.want(), mockAppender.samples)
|
||||
require.NoError(t, app.Commit())
|
||||
teststorage.RequireEqual(t, tt.want(), appTest.ResultSamples())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -157,7 +158,7 @@ func TestPrometheusConverter_addSumNumberDataPoints(t *testing.T) {
|
|||
metric func() pmetric.Metric
|
||||
scope scope
|
||||
promoteScope bool
|
||||
want func() []combinedSample
|
||||
want func() []sample
|
||||
}{
|
||||
{
|
||||
name: "sum without scope promotion",
|
||||
|
|
@ -171,17 +172,17 @@ func TestPrometheusConverter_addSumNumberDataPoints(t *testing.T) {
|
|||
},
|
||||
scope: defaultScope,
|
||||
promoteScope: false,
|
||||
want: func() []combinedSample {
|
||||
want: func() []sample {
|
||||
lbls := labels.FromStrings(
|
||||
model.MetricNameLabel, "test",
|
||||
)
|
||||
return []combinedSample{
|
||||
return []sample{
|
||||
{
|
||||
metricFamilyName: "test",
|
||||
ls: lbls,
|
||||
meta: metadata.Metadata{},
|
||||
t: convertTimeStamp(ts),
|
||||
v: 1,
|
||||
MF: "test",
|
||||
L: lbls,
|
||||
M: metadata.Metadata{},
|
||||
T: convertTimeStamp(ts),
|
||||
V: 1,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
|
@ -198,7 +199,7 @@ func TestPrometheusConverter_addSumNumberDataPoints(t *testing.T) {
|
|||
},
|
||||
scope: defaultScope,
|
||||
promoteScope: true,
|
||||
want: func() []combinedSample {
|
||||
want: func() []sample {
|
||||
lbls := labels.FromStrings(
|
||||
model.MetricNameLabel, "test",
|
||||
"otel_scope_name", defaultScope.name,
|
||||
|
|
@ -207,13 +208,13 @@ func TestPrometheusConverter_addSumNumberDataPoints(t *testing.T) {
|
|||
"otel_scope_attr1", "value1",
|
||||
"otel_scope_attr2", "value2",
|
||||
)
|
||||
return []combinedSample{
|
||||
return []sample{
|
||||
{
|
||||
metricFamilyName: "test",
|
||||
ls: lbls,
|
||||
meta: metadata.Metadata{},
|
||||
t: convertTimeStamp(ts),
|
||||
v: 1,
|
||||
MF: "test",
|
||||
L: lbls,
|
||||
M: metadata.Metadata{},
|
||||
T: convertTimeStamp(ts),
|
||||
V: 1,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
|
@ -232,18 +233,18 @@ func TestPrometheusConverter_addSumNumberDataPoints(t *testing.T) {
|
|||
},
|
||||
scope: defaultScope,
|
||||
promoteScope: false,
|
||||
want: func() []combinedSample {
|
||||
want: func() []sample {
|
||||
lbls := labels.FromStrings(
|
||||
model.MetricNameLabel, "test",
|
||||
)
|
||||
return []combinedSample{
|
||||
return []sample{
|
||||
{
|
||||
metricFamilyName: "test",
|
||||
ls: lbls,
|
||||
meta: metadata.Metadata{},
|
||||
t: convertTimeStamp(ts),
|
||||
v: 1,
|
||||
es: []exemplar.Exemplar{
|
||||
MF: "test",
|
||||
L: lbls,
|
||||
M: metadata.Metadata{},
|
||||
T: convertTimeStamp(ts),
|
||||
V: 1,
|
||||
ES: []exemplar.Exemplar{
|
||||
{Value: 2},
|
||||
},
|
||||
},
|
||||
|
|
@ -267,18 +268,18 @@ func TestPrometheusConverter_addSumNumberDataPoints(t *testing.T) {
|
|||
},
|
||||
scope: defaultScope,
|
||||
promoteScope: false,
|
||||
want: func() []combinedSample {
|
||||
want: func() []sample {
|
||||
lbls := labels.FromStrings(
|
||||
model.MetricNameLabel, "test_sum",
|
||||
)
|
||||
return []combinedSample{
|
||||
return []sample{
|
||||
{
|
||||
metricFamilyName: "test_sum",
|
||||
ls: lbls,
|
||||
meta: metadata.Metadata{},
|
||||
t: convertTimeStamp(ts),
|
||||
st: convertTimeStamp(ts),
|
||||
v: 1,
|
||||
MF: "test_sum",
|
||||
L: lbls,
|
||||
M: metadata.Metadata{},
|
||||
T: convertTimeStamp(ts),
|
||||
ST: convertTimeStamp(ts),
|
||||
V: 1,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
|
@ -298,17 +299,17 @@ func TestPrometheusConverter_addSumNumberDataPoints(t *testing.T) {
|
|||
},
|
||||
scope: defaultScope,
|
||||
promoteScope: false,
|
||||
want: func() []combinedSample {
|
||||
want: func() []sample {
|
||||
lbls := labels.FromStrings(
|
||||
model.MetricNameLabel, "test_sum",
|
||||
)
|
||||
return []combinedSample{
|
||||
return []sample{
|
||||
{
|
||||
metricFamilyName: "test_sum",
|
||||
ls: lbls,
|
||||
meta: metadata.Metadata{},
|
||||
t: convertTimeStamp(ts),
|
||||
v: 0,
|
||||
MF: "test_sum",
|
||||
L: lbls,
|
||||
M: metadata.Metadata{},
|
||||
T: convertTimeStamp(ts),
|
||||
V: 0,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
|
@ -328,17 +329,17 @@ func TestPrometheusConverter_addSumNumberDataPoints(t *testing.T) {
|
|||
},
|
||||
scope: defaultScope,
|
||||
promoteScope: false,
|
||||
want: func() []combinedSample {
|
||||
want: func() []sample {
|
||||
lbls := labels.FromStrings(
|
||||
model.MetricNameLabel, "test_sum",
|
||||
)
|
||||
return []combinedSample{
|
||||
return []sample{
|
||||
{
|
||||
metricFamilyName: "test_sum",
|
||||
ls: lbls,
|
||||
meta: metadata.Metadata{},
|
||||
t: convertTimeStamp(ts),
|
||||
v: 0,
|
||||
MF: "test_sum",
|
||||
L: lbls,
|
||||
M: metadata.Metadata{},
|
||||
T: convertTimeStamp(ts),
|
||||
V: 0,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
|
@ -347,8 +348,9 @@ func TestPrometheusConverter_addSumNumberDataPoints(t *testing.T) {
|
|||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
metric := tt.metric()
|
||||
mockAppender := &mockCombinedAppender{}
|
||||
converter := NewPrometheusConverter(mockAppender)
|
||||
appTest := teststorage.NewAppendable()
|
||||
app := appTest.AppenderV2(t.Context())
|
||||
converter := NewPrometheusConverter(app)
|
||||
settings := Settings{
|
||||
PromoteScopeMetadata: tt.promoteScope,
|
||||
}
|
||||
|
|
@ -366,9 +368,8 @@ func TestPrometheusConverter_addSumNumberDataPoints(t *testing.T) {
|
|||
MetricFamilyName: metric.Name(),
|
||||
},
|
||||
)
|
||||
require.NoError(t, mockAppender.Commit())
|
||||
|
||||
requireEqual(t, tt.want(), mockAppender.samples)
|
||||
require.NoError(t, app.Commit())
|
||||
teststorage.RequireEqual(t, tt.want(), appTest.ResultSamples())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue