Skip to content
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.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- add_host_metadata is no GA. {pull}13148[13148]
- Add `registered_domain` processor for deriving the registered domain from a given FQDN. {pull}13326[13326]
- Add support for RFC3339 time zone offsets in JSON output. {pull}13227[13227]
- Add autodetection mode for add_docker_metadata and enable it by default in included configuration files{pull}13374[13374]

*Auditbeat*

Expand Down
1 change: 1 addition & 0 deletions auditbeat/auditbeat.docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ auditbeat.modules:
- /etc
processors:
- add_cloud_metadata: ~
- add_docker_metadata: ~

output.elasticsearch:
hosts: '${ELASTICSEARCH_HOSTS:elasticsearch:9200}'
Expand Down
1 change: 1 addition & 0 deletions auditbeat/auditbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ output.elasticsearch:
processors:
- add_host_metadata: ~
- add_cloud_metadata: ~
- add_docker_metadata: ~

#================================ Logging =====================================

Expand Down
1 change: 1 addition & 0 deletions filebeat/filebeat.docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ filebeat.config:

processors:
- add_cloud_metadata: ~
- add_docker_metadata: ~

output.elasticsearch:
hosts: '${ELASTICSEARCH_HOSTS:elasticsearch:9200}'
Expand Down
1 change: 1 addition & 0 deletions filebeat/filebeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ output.elasticsearch:
processors:
- add_host_metadata: ~
- add_cloud_metadata: ~
- add_docker_metadata: ~

#================================ Logging =====================================

Expand Down
1 change: 1 addition & 0 deletions heartbeat/heartbeat.docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ heartbeat.monitors:

processors:
- add_cloud_metadata: ~
- add_docker_metadata: ~

output.elasticsearch:
hosts: '${ELASTICSEARCH_HOSTS:elasticsearch:9200}'
Expand Down
4 changes: 2 additions & 2 deletions heartbeat/heartbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ output.elasticsearch:
#================================ Processors =====================================

processors:
- add_observer_metadata:
- add_observer_metadata:
# Optional, but recommended geo settings for the location Heartbeat is running in
#geo:
#geo:
# Token describing this location
#name: us-east-1a

Expand Down
1 change: 1 addition & 0 deletions journalbeat/journalbeat.docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ journalbeat.inputs:

processors:
- add_cloud_metadata: ~
- add_docker_metadata: ~

output.elasticsearch:
hosts: '${ELASTICSEARCH_HOSTS:elasticsearch:9200}'
Expand Down
1 change: 1 addition & 0 deletions journalbeat/journalbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ output.elasticsearch:
processors:
- add_host_metadata: ~
- add_cloud_metadata: ~
- add_docker_metadata: ~

#================================ Logging =====================================

Expand Down
1 change: 1 addition & 0 deletions libbeat/_meta/config.docker.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
processors:
- add_cloud_metadata: ~
- add_docker_metadata: ~

output.elasticsearch:
hosts: '${ELASTICSEARCH_HOSTS:elasticsearch:9200}'
Expand Down
5 changes: 3 additions & 2 deletions libbeat/_meta/config.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ output.elasticsearch:
processors:
- add_host_metadata: ~
- add_cloud_metadata: ~
- add_docker_metadata: ~
Comment thread
jsoriano marked this conversation as resolved.
Outdated
{{else}}
processors:
- add_observer_metadata:
- add_observer_metadata:
# Optional, but recommended geo settings for the location {{ .BeatName | title }} is running in
#geo:
#geo:
# Token describing this location
#name: us-east-1a

Expand Down
6 changes: 6 additions & 0 deletions libbeat/common/docker/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ func NewWatcher(host string, tls *TLSConfig, storeShortID bool) (Watcher, error)
return nil, err
}

// Extra check to confirm that Docker is available
_, err = client.Info(context.Background())
if err != nil {
return nil, err
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder if this can affect other users of NewWatcher, it seems safe though.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes it could affect others (AutodiscoverBuilder) in case of a connectivity error, but it wont be a problem I think, since an error will be returned for a case that is indeed problematic.


return NewWatcherWithClient(client, 60*time.Second, storeShortID)
}

Expand Down
30 changes: 21 additions & 9 deletions libbeat/processors/add_docker_metadata/add_docker_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ type addDockerMetadata struct {
fields []string
sourceProcessor processors.Processor

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 `_`.
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 `_`.
dockerAvailable bool // If Docker exists in env, then it is set to true
}

// New constructs a new add_docker_metadata processor.
Expand All @@ -74,13 +75,19 @@ func buildDockerMetadataProcessor(cfg *common.Config, watcherConstructor docker.
return nil, errors.Wrapf(err, "fail to unpack the %v configuration", processorName)
}

var dockerAvailable bool

watcher, err := watcherConstructor(config.Host, config.TLS, config.MatchShortID)
if err != nil {
return nil, err
}

if err = watcher.Start(); err != nil {
return nil, err
dockerAvailable = false
errorMsg := fmt.Sprintf("%v: docker environment not detected: %v", processorName, err)
logp.Debug("add_docker_metadata", errorMsg)
} else {
dockerAvailable = true
logp.Debug("add_docker_metadata", "%v: docker environment detected", processorName)
if err = watcher.Start(); err != nil {
return nil, errors.Wrap(err, "failed to start watcher")
}
}

