Skip to content

Commit

Permalink
add getPromExemplarsV2 test
Browse files Browse the repository at this point in the history
  • Loading branch information
perebaj committed Jan 15, 2025
1 parent 13ee3b6 commit ab56d0a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
41 changes: 41 additions & 0 deletions pkg/translator/prometheusremotewrite/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/timestamp"
"github.com/prometheus/prometheus/prompb"
writev2 "github.com/prometheus/prometheus/prompb/io/prometheus/write/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/pdata/pcommon"
Expand Down Expand Up @@ -537,6 +538,46 @@ func Test_getPromExemplars(t *testing.T) {
}
}

func Test_getPromExemplarsV2(t *testing.T) {
tnow := time.Now()
tests := []struct {
name string
histogram pmetric.HistogramDataPoint
expected []writev2.Exemplar
}{
{
name: "with_exemplars_double_value",
histogram: getHistogramDataPointWithExemplars(t, tnow, floatVal1, traceIDValue1, spanIDValue1, label11, value11),
expected: []writev2.Exemplar{
{
Value: floatVal1,
Timestamp: timestamp.FromTime(tnow),
// TODO: after deal with examplar labels on getPromExemplarsV2, add the labels here
// LabelsRefs: []uint32{},
},
},
},
{
name: "with_exemplars_int_value",
histogram: getHistogramDataPointWithExemplars(t, tnow, intVal2, traceIDValue1, spanIDValue1, label11, value11),
expected: []writev2.Exemplar{
{
Value: float64(intVal2),
Timestamp: timestamp.FromTime(tnow),
// TODO: after deal with examplar labels on getPromExemplarsV2, add the labels here
// LabelsRefs: []uint32{},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
requests := getPromExemplarsV2(tt.histogram)
assert.Exactly(t, tt.expected, requests)
})
}
}

func TestAddResourceTargetInfo(t *testing.T) {
resourceAttrMap := map[string]any{
conventions.AttributeServiceName: "service-name",
Expand Down
7 changes: 2 additions & 5 deletions pkg/translator/prometheusremotewrite/number_data_points_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,8 @@ func (c *prometheusConverterV2) addSumNumberDataPoints(dataPoints pmetric.Number
if pt.Flags().NoRecordedValue() {
sample.Value = math.Float64frombits(value.StaleNaN)
}
ts := c.addSample(sample, lbls)
if ts != nil {
exemplars := getPromExemplarsV2[pmetric.NumberDataPoint](pt)
ts.Exemplars = append(ts.Exemplars, exemplars...)
}
// TODO: properly add exemplars to the TimeSeries
c.addSample(sample, lbls)

if settings.ExportCreatedMetric && metric.Sum().IsMonotonic() {
startTimestamp := pt.StartTimestamp()
Expand Down

0 comments on commit ab56d0a

Please sign in to comment.