Skip to content

Commit 686721c

Browse files
authored
chore: prom translation fix metric comparison func (#35763)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue #35741 Fixes Wrong comparison func implement in translator/prometheusremotewrite. <!--Describe what testing was performed and which tests were added.--> #### Testing <!--Describe the documentation added.--> #### Documentation <!--Please delete paragraphs that you did not use before submitting.--> Signed-off-by: Juraj Michalek <[email protected]>
1 parent 0986213 commit 686721c

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: pkg/translator/prometheusremotewrite
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Fix metric comparison func in prom translation layer
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [35741]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

pkg/translator/prometheusremotewrite/metrics_to_prw.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func isSameMetric(ts *prompb.TimeSeries, lbls []prompb.Label) bool {
155155
return false
156156
}
157157
for i, l := range ts.Labels {
158-
if l.Name != ts.Labels[i].Name || l.Value != ts.Labels[i].Value {
158+
if l.Name != lbls[i].Name || l.Value != lbls[i].Value {
159159
return false
160160
}
161161
}

pkg/translator/prometheusremotewrite/metrics_to_prw_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"testing"
99
"time"
1010

11+
"github.com/prometheus/prometheus/prompb"
12+
"github.com/stretchr/testify/assert"
1113
"github.com/stretchr/testify/require"
1214
"go.opentelemetry.io/collector/pdata/pcommon"
1315
"go.opentelemetry.io/collector/pdata/pmetric"
@@ -156,3 +158,46 @@ func generateExemplars(exemplars pmetric.ExemplarSlice, count int, ts pcommon.Ti
156158
e.SetTraceID(pcommon.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f})
157159
}
158160
}
161+
162+
func TestIsSameMetric(t *testing.T) {
163+
tests := []struct {
164+
name string
165+
labels func() []prompb.Label
166+
ts func() *prompb.TimeSeries
167+
same bool
168+
}{
169+
{
170+
name: "same",
171+
same: true,
172+
labels: func() []prompb.Label {
173+
return getPromLabels(label11, value11, label12, value12)
174+
},
175+
ts: func() *prompb.TimeSeries {
176+
return getTimeSeries(
177+
getPromLabels(label11, value11, label12, value12),
178+
getSample(float64(intVal1), msTime1),
179+
)
180+
},
181+
},
182+
{
183+
name: "not_same",
184+
same: false,
185+
labels: func() []prompb.Label {
186+
return getPromLabels(label11, value11, label12, value12)
187+
},
188+
ts: func() *prompb.TimeSeries {
189+
return getTimeSeries(
190+
getPromLabels(label11, value11, label21, value21),
191+
getSample(float64(intVal1), msTime1),
192+
)
193+
},
194+
},
195+
}
196+
197+
for _, tt := range tests {
198+
t.Run(tt.name, func(t *testing.T) {
199+
same := isSameMetric(tt.ts(), tt.labels())
200+
assert.Equal(t, tt.same, same)
201+
})
202+
}
203+
}

0 commit comments

Comments
 (0)