Skip to content

Commit

Permalink
Update the docker-driver doc about default labels (#3814)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Make it clear when to use pipeline_stages vs relabelling on docker-driver

Co-authored-by: Rui Lopes <[email protected]>
  • Loading branch information
kavirajk and rgl authored Jun 7, 2021
1 parent 3642fac commit f980feb
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions docs/sources/clients/docker-driver/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f980feb

Please sign in to comment.