// Use extract_field processor to get container ID from source file path.
Expand All @@ -106,6 +113,7 @@ func buildDockerMetadataProcessor(cfg *common.Config, watcherConstructor docker.
pidFields: config.MatchPIDs,
hostFS: config.HostFS,
dedot: config.DeDot,
dockerAvailable: dockerAvailable,
}, nil
}

Expand All @@ -121,8 +129,12 @@ func lazyCgroupCacheInit(d *addDockerMetadata) {
}

func (d *addDockerMetadata) Run(event *beat.Event) (*beat.Event, error) {
if !d.dockerAvailable {
return event, nil
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit. You could move this code to the very end of the function, before these declarations.

var cid string
var err error

// Extract CID from the filepath contained in the "log.file.path" field.
if d.sourceProcessor != nil {
lfp, _ := event.Fields.GetValue("log.file.path")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ func init() {
}
}

func TestInitializationNoDocker(t *testing.T) {
var testConfig = common.NewConfig()
testConfig.SetString("host", -1, "unix:///var/run42/docker.sock")

p, err := buildDockerMetadataProcessor(testConfig, docker.NewWatcher)
assert.NoError(t, err, "initializing add_docker_metadata processor")

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

assert.Equal(t, common.MapStr{}, result.Fields)
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for adding a test for this


func TestInitialization(t *testing.T) {
var testConfig = common.NewConfig()

Expand Down
1 change: 1 addition & 0 deletions metricbeat/metricbeat.docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ metricbeat.config.modules:

processors:
- add_cloud_metadata: ~
- add_docker_metadata: ~

output.elasticsearch:
hosts: '${ELASTICSEARCH_HOSTS:elasticsearch:9200}'
Expand Down
1 change: 1 addition & 0 deletions metricbeat/metricbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ output.elasticsearch:
processors:
- add_host_metadata: ~
- add_cloud_metadata: ~
- add_docker_metadata: ~

#================================ Logging =====================================

Expand Down
1 change: 1 addition & 0 deletions packetbeat/packetbeat.docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ packetbeat.protocols.tls:

processors:
- add_cloud_metadata: ~
- add_docker_metadata: ~

output.elasticsearch:
hosts: '${ELASTICSEARCH_HOSTS:elasticsearch:9200}'
Expand Down
1 change: 1 addition & 0 deletions packetbeat/packetbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ output.elasticsearch:
processors:
- add_host_metadata: ~
- add_cloud_metadata: ~
- add_docker_metadata: ~

#================================ Logging =====================================

Expand Down
1 change: 1 addition & 0 deletions winlogbeat/winlogbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ output.elasticsearch:
processors:
- add_host_metadata: ~
- add_cloud_metadata: ~
- add_docker_metadata: ~

#================================ Logging =====================================

Expand Down
1 change: 1 addition & 0 deletions x-pack/auditbeat/auditbeat.docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ auditbeat.modules:
- /etc
processors:
- add_cloud_metadata: ~
- add_docker_metadata: ~

output.elasticsearch:
hosts: '${ELASTICSEARCH_HOSTS:elasticsearch:9200}'
Expand Down
1 change: 1 addition & 0 deletions x-pack/auditbeat/auditbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ output.elasticsearch:
processors:
- add_host_metadata: ~
- add_cloud_metadata: ~
- add_docker_metadata: ~

#================================ Logging =====================================

Expand Down
1 change: 1 addition & 0 deletions x-pack/filebeat/filebeat.docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ filebeat.config:

processors:
- add_cloud_metadata: ~
- add_docker_metadata: ~

output.elasticsearch:
hosts: '${ELASTICSEARCH_HOSTS:elasticsearch:9200}'
Expand Down
1 change: 1 addition & 0 deletions x-pack/filebeat/filebeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ output.elasticsearch:
processors:
- add_host_metadata: ~
- add_cloud_metadata: ~
- add_docker_metadata: ~

#================================ Logging =====================================

Expand Down
1 change: 1 addition & 0 deletions x-pack/functionbeat/functionbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ output.elasticsearch:
processors:
- add_host_metadata: ~
- add_cloud_metadata: ~
- add_docker_metadata: ~

#================================ Logging =====================================

Expand Down
1 change: 1 addition & 0 deletions x-pack/metricbeat/metricbeat.docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ metricbeat.config.modules:

processors:
- add_cloud_metadata: ~
- add_docker_metadata: ~

output.elasticsearch:
hosts: '${ELASTICSEARCH_HOSTS:elasticsearch:9200}'
Expand Down
1 change: 1 addition & 0 deletions x-pack/metricbeat/metricbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ output.elasticsearch:
processors:
- add_host_metadata: ~
- add_cloud_metadata: ~
- add_docker_metadata: ~

#================================ Logging =====================================

Expand Down
1 change: 1 addition & 0 deletions x-pack/winlogbeat/winlogbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ output.elasticsearch:
processors:
- add_host_metadata: ~
- add_cloud_metadata: ~
- add_docker_metadata: ~

#================================ Logging =====================================

Expand Down