From ec40c28ece92cf24b1ab11ff67442567324a6b03 Mon Sep 17 00:00:00 2001 From: Alexander Pazukhin Date: Thu, 5 Sep 2019 16:59:06 +0300 Subject: [PATCH] resolve: #922. docker-driver compose labels support --- cmd/docker-driver/README.md | 2 +- cmd/docker-driver/config.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cmd/docker-driver/README.md b/cmd/docker-driver/README.md index 983beabd2733c..a68e73fd58615 100644 --- a/cmd/docker-driver/README.md +++ b/cmd/docker-driver/README.md @@ -98,7 +98,7 @@ docker stack deploy my_stack_name --compose-file docker-compose.yaml Once deployed the Grafana service will be sending logs automatically to Loki. -> **Note**: stack name and service name are automatically discovered and sent as Loki labels for each swarm service, this way you can filter by them in Grafana. +> **Note**: stack name and service name for each swarm service and project name and service name for each compose service are automatically discovered and sent as Loki labels, this way you can filter by them in Grafana. ## Labels diff --git a/cmd/docker-driver/config.go b/cmd/docker-driver/config.go index e8efaa8dab9ac..a66a0af47df01 100644 --- a/cmd/docker-driver/config.go +++ b/cmd/docker-driver/config.go @@ -45,6 +45,12 @@ const ( swarmServiceLabelName = "swarm_service" swarmStackLabelName = "swarm_stack" + composeServiceLabelKey = "com.docker.compose.service" + composeProjectLabelKey = "com.docker.compose.project" + + composeServiceLabelName = "compose_service" + composeProjectLabelName = "compose_project" + defaultExternalLabels = "container_name={{.Name}}" defaultHostLabelName = model.LabelName("host") ) @@ -225,6 +231,16 @@ func parseConfig(logCtx logger.Info) (*config, error) { attrs[swarmStackLabelName] = swarmStack } + // parse docker compose labels and adds them automatically to attrs + composeService := logCtx.ContainerLabels[composeServiceLabelKey] + if composeService != "" { + attrs[composeServiceLabelName] = composeService + } + composeProject := logCtx.ContainerLabels[composeProjectLabelKey] + if composeProject != "" { + attrs[composeProjectLabelName] = composeProject + } + for key, value := range attrs { labelName := model.LabelName(key) if !labelName.IsValid() {