Skip to content

Commit be89f4d

Browse files
authored
Cherry-pick to 6.x: Add DeDot in add_docker_metadata processor (#9505) (#9602)
* Cherry-pick to 6.x: Add DeDot in add_docker_metadata processor (#9505) * Add DeDot in add_docker_metadata processor * Add dedot into config and default to be false * Update changelog and documentation * Add documentation into processors-using.asciidoc * Run mage fmt update under x-pack filebeat * Run mage fmt update on x-pack metricbeat * Run update again * Run make update fmt from top level dir * Remove mistakes from rebase * Remove repeated doc (cherry picked from commit 58573a9) * remove extra line in data.json
1 parent 0218a8c commit be89f4d

18 files changed

+88
-2
lines changed

CHANGELOG.asciidoc

+1
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ https://github.com/elastic/beats/compare/v6.4.0...v6.5.0[View commits]
259259
- Report configured queue type. {pull}8091[8091]
260260
- Enable `host` and `cloud` metadata processors by default. {pull}8596[8596]
261261
- Autodiscovery no longer requires that the `condition` field be set. If left unset all configs will be matched. {pull}9029[9029]
262+
- Add DeDot method in add_docker_metadata processor in libbeat. {issue}9350[9350] {pull}9505[9505]
262263
263264
*Filebeat*
264265

auditbeat/auditbeat.reference.yml

+1
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ auditbeat.modules:
286286
# match_source_index: 4
287287
# match_short_id: false
288288
# cleanup_timeout: 60
289+
# labels.dedot: false
289290
# # To connect to Docker over TLS you must specify a client and CA certificate.
290291
# #ssl:
291292
# # certificate_authority: "/etc/pki/root/ca.pem"

auditbeat/docs/getting-started.asciidoc

+16
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,22 @@ endif::[]
9797
[[docker]]
9898
*docker:*
9999

100+
ifeval::["{release-state}"=="unreleased"]
101+
102+
Version {stack-version} of {beatname_uc} has not yet been released.
103+
104+
endif::[]
105+
106+
ifeval::["{release-state}"!="unreleased"]
107+
108+
["source","sh",subs="attributes"]
109+
------------------------------------------------
110+
curl -L -O https://artifacts.elastic.co/downloads/beats/{beatname_lc}/{beatname_lc}-{version}-linux-x86_64.tar.gz
111+
tar xzvf {beatname_lc}-{version}-linux-x86_64.tar.gz
112+
------------------------------------------------
113+
114+
endif::[]
115+
100116
See <<running-on-docker, Running on Docker>> for deploying Docker containers.
101117

102118
[[win]]

filebeat/filebeat.reference.yml

+1
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,7 @@ filebeat.inputs:
965965
# match_source_index: 4
966966
# match_short_id: false
967967
# cleanup_timeout: 60
968+
# labels.dedot: false
968969
# # To connect to Docker over TLS you must specify a client and CA certificate.
969970
# #ssl:
970971
# # certificate_authority: "/etc/pki/root/ca.pem"

heartbeat/heartbeat.reference.yml

+1
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ heartbeat.scheduler:
424424
# match_source_index: 4
425425
# match_short_id: false
426426
# cleanup_timeout: 60
427+
# labels.dedot: false
427428
# # To connect to Docker over TLS you must specify a client and CA certificate.
428429
# #ssl:
429430
# # certificate_authority: "/etc/pki/root/ca.pem"

journalbeat/journalbeat.reference.yml

+1
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ journalbeat.inputs:
237237
# match_source_index: 4
238238
# match_short_id: false
239239
# cleanup_timeout: 60
240+
# labels.dedot: false
240241
# # To connect to Docker over TLS you must specify a client and CA certificate.
241242
# #ssl:
242243
# # certificate_authority: "/etc/pki/root/ca.pem"

libbeat/_meta/config.reference.yml

+1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
# match_source_index: 4
180180
# match_short_id: false
181181
# cleanup_timeout: 60
182+
# labels.dedot: false
182183
# # To connect to Docker over TLS you must specify a client and CA certificate.
183184
# #ssl:
184185
# # certificate_authority: "/etc/pki/root/ca.pem"

libbeat/docs/processors-using.asciidoc

+4
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,7 @@ processors:
848848
#match_source_index: 4
849849
#match_short_id: true
850850
#cleanup_timeout: 60
851+
#labels.dedot: false
851852
# To connect to Docker over TLS you must specify a client and CA certificate.
852853
#ssl:
853854
# certificate_authority: "/etc/pki/root/ca.pem"
@@ -885,6 +886,9 @@ for container ID. It defaults to 4 to match
885886
`cleanup_timeout`:: (Optional) Time of inactivity to consider we can clean and
886887
forget metadata for a container, 60s by default.
887888

889+
`labels.dedot`:: (Optional) Default to be false. If set to true, replace dots in
890+
labels with `_`.
891+
888892
[[add-host-metadata]]
889893
=== Add Host metadata
890894

libbeat/processors/add_docker_metadata/add_docker_metadata.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ type addDockerMetadata struct {
6060
pidFields []string // Field names that contain PIDs.
6161
cgroups *common.Cache // Cache of PID (int) to cgropus (map[string]string).
6262
hostFS string // Directory where /proc is found
63+
dedot bool // If set to true, replace dots in labels with `_`.
6364
}
6465

6566
func newDockerMetadataProcessor(cfg *common.Config) (processors.Processor, error) {
@@ -103,6 +104,7 @@ func buildDockerMetadataProcessor(cfg *common.Config, watcherConstructor docker.
103104
sourceProcessor: sourceProcessor,
104105
pidFields: config.MatchPIDs,
105106
hostFS: config.HostFS,
107+
dedot: config.DeDot,
106108
}, nil
107109
}
108110

@@ -174,7 +176,12 @@ func (d *addDockerMetadata) Run(event *beat.Event) (*beat.Event, error) {
174176
if len(container.Labels) > 0 {
175177
labels := common.MapStr{}
176178
for k, v := range container.Labels {
177-
safemapstr.Put(labels, k, v)
179+
if d.dedot {
180+
label := common.DeDot(k)
181+
labels.Put(label, v)
182+
} else {
183+
safemapstr.Put(labels, k, v)
184+
}
178185
}
179186
meta.Put("container.labels", labels)
180187
}

libbeat/processors/add_docker_metadata/add_docker_metadata_test.go

+45
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,51 @@ func TestMatchContainer(t *testing.T) {
148148
}, result.Fields)
149149
}
150150

151+
func TestMatchContainerWithDedot(t *testing.T) {
152+
testConfig, err := common.NewConfigFrom(map[string]interface{}{
153+
"match_fields": []string{"foo"},
154+
"labels.dedot": true,
155+
})
156+
assert.NoError(t, err)
157+
158+
p, err := buildDockerMetadataProcessor(testConfig, MockWatcherFactory(
159+
map[string]*docker.Container{
160+
"container_id": &docker.Container{
161+
ID: "container_id",
162+
Image: "image",
163+
Name: "name",
164+
Labels: map[string]string{
165+
"a.x": "1",
166+
"b": "2",
167+
"b.foo": "3",
168+
},
169+
},
170+
}))
171+
assert.NoError(t, err, "initializing add_docker_metadata processor")
172+
173+
input := common.MapStr{
174+
"foo": "container_id",
175+
}
176+
result, err := p.Run(&beat.Event{Fields: input})
177+
assert.NoError(t, err, "processing an event")
178+
179+
assert.EqualValues(t, common.MapStr{
180+
"docker": common.MapStr{
181+
"container": common.MapStr{
182+
"id": "container_id",
183+
"image": "image",
184+
"labels": common.MapStr{
185+
"a_x": "1",
186+
"b": "2",
187+
"b_foo": "3",
188+
},
189+
"name": "name",
190+
},
191+
},
192+
"foo": "container_id",
193+
}, result.Fields)
194+
}
195+
151196
func TestMatchSource(t *testing.T) {
152197
// Use defaults
153198
testConfig, err := common.NewConfigFrom(map[string]interface{}{})

libbeat/processors/add_docker_metadata/config.go

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type Config struct {
3333
SourceIndex int `config:"match_source_index"` // Index in the source path split by / to look for container ID.
3434
MatchPIDs []string `config:"match_pids"` // A list of fields containing process IDs (PIDs).
3535
HostFS string `config:"system.hostfs"` // Specifies the mount point of the host’s filesystem for use in monitoring a host from within a container.
36+
DeDot bool `config:"labels.dedot"` // If set to true, replace dots in labels with `_`.
3637

3738
// Annotations are kept after container is killed, until they haven't been
3839
// accessed for a full `cleanup_timeout`:
@@ -45,5 +46,6 @@ func defaultConfig() Config {
4546
MatchSource: true,
4647
SourceIndex: 4, // Use 4 to match the CID in /var/lib/docker/containers/<container_id>/*.log.
4748
MatchPIDs: []string{"process.pid", "process.ppid"},
49+
DeDot: false,
4850
}
4951
}

metricbeat/metricbeat.reference.yml

+1
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,7 @@ metricbeat.modules:
864864
# match_source_index: 4
865865
# match_short_id: false
866866
# cleanup_timeout: 60
867+
# labels.dedot: false
867868
# # To connect to Docker over TLS you must specify a client and CA certificate.
868869
# #ssl:
869870
# # certificate_authority: "/etc/pki/root/ca.pem"

metricbeat/module/elasticsearch/node/_meta/data.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@
4747
"service": {
4848
"name": "elasticsearch"
4949
}
50-
}
50+
}

