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

Add autodetection mode for add_docker_metadata #13374

Merged
merged 6 commits into from
Sep 4, 2019

Conversation

ChrsMark
Copy link
Member

@ChrsMark ChrsMark commented Aug 28, 2019

This PR is a proposal for enabling autodetection mode for add_docker_metadata.

Currently we configure add_cloud_metadata and add_host_metadata by default in all Beats.

add_cloud_metadata does autodetection, and it will only enrich events if the beat is running on a known public cloud.

It would be useful to have the same for Docker (and Kubernetes), so if Beats is started in a scenario where Docker is available, it automatically enables metadata for it. If Docker is not present nothing will happen.

In this PR only the Docker part is covered. After we conclude to a final approach, a follow-up PR will come for the Kubernetes part.

How to test it

  1. With docker available
    a. Run metricbeat or filebeat in an environement where Docker is present.
    b. Verify that processor is being automatically enabled.
  2. With docker unavailable
    a. Run metricbeat or filebeat in an environement where Docker is not present.
    b. Verify that processor is not being automatically enabled.

@ChrsMark ChrsMark self-assigned this Aug 28, 2019
@ChrsMark ChrsMark added Team:Integrations Label for the Integrations team containers Related to containers use case in progress Pull request is currently in progress. labels Aug 28, 2019
@ChrsMark ChrsMark force-pushed the add_docker_metadata_autodetection branch 2 times, most recently from 93b280c to e95b724 Compare August 28, 2019 14:39
@ChrsMark ChrsMark force-pushed the add_docker_metadata_autodetection branch from 52ca9f6 to fc97617 Compare August 29, 2019 14:04
@ChrsMark
Copy link
Member Author

ChrsMark commented Aug 29, 2019

@jsoriano thanks for reviewing!

Your suggestion have been addressed, however the checks are failing due to the addition in filebeat.yml. Any ideas on how I could resolve this?

@jsoriano
Copy link
Member

Your suggestion has been addressed, however the checks are failing due to the addition in filebeat.yml. Any ideas on how I could resolve this?

filebeat.yml is generated from files in libbeat/_meta, you will need to make the change there and then run make update from the beats directory to regenerate all configuration files.

@ChrsMark ChrsMark requested review from a team as code owners August 30, 2019 10:09
@ChrsMark ChrsMark requested a review from jsoriano August 30, 2019 10:56
@ChrsMark ChrsMark force-pushed the add_docker_metadata_autodetection branch from 099ff3a to ca1d202 Compare September 2, 2019 13:05
@jsoriano jsoriano added the test-plan Add this PR to be manual test plan label Sep 2, 2019
Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

LGTM, I have added a couple of extra suggestions, let me know what you think.

