From f980febd975f24cc75240f4833849493ee013fce Mon Sep 17 00:00:00 2001 From: Kaviraj Date: Mon, 7 Jun 2021 12:18:51 +0200 Subject: [PATCH] Update the docker-driver doc about default labels (#3814) * Update the docker-driver doc about default labels Add more information on `container_name` default label and when it will be added to log line. * Update docs/sources/clients/docker-driver/configuration.md Co-authored-by: Rui Lopes * Make it clear when to use pipeline_stages vs relabelling on docker-driver Co-authored-by: Rui Lopes --- docs/sources/clients/docker-driver/configuration.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/sources/clients/docker-driver/configuration.md b/docs/sources/clients/docker-driver/configuration.md index dbde7c5c94cb..b7b56f31bf07 100644 --- a/docs/sources/clients/docker-driver/configuration.md +++ b/docs/sources/clients/docker-driver/configuration.md @@ -109,17 +109,18 @@ By default, the Docker driver will add the following labels to each log line: - `filename`: where the log is written to on disk - `host`: the hostname where the log has been generated -- `container_name`: the name of the container generating logs - `swarm_stack`, `swarm_service`: added when deploying from Docker Swarm. Custom labels can be added using the `loki-external-labels`, `loki-pipeline-stages`, `loki-pipeline-stage-file`, `labels`, `env`, and `env-regex` options. See the next section for all supported options. +`loki-external-labels` have the default value of `container_name={{.Name}}`. If you have custom value for `loki-external-labels` then that will replace the default value, meaning you won't have `container_name` label unless you explcity add it (e.g: `loki-external-lables: "job=docker,container_name={{.Name}}"`. + ## Pipeline stages While you can provide `loki-pipeline-stage-file` it can be hard to mount the configuration file to the driver root filesystem. -This is why another option `loki-pipeline-stages` is available allowing your to pass a list of stages inlined. +This is why another option `loki-pipeline-stages` is available allowing your to pass a list of stages inlined. Pipeline stages are run at last on every lines. The example [docker-compose](https://github.com/grafana/loki/blob/master/cmd/docker-driver/docker-compose.yaml) below configures 2 stages, one to extract level values and one to set it as a label: @@ -167,6 +168,8 @@ Providing both `loki-pipeline-stage-file` and `loki-pipeline-stages` will cause You can use [Prometheus relabeling](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config) configuration to modify labels discovered by the driver. The configuration must be passed as a YAML string like the [pipeline stages](#pipeline-stages). +Relabeling phase will happen only once per container and it is applied on the container metadata when it starts. So you can for example rename the labels that are only available during the starting of the container, not the labels available on log lines. Use [pipeline stages](#pipeline-stages) instead. + For example the configuration below will rename the label `swarm_stack` and `swarm_service` to respectively `namespace` and `service`. ```yaml