-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Add autodetection mode for add_docker_metadata #13374
Conversation
93b280c
to
e95b724
Compare
52ca9f6
to
fc97617
Compare
@jsoriano thanks for reviewing! Your suggestion have been addressed, however the checks are failing due to the addition in |
|
099ff3a
to
ca1d202
Compare
There was a problem hiding this 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.
cli, err := client.NewEnvClient() | ||
errorMsg := fmt.Sprintf("%v: docker environment not detected.", processorName) | ||
if err != nil { | ||
logp.Info(errorMsg) |
There was a problem hiding this comment.
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?
logp.Info(errorMsg) | |
logp.Debugf("%s: %v", errorMsg, err) |
And same thing for the other error some lines below.
6314ecf
to
9a36f81
Compare
9a36f81
to
5434efa
Compare
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>
5434efa
to
6f679bb
Compare
6f679bb
to
ecb905d
Compare
Signed-off-by: chrismark <chrismarkou92@gmail.com>
ecb905d
to
abfc865
Compare
Changed the implementation a little bit so as to perform the connectivity check for Docker with the proper configuration. |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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:
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) | ||
} |
There was a problem hiding this comment.
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
libbeat/common/docker/watcher.go
Outdated
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit.
// 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" | |||
|
There was a problem hiding this comment.
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.
@@ -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 | |||
} |
There was a problem hiding this comment.
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.
CHANGELOG.next.asciidoc
Outdated
@@ -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] |
There was a problem hiding this comment.
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.
- 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 | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
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.
…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)
…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)
…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)
…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)
…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)
This PR is a proposal for enabling autodetection mode for
add_docker_metadata
.Currently we configure
add_cloud_metadata
andadd_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
a. Run metricbeat or filebeat in an environement where Docker is present.
b. Verify that processor is being automatically enabled.
a. Run metricbeat or filebeat in an environement where Docker is not present.
b. Verify that processor is not being automatically enabled.