Skip to content

Commit 044579b

Browse files
[8.19](backport #47729) remove otel.component.id and otel.component.kind fields from beat receivers (#47786)
* remove otel.component.id and otel.component.kind fields from beat receivers (#47729) (cherry picked from commit ca1c17b) # Conflicts: # x-pack/filebeat/tests/integration/otel_lsexporter_test.go # x-pack/libbeat/outputs/otelconsumer/otelconsumer.go # x-pack/libbeat/outputs/otelconsumer/otelconsumer_test.go * fix backport * make linter happy * fix conflict resolution * fix integration test --------- Co-authored-by: Lee E Hinman <57081003+leehinman@users.noreply.github.com> Co-authored-by: Lee E. Hinman <lee.e.hinman@elastic.co>
1 parent 3ec344b commit 044579b

8 files changed

Lines changed: 63 additions & 137 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# REQUIRED
2+
# Kind can be one of:
3+
# - breaking-change: a change to previously-documented behavior
4+
# - deprecation: functionality that is being removed in a later release
5+
# - bug-fix: fixes a problem in a previous version
6+
# - enhancement: extends functionality but does not break or fix existing behavior
7+
# - feature: new functionality
8+
# - known-issue: problems that we are aware of in a given version
9+
# - security: impacts on the security of a product or a user’s deployment.
10+
# - upgrade: important information for someone upgrading from a prior version
11+
# - other: does not fit into any of the other categories
12+
kind: breaking-change
13+
14+
# REQUIRED for all kinds
15+
# Change summary; a 80ish characters long description of the change.
16+
summary: remove otel.component.id and otel.component.kind from beat receiver events
17+
18+
# REQUIRED for breaking-change, deprecation, known-issue
19+
# Long description; in case the summary is not enough to describe the change
20+
# this field accommodate a description without length limits.
21+
# description:
22+
23+
# REQUIRED for breaking-change, deprecation, known-issue
24+
# impact:
25+
26+
# REQUIRED for breaking-change, deprecation, known-issue
27+
# action:
28+
29+
# REQUIRED for all kinds
30+
# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
31+
component: all
32+
33+
# AUTOMATED
34+
# OPTIONAL to manually add other PR URLs
35+
# PR URL: A link the PR that added the changeset.
36+
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
37+
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
38+
# Please provide it if you are adding a fragment for a different PR.
39+
pr: https://github.com/elastic/beats/pull/47729
40+
41+
# AUTOMATED
42+
# OPTIONAL to manually add other issue URLs
43+
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
44+
# If not present is automatically filled by the tooling with the issue linked to the PR number.
45+
issue: https://github.com/elastic/beats/issues/47600

x-pack/filebeat/fbreceiver/receiver_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ func TestNewReceiver(t *testing.T) {
8383
AssertFunc: func(c *assert.CollectT, logs map[string][]mapstr.M, zapLogs *observer.ObservedLogs) {
8484
_ = zapLogs
8585
require.Lenf(c, logs["r1"], 1, "expected 1 log, got %d", len(logs["r1"]))
86-
assert.Equal(c, "filebeatreceiver/r1", logs["r1"][0].Flatten()["agent.otelcol.component.id"], "expected agent.otelcol.component.id field in log record")
87-
assert.Equal(c, "receiver", logs["r1"][0].Flatten()["agent.otelcol.component.kind"], "expected agent.otelcol.component.kind field in log record")
86+
assert.Equal(c, "test", logs["r1"][0].Flatten()["message"], "expected message field to contain string 'test'")
8887
var lastError strings.Builder
8988
assert.Conditionf(c, func() bool {
9089
return getFromSocket(t, &lastError, monitorSocket, "stats")
@@ -264,9 +263,7 @@ func TestMultipleReceivers(t *testing.T) {
264263
writeFile(c, helper.ingest, "A log line")
265264

266265
require.Greaterf(c, len(logs[helper.name]), 0, "receiver %v does not have any logs", helper)
267-
268-
assert.Equalf(c, "filebeatreceiver/"+helper.name, logs[helper.name][0].Flatten()["agent.otelcol.component.id"], "expected agent.otelcol.component.id field in %v log record", helper)
269-
assert.Equalf(c, "receiver", logs[helper.name][0].Flatten()["agent.otelcol.component.kind"], "expected agent.otelcol.component.kind field in %v log record", helper)
266+
assert.Equal(c, "test", logs[helper.name][0].Flatten()["message"], "expected message field to contain string 'test'")
270267

271268
// Verify that each receiver used its own JavaScript processor script.
272269
// This demonstrates path isolation: each receiver loads processor.js from its own path.config.

x-pack/filebeat/input/gcppubsub/otel_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,10 @@ service:
211211
defer findCancel()
212212

213213
otelDocs, err = estools.PerformQueryForRawQuery(findCtx, rawQuery, ".ds-logs-integration-"+otelNamespace+"*", es)
214-
msg.WriteString(fmt.Sprintf("failed to query ES for beat documents: %v", err))
214+
fmt.Fprintf(msg, "failed to query ES for beat documents: %v", err)
215215

216216
filebeatDocs, err = estools.PerformQueryForRawQuery(findCtx, rawQuery, ".ds-logs-integration-"+fbNameSpace+"*", es)
217-
msg.WriteString(fmt.Sprintf("failed to query ES for beat documents: %v", err))
217+
fmt.Fprintf(msg, "failed to query ES for beat documents: %v", err)
218218

219219
return otelDocs.Hits.Total.Value >= 1 && filebeatDocs.Hits.Total.Value >= 1
220220
},
@@ -228,11 +228,7 @@ service:
228228
"agent.ephemeral_id",
229229
"agent.id",
230230
"event.created",
231-
// only present in beats receivers
232-
"agent.otelcol.component.id",
233-
"agent.otelcol.component.kind",
234231
}
235232

236233
oteltest.AssertMapsEqual(t, filebeatDoc, otelDoc, ignoredFields, "expected documents to be equal")
237-
238234
}

x-pack/filebeat/tests/integration/otel_test.go

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ service:
110110
writeEventsToLogFile(t, logFilePath, numEvents)
111111
oteltestcol.New(t, fmt.Sprintf(otelCfgFile, logFilePath, tmpdir, otelMonitoringPort, fbOtelIndex))
112112

113-
var beatsCfgFile = `
113+
beatsCfgFile := `
114114
filebeat.inputs:
115115
- type: filestream
116116
id: filestream-input-id
@@ -184,18 +184,13 @@ http.port: %d
184184
"agent.id",
185185
"log.file.inode",
186186
"log.file.path",
187-
// only present in beats receivers
188-
"agent.otelcol.component.id",
189-
"agent.otelcol.component.kind",
190187
"log.file.device_id", // changes value between filebeat and otel receiver
191188
}
192189

193190
oteltest.AssertMapsEqual(t, filebeatDoc, otelDoc, ignoredFields, "expected documents to be equal")
194191

195-
assert.Equal(t, "filebeatreceiver", otelDoc.Flatten()["agent.otelcol.component.id"], "expected agent.otelcol.component.id field in log record")
196-
assert.Equal(t, "receiver", otelDoc.Flatten()["agent.otelcol.component.kind"], "expected agent.otelcol.component.kind field in log record")
197-
assert.NotContains(t, filebeatDoc.Flatten(), "agent.otelcol.component.id", "expected agent.otelcol.component.id field not to be present in filebeat log record")
198-
assert.NotContains(t, filebeatDoc.Flatten(), "agent.otelcol.component.kind", "expected agent.otelcol.component.kind field not to be present in filebeat log record")
192+
assert.Equal(t, "filebeat", otelDoc.Flatten()["agent.type"], "expected agent.type field to be 'filebeat' in otel docs")
193+
assert.Equal(t, "filebeat", filebeatDoc.Flatten()["agent.type"], "expected agent.type field to be 'filebeat' in filebeat docs")
199194
assertMonitoring(t, otelMonitoringPort)
200195
}
201196

@@ -367,9 +362,6 @@ service:
367362
"agent.ephemeral_id",
368363
"agent.id",
369364
"event.created",
370-
// only present in beats receivers
371-
"agent.otelcol.component.id",
372-
"agent.otelcol.component.kind",
373365
}
374366

375367
oteltest.AssertMapsEqual(t, filebeatDoc, otelDoc, ignoredFields, "expected documents to be equal")
@@ -572,17 +564,13 @@ http.port: %d
572564
"log.file.inode",
573565
"log.file.path",
574566
// only present in beats receivers
575-
"agent.otelcol.component.id",
576-
"agent.otelcol.component.kind",
577567
"log.file.device_id", // changes value between filebeat and otel receiver
578568
"container.id", // only present in filebeat
579569
}
580570

