Skip to content

Commit

Permalink
added a way to drop histogram bucket in singalfx exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
samiura committed Aug 18, 2023
1 parent cc7650f commit d500755
Show file tree
Hide file tree
Showing 10 changed files with 448 additions and 101 deletions.
28 changes: 28 additions & 0 deletions .chloggen/drop-histogram-metrics-first-part.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: 'enhancement'

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: 'signalfxexporter'


# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: 'Added a mechanism to drop histogram buckets'

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [25845]

# (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: ['user']
2 changes: 1 addition & 1 deletion exporter/signalfxexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ will be replaced with a `_`.
api_tls:
ca_file: "/etc/opt/certs/ca.pem"
```

- `drop_histogram_buckets`: (default = `false`) if set to true, histogram buckets will not be translated into datapoints with `_bucket` suffix but will be dropped instead, only datapoints with `_sum`, `_count`, `_min` (optional) and `_max` (optional) suffixes will be sent.
In addition, this exporter offers queued retry which is enabled by default.
Information about queued retry configuration parameters can be found
[here](https://github.com/open-telemetry/opentelemetry-collector/blob/main/exporter/exporterhelper/README.md).
Expand Down
4 changes: 4 additions & 0 deletions exporter/signalfxexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ type Config struct {
// MaxConnections is used to set a limit to the maximum idle HTTP connection the exporter can keep open.
// Deprecated: use HTTPClientSettings.MaxIdleConns or HTTPClientSettings.MaxIdleConnsPerHost instead.
MaxConnections int `mapstructure:"max_connections"`

// Whether to drop histogram bucket metrics dispatched to Splunk Observability.
// Default value is set to false.
DropHistogramBuckets bool `mapstructure:"drop_histogram_buckets"`
}

type DimensionClientConfig struct {
Expand Down
1 change: 1 addition & 0 deletions exporter/signalfxexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func newSignalFxExporter(
config.ExcludeMetrics,
config.IncludeMetrics,
config.NonAlphanumericDimensionChars,
config.DropHistogramBuckets,
)
if err != nil {
return nil, fmt.Errorf("failed to create metric converter: %w", err)
Expand Down
9 changes: 5 additions & 4 deletions exporter/signalfxexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func TestConsumeMetrics(t *testing.T) {
client, err := cfg.ToClient(componenttest.NewNopHost(), exportertest.NewNopCreateSettings().TelemetrySettings)
require.NoError(t, err)

c, err := translation.NewMetricsConverter(zap.NewNop(), nil, nil, nil, "")
c, err := translation.NewMetricsConverter(zap.NewNop(), nil, nil, nil, "", false)
require.NoError(t, err)
require.NotNil(t, c)
dpClient := &sfxDPClient{
Expand Down Expand Up @@ -729,6 +729,7 @@ func TestConsumeMetadata(t *testing.T) {
cfg.ExcludeMetrics,
cfg.IncludeMetrics,
cfg.NonAlphanumericDimensionChars,
false,
)
require.NoError(t, err)
type args struct {
Expand Down Expand Up @@ -1088,7 +1089,7 @@ func BenchmarkExporterConsumeData(b *testing.B) {
serverURL, err := url.Parse(server.URL)
assert.NoError(b, err)

c, err := translation.NewMetricsConverter(zap.NewNop(), nil, nil, nil, "")
c, err := translation.NewMetricsConverter(zap.NewNop(), nil, nil, nil, "", false)
require.NoError(b, err)
require.NotNil(b, c)
dpClient := &sfxDPClient{
Expand Down Expand Up @@ -1281,7 +1282,7 @@ func TestTLSIngestConnection(t *testing.T) {
func TestDefaultSystemCPUTimeExcludedAndTranslated(t *testing.T) {
translator, err := translation.NewMetricTranslator(defaultTranslationRules, 3600)
require.NoError(t, err)
converter, err := translation.NewMetricsConverter(zap.NewNop(), translator, defaultExcludeMetrics, nil, "_-.")
converter, err := translation.NewMetricsConverter(zap.NewNop(), translator, defaultExcludeMetrics, nil, "_-.", false)
require.NoError(t, err)

md := pmetric.NewMetrics()
Expand Down Expand Up @@ -1324,7 +1325,7 @@ func TestTLSAPIConnection(t *testing.T) {
cfg.ExcludeMetrics,
cfg.IncludeMetrics,
cfg.NonAlphanumericDimensionChars,
)
false)
require.NoError(t, err)

metadata := []*metadata.MetadataUpdate{
Expand Down
10 changes: 5 additions & 5 deletions exporter/signalfxexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestDefaultTranslationRules(t *testing.T) {
require.NoError(t, err)
data := testMetricsData()

c, err := translation.NewMetricsConverter(zap.NewNop(), tr, nil, nil, "")
c, err := translation.NewMetricsConverter(zap.NewNop(), tr, nil, nil, "", false)
require.NoError(t, err)
translated := c.MetricsToSignalFxV2(data)
require.NotNil(t, translated)
Expand Down Expand Up @@ -493,7 +493,7 @@ func TestHostmetricsCPUTranslations(t *testing.T) {
f := NewFactory()
cfg := f.CreateDefaultConfig().(*Config)
require.NoError(t, setDefaultExcludes(cfg))
converter, err := translation.NewMetricsConverter(zap.NewNop(), testGetTranslator(t), cfg.ExcludeMetrics, cfg.IncludeMetrics, "")
converter, err := translation.NewMetricsConverter(zap.NewNop(), testGetTranslator(t), cfg.ExcludeMetrics, cfg.IncludeMetrics, "", false)
require.NoError(t, err)

md1, err := golden.ReadMetrics(filepath.Join("testdata", "hostmetrics_system_cpu_time_1.yaml"))
Expand Down Expand Up @@ -534,7 +534,7 @@ func TestDefaultExcludesTranslated(t *testing.T) {
cfg := f.CreateDefaultConfig().(*Config)
require.NoError(t, setDefaultExcludes(cfg))

converter, err := translation.NewMetricsConverter(zap.NewNop(), testGetTranslator(t), cfg.ExcludeMetrics, cfg.IncludeMetrics, "")
converter, err := translation.NewMetricsConverter(zap.NewNop(), testGetTranslator(t), cfg.ExcludeMetrics, cfg.IncludeMetrics, "", false)
require.NoError(t, err)

var metrics []map[string]string
Expand All @@ -557,7 +557,7 @@ func TestDefaultExcludes_not_translated(t *testing.T) {
cfg := f.CreateDefaultConfig().(*Config)
require.NoError(t, setDefaultExcludes(cfg))

converter, err := translation.NewMetricsConverter(zap.NewNop(), nil, cfg.ExcludeMetrics, cfg.IncludeMetrics, "")
converter, err := translation.NewMetricsConverter(zap.NewNop(), nil, cfg.ExcludeMetrics, cfg.IncludeMetrics, "", false)
require.NoError(t, err)

var metrics []map[string]string
Expand All @@ -577,7 +577,7 @@ func BenchmarkMetricConversion(b *testing.B) {
tr, err := translation.NewMetricTranslator(rules, 1)
require.NoError(b, err)

c, err := translation.NewMetricsConverter(zap.NewNop(), tr, nil, nil, "")
c, err := translation.NewMetricsConverter(zap.NewNop(), tr, nil, nil, "", false)
require.NoError(b, err)

bytes, err := os.ReadFile("testdata/json/hostmetrics.json")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ func TestGetDimensionUpdateFromMetadata(t *testing.T) {
nil,
nil,
"-_.",
false,
)
require.NoError(t, err)
assert.Equal(t, tt.want, getDimensionUpdateFromMetadata(tt.args.metadata, *converter))
Expand Down
30 changes: 16 additions & 14 deletions exporter/signalfxexporter/internal/translation/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ var (
// MetricsConverter converts MetricsData to sfxpb DataPoints. It holds an optional
// MetricTranslator to translate SFx metrics using translation rules.
type MetricsConverter struct {
logger *zap.Logger
metricTranslator *MetricTranslator
filterSet *dpfilters.FilterSet
datapointValidator *datapointValidator
translator *signalfx.FromTranslator
logger *zap.Logger
metricTranslator *MetricTranslator
filterSet *dpfilters.FilterSet
datapointValidator *datapointValidator
translator *signalfx.FromTranslator
dropHistogramBuckets bool
}

// NewMetricsConverter creates a MetricsConverter from the passed in logger and
Expand All @@ -47,17 +48,19 @@ func NewMetricsConverter(
t *MetricTranslator,
excludes []dpfilters.MetricFilter,
includes []dpfilters.MetricFilter,
nonAlphanumericDimChars string) (*MetricsConverter, error) {
nonAlphanumericDimChars string,
dropHistogramBuckets bool) (*MetricsConverter, error) {
fs, err := dpfilters.NewFilterSet(excludes, includes)
if err != nil {
return nil, err
}
return &MetricsConverter{
logger: logger,
metricTranslator: t,
filterSet: fs,
datapointValidator: newDatapointValidator(logger, nonAlphanumericDimChars),
translator: &signalfx.FromTranslator{},
logger: logger,
metricTranslator: t,
filterSet: fs,
datapointValidator: newDatapointValidator(logger, nonAlphanumericDimChars),
translator: &signalfx.FromTranslator{},
dropHistogramBuckets: dropHistogramBuckets,
}, nil
}

Expand All @@ -66,7 +69,6 @@ func NewMetricsConverter(
// dropped because of errors or warnings.
func (c *MetricsConverter) MetricsToSignalFxV2(md pmetric.Metrics) []*sfxpb.DataPoint {
var sfxDataPoints []*sfxpb.DataPoint

rms := md.ResourceMetrics()
for i := 0; i < rms.Len(); i++ {
rm := rms.At(i)
Expand All @@ -75,9 +77,9 @@ func (c *MetricsConverter) MetricsToSignalFxV2(md pmetric.Metrics) []*sfxpb.Data
for j := 0; j < rm.ScopeMetrics().Len(); j++ {
ilm := rm.ScopeMetrics().At(j)
var initialDps []*sfxpb.DataPoint

for k := 0; k < ilm.Metrics().Len(); k++ {
dps := c.translator.FromMetric(ilm.Metrics().At(k), extraDimensions)
currentMetric := ilm.Metrics().At(k)
dps := c.translator.FromMetric(currentMetric, extraDimensions, c.dropHistogramBuckets)
initialDps = append(initialDps, dps...)
}

Expand Down
Loading

0 comments on commit d500755

Please sign in to comment.