Skip to content

Commit 3fa11af

Browse files
committed
Add conditions to copy_fields processor
This commit adds conditions to the `copy_fields` processor from the monitoring Filebeat to prevent it from failing and spamming the event logger at debug level with: `target field xxx already exists, drop or rename this field first`
1 parent 345f2ae commit 3fa11af

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Kind can be one of:
2+
# - breaking-change: a change to previously-documented behavior
3+
# - deprecation: functionality that is being removed in a later release
4+
# - bug-fix: fixes a problem in a previous version
5+
# - enhancement: extends functionality but does not break or fix existing behavior
6+
# - feature: new functionality
7+
# - known-issue: problems that we are aware of in a given version
8+
# - security: impacts on the security of a product or a user’s deployment.
9+
# - upgrade: important information for someone upgrading from a prior version
10+
# - other: does not fit into any of the other categories
11+
kind: bug-fix
12+
13+
# Change summary; a 80ish characters long description of the change.
14+
summary: >
15+
Add conditions to copy_fields processors to prevent spamming the debug logs
16+
17+
# Long description; in case the summary is not enough to describe the change
18+
# this field accommodate a description without length limits.
19+
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
20+
description:
21+
22+
# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
23+
component: elastic-agent
24+
25+
# PR URL; optional; the PR number that added the changeset.
26+
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
27+
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
28+
# Please provide it if you are adding a fragment for a different PR.
29+
pr: https://github.com/elastic/elastic-agent/pull/6730
30+
31+
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
32+
# If not present is automatically filled by the tooling with the issue linked to the PR number.
33+
issue: https://github.com/elastic/elastic-agent/issues/5299

internal/pkg/agent/application/monitoring/v1_monitor.go

+28
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,13 @@ func (b *BeatsMonitor) injectLogsInput(cfg map[string]interface{}, components []
424424
"to": "data_stream.dataset_original",
425425
},
426426
},
427+
"when": map[string]any{
428+
"not": map[string]any{
429+
"has_fields": []any{
430+
"data_stream.dataset_original",
431+
},
432+
},
433+
},
427434
},
428435
},
429436
// drop the dataset field so following copy_field can copy to it
@@ -443,13 +450,27 @@ func (b *BeatsMonitor) injectLogsInput(cfg map[string]interface{}, components []
443450
"to": "data_stream.dataset",
444451
},
445452
},
453+
"when": map[string]any{
454+
"not": map[string]any{
455+
"has_fields": []any{
456+
"data_stream.dataset",
457+
},
458+
},
459+
},
446460
"fail_on_error": false,
447461
"ignore_missing": true,
448462
},
449463
},
450464
// possible it's a log message from agent itself (doesn't have component.dataset)
451465
map[string]interface{}{
452466
"copy_fields": map[string]interface{}{
467+
"when": map[string]any{
468+
"not": map[string]any{
469+
"has_fields": []any{
470+
"data_stream.dataset",
471+
},
472+
},
473+
},
453474
"fields": []interface{}{
454475
map[string]interface{}{
455476
"from": "data_stream.dataset_original",
@@ -471,6 +492,13 @@ func (b *BeatsMonitor) injectLogsInput(cfg map[string]interface{}, components []
471492
// update event.dataset with the now used data_stream.dataset
472493
map[string]interface{}{
473494
"copy_fields": map[string]interface{}{
495+
"when": map[string]any{
496+
"not": map[string]any{
497+
"has_fields": []any{
498+
"event.dataset",
499+
},
500+
},
501+
},
474502
"fields": []interface{}{
475503
map[string]interface{}{
476504
"from": "data_stream.dataset",

0 commit comments

Comments
 (0)