Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick to 6.x: Add DeDot in add_docker_metadata processor (#9505) #9602

Merged
merged 2 commits into from
Dec 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ https://github.com/elastic/beats/compare/v6.4.0...v6.5.0[View commits]
- Report configured queue type. {pull}8091[8091]
- Enable `host` and `cloud` metadata processors by default. {pull}8596[8596]
- Autodiscovery no longer requires that the `condition` field be set. If left unset all configs will be matched. {pull}9029[9029]
- Add DeDot method in add_docker_metadata processor in libbeat. {issue}9350[9350] {pull}9505[9505]

*Filebeat*

Expand Down
1 change: 1 addition & 0 deletions auditbeat/auditbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ auditbeat.modules:
# match_source_index: 4
# match_short_id: false
# cleanup_timeout: 60
# labels.dedot: false
# # To connect to Docker over TLS you must specify a client and CA certificate.
# #ssl:
# # certificate_authority: "/etc/pki/root/ca.pem"
Expand Down
16 changes: 16 additions & 0 deletions auditbeat/docs/getting-started.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ endif::[]
[[docker]]
*docker:*

ifeval::["{release-state}"=="unreleased"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this related to this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's make update generated this in the original PR. Sorry I should have waited for one last review from you and Jaime.


Version {stack-version} of {beatname_uc} has not yet been released.

endif::[]

ifeval::["{release-state}"!="unreleased"]

["source","sh",subs="attributes"]
------------------------------------------------
curl -L -O https://artifacts.elastic.co/downloads/beats/{beatname_lc}/{beatname_lc}-{version}-linux-x86_64.tar.gz
tar xzvf {beatname_lc}-{version}-linux-x86_64.tar.gz
------------------------------------------------

endif::[]

See <<running-on-docker, Running on Docker>> for deploying Docker containers.

[[win]]
Expand Down
1 change: 1 addition & 0 deletions filebeat/filebeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,7 @@ filebeat.inputs:
# match_source_index: 4
# match_short_id: false
# cleanup_timeout: 60
# labels.dedot: false
# # To connect to Docker over TLS you must specify a client and CA certificate.
# #ssl:
# # certificate_authority: "/etc/pki/root/ca.pem"
Expand Down
1 change: 1 addition & 0 deletions heartbeat/heartbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ heartbeat.scheduler:
# match_source_index: 4
# match_short_id: false
# cleanup_timeout: 60
# labels.dedot: false
# # To connect to Docker over TLS you must specify a client and CA certificate.
# #ssl:
# # certificate_authority: "/etc/pki/root/ca.pem"
Expand Down
1 change: 1 addition & 0 deletions journalbeat/journalbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ journalbeat.inputs:
# match_source_index: 4
# match_short_id: false
# cleanup_timeout: 60
# labels.dedot: false
# # To connect to Docker over TLS you must specify a client and CA certificate.
# #ssl:
# # certificate_authority: "/etc/pki/root/ca.pem"
Expand Down
1 change: 1 addition & 0 deletions libbeat/_meta/config.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
# match_source_index: 4
# match_short_id: false
# cleanup_timeout: 60
# labels.dedot: false
# # To connect to Docker over TLS you must specify a client and CA certificate.
# #ssl:
# # certificate_authority: "/etc/pki/root/ca.pem"
Expand Down
4 changes: 4 additions & 0 deletions libbeat/docs/processors-using.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,7 @@ processors:
#match_source_index: 4
#match_short_id: true
#cleanup_timeout: 60
#labels.dedot: false
# To connect to Docker over TLS you must specify a client and CA certificate.
#ssl:
# certificate_authority: "/etc/pki/root/ca.pem"
Expand Down Expand Up @@ -885,6 +886,9 @@ for container ID. It defaults to 4 to match
`cleanup_timeout`:: (Optional) Time of inactivity to consider we can clean and
forget metadata for a container, 60s by default.

`labels.dedot`:: (Optional) Default to be false. If set to true, replace dots in
labels with `_`.

[[add-host-metadata]]
=== Add Host metadata

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

func newDockerMetadataProcessor(cfg *common.Config) (processors.Processor, error) {
Expand Down Expand Up @@ -103,6 +104,7 @@ func buildDockerMetadataProcessor(cfg *common.Config, watcherConstructor docker.
sourceProcessor: sourceProcessor,
pidFields: config.MatchPIDs,
hostFS: config.HostFS,
dedot: config.DeDot,
}, nil
}

Expand Down Expand Up @@ -174,7 +176,12 @@ func (d *addDockerMetadata) Run(event *beat.Event) (*beat.Event, error) {
if len(container.Labels) > 0 {
labels := common.MapStr{}
for k, v := range container.Labels {
safemapstr.Put(labels, k, v)
if d.dedot {
label := common.DeDot(k)
labels.Put(label, v)
} else {
safemapstr.Put(labels, k, v)
}
}
meta.Put("container.labels", labels)
}
Expand Down
45 changes: 45 additions & 0 deletions libbeat/processors/add_docker_metadata/add_docker_metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,51 @@ func TestMatchContainer(t *testing.T) {
}, result.Fields)
}

func TestMatchContainerWithDedot(t *testing.T) {
testConfig, err := common.NewConfigFrom(map[string]interface{}{
"match_fields": []string{"foo"},
"labels.dedot": true,
})
assert.NoError(t, err)

p, err := buildDockerMetadataProcessor(testConfig, MockWatcherFactory(
map[string]*docker.Container{
"container_id": &docker.Container{
ID: "container_id",
Image: "image",
Name: "name",
Labels: map[string]string{
"a.x": "1",
"b": "2",
"b.foo": "3",
},
},
}))
assert.NoError(t, err, "initializing add_docker_metadata processor")

input := common.MapStr{
"foo": "container_id",
}
result, err := p.Run(&beat.Event{Fields: input})
assert.NoError(t, err, "processing an event")

assert.EqualValues(t, common.MapStr{
"docker": common.MapStr{
"container": common.MapStr{
"id": "container_id",
"image": "image",
"labels": common.MapStr{
"a_x": "1",
"b": "2",
"b_foo": "3",
},
"name": "name",
},
},
"foo": "container_id",
}, result.Fields)
}

func TestMatchSource(t *testing.T) {
// Use defaults
testConfig, err := common.NewConfigFrom(map[string]interface{}{})
Expand Down
2 changes: 2 additions & 0 deletions libbeat/processors/add_docker_metadata/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Config struct {
SourceIndex int `config:"match_source_index"` // Index in the source path split by / to look for container ID.
MatchPIDs []string `config:"match_pids"` // A list of fields containing process IDs (PIDs).
HostFS string `config:"system.hostfs"` // Specifies the mount point of the host’s filesystem for use in monitoring a host from within a container.
DeDot bool `config:"labels.dedot"` // If set to true, replace dots in labels with `_`.

// Annotations are kept after container is killed, until they haven't been
// accessed for a full `cleanup_timeout`:
Expand All @@ -45,5 +46,6 @@ func defaultConfig() Config {
MatchSource: true,
SourceIndex: 4, // Use 4 to match the CID in /var/lib/docker/containers/<container_id>/*.log.
MatchPIDs: []string{"process.pid", "process.ppid"},
DeDot: false,
}
}
1 change: 1 addition & 0 deletions metricbeat/metricbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,7 @@ metricbeat.modules:
# match_source_index: 4
# match_short_id: false
# cleanup_timeout: 60
# labels.dedot: false
# # To connect to Docker over TLS you must specify a client and CA certificate.
# #ssl:
# # certificate_authority: "/etc/pki/root/ca.pem"
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/elasticsearch/node/_meta/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@
"service": {
"name": "elasticsearch"
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This change probably happened because you opened this file manually but it does not belong into this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah hmm and I thought it's just an extra line but after deleting the extra line, it still shows up different.

1 change: 1 addition & 0 deletions packetbeat/packetbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ packetbeat.protocols:
# match_source_index: 4
# match_short_id: false
# cleanup_timeout: 60
# labels.dedot: false
# # To connect to Docker over TLS you must specify a client and CA certificate.
# #ssl:
# # certificate_authority: "/etc/pki/root/ca.pem"
Expand Down
1 change: 1 addition & 0 deletions winlogbeat/winlogbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ winlogbeat.event_logs:
# match_source_index: 4
# match_short_id: false
# cleanup_timeout: 60
# labels.dedot: false
# # To connect to Docker over TLS you must specify a client and CA certificate.
# #ssl:
# # certificate_authority: "/etc/pki/root/ca.pem"
Expand Down
1 change: 1 addition & 0 deletions x-pack/filebeat/filebeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,7 @@ filebeat.inputs:
# match_source_index: 4
# match_short_id: false
# cleanup_timeout: 60
# labels.dedot: false
# # To connect to Docker over TLS you must specify a client and CA certificate.
# #ssl:
# # certificate_authority: "/etc/pki/root/ca.pem"
Expand Down
1 change: 1 addition & 0 deletions x-pack/functionbeat/functionbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ functionbeat.provider.aws.functions:
# match_source_index: 4
# match_short_id: false
# cleanup_timeout: 60
# labels.dedot: false
# # To connect to Docker over TLS you must specify a client and CA certificate.
# #ssl:
# # certificate_authority: "/etc/pki/root/ca.pem"
Expand Down
1 change: 1 addition & 0 deletions x-pack/metricbeat/metricbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,7 @@ metricbeat.modules:
# match_source_index: 4
# match_short_id: false
# cleanup_timeout: 60
# labels.dedot: false
# # To connect to Docker over TLS you must specify a client and CA certificate.
# #ssl:
# # certificate_authority: "/etc/pki/root/ca.pem"
Expand Down