Skip to content

Commit

Permalink
[exporterhelper] Fix incorrect deduplication of exporter queue metrics (
Browse files Browse the repository at this point in the history
#10550)

Fix incorrect deduplication of otelcol_exporter_queue_size and
otelcol_exporter_queue_capacity metrics if multiple exporters are used.

Fixes
#10444

The registered callbacks are ignored for now, which is the same behavior
as before. Ideally, we would need to unregister them properly.
  • Loading branch information
dmitryax authored Jul 8, 2024
1 parent b127da0 commit d545fb6
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 57 deletions.
20 changes: 20 additions & 0 deletions .chloggen/fix-incorrectly-deduplicated-exporterhelper-metric.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 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. otlpreceiver)
component: exporterhelper

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fix incorrect deduplication of otelcol_exporter_queue_size and otelcol_exporter_queue_capacity metrics if multiple exporters are used.

# One or more tracking issues or pull requests related to the change
issues: [10444]

# 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: []

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 17 additions & 13 deletions cmd/mdatagen/templates/telemetry.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func WithAttributeSet(set attribute.Set) telemetryBuilderOption {
{{- end }}

{{- range $name, $metric := .Telemetry.Metrics }}
{{- if $metric.Optional }}
{{- if $metric.Optional }}
// Init{{ $name.Render }} configures the {{ $name.Render }} metric.
func (builder *TelemetryBuilder) Init{{ $name.Render }}({{ if $metric.Data.Async -}}cb func() {{ $metric.Data.BasicType }}{{- end }}) error {
var err error
Expand All @@ -71,13 +71,16 @@ func (builder *TelemetryBuilder) Init{{ $name.Render }}({{ if $metric.Data.Async
{{- if eq $metric.Data.Type "Histogram" -}}
{{ if $metric.Data.Boundaries -}}metric.WithExplicitBucketBoundaries([]float64{ {{- range $metric.Data.Boundaries }} {{.}}, {{- end }} }...),{{- end }}
{{- end }}
{{ if $metric.Data.Async -}}
metric.With{{ casesTitle $metric.Data.BasicType }}Callback(func(_ context.Context, o metric.{{ casesTitle $metric.Data.BasicType }}Observer) error {
o.Observe(cb(), metric.WithAttributeSet(builder.attributeSet))
return nil
}),
{{- end }}
)
{{- if $metric.Data.Async }}
if err != nil {
return err
}
_, err = builder.meter.RegisterCallback(func(_ context.Context, o metric.Observer) error {
o.Observe{{ casesTitle $metric.Data.BasicType }}(builder.{{ $name.Render }}, cb(), metric.WithAttributeSet(builder.attributeSet))
return nil
}, builder.{{ $name.Render }})
{{- end }}
return err
}

Expand Down Expand Up @@ -117,14 +120,15 @@ func NewTelemetryBuilder(settings component.TelemetrySettings, options ...teleme
{{- if eq $metric.Data.Type "Histogram" -}}
{{ if $metric.Data.Boundaries -}}metric.WithExplicitBucketBoundaries([]float64{ {{- range $metric.Data.Boundaries }} {{.}}, {{- end }} }...),{{- end }}
{{- end }}
{{ if $metric.Data.Async -}}
metric.With{{ casesTitle $metric.Data.BasicType }}Callback(func(_ context.Context, o metric.{{ casesTitle $metric.Data.BasicType }}Observer) error {
o.Observe(builder.observe{{ $name.Render }}(), metric.WithAttributeSet(builder.attributeSet))
return nil
}),
{{- end }}
)
errs = errors.Join(errs, err)
{{- if $metric.Data.Async }}
_, err = builder.meter.RegisterCallback(func(_ context.Context, o metric.Observer) error {
o.Observe{{ casesTitle $metric.Data.BasicType }}(builder.{{ $name.Render }}, builder.observe{{ $name.Render }}(), metric.WithAttributeSet(builder.attributeSet))
return nil
}, builder.{{ $name.Render }})
errs = errors.Join(errs, err)
{{- end }}
{{- end }}
{{- end }}
return &builder, errs
Expand Down
22 changes: 14 additions & 8 deletions exporter/exporterhelper/internal/metadata/generated_telemetry.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 30 additions & 24 deletions service/internal/metadata/generated_telemetry.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d545fb6

Please sign in to comment.