From 7d614d72a0d4b4a15f485b6bc4f2ddc63aacbf65 Mon Sep 17 00:00:00 2001 From: Curtis Robert Date: Fri, 8 Dec 2023 08:32:01 -0800 Subject: [PATCH] [exporter/prometheus] Fix panic when mutating data (#29608) The prometheus exporter hit a panic when accumulating `Delta` metrics into `Cumulative` sums. This is because the exporter does not enable mutating data in its capability. This change enables the exporter to mutate data in a safe and supported way. Fixed #29574 **Testing** There are existing tests that hit the logic that was panicking, but the metrics are set to `StateMutable` in testing (which is the only way they can be created and setup for testing). I believe that means that before this change the tests were invalid (didn't represent reality), but after this change they'll properly represent the exporter's functionality. --- .chloggen/fix_prometheus_panic.yaml | 27 ++++++++++++++++++++++++++ exporter/prometheusexporter/factory.go | 2 ++ exporter/prometheusexporter/go.mod | 2 +- 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100755 .chloggen/fix_prometheus_panic.yaml diff --git a/.chloggen/fix_prometheus_panic.yaml b/.chloggen/fix_prometheus_panic.yaml new file mode 100755 index 000000000000..386604edfc52 --- /dev/null +++ b/.chloggen/fix_prometheus_panic.yaml @@ -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: prometheusexporter + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Fix panic when exporter mutates data + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [29574] + +# (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: [] diff --git a/exporter/prometheusexporter/factory.go b/exporter/prometheusexporter/factory.go index ab1581e4a872..b29253fe0f8c 100644 --- a/exporter/prometheusexporter/factory.go +++ b/exporter/prometheusexporter/factory.go @@ -8,6 +8,7 @@ import ( "time" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/exporter/exporterhelper" @@ -52,6 +53,7 @@ func createMetricsExporter( prometheus.ConsumeMetrics, exporterhelper.WithStart(prometheus.Start), exporterhelper.WithShutdown(prometheus.Shutdown), + exporterhelper.WithCapabilities(consumer.Capabilities{MutatesData: true}), ) if err != nil { return nil, err diff --git a/exporter/prometheusexporter/go.mod b/exporter/prometheusexporter/go.mod index 9daf822750b0..6d6c40eb3078 100644 --- a/exporter/prometheusexporter/go.mod +++ b/exporter/prometheusexporter/go.mod @@ -16,6 +16,7 @@ require ( go.opentelemetry.io/collector/config/confighttp v0.90.2-0.20231201205146-6e2fdc755b34 go.opentelemetry.io/collector/config/configtls v0.90.2-0.20231201205146-6e2fdc755b34 go.opentelemetry.io/collector/confmap v0.90.2-0.20231201205146-6e2fdc755b34 + go.opentelemetry.io/collector/consumer v0.90.2-0.20231201205146-6e2fdc755b34 go.opentelemetry.io/collector/exporter v0.90.2-0.20231201205146-6e2fdc755b34 go.opentelemetry.io/collector/pdata v1.0.1-0.20231201205146-6e2fdc755b34 go.opentelemetry.io/collector/receiver v0.90.2-0.20231201205146-6e2fdc755b34 @@ -140,7 +141,6 @@ require ( go.opentelemetry.io/collector/config/configopaque v0.90.2-0.20231201205146-6e2fdc755b34 // indirect go.opentelemetry.io/collector/config/configtelemetry v0.90.2-0.20231201205146-6e2fdc755b34 // indirect go.opentelemetry.io/collector/config/internal v0.90.2-0.20231201205146-6e2fdc755b34 // indirect - go.opentelemetry.io/collector/consumer v0.90.2-0.20231201205146-6e2fdc755b34 // indirect go.opentelemetry.io/collector/extension v0.90.2-0.20231201205146-6e2fdc755b34 // indirect go.opentelemetry.io/collector/extension/auth v0.90.2-0.20231201205146-6e2fdc755b34 // indirect go.opentelemetry.io/collector/featuregate v1.0.1-0.20231201205146-6e2fdc755b34 // indirect