Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ywwg committed Feb 4, 2025
1 parent cf81cc3 commit 965694c
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 25 deletions.
2 changes: 1 addition & 1 deletion assets/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/prometheus/common/assets

go 1.21
go 1.22.7

require github.com/stretchr/testify v1.10.0

Expand Down
2 changes: 0 additions & 2 deletions otlptranslator/prometheus/testutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ import (
var ilm pmetric.ScopeMetrics

func init() {

metrics := pmetric.NewMetrics()
resourceMetrics := metrics.ResourceMetrics().AppendEmpty()
ilm = resourceMetrics.ScopeMetrics().AppendEmpty()

}

// Returns a new Metric of type "Gauge" with specified name and unit
Expand Down
9 changes: 3 additions & 6 deletions otlptranslator/prometheusremotewrite/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ var seps = []byte{'\xff'}
// Unpaired string values are ignored. String pairs overwrite OTLP labels if collisions happen and
// 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.
func createAttributes(resource pcommon.Resource, attributes pcommon.Map, settings Settings,
ignoreAttrs []string, logOnOverwrite bool, extras ...string) []prompb.Label {
func createAttributes(resource pcommon.Resource, attributes pcommon.Map, settings Settings, ignoreAttrs []string, logOnOverwrite bool, extras ...string) []prompb.Label {
resourceAttrs := resource.Attributes()
serviceName, haveServiceName := resourceAttrs.Get(conventions.AttributeServiceName)
instance, haveInstanceID := resourceAttrs.Get(conventions.AttributeServiceInstanceID)
Expand Down Expand Up @@ -249,8 +248,7 @@ func isValidAggregationTemporality(metric pmetric.Metric) bool {
// with the user defined bucket boundaries of non-exponential OTel histograms.
// However, work is under way to resolve this shortcoming through a feature called native histograms custom buckets:
// https://github.com/prometheus/prometheus/issues/13485.
func (c *PrometheusConverter) addHistogramDataPoints(ctx context.Context, dataPoints pmetric.HistogramDataPointSlice,
resource pcommon.Resource, settings Settings, baseName string) error {
func (c *PrometheusConverter) addHistogramDataPoints(ctx context.Context, dataPoints pmetric.HistogramDataPointSlice, resource pcommon.Resource, settings Settings, baseName string) error {
for x := 0; x < dataPoints.Len(); x++ {
if err := c.everyN.checkContext(ctx); err != nil {
return err
Expand Down Expand Up @@ -449,8 +447,7 @@ func mostRecentTimestampInMetric(metric pmetric.Metric) pcommon.Timestamp {
return ts
}

func (c *PrometheusConverter) addSummaryDataPoints(ctx context.Context, dataPoints pmetric.SummaryDataPointSlice, resource pcommon.Resource,
settings Settings, baseName string) error {
func (c *PrometheusConverter) addSummaryDataPoints(ctx context.Context, dataPoints pmetric.SummaryDataPointSlice, resource pcommon.Resource, settings Settings, baseName string) error {
for x := 0; x < dataPoints.Len(); x++ {
if err := c.everyN.checkContext(ctx); err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions otlptranslator/prometheusremotewrite/histograms.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"math"

"github.com/prometheus/common/model"

"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"

Expand All @@ -34,8 +35,7 @@ const defaultZeroThreshold = 1e-128

// addExponentialHistogramDataPoints adds OTel exponential histogram data points to the corresponding time series
// as native histogram samples.
func (c *PrometheusConverter) addExponentialHistogramDataPoints(ctx context.Context, dataPoints pmetric.ExponentialHistogramDataPointSlice,
resource pcommon.Resource, settings Settings, promName string) (annotations.Annotations, error) {
func (c *PrometheusConverter) addExponentialHistogramDataPoints(ctx context.Context, dataPoints pmetric.ExponentialHistogramDataPointSlice, resource pcommon.Resource, settings Settings, promName string) (annotations.Annotations, error) {
var annots annotations.Annotations
for x := 0; x < dataPoints.Len(); x++ {
if err := c.everyN.checkContext(ctx); err != nil {
Expand Down
5 changes: 3 additions & 2 deletions otlptranslator/prometheusremotewrite/histograms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"time"

"github.com/prometheus/common/model"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/pdata/pcommon"
Expand Down Expand Up @@ -590,7 +591,7 @@ func validateExponentialHistogramCount(t *testing.T, h pmetric.ExponentialHistog
for _, bucket := range h.Negative().BucketCounts().AsRaw() {
actualCount += bucket
}
require.Equal(t, h.Count(), actualCount, "exponential histogram count mismatch")
require.Equalf(t, h.Count(), actualCount, "exponential histogram count mismatch")
}

func validateNativeHistogramCount(t *testing.T, h prompb.Histogram) {
Expand All @@ -610,7 +611,7 @@ func validateNativeHistogramCount(t *testing.T, h prompb.Histogram) {
prevBucket += delta
actualCount += uint64(prevBucket)
}
assert.Equal(t, want, actualCount, "native histogram count mismatch")
assert.Equalf(t, want, actualCount, "native histogram count mismatch")
}

func TestPrometheusConverter_addExponentialHistogramDataPoints(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion otlptranslator/prometheusremotewrite/metrics_to_prw.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ import (
"fmt"
"sort"

prometheustranslator "github.com/prometheus/common/otlptranslator/prometheus"

"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.uber.org/multierr"

prometheustranslator "github.com/prometheus/common/otlptranslator/prometheus"
"github.com/prometheus/prometheus/prompb"
"github.com/prometheus/prometheus/util/annotations"
)
Expand Down
3 changes: 2 additions & 1 deletion otlptranslator/prometheusremotewrite/metrics_to_prw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ import (
"testing"
"time"

prometheustranslator "github.com/prometheus/common/otlptranslator/prometheus"

"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/pdata/pmetric/pmetricotlp"

prometheustranslator "github.com/prometheus/common/otlptranslator/prometheus"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/prompb"
)
Expand Down
7 changes: 3 additions & 4 deletions otlptranslator/prometheusremotewrite/number_data_points.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import (
"math"

"github.com/prometheus/common/model"

"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"

"github.com/prometheus/prometheus/model/value"
"github.com/prometheus/prometheus/prompb"
)

func (c *PrometheusConverter) addGaugeNumberDataPoints(ctx context.Context, dataPoints pmetric.NumberDataPointSlice,
resource pcommon.Resource, settings Settings, name string) error {
func (c *PrometheusConverter) addGaugeNumberDataPoints(ctx context.Context, dataPoints pmetric.NumberDataPointSlice, resource pcommon.Resource, settings Settings, name string) error {
for x := 0; x < dataPoints.Len(); x++ {
if err := c.everyN.checkContext(ctx); err != nil {
return err
Expand Down Expand Up @@ -64,8 +64,7 @@ func (c *PrometheusConverter) addGaugeNumberDataPoints(ctx context.Context, data
return nil
}

func (c *PrometheusConverter) addSumNumberDataPoints(ctx context.Context, dataPoints pmetric.NumberDataPointSlice,
resource pcommon.Resource, metric pmetric.Metric, settings Settings, name string) error {
func (c *PrometheusConverter) addSumNumberDataPoints(ctx context.Context, dataPoints pmetric.NumberDataPointSlice, resource pcommon.Resource, metric pmetric.Metric, settings Settings, name string) error {
for x := 0; x < dataPoints.Len(); x++ {
if err := c.everyN.checkContext(ctx); err != nil {
return err
Expand Down
16 changes: 10 additions & 6 deletions otlptranslator/prometheusremotewrite/number_data_points_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import (
"time"

"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/pmetric"

Expand Down Expand Up @@ -56,7 +58,8 @@ func TestPrometheusConverter_addGaugeNumberDataPoints(t *testing.T) {
{
Value: 1,
Timestamp: convertTimeStamp(pcommon.Timestamp(ts)),
}},
},
},
},
}
},
Expand All @@ -67,15 +70,15 @@ func TestPrometheusConverter_addGaugeNumberDataPoints(t *testing.T) {
metric := tt.metric()
converter := NewPrometheusConverter()

converter.addGaugeNumberDataPoints(
require.NoError(t, converter.addGaugeNumberDataPoints(
context.Background(),
metric.Gauge().DataPoints(),
pcommon.NewResource(),
Settings{
ExportCreatedMetric: true,
},
metric.Name(),
)
))

assert.Equal(t, tt.want(), converter.unique)
assert.Empty(t, converter.conflicts)
Expand Down Expand Up @@ -111,7 +114,8 @@ func TestPrometheusConverter_addSumNumberDataPoints(t *testing.T) {
{
Value: 1,
Timestamp: convertTimeStamp(ts),
}},
},
},
},
}
},
Expand Down Expand Up @@ -244,7 +248,7 @@ func TestPrometheusConverter_addSumNumberDataPoints(t *testing.T) {
metric := tt.metric()
converter := NewPrometheusConverter()

converter.addSumNumberDataPoints(
require.NoError(t, converter.addSumNumberDataPoints(
context.Background(),
metric.Sum().DataPoints(),
pcommon.NewResource(),
Expand All @@ -253,7 +257,7 @@ func TestPrometheusConverter_addSumNumberDataPoints(t *testing.T) {
ExportCreatedMetric: true,
},
metric.Name(),
)
))

assert.Equal(t, tt.want(), converter.unique)
assert.Empty(t, converter.conflicts)
Expand Down

0 comments on commit 965694c

Please sign in to comment.