Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,4 @@ go 1.23.0

toolchain go1.24.1

require (
github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc
github.com/stretchr/testify v1.10.0
)

require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
require github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc
23 changes: 0 additions & 23 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,25 +1,2 @@
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc h1:GN2Lv3MGO7AS6PrRoT6yV5+wkrOpcszoIsO4+4ds248=
github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc/go.mod h1:+JKpmjMGhpgPL+rXZ5nsZieVzvarn86asRlBg4uNGnk=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
17 changes: 10 additions & 7 deletions metric_namer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
package otlptranslator

import (
"strings"
"testing"

"github.com/stretchr/testify/require"
)

func TestMetricNamer_Build(t *testing.T) {
Expand Down Expand Up @@ -1101,22 +1100,26 @@ func TestMetricNamer_Build(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
// Build metric name using MetricNamer
gotMetricName := tt.namer.Build(tt.metric)
require.Equal(t, tt.expectedMetricName, gotMetricName)
if tt.expectedMetricName != gotMetricName {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you can rename expected to want

t.Errorf("namer.Build(%v), got %q, want %q", tt.metric, gotMetricName, tt.expectedMetricName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
t.Errorf("namer.Build(%v), got %q, want %q", tt.metric, gotMetricName, tt.expectedMetricName)
t.Errorf("namer.Build(%q) = %q, want %q", tt.metric, gotMetricName, tt.expectedMetricName)

}

// Build unit name using UnitNamer to verify correlation when suffixes are enabled
if tt.namer.WithMetricSuffixes {
unitNamer := UnitNamer{
UTF8Allowed: tt.namer.UTF8Allowed,
}
gotUnitName := unitNamer.Build(tt.metric.Unit)
require.Equal(t, tt.expectedUnitName, gotUnitName)
if tt.expectedUnitName != gotUnitName {
t.Errorf("unitNamer.Build(%q), got %q, want %q", tt.metric.Unit, gotUnitName, tt.expectedUnitName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
t.Errorf("unitNamer.Build(%q), got %q, want %q", tt.metric.Unit, gotUnitName, tt.expectedUnitName)
t.Errorf("unitNamer.Build(%q) = %q, want %q", tt.metric.Unit, gotUnitName, tt.expectedUnitName)

}

// Verify correlation: if UnitNamer produces a non-empty unit name,
// it should be contained in the metric name when WithMetricSuffixes=true
if gotUnitName != "" && tt.namer.WithMetricSuffixes {
require.Contains(t, gotMetricName, gotUnitName,
"Metric name '%s' should contain unit name '%s' when WithMetricSuffixes=true",
gotMetricName, gotUnitName)
if !strings.Contains(gotMetricName, gotUnitName) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can simply add && !strings.Contains(gotMetricName, gotUnitName) to line 1119
I also think that gotUnitName != "" can be omitted.
Then we would have

if tt.namer.WithMetricSuffixes && !strings.Contains(gotMetricName, gotUnitName) {

t.Errorf("Metric name '%q' should contain unit name '%s' when WithMetricSuffixes=true", gotMetricName, gotUnitName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
t.Errorf("Metric name '%q' should contain unit name '%s' when WithMetricSuffixes=true", gotMetricName, gotUnitName)
t.Errorf("Metric name %q should contain unit name %q when WithMetricSuffixes=true", gotMetricName, gotUnitName)

}
}
}
})
Expand Down
10 changes: 6 additions & 4 deletions normalize_label_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ package otlptranslator
import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
)

func TestNormalizeLabel(t *testing.T) {
Expand All @@ -46,9 +44,13 @@ func TestNormalizeLabel(t *testing.T) {
result := labelNamer.Build(test.label)

if utf8Allowed {
require.Equal(t, test.label, result)
if test.label != result {
t.Errorf("labelNamer.Build(%q), got %q, want %q", test.label, result, test.label)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
t.Errorf("labelNamer.Build(%q), got %q, want %q", test.label, result, test.label)
t.Errorf("labelNamer.Build(%q) = %q, want %q", test.label, result, test.label)

}
} else {
require.Equal(t, test.expected, result)
if test.expected != result {
t.Errorf("labelNamer.Build(%q), got %q, want %q", test.label, result, test.expected)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
t.Errorf("labelNamer.Build(%q), got %q, want %q", test.label, result, test.expected)
t.Errorf("labelNamer.Build(%q) = %q, want %q", test.label, result, test.expected)

}
}
})
}
Expand Down