Skip to content

Commit 0813c56

Browse files
committed
[signalfxexporter] avoid stringify every data point that does not match the filter
Signed-off-by: Bogdan Drutu <[email protected]>
1 parent 4ed3faa commit 0813c56

File tree

4 files changed

+15
-34
lines changed

4 files changed

+15
-34
lines changed

.chloggen/improveperf.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: enhancement
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
5+
component: signalfxexporter
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: Avoid stringify every data point that does not match the filter.
9+
10+
# One or more tracking issues related to the change
11+
issues: [18274]

exporter/signalfxexporter/dpclient.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (s *sfxDPClient) pushMetricsData(
9595
sfxDataPoints := s.converter.MetricsToSignalFxV2(md)
9696
if s.logDataPoints {
9797
for _, dp := range sfxDataPoints {
98-
s.logger.Debug("Dispatching SFx datapoint", zap.String("dp", translation.DatapointToString(dp)))
98+
s.logger.Debug("Dispatching SFx datapoint", zap.Stringer("dp", dp))
9999
}
100100
}
101101
return s.pushMetricsDataForToken(ctx, sfxDataPoints, metricToken)

exporter/signalfxexporter/internal/translation/converter.go

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package translation // import "github.com/open-telemetry/opentelemetry-collector
1616

1717
import (
1818
"fmt"
19-
"strconv"
2019
"strings"
2120
"time"
2221
"unicode"
@@ -114,7 +113,7 @@ func (c *MetricsConverter) translateAndFilter(dps []*sfxpb.DataPoint) []*sfxpb.D
114113
}
115114
resultSliceLen++
116115
} else {
117-
c.logger.Debug("Datapoint does not match filter, skipping", zap.String("dp", DatapointToString(dp)))
116+
c.logger.Debug("Datapoint does not match filter, skipping", zap.Stringer("dp", dp))
118117
}
119118
}
120119
dps = dps[:resultSliceLen]
@@ -251,7 +250,7 @@ func (dpv *datapointValidator) isValidNumberOfDimension(dp *sfxpb.DataPoint) boo
251250
if len(dp.Dimensions) > maxNumberOfDimensions {
252251
dpv.logger.Debug("dropping datapoint",
253252
zap.String("reason", invalidNumberOfDimensions),
254-
zap.String("datapoint", DatapointToString(dp)),
253+
zap.Stringer("datapoint", dp),
255254
zap.Int("number_of_dimensions", len(dp.Dimensions)),
256255
)
257256
return false
@@ -307,32 +306,3 @@ func CreateSampledLogger(logger *zap.Logger) *zap.Logger {
307306
})
308307
return logger.WithOptions(opts)
309308
}
310-
311-
func DatapointToString(dp *sfxpb.DataPoint) string {
312-
var tsStr string
313-
if dp.Timestamp != 0 {
314-
tsStr = strconv.FormatInt(dp.Timestamp, 10)
315-
}
316-
317-
var dimsStr string
318-
for _, dim := range dp.Dimensions {
319-
dimsStr += dim.String()
320-
}
321-
322-
return fmt.Sprintf("%s: %s (%s) %s\n%s", dp.Metric, dp.Value.String(), dpTypeToString(*dp.MetricType), tsStr, dimsStr)
323-
}
324-
325-
func dpTypeToString(t sfxpb.MetricType) string {
326-
switch t {
327-
case sfxpb.MetricType_GAUGE:
328-
return "Gauge"
329-
case sfxpb.MetricType_COUNTER:
330-
return "Counter"
331-
case sfxpb.MetricType_ENUM:
332-
return "Enum"
333-
case sfxpb.MetricType_CUMULATIVE_COUNTER:
334-
return "Cumulative Counter"
335-
default:
336-
return fmt.Sprintf("unsupported type %d", t)
337-
}
338-
}

exporter/signalfxexporter/internal/translation/converter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ func TestInvalidNumberOfDimensions(t *testing.T) {
769769
assert.Equal(t, "dropping datapoint", observedLogs.All()[0].Message)
770770
assert.ElementsMatch(t, []zap.Field{
771771
{Type: zapcore.StringType, Key: "reason", String: invalidNumberOfDimensions},
772-
{Type: zapcore.StringType, Key: "datapoint", String: DatapointToString(dpSFX)},
772+
{Type: zapcore.StringerType, Key: "datapoint", Interface: dpSFX},
773773
{Type: zapcore.Int64Type, Key: "number_of_dimensions", Integer: 37},
774774
}, observedLogs.All()[0].Context)
775775
}

0 commit comments

Comments
 (0)