packetbeat/packetbeat.reference.yml

+1
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,7 @@ packetbeat.protocols:
660660
# match_source_index: 4
661661
# match_short_id: false
662662
# cleanup_timeout: 60
663+
# labels.dedot: false
663664
# # To connect to Docker over TLS you must specify a client and CA certificate.
664665
# #ssl:
665666
# # certificate_authority: "/etc/pki/root/ca.pem"

winlogbeat/winlogbeat.reference.yml

+1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ winlogbeat.event_logs:
208208
# match_source_index: 4
209209
# match_short_id: false
210210
# cleanup_timeout: 60
211+
# labels.dedot: false
211212
# # To connect to Docker over TLS you must specify a client and CA certificate.
212213
# #ssl:
213214
# # certificate_authority: "/etc/pki/root/ca.pem"

x-pack/filebeat/filebeat.reference.yml

+1
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,7 @@ filebeat.inputs:
993993
# match_source_index: 4
994994
# match_short_id: false
995995
# cleanup_timeout: 60
996+
# labels.dedot: false
996997
# # To connect to Docker over TLS you must specify a client and CA certificate.
997998
# #ssl:
998999
# # certificate_authority: "/etc/pki/root/ca.pem"

x-pack/functionbeat/functionbeat.reference.yml

+1
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ functionbeat.provider.aws.functions:
273273
# match_source_index: 4
274274
# match_short_id: false
275275
# cleanup_timeout: 60
276+
# labels.dedot: false
276277
# # To connect to Docker over TLS you must specify a client and CA certificate.
277278
# #ssl:
278279
# # certificate_authority: "/etc/pki/root/ca.pem"

x-pack/metricbeat/metricbeat.reference.yml

+1
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,7 @@ metricbeat.modules:
872872
# match_source_index: 4
873873
# match_short_id: false
874874
# cleanup_timeout: 60
875+
# labels.dedot: false
875876
# # To connect to Docker over TLS you must specify a client and CA certificate.
876877
# #ssl:
877878
# # certificate_authority: "/etc/pki/root/ca.pem"

0 commit comments

Comments
 (0)