Skip to content

Commit

Permalink
chore: prom translation fix metric comparison func (#35763)
Browse files Browse the repository at this point in the history
<!--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]>
  • Loading branch information
jmichalek132 authored Oct 16, 2024
1 parent 0986213 commit 686721c
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
27 changes: 27 additions & 0 deletions .chloggen/jm-prom-translation-fix-comparison-func.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: pkg/translator/prometheusremotewrite

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fix metric comparison func in prom translation layer

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [35741]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
2 changes: 1 addition & 1 deletion pkg/translator/prometheusremotewrite/metrics_to_prw.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func isSameMetric(ts *prompb.TimeSeries, lbls []prompb.Label) bool {
return false
}
for i, l := range ts.Labels {
if l.Name != ts.Labels[i].Name || l.Value != ts.Labels[i].Value {
if l.Name != lbls[i].Name || l.Value != lbls[i].Value {
return false
}
}
Expand Down
45 changes: 45 additions & 0 deletions pkg/translator/prometheusremotewrite/metrics_to_prw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"testing"
"time"

"github.com/prometheus/prometheus/prompb"
"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 @@ -156,3 +158,46 @@ func generateExemplars(exemplars pmetric.ExemplarSlice, count int, ts pcommon.Ti
e.SetTraceID(pcommon.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f})
}
}

func TestIsSameMetric(t *testing.T) {
tests := []struct {
name string
labels func() []prompb.Label
ts func() *prompb.TimeSeries
same bool
}{
{
name: "same",
same: true,
labels: func() []prompb.Label {
return getPromLabels(label11, value11, label12, value12)
},
ts: func() *prompb.TimeSeries {
return getTimeSeries(
getPromLabels(label11, value11, label12, value12),
getSample(float64(intVal1), msTime1),
)
},
},
{
name: "not_same",
same: false,
labels: func() []prompb.Label {
return getPromLabels(label11, value11, label12, value12)
},
ts: func() *prompb.TimeSeries {
return getTimeSeries(
getPromLabels(label11, value11, label21, value21),
getSample(float64(intVal1), msTime1),
)
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
same := isSameMetric(tt.ts(), tt.labels())
assert.Equal(t, tt.same, same)
})
}
}

0 comments on commit 686721c

Please sign in to comment.