Skip to content

Commit

Permalink
[exporter/prometheus] Fix panic when mutating data (#29608)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
crobert-1 authored Dec 8, 2023
1 parent c0165f5 commit 7d614d7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
27 changes: 27 additions & 0 deletions .chloggen/fix_prometheus_panic.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: 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: []
2 changes: 2 additions & 0 deletions exporter/prometheusexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion exporter/prometheusexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7d614d7

Please sign in to comment.