Skip to content

Commit 6bd74ae

Browse files
authored
[exporter/elasticsearch] deprecate 'dedup' config (#33779)
**Description:** Deprecate `exporter/elasticsearch`'s "dedup" configuration. In a future release we will remove this configuration, and always deduplicate wherever necessary. **Link to tracking Issue:** #33773 **Testing:** N/A **Documentation:** Updated the README.
1 parent a12660d commit 6bd74ae

File tree

5 files changed

+77
-4
lines changed

5 files changed

+77
-4
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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: deprecation
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: exporter/elasticsearch
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Deprecate the "dedup" configuration.
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: [33773]
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: dedup has been deprecated, and will always be enabled in future.
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

exporter/elasticsearchexporter/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ behaviours, which may be configured throug the following settings:
127127
field names for span events.
128128
- `fields` (optional): Configure additional fields mappings.
129129
- `file` (optional): Read additional field mappings from the provided YAML file.
130-
- `dedup` (default=true): Try to find and remove duplicate fields/attributes
131-
from events before publishing to Elasticsearch. Some structured logging
132-
libraries can produce duplicate fields (for example zap). Elasticsearch
133-
will reject documents that have duplicate fields.
130+
- `dedup` (default=true; DEPRECATED, in future deduplication will always be enabled):
131+
Try to find and remove duplicate fields/attributes from events before publishing
132+
to Elasticsearch. Some structured logging libraries can produce duplicate fields
133+
(for example zap). Elasticsearch will reject documents that have duplicate fields.
134134
- `dedot` (default=true): When enabled attributes with `.` will be split into
135135
proper json objects.
136136

exporter/elasticsearchexporter/config.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"go.opentelemetry.io/collector/config/confighttp"
1616
"go.opentelemetry.io/collector/config/configopaque"
1717
"go.opentelemetry.io/collector/exporter/exporterhelper"
18+
"go.uber.org/zap"
1819
)
1920

2021
// Config defines configuration for Elastic exporter.
@@ -157,6 +158,10 @@ type MappingsSettings struct {
157158
File string `mapstructure:"file"`
158159

159160
// Try to find and remove duplicate fields
161+
//
162+
// Deprecated: [v0.104.0] deduplication will always be applied in future,
163+
// with no option to disable. Disabling deduplication is not meaningful,
164+
// as Elasticsearch will reject documents with duplicate JSON object keys.
160165
Dedup bool `mapstructure:"dedup"`
161166

162167
Dedot bool `mapstructure:"dedot"`
@@ -309,3 +314,9 @@ func parseCloudID(input string) (*url.URL, error) {
309314
func (cfg *Config) MappingMode() MappingMode {
310315
return mappingModes[cfg.Mapping.Mode]
311316
}
317+
318+
func logConfigDeprecationWarnings(cfg *Config, logger *zap.Logger) {
319+
if !cfg.Mapping.Dedup {
320+
logger.Warn("dedup has been deprecated, and will always be enabled in future")
321+
}
322+
}

exporter/elasticsearchexporter/factory.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ func createLogsExporter(
9292
set.Logger.Warn("index option are deprecated and replaced with logs_index and traces_index.")
9393
index = cf.Index
9494
}
95+
logConfigDeprecationWarnings(cf, set.Logger)
9596

9697
exporter, err := newExporter(cf, set, index, cf.LogsDynamicIndex.Enabled)
9798
if err != nil {
@@ -115,6 +116,7 @@ func createMetricsExporter(
115116
cfg component.Config,
116117
) (exporter.Metrics, error) {
117118
cf := cfg.(*Config)
119+
logConfigDeprecationWarnings(cf, set.Logger)
118120

119121
exporter, err := newExporter(cf, set, cf.MetricsIndex, cf.MetricsDynamicIndex.Enabled)
120122
if err != nil {
@@ -136,6 +138,7 @@ func createTracesExporter(ctx context.Context,
136138
cfg component.Config) (exporter.Traces, error) {
137139

138140
cf := cfg.(*Config)
141+
logConfigDeprecationWarnings(cf, set.Logger)
139142

140143
exporter, err := newExporter(cf, set, cf.TracesIndex, cf.TracesDynamicIndex.Enabled)
141144
if err != nil {

exporter/elasticsearchexporter/factory_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"github.com/stretchr/testify/require"
1212
"go.opentelemetry.io/collector/component/componenttest"
1313
"go.opentelemetry.io/collector/exporter/exportertest"
14+
"go.uber.org/zap"
15+
"go.uber.org/zap/zaptest/observer"
1416
)
1517

1618
func TestCreateDefaultConfig(t *testing.T) {
@@ -94,3 +96,33 @@ func TestFactory_CreateLogsAndTracesExporterWithDeprecatedIndexOption(t *testing
9496
require.NotNil(t, tracesExporter)
9597
require.NoError(t, tracesExporter.Shutdown(context.Background()))
9698
}
99+
100+
func TestFactory_DedupDeprecated(t *testing.T) {
101+
factory := NewFactory()
102+
cfg := withDefaultConfig(func(cfg *Config) {
103+
cfg.Endpoint = "http://testing.invalid:9200"
104+
cfg.Mapping.Dedup = false
105+
})
106+
107+
loggerCore, logObserver := observer.New(zap.WarnLevel)
108+
set := exportertest.NewNopSettings()
109+
set.Logger = zap.New(loggerCore)
110+
111+
logsExporter, err := factory.CreateLogsExporter(context.Background(), set, cfg)
112+
require.NoError(t, err)
113+
require.NoError(t, logsExporter.Shutdown(context.Background()))
114+
115+
tracesExporter, err := factory.CreateTracesExporter(context.Background(), set, cfg)
116+
require.NoError(t, err)
117+
require.NoError(t, tracesExporter.Shutdown(context.Background()))
118+
119+
metricsExporter, err := factory.CreateMetricsExporter(context.Background(), set, cfg)
120+
require.NoError(t, err)
121+
require.NoError(t, metricsExporter.Shutdown(context.Background()))
122+
123+
records := logObserver.AllUntimed()
124+
assert.Len(t, records, 3)
125+
assert.Equal(t, "dedup has been deprecated, and will always be enabled in future", records[0].Message)
126+
assert.Equal(t, "dedup has been deprecated, and will always be enabled in future", records[1].Message)
127+
assert.Equal(t, "dedup has been deprecated, and will always be enabled in future", records[2].Message)
128+
}

0 commit comments

Comments
 (0)