Skip to content

Commit

Permalink
[exporter/prometheusremotewrite] respect integer exemplar values (#36688
Browse files Browse the repository at this point in the history
)

Co-authored-by: Evan Bradley <[email protected]>
  • Loading branch information
perebaj and evan-bradley authored Dec 6, 2024
1 parent 5eedf95 commit 50630c4
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
27 changes: 27 additions & 0 deletions .chloggen/exporter_prometheusremotewriteexporter_exemplar-int.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: exporter/prometheusremotewrite

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fix exemplar handling when the exemplar is an integer value.

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

# (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: Send metrics with exemplars as integer values now are correctly handled.

# 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]
15 changes: 12 additions & 3 deletions pkg/translator/prometheusremotewrite/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,18 @@ func getPromExemplars[T exemplarType](pt T) []prompb.Exemplar {
exemplar := pt.Exemplars().At(i)
exemplarRunes := 0

promExemplar := prompb.Exemplar{
Value: exemplar.DoubleValue(),
Timestamp: timestamp.FromTime(exemplar.Timestamp().AsTime()),
var promExemplar prompb.Exemplar
switch exemplar.ValueType() {
case pmetric.ExemplarValueTypeInt:
promExemplar = prompb.Exemplar{
Value: float64(exemplar.IntValue()),
Timestamp: timestamp.FromTime(exemplar.Timestamp().AsTime()),
}
case pmetric.ExemplarValueTypeDouble:
promExemplar = prompb.Exemplar{
Value: exemplar.DoubleValue(),
Timestamp: timestamp.FromTime(exemplar.Timestamp().AsTime()),
}
}
if traceID := exemplar.TraceID(); !traceID.IsEmpty() {
val := hex.EncodeToString(traceID[:])
Expand Down
11 changes: 11 additions & 0 deletions pkg/translator/prometheusremotewrite/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,17 @@ func Test_getPromExemplars(t *testing.T) {
},
},
},
{
"with_exemplars_int_value",
getHistogramDataPointWithExemplars(t, tnow, intVal2, traceIDValue1, spanIDValue1, label11, value11),
[]prompb.Exemplar{
{
Value: float64(intVal2),
Timestamp: timestamp.FromTime(tnow),
Labels: []prompb.Label{getLabel(prometheustranslator.ExemplarTraceIDKey, traceIDValue1), getLabel(prometheustranslator.ExemplarSpanIDKey, spanIDValue1), getLabel(label11, value11)},
},
},
},
{
"too_many_runes_drops_labels",
getHistogramDataPointWithExemplars(t, tnow, floatVal1, "", "", keyWith129Runes, ""),
Expand Down
9 changes: 7 additions & 2 deletions pkg/translator/prometheusremotewrite/testutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,16 @@ func getTimeSeriesWithSamplesAndExemplars(labels []prompb.Label, samples []promp
}
}

func getHistogramDataPointWithExemplars(t *testing.T, time time.Time, value float64, traceID string, spanID string, attributeKey string, attributeValue string) pmetric.HistogramDataPoint {
func getHistogramDataPointWithExemplars[V int64 | float64](t *testing.T, time time.Time, value V, traceID string, spanID string, attributeKey string, attributeValue string) pmetric.HistogramDataPoint {
h := pmetric.NewHistogramDataPoint()

e := h.Exemplars().AppendEmpty()
e.SetDoubleValue(value)
switch v := (any)(value).(type) {
case int64:
e.SetIntValue(v)
case float64:
e.SetDoubleValue(v)
}
e.SetTimestamp(pcommon.NewTimestampFromTime(time))
if attributeKey != "" || attributeValue != "" {
e.FilteredAttributes().PutStr(attributeKey, attributeValue)
Expand Down

0 comments on commit 50630c4

Please sign in to comment.