-
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 support for port mapping in docker hints #31243
Conversation
Signed-off-by: chrismark <[email protected]>
This pull request doesn't have a |
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.
Nice. LGTM.
Please add a changelog entry.
And would it be possible to add tests for this?
Yeap, I'm planning to add docs/changelog and good idea adding tests too! |
Signed-off-by: chrismark <[email protected]>
libbeat/tests/docker/docker.go
Outdated
@@ -43,7 +43,7 @@ func NewClient() (Client, error) { | |||
} | |||
|
|||
// ContainerStart pulls and starts the given container | |||
func (c Client) ContainerStart(image string, cmd []string, labels map[string]string) (string, error) { | |||
func (c Client) ContainerStart(image string, cmd []string, labels map[string]string, hostConfig *container.HostConfig) (string, error) { |
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. Consider defining new method to keep backwards compatibility. Though probably nothing is using this method outside of beats.
func (c Client) ContainerStart(image string, cmd []string, labels map[string]string, hostConfig *container.HostConfig) (string, error) { | |
// ... | |
type StartOptions struct { | |
HostConfig *container.HostConfig | |
} | |
// ... | |
func ContainerStart(image string, cmd []string, labels map[string]string) (string, error) { | |
return ContainerStartWithOptions(image, cmd, labels, StartOptions{}) | |
} | |
// ... | |
func (c Client) ContainerStartWithOptions(image string, cmd []string, labels map[string]string, options StartOptions) (string, error) { | |
... |
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.
Thank you! This test is not correct nevertheless so I will revert this. Unfortunately we don't have proper tests at the moment that I could extend to cover this feature addition.
Signed-off-by: chrismark <[email protected]>
Signed-off-by: chrismark <[email protected]>
Signed-off-by: chrismark <[email protected]>
Signed-off-by: chrismark <[email protected]>
Signed-off-by: chrismark <[email protected]>
Signed-off-by: chrismark <[email protected]>
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
…er-tar-gz * upstream/main: (139 commits) [Automation] Update elastic stack version to 8.3.0-c655cda8 for testing (elastic#31322) Define a queue metrics reporter interface (elastic#31289) [Oracle Module] Change tablespace metricset collection period (elastic#31259) libbeat/reader/syslog: relax timestamp parsing to allow leading zero (elastic#31254) [Automation] Update elastic stack version to 8.3.0-55ba6f37 for testing (elastic#31311) [libbeat] Remove unused fields and functions in the memory queue (elastic#31302) [libbeat] Cleaning up some unneeded helper types (elastic#31290) Readme for kibana module (elastic#31276) [Automation] Update elastic stack version to 8.3.0-4be61f32 for testing (elastic#31296) x-pack/winlogbeat/module/routing/ingest: fix typo for channel name (elastic#31291) Small pipeline cleanup removing some unused data fields (elastic#31288) removing info log (elastic#30971) Simplify TLS config deserialization (elastic#31168) Detect new files under known paths in filestream input (elastic#31268) Add support for port mapping in docker hints (elastic#31243) Update qa-labels.yml (elastic#31260) libbeat: log debug for `proxy_url` and fixed docs (elastic#31130) [heartbeat][docs] Add note about ensuring correct index settings for uptime (elastic#31146) [Automation] Update elastic stack version to 8.3.0-2c8f9574 for testing (elastic#31256) [Filebeat] fix m365_defender pipeline bug (elastic#31227) ...
What does this PR do?
Add support for port mapping in docker autodiscover. The idea is similar to what we do for Kubernetes which was added at #19398.
The idea is to make it possible for collecting metrics using the HostPort of the container as described at #19825, by referring to the proper internal port of the container (see manual testing notes for an example).
Why is it important?
To cover cases like #19825.
How to test this PR locally
./metricbeat -e -d "module" -c metricbeat.yml
docker run --name nats --rm -p 4222:4222 -p 8081:8222 --label co.elastic.metrics/module="nats" --label co.elastic.metrics/metricsets="stats" --label co.elastic.metrics/hosts='localhost:${data.ports.8222}' nats:2.1.4 --http_port 8222
localhost:8222
endpoint.Related issues