Skip to content

Commit 57704ce

Browse files
authored
[prometheusremotewritereceiver] drop summary and classic histograms (#40975)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description * Drop classic histograms * Drop Summaries * Setting metric attributes just for metric types that we will handle, this to avoid accessing nil vars More about how we found this "bug" ⬇️ [Reference](https://cloud-native.slack.com/archives/CJFCJHG4Q/p1751045531132159) <!--Please delete paragraphs that you did not use before submitting.-->
1 parent 7342430 commit 57704ce

File tree

3 files changed

+98
-21
lines changed

3 files changed

+98
-21
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: 'prometheusremotewritereceiver'
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: 'Drop summary and classic histogram series as we will not handle them.'
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: [40975]
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]

receiver/prometheusremotewritereceiver/receiver.go

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -340,26 +340,27 @@ func (prw *prometheusRemoteWriteReceiver) translateV2(_ context.Context, req *wr
340340
metric, exists := metricCache[metricKey]
341341
// If the metric does not exist, we create an empty metric and add it to the cache.
342342
if !exists {
343-
metric = scope.Metrics().AppendEmpty()
344-
metric.SetName(metricName)
345-
metric.SetUnit(unit)
346-
metric.SetDescription(description)
347-
348343
switch ts.Metadata.Type {
349344
case writev2.Metadata_METRIC_TYPE_GAUGE:
345+
metric = setMetric(scope, metricName, unit, description)
350346
metric.SetEmptyGauge()
351347
case writev2.Metadata_METRIC_TYPE_COUNTER:
348+
metric = setMetric(scope, metricName, unit, description)
352349
sum := metric.SetEmptySum()
353350
sum.SetIsMonotonic(true)
354351
sum.SetAggregationTemporality(pmetric.AggregationTemporalityCumulative)
355352
case writev2.Metadata_METRIC_TYPE_HISTOGRAM:
356353
// Histograms that comes with samples are considered as classic histograms and are not supported.
357-
if len(ts.Samples) == 0 {
358-
hist := metric.SetEmptyExponentialHistogram()
359-
hist.SetAggregationTemporality(pmetric.AggregationTemporalityCumulative)
354+
if len(ts.Samples) != 0 {
355+
// Drop classic histogram series as we will not handle them.
356+
continue
360357
}
358+
metric = setMetric(scope, metricName, unit, description)
359+
hist := metric.SetEmptyExponentialHistogram()
360+
hist.SetAggregationTemporality(pmetric.AggregationTemporalityCumulative)
361361
case writev2.Metadata_METRIC_TYPE_SUMMARY:
362-
metric.SetEmptySummary()
362+
// Drop summary series as we will not handle them.
363+
continue
363364
}
364365

365366
metricCache[metricKey] = metric
@@ -378,12 +379,14 @@ func (prw *prometheusRemoteWriteReceiver) translateV2(_ context.Context, req *wr
378379
case writev2.Metadata_METRIC_TYPE_COUNTER:
379380
addNumberDatapoints(metric.Sum().DataPoints(), ls, ts, &stats)
380381
case writev2.Metadata_METRIC_TYPE_HISTOGRAM:
381-
// Histograms that comes with samples are considered as classic histograms and are not supported.
382-
if len(ts.Samples) == 0 {
383-
addExponentialHistogramDatapoints(metric.ExponentialHistogram().DataPoints(), ls, ts, &stats)
382+
if len(ts.Samples) != 0 {
383+
// Drop classic histogram series as we will not handle them.
384+
continue
384385
}
386+
addExponentialHistogramDatapoints(metric.ExponentialHistogram().DataPoints(), ls, ts, &stats)
385387
case writev2.Metadata_METRIC_TYPE_SUMMARY:
386-
addSummaryDatapoints(metric.Summary().DataPoints(), ls, ts)
388+
// Drop summary series as we will not handle them.
389+
continue
387390
default:
388391
badRequestErrors = errors.Join(badRequestErrors, fmt.Errorf("unsupported metric type %q for metric %q", ts.Metadata.Type, metricName))
389392
}
@@ -392,6 +395,15 @@ func (prw *prometheusRemoteWriteReceiver) translateV2(_ context.Context, req *wr
392395
return otelMetrics, stats, badRequestErrors
393396
}
394397

398+
// setMetric append a new empty metric and assign the name, unit and description to it.
399+
func setMetric(scope pmetric.ScopeMetrics, metricName, unit, description string) pmetric.Metric {
400+
metric := scope.Metrics().AppendEmpty()
401+
metric.SetName(metricName)
402+
metric.SetUnit(unit)
403+
metric.SetDescription(description)
404+
return metric
405+
}
406+
395407
// parseJobAndInstance turns the job and instance labels service resource attributes.
396408
// Following the specification at https://opentelemetry.io/docs/specs/otel/compatibility/prometheus_and_openmetrics/
397409
func parseJobAndInstance(dest pcommon.Map, job, instance string) {
@@ -425,10 +437,6 @@ func addNumberDatapoints(datapoints pmetric.NumberDataPointSlice, ls labels.Labe
425437
stats.Samples += len(ts.Samples)
426438
}
427439

428-
func addSummaryDatapoints(_ pmetric.SummaryDataPointSlice, _ labels.Labels, _ writev2.TimeSeries) {
429-
// TODO: Implement this function
430-
}
431-
432440
func addExponentialHistogramDatapoints(datapoints pmetric.ExponentialHistogramDataPointSlice, ls labels.Labels, ts writev2.TimeSeries, stats *promremote.WriteResponseStats) {
433441
for _, histogram := range ts.Histograms {
434442
// Drop histograms with RESET_HINT_GAUGE or negative counts.

receiver/prometheusremotewritereceiver/receiver_test.go

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -970,10 +970,52 @@ func TestTranslateV2(t *testing.T) {
970970
sm.Scope().SetName("scope1")
971971
sm.Scope().SetVersion("v1")
972972

973-
m := sm.Metrics().AppendEmpty()
974-
m.SetName("test_metric")
975-
m.SetUnit("")
976-
m.SetDescription("")
973+
return metrics
974+
}(),
975+
},
976+
{
977+
name: "summary - should be dropped",
978+
request: &writev2.Request{
979+
Symbols: []string{
980+
"",
981+
"__name__", "test_metric", // 1, 2
982+
"job", "service-x/test", // 3, 4
983+
"instance", "107cn001", // 5, 6
984+
"otel_scope_name", "scope1", // 7, 8
985+
"otel_scope_version", "v1", // 9, 10
986+
},
987+
Timeseries: []writev2.TimeSeries{
988+
{
989+
Metadata: writev2.Metadata{
990+
Type: writev2.Metadata_METRIC_TYPE_SUMMARY,
991+
},
992+
Samples: []writev2.Sample{
993+
{
994+
Value: 1,
995+
Timestamp: 1,
996+
},
997+
},
998+
LabelsRefs: []uint32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
999+
},
1000+
},
1001+
},
1002+
expectedStats: remote.WriteResponseStats{
1003+
Confirmed: true,
1004+
Samples: 0,
1005+
Histograms: 0,
1006+
Exemplars: 0,
1007+
},
1008+
expectedMetrics: func() pmetric.Metrics {
1009+
metrics := pmetric.NewMetrics()
1010+
rm := metrics.ResourceMetrics().AppendEmpty()
1011+
attrs := rm.Resource().Attributes()
1012+
attrs.PutStr("service.namespace", "service-x")
1013+
attrs.PutStr("service.name", "test")
1014+
attrs.PutStr("service.instance.id", "107cn001")
1015+
1016+
sm := rm.ScopeMetrics().AppendEmpty()
1017+
sm.Scope().SetName("scope1")
1018+
sm.Scope().SetVersion("v1")
9771019

9781020
return metrics
9791021
}(),

0 commit comments

Comments
 (0)