mirror of
https://github.com/prometheus/prometheus.git
synced 2025-08-06 14:17:12 +02:00
Remove golangci-lint exclusions for OTLP code (#16250)
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
parent
c90b387d89
commit
f5f22e7201
@ -40,10 +40,6 @@ issues:
|
|||||||
exclude-files:
|
exclude-files:
|
||||||
# Skip autogenerated files.
|
# Skip autogenerated files.
|
||||||
- ^.*\.(pb|y)\.go$
|
- ^.*\.(pb|y)\.go$
|
||||||
exclude-dirs:
|
|
||||||
# Copied it from a different source.
|
|
||||||
- storage/remote/otlptranslator/prometheusremotewrite
|
|
||||||
- storage/remote/otlptranslator/prometheus
|
|
||||||
exclude-rules:
|
exclude-rules:
|
||||||
- linters:
|
- linters:
|
||||||
- errcheck
|
- errcheck
|
||||||
|
@ -116,7 +116,8 @@ var seps = []byte{'\xff'}
|
|||||||
// if logOnOverwrite is true, the overwrite is logged. Resulting label names are sanitized.
|
// if logOnOverwrite is true, the overwrite is logged. Resulting label names are sanitized.
|
||||||
// If settings.PromoteResourceAttributes is not empty, it's a set of resource attributes that should be promoted to labels.
|
// If settings.PromoteResourceAttributes is not empty, it's a set of resource attributes that should be promoted to labels.
|
||||||
func createAttributes(resource pcommon.Resource, attributes pcommon.Map, settings Settings,
|
func createAttributes(resource pcommon.Resource, attributes pcommon.Map, settings Settings,
|
||||||
ignoreAttrs []string, logOnOverwrite bool, extras ...string) []prompb.Label {
|
ignoreAttrs []string, logOnOverwrite bool, extras ...string,
|
||||||
|
) []prompb.Label {
|
||||||
resourceAttrs := resource.Attributes()
|
resourceAttrs := resource.Attributes()
|
||||||
serviceName, haveServiceName := resourceAttrs.Get(conventions.AttributeServiceName)
|
serviceName, haveServiceName := resourceAttrs.Get(conventions.AttributeServiceName)
|
||||||
instance, haveInstanceID := resourceAttrs.Get(conventions.AttributeServiceInstanceID)
|
instance, haveInstanceID := resourceAttrs.Get(conventions.AttributeServiceInstanceID)
|
||||||
@ -248,7 +249,8 @@ func isValidAggregationTemporality(metric pmetric.Metric) bool {
|
|||||||
// However, work is under way to resolve this shortcoming through a feature called native histograms custom buckets:
|
// However, work is under way to resolve this shortcoming through a feature called native histograms custom buckets:
|
||||||
// https://github.com/prometheus/prometheus/issues/13485.
|
// https://github.com/prometheus/prometheus/issues/13485.
|
||||||
func (c *PrometheusConverter) addHistogramDataPoints(ctx context.Context, dataPoints pmetric.HistogramDataPointSlice,
|
func (c *PrometheusConverter) addHistogramDataPoints(ctx context.Context, dataPoints pmetric.HistogramDataPointSlice,
|
||||||
resource pcommon.Resource, settings Settings, baseName string) error {
|
resource pcommon.Resource, settings Settings, baseName string,
|
||||||
|
) error {
|
||||||
for x := 0; x < dataPoints.Len(); x++ {
|
for x := 0; x < dataPoints.Len(); x++ {
|
||||||
if err := c.everyN.checkContext(ctx); err != nil {
|
if err := c.everyN.checkContext(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -272,7 +274,6 @@ func (c *PrometheusConverter) addHistogramDataPoints(ctx context.Context, dataPo
|
|||||||
|
|
||||||
sumlabels := createLabels(baseName+sumStr, baseLabels)
|
sumlabels := createLabels(baseName+sumStr, baseLabels)
|
||||||
c.addSample(sum, sumlabels)
|
c.addSample(sum, sumlabels)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// treat count as a sample in an individual TimeSeries
|
// treat count as a sample in an individual TimeSeries
|
||||||
@ -412,7 +413,7 @@ func getPromExemplars[T exemplarType](ctx context.Context, everyN *everyNTimes,
|
|||||||
return promExemplars, nil
|
return promExemplars, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// mostRecentTimestampInMetric returns the latest timestamp in a batch of metrics
|
// mostRecentTimestampInMetric returns the latest timestamp in a batch of metrics.
|
||||||
func mostRecentTimestampInMetric(metric pmetric.Metric) pcommon.Timestamp {
|
func mostRecentTimestampInMetric(metric pmetric.Metric) pcommon.Timestamp {
|
||||||
var ts pcommon.Timestamp
|
var ts pcommon.Timestamp
|
||||||
// handle individual metric based on type
|
// handle individual metric based on type
|
||||||
@ -448,7 +449,8 @@ func mostRecentTimestampInMetric(metric pmetric.Metric) pcommon.Timestamp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *PrometheusConverter) addSummaryDataPoints(ctx context.Context, dataPoints pmetric.SummaryDataPointSlice, resource pcommon.Resource,
|
func (c *PrometheusConverter) addSummaryDataPoints(ctx context.Context, dataPoints pmetric.SummaryDataPointSlice, resource pcommon.Resource,
|
||||||
settings Settings, baseName string) error {
|
settings Settings, baseName string,
|
||||||
|
) error {
|
||||||
for x := 0; x < dataPoints.Len(); x++ {
|
for x := 0; x < dataPoints.Len(); x++ {
|
||||||
if err := c.everyN.checkContext(ctx); err != nil {
|
if err := c.everyN.checkContext(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -562,7 +564,7 @@ func (c *PrometheusConverter) getOrCreateTimeSeries(lbls []prompb.Label) (*promp
|
|||||||
// addTimeSeriesIfNeeded adds a corresponding time series if it doesn't already exist.
|
// addTimeSeriesIfNeeded adds a corresponding time series if it doesn't already exist.
|
||||||
// If the time series doesn't already exist, it gets added with startTimestamp for its value and timestamp for its timestamp,
|
// If the time series doesn't already exist, it gets added with startTimestamp for its value and timestamp for its timestamp,
|
||||||
// both converted to milliseconds.
|
// both converted to milliseconds.
|
||||||
func (c *PrometheusConverter) addTimeSeriesIfNeeded(lbls []prompb.Label, startTimestamp pcommon.Timestamp, timestamp pcommon.Timestamp) {
|
func (c *PrometheusConverter) addTimeSeriesIfNeeded(lbls []prompb.Label, startTimestamp, timestamp pcommon.Timestamp) {
|
||||||
ts, created := c.getOrCreateTimeSeries(lbls)
|
ts, created := c.getOrCreateTimeSeries(lbls)
|
||||||
if created {
|
if created {
|
||||||
ts.Samples = []prompb.Sample{
|
ts.Samples = []prompb.Sample{
|
||||||
@ -631,7 +633,7 @@ func addResourceTargetInfo(resource pcommon.Resource, settings Settings, timesta
|
|||||||
converter.addSample(sample, labels)
|
converter.addSample(sample, labels)
|
||||||
}
|
}
|
||||||
|
|
||||||
// convertTimeStamp converts OTLP timestamp in ns to timestamp in ms
|
// convertTimeStamp converts OTLP timestamp in ns to timestamp in ms.
|
||||||
func convertTimeStamp(timestamp pcommon.Timestamp) int64 {
|
func convertTimeStamp(timestamp pcommon.Timestamp) int64 {
|
||||||
return int64(timestamp) / 1_000_000
|
return int64(timestamp) / 1_000_000
|
||||||
}
|
}
|
||||||
|
@ -21,11 +21,11 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"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/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/prometheus/prometheus/prompb"
|
"github.com/prometheus/prometheus/prompb"
|
||||||
)
|
)
|
||||||
@ -204,7 +204,7 @@ func TestCreateAttributes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
lbls := createAttributes(resource, attrs, settings, tc.ignoreAttrs, false, model.MetricNameLabel, "test_metric")
|
lbls := createAttributes(resource, attrs, settings, tc.ignoreAttrs, false, model.MetricNameLabel, "test_metric")
|
||||||
|
|
||||||
assert.ElementsMatch(t, lbls, tc.expectedLabels)
|
require.ElementsMatch(t, lbls, tc.expectedLabels)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -222,7 +222,7 @@ func Test_convertTimeStamp(t *testing.T) {
|
|||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
got := convertTimeStamp(tt.arg)
|
got := convertTimeStamp(tt.arg)
|
||||||
assert.Equal(t, tt.want, got)
|
require.Equal(t, tt.want, got)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -330,8 +330,8 @@ func TestPrometheusConverter_AddSummaryDataPoints(t *testing.T) {
|
|||||||
metric.Name(),
|
metric.Name(),
|
||||||
)
|
)
|
||||||
|
|
||||||
assert.Equal(t, tt.want(), converter.unique)
|
require.Equal(t, tt.want(), converter.unique)
|
||||||
assert.Empty(t, converter.conflicts)
|
require.Empty(t, converter.conflicts)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -441,8 +441,8 @@ func TestPrometheusConverter_AddHistogramDataPoints(t *testing.T) {
|
|||||||
metric.Name(),
|
metric.Name(),
|
||||||
)
|
)
|
||||||
|
|
||||||
assert.Equal(t, tt.want(), converter.unique)
|
require.Equal(t, tt.want(), converter.unique)
|
||||||
assert.Empty(t, converter.conflicts)
|
require.Empty(t, converter.conflicts)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -457,9 +457,9 @@ func TestGetPromExemplars(t *testing.T) {
|
|||||||
exemplar.SetTimestamp(pcommon.Timestamp(time.Now().UnixNano()))
|
exemplar.SetTimestamp(pcommon.Timestamp(time.Now().UnixNano()))
|
||||||
exemplar.SetIntValue(42)
|
exemplar.SetIntValue(42)
|
||||||
exemplars, err := getPromExemplars(ctx, everyN, pt)
|
exemplars, err := getPromExemplars(ctx, everyN, pt)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Len(t, exemplars, 1)
|
require.Len(t, exemplars, 1)
|
||||||
assert.Equal(t, float64(42), exemplars[0].Value)
|
require.Equal(t, float64(42), exemplars[0].Value)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Exemplars with double value", func(t *testing.T) {
|
t.Run("Exemplars with double value", func(t *testing.T) {
|
||||||
@ -468,9 +468,9 @@ func TestGetPromExemplars(t *testing.T) {
|
|||||||
exemplar.SetTimestamp(pcommon.Timestamp(time.Now().UnixNano()))
|
exemplar.SetTimestamp(pcommon.Timestamp(time.Now().UnixNano()))
|
||||||
exemplar.SetDoubleValue(69.420)
|
exemplar.SetDoubleValue(69.420)
|
||||||
exemplars, err := getPromExemplars(ctx, everyN, pt)
|
exemplars, err := getPromExemplars(ctx, everyN, pt)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Len(t, exemplars, 1)
|
require.Len(t, exemplars, 1)
|
||||||
assert.Equal(t, 69.420, exemplars[0].Value)
|
require.Equal(t, 69.420, exemplars[0].Value)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Exemplars with unsupported value type", func(t *testing.T) {
|
t.Run("Exemplars with unsupported value type", func(t *testing.T) {
|
||||||
@ -478,6 +478,6 @@ func TestGetPromExemplars(t *testing.T) {
|
|||||||
exemplar := pt.Exemplars().AppendEmpty()
|
exemplar := pt.Exemplars().AppendEmpty()
|
||||||
exemplar.SetTimestamp(pcommon.Timestamp(time.Now().UnixNano()))
|
exemplar.SetTimestamp(pcommon.Timestamp(time.Now().UnixNano()))
|
||||||
_, err := getPromExemplars(ctx, everyN, pt)
|
_, err := getPromExemplars(ctx, everyN, pt)
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -19,13 +19,13 @@ package prometheusremotewrite
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/prometheus/prometheus/model/histogram"
|
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
"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/prometheus/prometheus/model/histogram"
|
||||||
"github.com/prometheus/prometheus/model/value"
|
"github.com/prometheus/prometheus/model/value"
|
||||||
"github.com/prometheus/prometheus/prompb"
|
"github.com/prometheus/prometheus/prompb"
|
||||||
"github.com/prometheus/prometheus/util/annotations"
|
"github.com/prometheus/prometheus/util/annotations"
|
||||||
@ -36,7 +36,8 @@ const defaultZeroThreshold = 1e-128
|
|||||||
// addExponentialHistogramDataPoints adds OTel exponential histogram data points to the corresponding time series
|
// addExponentialHistogramDataPoints adds OTel exponential histogram data points to the corresponding time series
|
||||||
// as native histogram samples.
|
// as native histogram samples.
|
||||||
func (c *PrometheusConverter) addExponentialHistogramDataPoints(ctx context.Context, dataPoints pmetric.ExponentialHistogramDataPointSlice,
|
func (c *PrometheusConverter) addExponentialHistogramDataPoints(ctx context.Context, dataPoints pmetric.ExponentialHistogramDataPointSlice,
|
||||||
resource pcommon.Resource, settings Settings, promName string) (annotations.Annotations, error) {
|
resource pcommon.Resource, settings Settings, promName string,
|
||||||
|
) (annotations.Annotations, error) {
|
||||||
var annots annotations.Annotations
|
var annots annotations.Annotations
|
||||||
for x := 0; x < dataPoints.Len(); x++ {
|
for x := 0; x < dataPoints.Len(); x++ {
|
||||||
if err := c.everyN.checkContext(ctx); err != nil {
|
if err := c.everyN.checkContext(ctx); err != nil {
|
||||||
@ -151,7 +152,7 @@ func exponentialToNativeHistogram(p pmetric.ExponentialHistogramDataPoint) (prom
|
|||||||
//
|
//
|
||||||
// When converting from OTel Explicit Histograms to Native Histograms with Custom Buckets,
|
// When converting from OTel Explicit Histograms to Native Histograms with Custom Buckets,
|
||||||
// the bucket indexes are not scaled, and the indices are not adjusted by 1.
|
// the bucket indexes are not scaled, and the indices are not adjusted by 1.
|
||||||
func convertBucketsLayout(bucketCounts []uint64, offset int32, scaleDown int32, adjustOffset bool) ([]prompb.BucketSpan, []int64) {
|
func convertBucketsLayout(bucketCounts []uint64, offset, scaleDown int32, adjustOffset bool) ([]prompb.BucketSpan, []int64) {
|
||||||
if len(bucketCounts) == 0 {
|
if len(bucketCounts) == 0 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@ -240,7 +241,8 @@ func convertBucketsLayout(bucketCounts []uint64, offset int32, scaleDown int32,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *PrometheusConverter) addCustomBucketsHistogramDataPoints(ctx context.Context, dataPoints pmetric.HistogramDataPointSlice,
|
func (c *PrometheusConverter) addCustomBucketsHistogramDataPoints(ctx context.Context, dataPoints pmetric.HistogramDataPointSlice,
|
||||||
resource pcommon.Resource, settings Settings, promName string) (annotations.Annotations, error) {
|
resource pcommon.Resource, settings Settings, promName string,
|
||||||
|
) (annotations.Annotations, error) {
|
||||||
var annots annotations.Annotations
|
var annots annotations.Annotations
|
||||||
|
|
||||||
for x := 0; x < dataPoints.Len(); x++ {
|
for x := 0; x < dataPoints.Len(); x++ {
|
||||||
|
@ -24,7 +24,6 @@ import (
|
|||||||
|
|
||||||
"github.com/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
"github.com/prometheus/otlptranslator"
|
"github.com/prometheus/otlptranslator"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"go.opentelemetry.io/collector/pdata/pcommon"
|
"go.opentelemetry.io/collector/pdata/pcommon"
|
||||||
"go.opentelemetry.io/collector/pdata/pmetric"
|
"go.opentelemetry.io/collector/pdata/pmetric"
|
||||||
@ -380,8 +379,8 @@ func TestConvertBucketsLayout(t *testing.T) {
|
|||||||
for scaleDown, wantLayout := range tt.wantLayout {
|
for scaleDown, wantLayout := range tt.wantLayout {
|
||||||
t.Run(fmt.Sprintf("%s-scaleby-%d", tt.name, scaleDown), func(t *testing.T) {
|
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)
|
gotSpans, gotDeltas := convertBucketsLayout(tt.buckets().BucketCounts().AsRaw(), tt.buckets().Offset(), scaleDown, true)
|
||||||
assert.Equal(t, wantLayout.wantSpans, gotSpans)
|
require.Equal(t, wantLayout.wantSpans, gotSpans)
|
||||||
assert.Equal(t, wantLayout.wantDeltas, gotDeltas)
|
require.Equal(t, wantLayout.wantDeltas, gotDeltas)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -569,13 +568,13 @@ func TestExponentialToNativeHistogram(t *testing.T) {
|
|||||||
validateExponentialHistogramCount(t, tt.exponentialHist()) // Sanity check.
|
validateExponentialHistogramCount(t, tt.exponentialHist()) // Sanity check.
|
||||||
got, annots, err := exponentialToNativeHistogram(tt.exponentialHist())
|
got, annots, err := exponentialToNativeHistogram(tt.exponentialHist())
|
||||||
if tt.wantErrMessage != "" {
|
if tt.wantErrMessage != "" {
|
||||||
assert.ErrorContains(t, err, tt.wantErrMessage)
|
require.ErrorContains(t, err, tt.wantErrMessage)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Empty(t, annots)
|
require.Empty(t, annots)
|
||||||
assert.Equal(t, tt.wantNativeHist(), got)
|
require.Equal(t, tt.wantNativeHist(), got)
|
||||||
validateNativeHistogramCount(t, got)
|
validateNativeHistogramCount(t, got)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -617,7 +616,7 @@ func validateNativeHistogramCount(t *testing.T, h prompb.Histogram) {
|
|||||||
prevBucket += delta
|
prevBucket += delta
|
||||||
actualCount += uint64(prevBucket)
|
actualCount += uint64(prevBucket)
|
||||||
}
|
}
|
||||||
assert.Equal(t, want, actualCount, "native histogram count mismatch")
|
require.Equal(t, want, actualCount, "native histogram count mismatch")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrometheusConverter_addExponentialHistogramDataPoints(t *testing.T) {
|
func TestPrometheusConverter_addExponentialHistogramDataPoints(t *testing.T) {
|
||||||
@ -774,8 +773,8 @@ func TestPrometheusConverter_addExponentialHistogramDataPoints(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Empty(t, annots)
|
require.Empty(t, annots)
|
||||||
|
|
||||||
assert.Equal(t, tt.wantSeries(), converter.unique)
|
require.Equal(t, tt.wantSeries(), converter.unique)
|
||||||
assert.Empty(t, converter.conflicts)
|
require.Empty(t, converter.conflicts)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -814,7 +813,7 @@ func TestConvertExplicitHistogramBucketsToNHCBLayout(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "trailing empty buckets",
|
name: "trailing empty buckets",
|
||||||
buckets: []uint64{0, 0, 1, 1, 2, 3, 0, 0}, //TODO: add tests for 3 trailing buckets
|
buckets: []uint64{0, 0, 1, 1, 2, 3, 0, 0}, // TODO: add tests for 3 trailing buckets
|
||||||
wantLayout: expectedBucketLayout{
|
wantLayout: expectedBucketLayout{
|
||||||
wantSpans: []prompb.BucketSpan{
|
wantSpans: []prompb.BucketSpan{
|
||||||
{
|
{
|
||||||
@ -880,8 +879,8 @@ func TestConvertExplicitHistogramBucketsToNHCBLayout(t *testing.T) {
|
|||||||
bucketCounts := buckets[offset:]
|
bucketCounts := buckets[offset:]
|
||||||
|
|
||||||
gotSpans, gotDeltas := convertBucketsLayout(bucketCounts, int32(offset), 0, false)
|
gotSpans, gotDeltas := convertBucketsLayout(bucketCounts, int32(offset), 0, false)
|
||||||
assert.Equal(t, tt.wantLayout.wantSpans, gotSpans)
|
require.Equal(t, tt.wantLayout.wantSpans, gotSpans)
|
||||||
assert.Equal(t, tt.wantLayout.wantDeltas, gotDeltas)
|
require.Equal(t, tt.wantLayout.wantDeltas, gotDeltas)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -975,13 +974,13 @@ func TestHistogramToCustomBucketsHistogram(t *testing.T) {
|
|||||||
validateHistogramCount(t, tt.hist())
|
validateHistogramCount(t, tt.hist())
|
||||||
got, annots, err := explicitHistogramToCustomBucketsHistogram(tt.hist())
|
got, annots, err := explicitHistogramToCustomBucketsHistogram(tt.hist())
|
||||||
if tt.wantErrMessage != "" {
|
if tt.wantErrMessage != "" {
|
||||||
assert.ErrorContains(t, err, tt.wantErrMessage)
|
require.ErrorContains(t, err, tt.wantErrMessage)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Empty(t, annots)
|
require.Empty(t, annots)
|
||||||
assert.Equal(t, tt.wantNativeHist(), got)
|
require.Equal(t, tt.wantNativeHist(), got)
|
||||||
validateNativeHistogramCount(t, got)
|
validateNativeHistogramCount(t, got)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -1143,8 +1142,8 @@ func TestPrometheusConverter_addCustomBucketsHistogramDataPoints(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Empty(t, annots)
|
require.Empty(t, annots)
|
||||||
|
|
||||||
assert.Equal(t, tt.wantSeries(), converter.unique)
|
require.Equal(t, tt.wantSeries(), converter.unique)
|
||||||
assert.Empty(t, converter.conflicts)
|
require.Empty(t, converter.conflicts)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,12 +72,12 @@ func TestFromMetrics(t *testing.T) {
|
|||||||
ts := converter.TimeSeries()
|
ts := converter.TimeSeries()
|
||||||
require.Len(t, ts, 1408+1) // +1 for the target_info.
|
require.Len(t, ts, 1408+1) // +1 for the target_info.
|
||||||
|
|
||||||
target_info_count := 0
|
tgtInfoCount := 0
|
||||||
for _, s := range ts {
|
for _, s := range ts {
|
||||||
b := labels.NewScratchBuilder(2)
|
b := labels.NewScratchBuilder(2)
|
||||||
lbls := s.ToLabels(&b, nil)
|
lbls := s.ToLabels(&b, nil)
|
||||||
if lbls.Get(labels.MetricName) == "target_info" {
|
if lbls.Get(labels.MetricName) == "target_info" {
|
||||||
target_info_count++
|
tgtInfoCount++
|
||||||
require.Equal(t, "test-namespace/test-service", lbls.Get("job"))
|
require.Equal(t, "test-namespace/test-service", lbls.Get("job"))
|
||||||
require.Equal(t, "id1234", lbls.Get("instance"))
|
require.Equal(t, "id1234", lbls.Get("instance"))
|
||||||
if keepIdentifyingResourceAttributes {
|
if keepIdentifyingResourceAttributes {
|
||||||
@ -91,7 +91,7 @@ func TestFromMetrics(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
require.Equal(t, 1, target_info_count)
|
require.Equal(t, 1, tgtInfoCount)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ func TestFromMetrics(t *testing.T) {
|
|||||||
|
|
||||||
if convertHistogramsToNHCB {
|
if convertHistogramsToNHCB {
|
||||||
require.Len(t, series[0].Histograms, 1)
|
require.Len(t, series[0].Histograms, 1)
|
||||||
require.Len(t, series[0].Samples, 0)
|
require.Empty(t, series[0].Samples)
|
||||||
} else {
|
} else {
|
||||||
require.Len(t, series, 3)
|
require.Len(t, series, 3)
|
||||||
for i := range series {
|
for i := range series {
|
||||||
|
@ -29,7 +29,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (c *PrometheusConverter) addGaugeNumberDataPoints(ctx context.Context, dataPoints pmetric.NumberDataPointSlice,
|
func (c *PrometheusConverter) addGaugeNumberDataPoints(ctx context.Context, dataPoints pmetric.NumberDataPointSlice,
|
||||||
resource pcommon.Resource, settings Settings, name string) error {
|
resource pcommon.Resource, settings Settings, name string,
|
||||||
|
) error {
|
||||||
for x := 0; x < dataPoints.Len(); x++ {
|
for x := 0; x < dataPoints.Len(); x++ {
|
||||||
if err := c.everyN.checkContext(ctx); err != nil {
|
if err := c.everyN.checkContext(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -65,7 +66,8 @@ func (c *PrometheusConverter) addGaugeNumberDataPoints(ctx context.Context, data
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *PrometheusConverter) addSumNumberDataPoints(ctx context.Context, dataPoints pmetric.NumberDataPointSlice,
|
func (c *PrometheusConverter) addSumNumberDataPoints(ctx context.Context, dataPoints pmetric.NumberDataPointSlice,
|
||||||
resource pcommon.Resource, metric pmetric.Metric, settings Settings, name string) error {
|
resource pcommon.Resource, metric pmetric.Metric, settings Settings, name string,
|
||||||
|
) error {
|
||||||
for x := 0; x < dataPoints.Len(); x++ {
|
for x := 0; x < dataPoints.Len(); x++ {
|
||||||
if err := c.everyN.checkContext(ctx); err != nil {
|
if err := c.everyN.checkContext(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -22,7 +22,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
"go.opentelemetry.io/collector/pdata/pcommon"
|
"go.opentelemetry.io/collector/pdata/pcommon"
|
||||||
"go.opentelemetry.io/collector/pdata/pmetric"
|
"go.opentelemetry.io/collector/pdata/pmetric"
|
||||||
|
|
||||||
@ -56,7 +56,8 @@ func TestPrometheusConverter_addGaugeNumberDataPoints(t *testing.T) {
|
|||||||
{
|
{
|
||||||
Value: 1,
|
Value: 1,
|
||||||
Timestamp: convertTimeStamp(pcommon.Timestamp(ts)),
|
Timestamp: convertTimeStamp(pcommon.Timestamp(ts)),
|
||||||
}},
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -77,8 +78,8 @@ func TestPrometheusConverter_addGaugeNumberDataPoints(t *testing.T) {
|
|||||||
metric.Name(),
|
metric.Name(),
|
||||||
)
|
)
|
||||||
|
|
||||||
assert.Equal(t, tt.want(), converter.unique)
|
require.Equal(t, tt.want(), converter.unique)
|
||||||
assert.Empty(t, converter.conflicts)
|
require.Empty(t, converter.conflicts)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -111,7 +112,8 @@ func TestPrometheusConverter_addSumNumberDataPoints(t *testing.T) {
|
|||||||
{
|
{
|
||||||
Value: 1,
|
Value: 1,
|
||||||
Timestamp: convertTimeStamp(ts),
|
Timestamp: convertTimeStamp(ts),
|
||||||
}},
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -255,8 +257,8 @@ func TestPrometheusConverter_addSumNumberDataPoints(t *testing.T) {
|
|||||||
metric.Name(),
|
metric.Name(),
|
||||||
)
|
)
|
||||||
|
|
||||||
assert.Equal(t, tt.want(), converter.unique)
|
require.Equal(t, tt.want(), converter.unique)
|
||||||
assert.Empty(t, converter.conflicts)
|
require.Empty(t, converter.conflicts)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user