-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
[ENHANCEMENT] Docker SD: add MatchFirstNetwork for containers with multiple networks #10490
[ENHANCEMENT] Docker SD: add MatchFirstNetwork for containers with multiple networks #10490
Conversation
55ccc78
to
9f8da93
Compare
966be77
to
43e9527
Compare
43e9527
to
2164cfe
Compare
We discussed this in the bug-scrub meeting. It looks useful, but the intention is a little hard to understand. @roidelapluie can you take a look? |
docs/configuration/configuration.md
Outdated
@@ -718,6 718,9 @@ tls_config: | |||
# The host to use if the container is in host networking mode. | |||
[ host_networking_host: <string> | default = "localhost" ] | |||
|
|||
# Whether filter networks by user defined network mode if the container has multiple networks. | |||
[ filter_networks: <boolean> | default = true ] |
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.
(During Prometheus bug scrub meeting): This flag seems too fuzzy e.g. "filter" can both mean filter out, and filter in (choose). Also this option is doing more than that (if no user defined network then something else is performed).
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.
@bwplotka Perhaps the configuration is defined as match_first_network more appropriate.
In shared network mode, the current container has no network definition,for example:
As shown above, networks are undefined and the shared network is defined in HostConfig, which corresponds to NetworkMode, for example:
If the container to which networkmode points to has the specified network, NetworkMode points to a container that has a specified network, the container's network is the destination network, otherwise the loop continues. If the container defines multiple networks, for Prometheus, only one available network is needed to obtain monitoring metrics, so a configuration is required here to allow users to match the first network to avoid duplicate collection targets. |
Thanks. This reads like a programmer-level description to me. The description should reference the new setting (i.e. filter_networks or match_first_network). |
Much better, thanks. |
1fc57f3
to
5328fc8
Compare
Any idea when this might be merged? |
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 don't know enough about Docker behaviour to say whether this valid, but the code looks plausible. I'm ok to merge and see if anyone complains.
Looks like something else changed underneath:
|
I'll take care of it. |
/hold for local tests. |
b43f477
to
8ba405d
Compare
071ccd3
to
ca1215c
Compare
I'am confused about golangci-lint check result:
I did do the goimport processing, but nothing changed
Am I missing something? |
ca1215c
to
ab10917
Compare
discovery/moby/docker.go
Outdated
@@ -73,7 76,8 @@ type DockerSDConfig struct { | |||
Filters []Filter `yaml:"filters"` | |||
HostNetworkingHost string `yaml:"host_networking_host"` | |||
|
|||
RefreshInterval model.Duration `yaml:"refresh_interval"` | |||
RefreshInterval model.Duration `yaml:"refresh_interval"` | |||
MatchFirstNetwork bool `yaml:"match_first_network "` |
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.
There's an extra space.
`yaml:"match_first_network "`
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.
Updated.
Network shared mode:
|
Multi networks and shared mode:
|
ab10917
to
0d25931
Compare
/hold cancel. |
For others requiring multiple networks, and got to that PR because the default value changed, this is how i managed my scrape config originally scrape_configs:
- job_name: "docker-containers"
docker_sd_configs:
- host: unix:///var/run/docker.sock # You can also use http/https to connect to the Docker daemon.
relabel_configs:
# Only keep containers that have a `prometheus-job` label.
- source_labels: [__meta_docker_container_label_prometheus_job]
regex: .
action: keep
# Only keep containers in "monitoring" network
- source_labels: [__meta_docker_network_name]
regex: monitoring
action: keep
# Extract Port or overwrite `prometheus-port` label.
- source_labels: [__address__]
regex: '[^\s] :(\d )'
target_label: __tmp_port
- source_labels: [__meta_docker_container_label_prometheus_port]
target_label: __tmp_port
action: keepequal
# Use the task labels that are prefixed by `prometheus-`.
- regex: __meta_docker_container_label_prometheus_(. )
action: labelmap
replacement: $1
- target_label: host
replacement: hostname01 # static hostname
- source_labels: ['__meta_docker_container_label_com_docker_compose_project']
target_label: 'project'
- source_labels: ['__meta_docker_container_label_com_docker_compose_service']
target_label: 'service'
- source_labels: ['__meta_docker_container_label_com_docker_compose_container_number']
target_label: 'container_number' |
@cs8898 You can use multiple networks by setting the configuration match_first_network to false.
|
@DrAuYueng already did that, just added my config as reference, because it basically solves the same "problem". So all fine, at least the docu was updated, so i was able, to find the relevant config key quiet fast |
Fixes docker sd service misssing in shared mode(#10141).
Provide a feature called
MatchFirstNetwork
that allows matching the first network if the container has multiple networks defined, thus avoiding collecting duplicate targets(#8831).Signed-off-by: DrAuYueng [email protected]