581571
oteltest.AssertMapsEqual(t, filebeatDoc, otelDoc, ignoredFields, "expected documents to be equal")
582-
assert.Equal(t, "filebeatreceiver/filestream", otelDoc.Flatten()["agent.otelcol.component.id"], "expected agent.otelcol.component.id field in log record")
583-
assert.Equal(t, "receiver", otelDoc.Flatten()["agent.otelcol.component.kind"], "expected agent.otelcol.component.kind field in log record")
584-
assert.NotContains(t, filebeatDoc.Flatten(), "agent.otelcol.component.id", "expected agent.otelcol.component.id field not to be present in filebeat log record")
585-
assert.NotContains(t, filebeatDoc.Flatten(), "agent.otelcol.component.kind", "expected agent.otelcol.component.kind field not to be present in filebeat log record")
572+
assert.Equal(t, "filebeat", otelDoc.Flatten()["agent.type"], "expected agent.type field to be 'filebeat' in otel docs")
573+
assert.Equal(t, "filebeat", filebeatDoc.Flatten()["agent.type"], "expected agent.type field to be 'filebeat' in filebeat docs")
586574
assertMonitoring(t, otelConfig.MonitoringPort)
587575
assertMonitoring(t, filebeatMonitoringPort) // filebeat
588576
}
@@ -1006,7 +994,6 @@ service:
1006994
}
1007995

