Skip to content

Commit

Permalink
fix(sumologicexporter): translate Telegraf metrics with OTLP format
Browse files Browse the repository at this point in the history
This change fixes a regression introduced in #536
that caused the metric name translations
(the feature under the `translate_telegraf_attributes` setting)
to not work when using the OTLP format.
This change refactors the code so that all modifications to metrics
(attribute translation, metrics translation, dropping routing attribute)
are done before branching the code into different sending formats.
  • Loading branch information
andrzej-stencel committed Jul 7, 2022
1 parent 6acb381 commit 0b698bf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
24 changes: 10 additions & 14 deletions pkg/exporter/sumologicexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,19 +283,6 @@ func (se *sumologicexporter) pushMetricsData(ctx context.Context, md pmetric.Met
tracesUrl,
)

// Follow different execution path for OTLP format
if sdr.config.MetricFormat == OTLPMetricFormat {
if err := sdr.sendOTLPMetrics(ctx, md); err != nil {
se.handleUnauthorizedErrors(ctx, err)
return consumererror.NewMetrics(err, md)
}
return nil
}

var (
errs []error
)

// Transform metrics metadata
// this includes dropping the routing attribute and translating attributes
rms := md.ResourceMetrics()
Expand All @@ -321,7 +308,16 @@ func (se *sumologicexporter) pushMetricsData(ctx context.Context, md pmetric.Met
}
}

droppedMetrics, errs := sdr.sendNonOTLPMetrics(ctx, md)
var droppedMetrics pmetric.Metrics
var errs []error
if sdr.config.MetricFormat == OTLPMetricFormat {
if err := sdr.sendOTLPMetrics(ctx, md); err != nil {
droppedMetrics = md
errs = []error{err}
}
} else {
droppedMetrics, errs = sdr.sendNonOTLPMetrics(ctx, md)
}

if len(errs) > 0 {
se.handleUnauthorizedErrors(ctx, errs...)
Expand Down
5 changes: 0 additions & 5 deletions pkg/exporter/sumologicexporter/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,11 +596,6 @@ func (s *sender) sendOTLPMetrics(ctx context.Context, md pmetric.Metrics) error
for i := 0; i < rms.Len(); i++ {
rm := rms.At(i)

if s.config.TranslateAttributes {
translateAttributes(rm.Resource().Attributes()).
CopyTo(rm.Resource().Attributes())
}

s.addSourceResourceAttributes(rm.Resource().Attributes())
}

Expand Down

0 comments on commit 0b698bf

Please sign in to comment.