Skip to content

Commit f191ae9

Browse files
authored
[exporter/signalfx] Remove deprecated translation_rules configuration option (#35332)
**Description:** The `translation_rules` option has been deprecated since #18218, we can now delete the option. Internally, to be able to still have the default translation rules without the `translation_rules` config option, a new config structure has been added, but is not nested within the exporter's `Config`, it's its own struct.
1 parent 13ba396 commit f191ae9

File tree

7 files changed

+87
-148
lines changed

7 files changed

+87
-148
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: breaking
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: signalfxexporter
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Remove the deprecated configuration option `translation_rules`
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [35332]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: |
19+
Please use processors to handle desired metric transformations instead. Find migration guidance in the
20+
[translation rules migration guide](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/exporter/signalfxexporter/docs/translation_rules_migration_guide.md).
21+
22+
# If your change doesn't affect end users or the exported elements of any package,
23+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
24+
# Optional: The change log or logs in which this entry should be included.
25+
# e.g. '[user]' or '[user, api]'
26+
# Include 'user' if the change is relevant to end users.
27+
# Include 'api' if there is a change to a library API.
28+
# Default: '[user]'
29+
change_logs: []

exporter/signalfxexporter/README.md

+6-22
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ The following configuration options can also be configured:
8181
updates.
8282
- `disable_default_translation_rules` (default = `false`): Disable default translation
8383
of the OTel metrics to a SignalFx compatible format. The default translation rules are
84-
defined in `translation/constants.go`.
84+
defined in [`internal/translation/constants.go`](./internal/translation/constants.go).
8585
- `timeout` (default = 10s): Amount of time to wait for a send operation to
8686
complete.
8787
- `http2_read_idle_timeout` (default = 10s): Send a ping frame for a health check if the connection has been idle for the configured value.
@@ -179,7 +179,7 @@ One of `realm` and `api_url` are required.
179179
## Default Metric Filters
180180
[List of metrics excluded by default](./internal/translation/default_metrics.go)
181181

182-
Some OpenTelemetry receivers may send metrics that SignalFx considers to be categorized as custom metrics. In order to prevent unwanted overage usage due to custom metrics from these receivers, the SignalFx exporter has a [set of metrics excluded by default](./internal/translation/default_metrics.go). Some exclusion rules use regex to exclude multiple metric names. Some metrics are only excluded if specific resource labels (dimensions) are present. If `translation_rules` are configured and new metrics match a default exclusion, the new metric will still be excluded. Users may configure the SignalFx exporter's `include_metrics` config option to override the any of the default exclusions, as `include_metrics` will always take precedence over any exclusions. An example of `include_metrics` is shown below.
182+
Some OpenTelemetry receivers may send metrics that SignalFx considers to be categorized as custom metrics. In order to prevent unwanted overage usage due to custom metrics from these receivers, the SignalFx exporter has a [set of metrics excluded by default](./internal/translation/default_metrics.go). Some exclusion rules use regex to exclude multiple metric names. Some metrics are only excluded if specific resource labels (dimensions) are present. If the default translation rules are enabled and match an exclusion rule, the exclusion takes precedence. Users may configure the SignalFx exporter's `include_metrics` config option to override the any of the default exclusions, as `include_metrics` will always take precedence over any exclusions. An example of `include_metrics` is shown below.
183183

184184
```
185185
exporters:
@@ -205,25 +205,9 @@ exporters:
205205
206206
## Translation Rules and Metric Transformations
207207
208-
The `translation_rules` metrics configuration field accepts a list of metric-transforming actions to
209-
help ensure compatibility with custom charts and dashboards when using the OpenTelemetry Collector. It also provides the ability to produce custom metrics by copying, calculating new, or aggregating other metric values without requiring an additional processor.
210-
The rule language is expressed in yaml mappings and is [documented here](./internal/translation/translator.go). Translation rules currently allow the following actions:
211-
212-
* `aggregate_metric` - Aggregates a metric through removal of specified dimensions
213-
* `calculate_new_metric` - Creates a new metric via operating on two constituent ones
214-
* `convert_values` - Convert float values to int or int to float for specified metric names
215-
* `copy_metrics` - Creates a new metric as a copy of another
216-
* `delta_metric` - Creates a new delta metric for a specified non-delta one
217-
* `divide_int` - Scales a metric's integer value by a given factor
218-
* `drop_dimensions` - Drops dimensions for specified metrics, or globally
219-
* `drop_metrics` - Drops all metrics with a given name
220-
* `multiply_float` - Scales a metric's float value by a given float factor
221-
* `multiply_int` - Scales a metric's int value by a given int factor
222-
* `rename_dimension_keys` - Renames dimensions for specified metrics, or globally
223-
* `rename_metrics` - Replaces a given metric name with specified one
224-
* `split_metric` - Splits a given metric into multiple new ones for a specified dimension
225-
226-
The translation rules defined in [`translation/constants.go`](./internal/translation/constants.go) are used by default for this value. The default rules will create the following aggregated metrics from the [`hostmetrics` receiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/hostmetricsreceiver/README.md):
208+
The default translation rules defined in [`translation/constants.go`](./internal/translation/constants.go) are used by the SignalFx exporter
209+
to help ensure compatibility with custom charts and dashboards when using the OpenTelemetry Collector.
210+
The default rules will create the following aggregated metrics from the [`hostmetrics` receiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/hostmetricsreceiver/README.md):
227211
228212
* cpu.idle
229213
* cpu.interrupt
@@ -264,7 +248,7 @@ The CPU number is assigned to the dimension `cpu`
264248
* cpu.user
265249
* cpu.wait
266250
267-
These metrics are intended to be reported directly to Splunk IM by the SignalFx exporter. Any desired changes to their attributes or values should be made via additional translation rules or from their constituent host metrics.
251+
These metrics are intended to be reported directly to Splunk IM by the SignalFx exporter. Any desired changes to their attributes or values should be made via their constituent host metrics.
268252
269253
## Example Config
270254

exporter/signalfxexporter/config.go

+21-25
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"go.opentelemetry.io/collector/config/configtls"
1616
"go.opentelemetry.io/collector/confmap"
1717
"go.opentelemetry.io/collector/exporter/exporterhelper"
18-
"go.uber.org/zap"
1918
"gopkg.in/yaml.v3"
2019

2120
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/signalfxexporter/internal/correlation"
@@ -24,17 +23,27 @@ import (
2423
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk"
2524
)
2625

27-
const (
28-
translationRulesConfigKey = "translation_rules"
29-
)
26+
// This mimics the original translation_rules config option (now deleted), but is not reachable
27+
// by user configuration. It's only used by defaultTranslationRules to parse the
28+
// YAML into a []translation.Rule object.
29+
type translationRulesConfig struct {
30+
TranslationRules []translation.Rule `mapstructure:"translation_rules"`
31+
}
3032

3133
var defaultTranslationRules = func() []translation.Rule {
32-
cfg, err := loadConfig([]byte(translation.DefaultTranslationRulesYaml))
34+
var data map[string]any
35+
var defaultRules translationRulesConfig
36+
3337
// It is safe to panic since this is deterministic, and will not fail anywhere else if it doesn't fail all the time.
34-
if err != nil {
38+
if err := yaml.Unmarshal([]byte(translation.DefaultTranslationRulesYaml), &data); err != nil {
3539
panic(err)
3640
}
37-
return cfg.TranslationRules
41+
42+
if err := confmap.NewFromStringMap(data).Unmarshal(&defaultRules); err != nil {
43+
panic(fmt.Errorf("failed to load default translation rules: %w", err))
44+
}
45+
46+
return defaultRules.TranslationRules
3847
}()
3948

4049
var defaultExcludeMetrics = func() []dpfilters.MetricFilter {
@@ -89,11 +98,6 @@ type Config struct {
8998

9099
splunk.AccessTokenPassthroughConfig `mapstructure:",squash"`
91100

92-
// TranslationRules defines a set of rules how to translate metrics to a SignalFx compatible format
93-
// Rules defined in translation/constants.go are used by default.
94-
// Deprecated: Use metricstransform processor to do metrics transformations.
95-
TranslationRules []translation.Rule `mapstructure:"translation_rules"`
96-
97101
DisableDefaultTranslationRules bool `mapstructure:"disable_default_translation_rules"`
98102

99103
// DeltaTranslationTTL specifies in seconds the max duration to keep the most recent datapoint for any
@@ -150,25 +154,17 @@ type DimensionClientConfig struct {
150154
Timeout time.Duration `mapstructure:"timeout"`
151155
}
152156

153-
func (cfg *Config) getMetricTranslator(logger *zap.Logger, done chan struct{}) (*translation.MetricTranslator, error) {
154-
rules := defaultTranslationRules
155-
if cfg.TranslationRules != nil {
156-
// Previous way to disable default translation rules.
157-
if len(cfg.TranslationRules) == 0 {
158-
logger.Warn("You are using the deprecated `translation_rules` option that will be removed soon; Use `disable_default_translation_rules` to disable the default rules in a gateway mode.")
159-
rules = []translation.Rule{}
160-
} else {
161-
logger.Warn("You are using the deprecated `translation_rules` option that will be removed soon; Use metricstransform processor instead.")
162-
rules = cfg.TranslationRules
163-
}
164-
}
157+
func (cfg *Config) getMetricTranslator(done chan struct{}) (*translation.MetricTranslator, error) {
158+
var rules []translation.Rule
165159
// The new way to disable default translation rules. This override any setting of the default TranslationRules.
166160
if cfg.DisableDefaultTranslationRules {
167161
rules = []translation.Rule{}
162+
} else {
163+
rules = defaultTranslationRules
168164
}
169165
metricTranslator, err := translation.NewMetricTranslator(rules, cfg.DeltaTranslationTTL, done)
170166
if err != nil {
171-
return nil, fmt.Errorf("invalid \"%s\": %w", translationRulesConfigKey, err)
167+
return nil, fmt.Errorf("invalid default translation rules: %w", err)
172168
}
173169

174170
return metricTranslator, nil

exporter/signalfxexporter/config_test.go

+2-77
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"go.opentelemetry.io/collector/confmap/confmaptest"
2222
"go.opentelemetry.io/collector/confmap/xconfmap"
2323
"go.opentelemetry.io/collector/exporter/exporterhelper"
24-
"go.uber.org/zap"
2524

2625
apmcorrelation "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/signalfxexporter/internal/apm/correlations"
2726
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/signalfxexporter/internal/correlation"
@@ -86,7 +85,6 @@ func TestLoadConfig(t *testing.T) {
8685
IdleConnTimeout: 30 * time.Second,
8786
Timeout: 10 * time.Second,
8887
},
89-
TranslationRules: nil,
9088
ExcludeMetrics: nil,
9189
IncludeMetrics: nil,
9290
DeltaTranslationTTL: 3600,
@@ -162,40 +160,6 @@ func TestLoadConfig(t *testing.T) {
162160
IdleConnTimeout: 2 * time.Hour,
163161
Timeout: 20 * time.Second,
164162
},
165-
TranslationRules: []translation.Rule{
166-
{
167-
Action: translation.ActionRenameDimensionKeys,
168-
Mapping: map[string]string{
169-
"k8s.cluster.name": "kubernetes_cluster",
170-
},
171-
},
172-
{
173-
Action: translation.ActionDropDimensions,
174-
DimensionPairs: map[string]map[string]bool{
175-
"foo": nil,
176-
"foo1": {"bar": true},
177-
},
178-
},
179-
{
180-
Action: translation.ActionDropDimensions,
181-
MetricName: "metric",
182-
DimensionPairs: map[string]map[string]bool{
183-
"foo": nil,
184-
"foo1": {"bar": true},
185-
},
186-
},
187-
{
188-
Action: translation.ActionDropDimensions,
189-
MetricNames: map[string]bool{
190-
"metric1": true,
191-
"metric2": true,
192-
},
193-
DimensionPairs: map[string]map[string]bool{
194-
"foo": nil,
195-
"foo1": {"bar": true},
196-
},
197-
},
198-
},
199163
ExcludeMetrics: []dpfilters.MetricFilter{
200164
{
201165
MetricName: "metric1",
@@ -313,7 +277,7 @@ func TestConfigGetMetricTranslator(t *testing.T) {
313277
wantErr bool
314278
}{
315279
{
316-
name: "Test empty config",
280+
name: "Test default translation rules",
317281
cfg: &Config{
318282
DeltaTranslationTTL: 3600,
319283
},
@@ -323,18 +287,6 @@ func TestConfigGetMetricTranslator(t *testing.T) {
323287
return translator
324288
}(),
325289
},
326-
{
327-
name: "Test empty rules",
328-
cfg: &Config{
329-
TranslationRules: []translation.Rule{},
330-
DeltaTranslationTTL: 3600,
331-
},
332-
want: func() *translation.MetricTranslator {
333-
translator, err := translation.NewMetricTranslator([]translation.Rule{}, 3600, done)
334-
require.NoError(t, err)
335-
return translator
336-
}(),
337-
},
338290
{
339291
name: "Test disable rules",
340292
cfg: &Config{
@@ -347,37 +299,10 @@ func TestConfigGetMetricTranslator(t *testing.T) {
347299
return translator
348300
}(),
349301
},
350-
{
351-
name: "Test disable rules overrides rules",
352-
cfg: &Config{
353-
TranslationRules: []translation.Rule{{Action: translation.ActionDropDimensions}},
354-
DisableDefaultTranslationRules: true,
355-
DeltaTranslationTTL: 3600,
356-
},
357-
want: func() *translation.MetricTranslator {
358-
translator, err := translation.NewMetricTranslator([]translation.Rule{}, 3600, done)
359-
require.NoError(t, err)
360-
return translator
361-
}(),
362-
},
363-
{
364-
name: "Test invalid translation rules",
365-
cfg: &Config{
366-
Realm: "us0",
367-
AccessToken: "access_token",
368-
TranslationRules: []translation.Rule{
369-
{
370-
Action: translation.ActionRenameDimensionKeys,
371-
},
372-
},
373-
DeltaTranslationTTL: 3600,
374-
},
375-
wantErr: true,
376-
},
377302
}
378303
for _, tt := range tests {
379304
t.Run(tt.name, func(t *testing.T) {
380-
got, err := tt.cfg.getMetricTranslator(zap.NewNop(), done)
305+
got, err := tt.cfg.getMetricTranslator(done)
381306
if tt.wantErr {
382307
assert.Error(t, err)
383308
return
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Translation Rules Migration Guide
2+
3+
## Context
4+
5+
The `translation_rules` configuration option of the SignalFx exporter
6+
[has been deprecated](https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/18218)
7+
and [removed](https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/35332) in an effort to
8+
reduce the exporter's complexity and leverage existing functionality in existing
9+
OpenTelemetry Collector processors.
10+
11+
## Migration Guide
12+
13+
The following table can be referenced to map existing translation rule actions to processors that
14+
can be used to accomplish the same functionality.
15+
16+
| Deleted Translation rule | Replacement option | Replacement example |
17+
| -----------------|--------------------|----------------------|
18+
| aggregate_metric | `transform` processor's `aggregate_on_attributes` function with the `metric` context | [aggregate example](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/transformprocessor#aggregate_on_attributes) |
19+
| calculate_new_metric | `metricsgeneration` processor's `calculate` functionality | [calculate example](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/metricsgenerationprocessor#example-configurations) |
20+
| convert_values | `transform` processor's `Double` or `Int` converter on a `datapoint` context | [`Double` example](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/ottlfuncs#double), [`Int` example](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/ottlfuncs#int) |
21+
| copy_metrics | `metricstransform` processor's `insert` functionality | [copy all datapoints](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/metricstransformprocessor#create-a-new-metric-from-an-existing-metric), [conditionally copy datapoints](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/metricstransformprocessor#create-a-new-metric-from-an-existing-metric-with-matching-label-values) |
22+
| delta_metric | `cumulativetodelta` processor. To preserve original metrics, first copy the original metric, then use the copied metric in the `cumulativetodelta` processor | [specify which metrics to convert example](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/cumulativetodeltaprocessor#examples)
23+
| drop_dimensions | `transform` processor's `delete_keys` function with the `datapoint` context | [simple example](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/ottlfuncs#delete_key), use a `where` clause with the given example to filter based upon the metric name or dimension value |
24+
| drop_metrics | `filter` processor | [drop by name and value example](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/filterprocessor#dropping-specific-metric-and-value) |
25+
| multiply_int, divide_int, multiply_float | `metricstransform` processor's `scale` value functionality | [one metric](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/metricstransformprocessor#scale-value) |
26+
| rename_dimension_keys | `metricstransform` processor's update label function | [one metric](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/metricstransformprocessor#rename-labels), [multiple metrics](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/metricstransformprocessor#rename-labels-for-multiple-metrics) |
27+
| rename_metrics | `metricstransform` processor's rename metric functionality | [one metric](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/metricstransformprocessor#rename-metric), [multiple metrics](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/metricstransformprocessor#rename-multiple-metrics-using-substitution) |
28+
| split_metric | `metricstransform` processor's `insert` functionality and `filter` processor | Refer to the replacement guidance for the `copy_metrics` and `drop_metrics` translation rules |

exporter/signalfxexporter/exporter.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func newSignalFxExporter(
6969
return nil, errors.New("nil config")
7070
}
7171

72-
metricTranslator, err := config.getMetricTranslator(createSettings.TelemetrySettings.Logger, make(chan struct{}))
72+
metricTranslator, err := config.getMetricTranslator(make(chan struct{}))
7373
if err != nil {
7474
return nil, err
7575
}

exporter/signalfxexporter/testdata/config.yaml

-23
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,6 @@ signalfx/allsettings:
2020
added-entry: "added value"
2121
dot.test: test
2222
access_token_passthrough: false
23-
translation_rules:
24-
- action: rename_dimension_keys
25-
mapping:
26-
k8s.cluster.name: kubernetes_cluster
27-
- action: drop_dimensions
28-
dimension_pairs:
29-
foo:
30-
foo1:
31-
bar: true
32-
- action: drop_dimensions
33-
metric_name: metric
34-
dimension_pairs:
35-
foo:
36-
foo1:
37-
bar: true
38-
- action: drop_dimensions
39-
metric_names:
40-
metric1: true
41-
metric2: true
42-
dimension_pairs:
43-
foo:
44-
foo1:
45-
bar: true
4623
exclude_metrics:
4724
- metric_name: metric1
4825
- metric_names: [metric2, metric3]

0 commit comments

Comments
 (0)