1008996
func TestFileBeatKerberos(t *testing.T) {
1009-
1010997
wantEvents := 1
1011998
krbURL := "http://localhost:9203" // this is kerberos client - we've hardcoded the URL here
1012999
tempFile := t.TempDir()
@@ -1113,7 +1100,6 @@ service:
11131100
assert.GreaterOrEqual(ct, otelDocs.Hits.Total.Value, wantEvents, "expected at least %d events, got %d", wantEvents, otelDocs.Hits.Total.Value)
11141101
},
11151102
2*time.Minute, 1*time.Second)
1116-
11171103
}
11181104

11191105
func TestFilebeatOTelBeatProcessorE2E(t *testing.T) {
@@ -1305,7 +1291,6 @@ exporters:
13051291

13061292
// setupRoleMapping sets up role mapping for the Kerberos user beats@elastic
13071293
func setupRoleMapping(t *testing.T, client *elasticsearch.Client) {
1308-
13091294
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
13101295
defer cancel()
13111296

@@ -1339,5 +1324,4 @@ func setupRoleMapping(t *testing.T, client *elasticsearch.Client) {
13391324
defer resp.Body.Close()
13401325

13411326
require.Equal(t, resp.StatusCode, http.StatusOK, "incorrect response code")
1342-
13431327
}

x-pack/libbeat/outputs/otelconsumer/otelconsumer.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ const (
3232
esDocumentIDAttribute = "elasticsearch.document_id"
3333
beatNameCtxKey = "beat_name"
3434
beatVersionCtxtKey = "beat_version"
35-
// otelComponentIDKey is the key used to store the Beat receiver's component id in the beat event.
36-
otelComponentIDKey = "otelcol.component.id"
37-
// otelComponentKindKey is the key used to store the Beat receiver's component kind in the beat event. This is always "receiver".
38-
otelComponentKindKey = "otelcol.component.kind"
3935
)
4036

4137
func init() {
@@ -143,15 +139,6 @@ func (out *otelConsumer) logsPublish(ctx context.Context, batch publisher.Batch)
143139
}
144140
logRecord.SetObservedTimestamp(observedTimestamp)
145141

146-
if agent, _ := beatEvent.GetValue("agent"); agent != nil {
147-
switch agent := agent.(type) {
148-
case mapstr.M:
149-
agent[otelComponentIDKey] = out.beatInfo.ComponentID
150-
agent[otelComponentKindKey] = "receiver"
151-
beatEvent["agent"] = agent
152-
}
153-
}
154-
155142
otelmap.ConvertNonPrimitive(beatEvent)
156143

157144
// if data_stream field is set on beatEvent. Add it to logrecord.Attributes to support dynamic indexing

x-pack/libbeat/outputs/otelconsumer/otelconsumer_test.go

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -281,73 +281,4 @@ func TestPublish(t *testing.T) {
281281
assert.Len(t, batch.Signals, 1)
282282
assert.Equal(t, outest.BatchACK, batch.Signals[0].Tag)
283283
})
284-
t.Run("sets otel specific-fields", func(t *testing.T) {
285-
testCases := []struct {
286-
name string
287-
componentID string
288-
componentKind string
289-
expectedComponentID string
290-
expectedComponentKind string
291-
}{
292-
{
293-
name: "sets beat component ID",
294-
componentID: "filebeatreceiver/1",
295-
expectedComponentID: "filebeatreceiver/1",
296-
expectedComponentKind: "receiver",
297-
},
298-
}
299-
300-
for _, tc := range testCases {
301-
t.Run(tc.name, func(t *testing.T) {
302-
event := beat.Event{
303-
Fields: mapstr.M{
304-
"field": 1,
305-
"agent": mapstr.M{},
306-
},
307-
Meta: mapstr.M{
308-
"_id": "abc123",
309-
},
310-
}
311-
ch := make(chan plog.Logs, 1)
312-
batch := outest.NewBatch(event)
313-
var countLogs int
314-
otelConsumer := makeOtelConsumer(t, func(ctx context.Context, ld plog.Logs) error {
315-
countLogs = countLogs + ld.LogRecordCount()
316-
ch <- ld
317-
return nil
318-
})
319-
otelConsumer.beatInfo.ComponentID = tc.componentID
320-
err := otelConsumer.Publish(ctx, batch)
321-
assert.NoError(t, err)
322-
assert.Len(t, batch.Signals, 1)
323-
assert.Equal(t, outest.BatchACK, batch.Signals[0].Tag)
324-
assert.Equal(t, len(batch.Events()), countLogs, "all events should be consumed")
325-
log := <-ch
326-
for i := 0; i < log.ResourceLogs().Len(); i++ {
327-
resourceLog := log.ResourceLogs().At(i)
328-
for j := 0; j < resourceLog.ScopeLogs().Len(); j++ {
329-
scopeLog := resourceLog.ScopeLogs().At(j)
330-
for k := 0; k < scopeLog.LogRecords().Len(); k++ {
331-
logRecord := scopeLog.LogRecords().At(k)
332-
body := logRecord.Body().Map()
333-
334-
// Traverse nested "agent.otelcol.component" structure
335-
agentVal, ok := body.Get("agent")
336-
require.True(t, ok, "expected 'agent' in log body")
337-
338-
agentMap := agentVal.Map()
339-
idVal, ok := agentMap.Get("otelcol.component.id")
340-
require.True(t, ok, "expected 'agent.otelcol.component.id' in log body")
341-
assert.Equal(t, tc.expectedComponentID, idVal.AsString())
342-
343-
kindVal, ok := agentMap.Get("otelcol.component.kind")
344-
require.True(t, ok, "expected 'agent.otelcol.component.kind' in log body")
345-
assert.Equal(t, tc.expectedComponentKind, kindVal.AsString())
346-
}
347-
}
348-
}
349-
350-
})
351-
}
352-
})
353284
}