libbeat/_meta/config.yml.tmpl Show resolved Hide resolved
cli, err := client.NewEnvClient()
errorMsg := fmt.Sprintf("%v: docker environment not detected.", processorName)
if err != nil {
logp.Info(errorMsg)
Copy link
Member

Choose a reason for hiding this comment

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

Log this error at debug level, and with the error too?

Suggested change
logp.Info(errorMsg)
logp.Debugf("%s: %v", errorMsg, err)

And same thing for the other error some lines below.

@ChrsMark ChrsMark force-pushed the add_docker_metadata_autodetection branch 2 times, most recently from 6314ecf to 9a36f81 Compare September 3, 2019 07:25
@zube zube bot removed the [zube]: In Progress label Sep 3, 2019
@ChrsMark ChrsMark force-pushed the add_docker_metadata_autodetection branch from 9a36f81 to 5434efa Compare September 3, 2019 09:49
Signed-off-by: chrismark <chrismarkou92@gmail.com>
Signed-off-by: chrismark <chrismarkou92@gmail.com>
Signed-off-by: chrismark <chrismarkou92@gmail.com>
Signed-off-by: chrismark <chrismarkou92@gmail.com>
@ChrsMark ChrsMark force-pushed the add_docker_metadata_autodetection branch from 5434efa to 6f679bb Compare September 3, 2019 09:50
@ChrsMark ChrsMark changed the title Enable autodetection mode for add_docker_metadata Add autodetection mode for add_docker_metadata Sep 3, 2019
@ChrsMark ChrsMark force-pushed the add_docker_metadata_autodetection branch from 6f679bb to ecb905d Compare September 3, 2019 09:53
Signed-off-by: chrismark <chrismarkou92@gmail.com>
@ChrsMark ChrsMark force-pushed the add_docker_metadata_autodetection branch from ecb905d to abfc865 Compare September 3, 2019 10:11
@ChrsMark
Copy link
Member Author

ChrsMark commented Sep 3, 2019

Changed the implementation a little bit so as to perform the connectivity check for Docker with the proper configuration.
Also added a test for the case of Docker is unreachable.

Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

Ok, I think we can go on with this 👍 I have added some comments about some minor details.

dockerAvailable = true
logp.Debug("add_docker_metadata", "%v: docker environment detected", processorName)
if err = watcher.Start(); err != nil {
return nil, err
Copy link
Member

Choose a reason for hiding this comment

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

You can use errors.Wrap to give a bit more of context here:

Suggested change
return nil, err
return nil, errors.Wrap(err, "failed to start watcher")

assert.NoError(t, err, "processing an event")

assert.Equal(t, common.MapStr{}, result.Fields)
}
Copy link
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

@@ -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
Copy link
Member

Choose a reason for hiding this comment

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

Nit.

Suggested change
// extra check to confirm that Docker is available
// Extra check to confirm that Docker is available

@@ -19,6 +19,7 @@ package add_docker_metadata

import (
"fmt"

Copy link
Member

Choose a reason for hiding this comment

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

Please remove this extra new line.

Suggested change

@@ -123,6 +132,9 @@ func lazyCgroupCacheInit(d *addDockerMetadata) {
func (d *addDockerMetadata) Run(event *beat.Event) (*beat.Event, error) {
var cid string
var err error
if !d.dockerAvailable {
return event, nil
}
Copy link
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.

@@ -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 {pull}13374[13374]
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should mention something about enabling it by default.

Suggested change
- Add autodetection mode for add_docker_metadata {pull}13374[13374]
- Add autodetection mode for add_docker_metadata and enable it by default in included configuration files {pull}13374[13374]

_, err = client.Info(context.Background())
if err != nil {
return nil, err
}
Copy link
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
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.

Signed-off-by: chrismark <chrismarkou92@gmail.com>
@ChrsMark ChrsMark merged commit 8e5bdc3 into elastic:master Sep 4, 2019
@ChrsMark ChrsMark removed the in progress Pull request is currently in progress. label Sep 4, 2019
kvch added a commit that referenced this pull request Nov 12, 2019
The PR #13374 adds `add_docker_metadata` for all Beats. However, this results in the following error in Functionbeat when deployed to AWS:
```
Exiting: error initializing processors: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
```

Thus, the function fails to start and process messages.

This PR removes the processor from the configuration of Functionbeat. So the function is able to start with the default processor configuration.
kvch added a commit to kvch/beats that referenced this pull request Nov 12, 2019
…4424)

The PR elastic#13374 adds `add_docker_metadata` for all Beats. However, this results in the following error in Functionbeat when deployed to AWS:
```
Exiting: error initializing processors: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
```

Thus, the function fails to start and process messages.

This PR removes the processor from the configuration of Functionbeat. So the function is able to start with the default processor configuration.
(cherry picked from commit d9a4c9c)
kvch added a commit to kvch/beats that referenced this pull request Nov 12, 2019
…4424)

The PR elastic#13374 adds `add_docker_metadata` for all Beats. However, this results in the following error in Functionbeat when deployed to AWS:
```
Exiting: error initializing processors: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
```

Thus, the function fails to start and process messages.

This PR removes the processor from the configuration of Functionbeat. So the function is able to start with the default processor configuration.
(cherry picked from commit d9a4c9c)
kvch added a commit that referenced this pull request Nov 22, 2019
…14480)

The PR #13374 adds `add_docker_metadata` for all Beats. However, this results in the following error in Functionbeat when deployed to AWS:
```
Exiting: error initializing processors: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
```

Thus, the function fails to start and process messages.

This PR removes the processor from the configuration of Functionbeat. So the function is able to start with the default processor configuration.
(cherry picked from commit d9a4c9c)
kvch added a commit that referenced this pull request Nov 22, 2019
…14479)

The PR #13374 adds `add_docker_metadata` for all Beats. However, this results in the following error in Functionbeat when deployed to AWS:
```
Exiting: error initializing processors: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
```

Thus, the function fails to start and process messages.

This PR removes the processor from the configuration of Functionbeat. So the function is able to start with the default processor configuration.
(cherry picked from commit d9a4c9c)
leweafan pushed a commit to leweafan/beats that referenced this pull request Apr 28, 2023
…4424) (elastic#14480)

The PR elastic#13374 adds `add_docker_metadata` for all Beats. However, this results in the following error in Functionbeat when deployed to AWS:
```
Exiting: error initializing processors: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
```

Thus, the function fails to start and process messages.

This PR removes the processor from the configuration of Functionbeat. So the function is able to start with the default processor configuration.
(cherry picked from commit c25f71a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
containers Related to containers use case Team:Integrations Label for the Integrations team test-plan Add this PR to be manual test plan v7.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants