From ddb65ea43a8ae746e364f66efbb93e1dfab8d001 Mon Sep 17 00:00:00 2001 From: Weifeng Wang Date: Sun, 10 Mar 2024 23:27:56 +0800 Subject: [PATCH] update docker compose common relabel Signed-off-by: Weifeng Wang code clean Signed-off-by: Weifeng Wang --- .../common/config/agent-flow/logs.river | 43 +------------ .../common/config/agent-flow/metrics.river | 43 +------------ .../agent-flow/modules/docker_compose.river | 63 +++++++++++++++++++ .../agent-flow/monolithic-mode-all.river | 43 +------------ .../common/config/agent-flow/traces.river | 43 +------------ 5 files changed, 67 insertions(+), 168 deletions(-) diff --git a/docker-compose/common/config/agent-flow/logs.river b/docker-compose/common/config/agent-flow/logs.river index 9e36d42b..825dbf43 100644 --- a/docker-compose/common/config/agent-flow/logs.river +++ b/docker-compose/common/config/agent-flow/logs.river @@ -13,49 +13,8 @@ module.file "docker_compose" { } } -discovery.docker "containers" { - host = "unix:///var/run/docker.sock" - - filter { - name = "status" - values = ["running"] - } -} - discovery.relabel "containers" { - targets = discovery.docker.containers.targets - - // filter by service name - rule { - source_labels = ["__meta_docker_container_label_com_docker_compose_service"] - action = "keep" - regex = "(agent|mimir|mimir-.*|grafana|loki|loki-.*|tempo|tempo-.*|pyroscope|distributor|ingester|query-frontend|query-scheduler|querier|ruler|index-gateway|compactor|gateway)" - } - - rule { - source_labels = ["__meta_docker_container_label_com_docker_compose_service"] - regex = "(.*)" - replacement = "monitoring-system/$1" - target_label = "job" - } - - rule { - source_labels = ["__meta_docker_container_label_com_docker_compose_service"] - regex = "(.*)" - target_label = "pod" - } - - rule { - source_labels = ["__meta_docker_container_label_com_docker_compose_service"] - regex = "(.*)" - target_label = "app" - } - - rule { - source_labels = ["__meta_docker_container_name"] - regex = "/(.*)" - target_label = "container" - } + targets = module.file.docker_compose.exports.relabelings_common.output } /******************************************** diff --git a/docker-compose/common/config/agent-flow/metrics.river b/docker-compose/common/config/agent-flow/metrics.river index 2535d8af..59d44c62 100644 --- a/docker-compose/common/config/agent-flow/metrics.river +++ b/docker-compose/common/config/agent-flow/metrics.river @@ -13,49 +13,8 @@ module.file "docker_compose" { } } -discovery.docker "containers" { - host = "unix:///var/run/docker.sock" - - filter { - name = "status" - values = ["running"] - } -} - discovery.relabel "containers" { - targets = discovery.docker.containers.targets - - // filter by service name - rule { - source_labels = ["__meta_docker_container_label_com_docker_compose_service"] - action = "keep" - regex = "(agent|mimir|mimir-.*|grafana|loki|loki-.*|tempo|tempo-.*|pyroscope|distributor|ingester|query-frontend|querier|query-scheduler|store-gateway|alertmanager|compactor|ruler|overrides-exporter)" - } - - rule { - source_labels = ["__meta_docker_container_label_com_docker_compose_service"] - regex = "(.*)" - replacement = "monitoring-system/$1" - target_label = "job" - } - - rule { - source_labels = ["__meta_docker_container_label_com_docker_compose_service"] - regex = "(.*)" - target_label = "pod" - } - - rule { - source_labels = ["__meta_docker_container_label_com_docker_compose_service"] - regex = "(.*)" - target_label = "service_name" - } - - rule { - source_labels = ["__meta_docker_container_name"] - regex = "/(.*)" - target_label = "container" - } + targets = module.file.docker_compose.exports.relabelings_common.output } /******************************************** diff --git a/docker-compose/common/config/agent-flow/modules/docker_compose.river b/docker-compose/common/config/agent-flow/modules/docker_compose.river index 5bc9d41a..244da188 100644 --- a/docker-compose/common/config/agent-flow/modules/docker_compose.river +++ b/docker-compose/common/config/agent-flow/modules/docker_compose.river @@ -44,6 +44,10 @@ argument "profiles_endpoint" { * EXPORTS ********************************************/ +export "relabelings_common" { + value = discovery.relabel.common +} + export "metrics_receiver" { value = prometheus.remote_write.docker_compose.receiver } @@ -116,3 +120,62 @@ pyroscope.write "docker_compose" { "namespace" = argument.namespace.value, } } + +discovery.docker "containers" { + host = "unix:///var/run/docker.sock" + + filter { + name = "status" + values = ["running"] + } +} + +discovery.relabel "common" { + targets = discovery.docker.containers.targets + + // filter by service name + rule { + action = "keep" + source_labels = [ + "__meta_docker_container_label_com_docker_compose_service", + ] + regex = "(agent|mimir|mimir-.*|grafana|loki|loki-.*|tempo|tempo-.*|pyroscope|distributor|ingester|query-frontend|querier|query-scheduler|ruler|compactor|store-gateway|alertmanager|overrides-exporter|index-gateway|gateway)" + } + + rule { + action = "replace" + source_labels = [ + "__meta_docker_container_label_com_docker_compose_service", + ] + regex = "^(?:;*)?([^;]+).*$" + replacement = argument.namespace.value + "/$1" + target_label = "job" + } + + rule { + action = "replace" + source_labels = [ + "__meta_docker_container_label_com_docker_compose_service", + ] + regex = "^(?:;*)?([^;]+).*$" + replacement = "$1" + target_label = "pod" + } + + rule { + action = "replace" + source_labels = [ + "__meta_docker_container_label_com_docker_compose_service", + "__meta_docker_container_label_app", + ] + regex = "^(?:;*)?([^;]+).*$" + replacement = "$1" + target_label = "app" + } + + rule { + source_labels = ["__meta_docker_container_name"] + regex = "/(.*)" + target_label = "container" + } +} diff --git a/docker-compose/common/config/agent-flow/monolithic-mode-all.river b/docker-compose/common/config/agent-flow/monolithic-mode-all.river index bf5e3c1f..21e37f87 100644 --- a/docker-compose/common/config/agent-flow/monolithic-mode-all.river +++ b/docker-compose/common/config/agent-flow/monolithic-mode-all.river @@ -14,49 +14,8 @@ module.file "docker_compose" { filename = env("AGENT_CONFIG_FOLDER") + "/modules/docker_compose.river" } -discovery.docker "containers" { - host = "unix:///var/run/docker.sock" - - filter { - name = "status" - values = ["running"] - } -} - discovery.relabel "containers" { - targets = discovery.docker.containers.targets - - // filter by service name - rule { - source_labels = ["__meta_docker_container_label_com_docker_compose_service"] - action = "keep" - regex = "(agent|mimir|grafana|loki|loki-.*|tempo|pyroscope)" - } - - rule { - source_labels = ["__meta_docker_container_label_com_docker_compose_service"] - regex = "(.*)" - replacement = "monitoring-system/$1" - target_label = "job" - } - - rule { - source_labels = ["__meta_docker_container_label_com_docker_compose_service"] - regex = "(.*)" - target_label = "pod" - } - - rule { - source_labels = ["__meta_docker_container_label_com_docker_compose_service"] - regex = "(.*)" - target_label = "app" - } - - rule { - source_labels = ["__meta_docker_container_name"] - regex = "/(.*)" - target_label = "container" - } + targets = module.file.docker_compose.exports.relabelings_common.output } /******************************************** diff --git a/docker-compose/common/config/agent-flow/traces.river b/docker-compose/common/config/agent-flow/traces.river index 0840fe86..cb8a7600 100644 --- a/docker-compose/common/config/agent-flow/traces.river +++ b/docker-compose/common/config/agent-flow/traces.river @@ -19,49 +19,8 @@ module.file "docker_compose" { } } -discovery.docker "containers" { - host = "unix:///var/run/docker.sock" - - filter { - name = "status" - values = ["running"] - } -} - discovery.relabel "containers" { - targets = discovery.docker.containers.targets - - // filter by service name - rule { - source_labels = ["__meta_docker_container_label_com_docker_compose_service"] - action = "keep" - regex = "(agent|mimir|grafana|loki|loki-.*|tempo|pyroscope)" - } - - rule { - source_labels = ["__meta_docker_container_label_com_docker_compose_service"] - regex = "(.*)" - replacement = "monitoring-system/$1" - target_label = "job" - } - - rule { - source_labels = ["__meta_docker_container_label_com_docker_compose_service"] - regex = "(.*)" - target_label = "pod" - } - - rule { - source_labels = ["__meta_docker_container_label_com_docker_compose_service"] - regex = "(.*)" - target_label = "app" - } - - rule { - source_labels = ["__meta_docker_container_name"] - regex = "/(.*)" - target_label = "container" - } + targets = module.file.docker_compose.exports.relabelings_common.output } /********************************************