Skip to content

Commit 738443c

Browse files
leehinmanmergify[bot]
authored andcommitted
remove otel.component.id and otel.component.kind fields from beat receivers (#47729)
* remove component id and component kind fields from beat receivers * add real PR link * update integration tests * fix merge mistake (cherry picked from commit ca1c17b)
1 parent 63bdfd3 commit 738443c

File tree

9 files changed

+63
-138
lines changed

9 files changed

+63
-138
lines changed
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: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ func TestNewReceiver(t *testing.T) {
9393
AssertFunc: func(c *assert.CollectT, logs map[string][]mapstr.M, zapLogs *observer.ObservedLogs) {
9494
_ = zapLogs
9595
require.Lenf(c, logs["r1"], 1, "expected 1 log, got %d", len(logs["r1"]))
96-
assert.Equal(c, "filebeatreceiver/r1", logs["r1"][0].Flatten()["agent.otelcol.component.id"], "expected agent.otelcol.component.id field in log record")
97-
assert.Equal(c, "receiver", logs["r1"][0].Flatten()["agent.otelcol.component.kind"], "expected agent.otelcol.component.kind field in log record")
96+
assert.Equal(c, "test", logs["r1"][0].Flatten()["message"], "expected message field to contain string 'test'")
9897
var lastError strings.Builder
9998
assert.Conditionf(c, func() bool {
10099
return getFromSocket(t, &lastError, monitorSocket, "stats")
@@ -259,10 +258,8 @@ func TestMultipleReceivers(t *testing.T) {
259258
require.Greater(c, len(logs["r1"]), 0, "receiver r1 does not have any logs")
260259
require.Greater(c, len(logs["r2"]), 0, "receiver r2 does not have any logs")
261260

262-
assert.Equal(c, "filebeatreceiver/r1", logs["r1"][0].Flatten()["agent.otelcol.component.id"], "expected agent.otelcol.component.id field in r1 log record")
263-
assert.Equal(c, "receiver", logs["r1"][0].Flatten()["agent.otelcol.component.kind"], "expected agent.otelcol.component.kind field in r1 log record")
264-
assert.Equal(c, "filebeatreceiver/r2", logs["r2"][0].Flatten()["agent.otelcol.component.id"], "expected agent.otelcol.component.id field in r2 log record")
265-
assert.Equal(c, "receiver", logs["r2"][0].Flatten()["agent.otelcol.component.kind"], "expected agent.otelcol.component.kind field in r2 log record")
261+
assert.Equal(c, "test", logs["r1"][0].Flatten()["message"], "expected r1 message field to be 'test'")
262+
assert.Equal(c, "test", logs["r2"][0].Flatten()["message"], "expected r2 message field to be 'test'")
266263

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

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,7 @@ processors:
175175
"agent.ephemeral_id",
176176
"agent.id",
177177
"event.created",
178-
// only present in beats receivers
179-
"agent.otelcol.component.id",
180-
"agent.otelcol.component.kind",
181178
}
182179

183180
oteltest.AssertMapsEqual(t, filebeatDoc, otelDoc, ignoredFields, "expected documents to be equal")
184-
185181
}

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func TestDataShapeOTelVSClassicE2E(t *testing.T) {
6565

6666
// Agent does not support `index` setting, while beats does.
6767
// Our focus is on agent classic vs otel mode comparison, so we do not test `index` for filebeat
68-
var beatsCfgFile = `
68+
beatsCfgFile := `
6969
filebeat.inputs:
7070
- type: filestream
7171
id: filestream-input-id
@@ -175,8 +175,6 @@ service:
175175
"log.file.inode",
176176
"log.file.path",
177177
// only present in beats receivers
178-
"agent.otelcol.component.id",
179-
"agent.otelcol.component.kind",
180178
"log.file.device_id",
181179
"log.file.fingerprint",
182180
}
@@ -272,7 +270,6 @@ service:
272270
require.NoError(t, err, "failed to read otel events")
273271
require.Equal(t, numEvents, len(otelEvents),
274272
"different number of events: sent=%d, get=%d", numEvents, len(otelEvents))
275-
276273
}
277274

278275
func generateEvents(numEvents int) []string {
@@ -381,10 +378,8 @@ func compareOutputFiles(t *testing.T, fbFilePath, otelFilePath string, ignoredFi
381378
oteltest.AssertMapsEqual(t, fbEvent.data, otelEvent.data, ignoredFields,
382379
fmt.Sprintf("event comparison failed for ID %s (line %d)", fbEvent.id, i))
383380

384-
assert.Equal(t, "filebeatreceiver", otelEvent.data.Flatten()["agent.otelcol.component.id"], "expected agent.otelcol.component.id field in log record")
385-
assert.Equal(t, "receiver", otelEvent.data.Flatten()["agent.otelcol.component.kind"], "expected agent.otelcol.component.kind field in log record")
386-
assert.NotContains(t, fbEvent.data.Flatten(), "agent.otelcol.component.id", "expected agent.otelcol.component.id field not to be present in filebeat log record")
387-
assert.NotContains(t, fbEvent.data.Flatten(), "agent.otelcol.component.kind", "expected agent.otelcol.component.kind field not to be present in filebeat log record")
381+
assert.Equal(t, "filebeat", otelEvent.data.Flatten()["agent.type"], "expected agent.type to be 'filebeat' in otel data")
382+
assert.Equal(t, "filebeat", fbEvent.data.Flatten()["agent.type"], "expected agent.type to be 'filebeat' in filebeat data")
388383
}
389384
}
390385

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ service:
112112
writeEventsToLogFile(t, logFilePath, numEvents)
113113
oteltestcol.New(t, fmt.Sprintf(otelCfgFile, logFilePath, tmpdir, otelMonitoringPort, fbOtelIndex))
114114

115-
var beatsCfgFile = `
115+
beatsCfgFile := `
116116
filebeat.inputs:
117117
- type: filestream
118118
id: filestream-input-id
@@ -186,18 +186,13 @@ http.port: %d
186186
"agent.id",
187187
"log.file.inode",
188188
"log.file.path",
189-
// only present in beats receivers
190-
"agent.otelcol.component.id",
191-
"agent.otelcol.component.kind",
192189
"log.file.device_id", // changes value between filebeat and otel receiver
193190
}
194191

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

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

@@ -371,9 +366,6 @@ service:
371366
"agent.ephemeral_id",
372367
"agent.id",
373368
"event.created",
374-
// only present in beats receivers
375-
"agent.otelcol.component.id",
376-
"agent.otelcol.component.kind",
377369
}
378370

379371
oteltest.AssertMapsEqual(t, filebeatDoc, otelDoc, ignoredFields, "expected documents to be equal")
@@ -1126,7 +1118,6 @@ service:
11261118
}
11271119

11281120
func TestFileBeatKerberos(t *testing.T) {
1129-
11301121
wantEvents := 1
11311122
krbURL := "http://localhost:9203" // this is kerberos client - we've hardcoded the URL here
11321123
tempFile := t.TempDir()
@@ -1235,12 +1226,10 @@ service:
12351226
assert.GreaterOrEqual(ct, otelDocs.Hits.Total.Value, wantEvents, "expected at least %d events, got %d", wantEvents, otelDocs.Hits.Total.Value)
12361227
},
12371228
2*time.Minute, 1*time.Second)
1238-
12391229
}
12401230

12411231
// setupRoleMapping sets up role mapping for the Kerberos user beats@elastic
12421232
func setupRoleMapping(t *testing.T, client *elasticsearch.Client) {
1243-
12441233
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
12451234
defer cancel()
12461235

@@ -1274,5 +1263,4 @@ func setupRoleMapping(t *testing.T, client *elasticsearch.Client) {
12741263
defer resp.Body.Close()
12751264

12761265
require.Equal(t, resp.StatusCode, http.StatusOK, "incorrect response code")
1277-
12781266
}

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ import (
3131
const (
3232
// esDocumentIDAttribute is the attribute key used to store the document ID in the log record.
3333
esDocumentIDAttribute = "elasticsearch.document_id"
34-
// otelComponentIDKey is the key used to store the Beat receiver's component id in the beat event.
35-
otelComponentIDKey = "otelcol.component.id"
36-
// otelComponentKindKey is the key used to store the Beat receiver's component kind in the beat event. This is always "receiver".
37-
otelComponentKindKey = "otelcol.component.kind"
3834
)
3935

4036
func init() {
@@ -153,15 +149,6 @@ func (out *otelConsumer) logsPublish(ctx context.Context, batch publisher.Batch)
153149
}
154150
logRecord.SetObservedTimestamp(observedTimestamp)
155151

156-
if agent, _ := beatEvent.GetValue("agent"); agent != nil {
157-
switch agent := agent.(type) {
158-
case mapstr.M:
159-
agent[otelComponentIDKey] = out.beatInfo.ComponentID
160-
agent[otelComponentKindKey] = "receiver"
161-
beatEvent["agent"] = agent
162-
}
163-
}
164-
165152
otelmap.ConvertNonPrimitive(beatEvent)
166153

167154
// 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
@@ -289,75 +289,6 @@ func TestPublish(t *testing.T) {
289289
assert.Len(t, batch.Signals, 1)
290290
assert.Equal(t, outest.BatchACK, batch.Signals[0].Tag)
291291
})
292-
t.Run("sets otel specific-fields", func(t *testing.T) {
293-
testCases := []struct {
294-
name string
295-
componentID string
296-
componentKind string
297-
expectedComponentID string
298-
expectedComponentKind string
299-
}{
300-
{
301-
name: "sets beat component ID",
302-
componentID: "filebeatreceiver/1",
303-
expectedComponentID: "filebeatreceiver/1",
304-
expectedComponentKind: "receiver",
305-
},
306-
}
307-
308-
for _, tc := range testCases {
309-
t.Run(tc.name, func(t *testing.T) {
310-
event := beat.Event{
311-
Fields: mapstr.M{
312-
"field": 1,
313-
"agent": mapstr.M{},
314-
},
315-
Meta: mapstr.M{
316-
"_id": "abc123",
317-
},
318-
}
319-
ch := make(chan plog.Logs, 1)
320-
batch := outest.NewBatch(event)
321-
var countLogs int
322-
otelConsumer := makeOtelConsumer(t, func(ctx context.Context, ld plog.Logs) error {
323-
countLogs = countLogs + ld.LogRecordCount()
324-
ch <- ld
325-
return nil
326-
})
327-
otelConsumer.beatInfo.ComponentID = tc.componentID
328-
err := otelConsumer.Publish(ctx, batch)
329-
assert.NoError(t, err)
330-
assert.Len(t, batch.Signals, 1)
331-
assert.Equal(t, outest.BatchACK, batch.Signals[0].Tag)
332-
assert.Equal(t, len(batch.Events()), countLogs, "all events should be consumed")
333-
log := <-ch
334-
for i := 0; i < log.ResourceLogs().Len(); i++ {
335-
resourceLog := log.ResourceLogs().At(i)
336-
for j := 0; j < resourceLog.ScopeLogs().Len(); j++ {
337-
scopeLog := resourceLog.ScopeLogs().At(j)
338-
for k := 0; k < scopeLog.LogRecords().Len(); k++ {
339-
logRecord := scopeLog.LogRecords().At(k)
340-
body := logRecord.Body().Map()
341-
342-
// Traverse nested "agent.otelcol.component" structure
343-
agentVal, ok := body.Get("agent")
344-
require.True(t, ok, "expected 'agent' in log body")
345-
346-
agentMap := agentVal.Map()
347-
idVal, ok := agentMap.Get("otelcol.component.id")
348-
require.True(t, ok, "expected 'agent.otelcol.component.id' in log body")
349-
assert.Equal(t, tc.expectedComponentID, idVal.AsString())
350-
351-
kindVal, ok := agentMap.Get("otelcol.component.kind")
352-
require.True(t, ok, "expected 'agent.otelcol.component.kind' in log body")
353-
assert.Equal(t, tc.expectedComponentKind, kindVal.AsString())
354-
}
355-
}
356-
}
357-
358-
})
359-
}
360-
})
361292
t.Run("sets the client context metadata with the beat info", func(t *testing.T) {
362293
batch := outest.NewBatch(event1)
363294
otelConsumer := makeOtelConsumer(t, func(ctx context.Context, ld plog.Logs) error {

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")
@@ -204,10 +204,8 @@ func TestMultipleReceivers(t *testing.T) {
204204
require.Conditionf(c, func() bool {
205205
return len(logs["r1"]) > 0 && len(logs["r2"]) > 0
206206
}, "expected at least one ingest log for each receiver, got logs: %v", logs)
207-
assert.Equal(c, "metricbeatreceiver/r1", logs["r1"][0].Flatten()["agent.otelcol.component.id"], "expected agent.otelcol.component.id field in r1 log record")
208-
assert.Equal(c, "receiver", logs["r1"][0].Flatten()["agent.otelcol.component.kind"], "expected agent.otelcol.component.kind field in r1 log record")
209-
assert.Equal(c, "metricbeatreceiver/r2", logs["r2"][0].Flatten()["agent.otelcol.component.id"], "expected agent.otelcol.component.id field in r2 log record")
210-
assert.Equal(c, "receiver", logs["r2"][0].Flatten()["agent.otelcol.component.kind"], "expected otelcol.component.kind field in r2 log record")
207+
assert.Equal(c, "metricbeat", logs["r1"][0].Flatten()["agent.type"], "expected agent.type field to be 'metricbeat' in r1")
208+
assert.Equal(c, "metricbeat", logs["r2"][0].Flatten()["agent.type"], "expected agent.type field to be 'metricbeat' in r2")
211209

212210
// Make sure that each receiver has a separate logger
213211
// 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
@@ -124,7 +124,7 @@ service:
124124

125125
oteltestcol.New(t, configBuffer.String())
126126

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

@@ -549,12 +542,7 @@ service:
549542
assert.GreaterOrEqualf(ct, r1Docs.Hits.Total.Value, 1, "expected at least 1 log for receiver 1, got %d", r1Docs.Hits.Total.Value)
550543
},
551544
1*time.Minute, 100*time.Millisecond, "expected at least 1 log for each receiver")
552-
ignoredFields := []string{
553-
// only present in beats receivers
554-
"agent.otelcol.component.id",
555-
"agent.otelcol.component.kind",
556-
}
557-
assertMapstrKeysEqual(t, r0Docs.Hits.Hits[0].Source, r1Docs.Hits.Hits[0].Source, ignoredFields, "expected documents keys to be equal")
545+
assertMapstrKeysEqual(t, r0Docs.Hits.Hits[0].Source, r1Docs.Hits.Hits[0].Source, nil, "expected documents keys to be equal")
558546
for _, rec := range otelConfig.Receivers {
559547
assertMonitoring(t, rec.MonitoringPort)
560548
}

0 commit comments

Comments
 (0)