x-pack/metricbeat/mbreceiver/receiver_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ func TestNewReceiver(t *testing.T) {
8787
require.Conditionf(c, func() bool {
8888
return len(logs["r1"]) > 0
8989
}, "expected at least one ingest log, got logs: %v", logs["r1"])
90-
assert.Equal(c, "metricbeatreceiver/r1", logs["r1"][0].Flatten()["agent.otelcol.component.id"], "expected agent.otelcol.component.id field in log record")
91-
assert.Equal(c, "receiver", logs["r1"][0].Flatten()["agent.otelcol.component.kind"], "expected agent.otelcol.component.kind field in log record")
90+
assert.Equal(c, "metricbeat", logs["r1"][0].Flatten()["agent.type"], "expected agent.type field in to be 'metricbeat'")
91+
9292
var lastError strings.Builder
9393
assert.Conditionf(c, func() bool {
9494
return getFromSocket(t, &lastError, monitorSocket, "stats")
@@ -198,10 +198,8 @@ func TestMultipleReceivers(t *testing.T) {
198198
require.Conditionf(c, func() bool {
199199
return len(logs["r1"]) > 0 && len(logs["r2"]) > 0
200200
}, "expected at least one ingest log for each receiver, got logs: %v", logs)
201-
assert.Equal(c, "metricbeatreceiver/r1", logs["r1"][0].Flatten()["agent.otelcol.component.id"], "expected agent.otelcol.component.id field in r1 log record")
202-
assert.Equal(c, "receiver", logs["r1"][0].Flatten()["agent.otelcol.component.kind"], "expected agent.otelcol.component.kind field in r1 log record")
203-
assert.Equal(c, "metricbeatreceiver/r2", logs["r2"][0].Flatten()["agent.otelcol.component.id"], "expected agent.otelcol.component.id field in r2 log record")
204-
assert.Equal(c, "receiver", logs["r2"][0].Flatten()["agent.otelcol.component.kind"], "expected otelcol.component.kind field in r2 log record")
201+
assert.Equal(c, "metricbeat", logs["r1"][0].Flatten()["agent.type"], "expected agent.type field to be 'metricbeat' in r1")
202+
assert.Equal(c, "metricbeat", logs["r2"][0].Flatten()["agent.type"], "expected agent.type field to be 'metricbeat' in r2")
205203

206204
// Make sure that each receiver has a separate logger
207205
// instance and does not interfere with others. Previously, the

x-pack/metricbeat/tests/integration/otel_test.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ service:
122122

123123
oteltestcol.New(t, configBuffer.String())
124124

125-
var beatsCfgFile = `
125+
beatsCfgFile := `
126126
metricbeat:
127127
modules:
128128
- module: system
@@ -205,16 +205,9 @@ http.port: {{.MonitoringPort}}
205205
var metricbeatDoc, otelDoc mapstr.M
206206
otelDoc = otelDocs.Hits.Hits[0].Source
207207
metricbeatDoc = metricbeatDocs.Hits.Hits[0].Source
208-
ignoredFields := []string{
209-
// only present in beats receivers
210-
"agent.otelcol.component.id",
211-
"agent.otelcol.component.kind",
212-
}
213-
assert.Equal(t, "metricbeatreceiver", otelDoc.Flatten()["agent.otelcol.component.id"], "expected agent.otelcol.component.id field in log record")
214-
assert.Equal(t, "receiver", otelDoc.Flatten()["agent.otelcol.component.kind"], "expected agent.otelcol.component.kind field in log record")
215-
assert.NotContains(t, metricbeatDoc.Flatten(), "agent.otelcol.component.id", "expected agent.otelcol.component.id field not to be present in metricbeat log record")
216-
assert.NotContains(t, metricbeatDoc.Flatten(), "agent.otelcol.component.kind", "expected agent.otelcol.component.kind field not to be present in metricbeat log record")
217-
assertMapstrKeysEqual(t, otelDoc, metricbeatDoc, ignoredFields, "expected documents keys to be equal")
208+
assert.Equal(t, "metricbeat", otelDoc.Flatten()["agent.type"], "expected agent.type field to be 'metricbeat' in otel docs")
209+
assert.Equal(t, "metricbeat", metricbeatDoc.Flatten()["agent.type"], "expected agent.type field to be 'metricbeat' in metricbeat docs")
210+
assertMapstrKeysEqual(t, otelDoc, metricbeatDoc, nil, "expected documents keys to be equal")
218211
assertMonitoring(t, metricbeatMonitoringPort)
219212
}
220213

@@ -543,12 +536,7 @@ service:
543536
assert.GreaterOrEqualf(ct, r1Docs.Hits.Total.Value, 1, "expected at least 1 log for receiver 1, got %d", r1Docs.Hits.Total.Value)
544537
},
545538
1*time.Minute, 100*time.Millisecond, "expected at least 1 log for each receiver")
546-
ignoredFields := []string{
547-
// only present in beats receivers
548-
"agent.otelcol.component.id",
549-
"agent.otelcol.component.kind",
550-
}
551-
assertMapstrKeysEqual(t, r0Docs.Hits.Hits[0].Source, r1Docs.Hits.Hits[0].Source, ignoredFields, "expected documents keys to be equal")
539+
assertMapstrKeysEqual(t, r0Docs.Hits.Hits[0].Source, r1Docs.Hits.Hits[0].Source, nil, "expected documents keys to be equal")
552540
for _, rec := range otelConfig.Receivers {
553541
assertMonitoring(t, rec.MonitoringPort)
554542
}

0 commit comments

Comments
 (0)