Search code examples
kubernetesprometheusgrafanagrafana-loki

How to add additional labels in log stream with grafana loki


i have like 2 or 3 clusters that i am collecting logs from centrally using grafana loki. I want to able to distinguish the logs from each of environment, each environment is its own k8s cluster. But i still see only the stock labels that are added and not the ones i am trying to add

Here's how i tried to add the labels using external_labels:

promtail:
  enabled: true
  config:
    logLevel: info
    serverPort: 3100
    clients:
      - url: http://loki:3100/loki/api/v1/push
  external_labels:
    cluster: prod
  scrape_configs:
    - job_name: kubernetes
      kubernetes_sd_configs:
        - role: pod
      label_config:
        external_labels:
          cluster: prod

Is this the correct approach or am i missing something?


Solution

  • The following configuration worked for me:

    promtail:
      enabled: true
      config:
        logLevel: info
        serverPort: 3100
        clients:
          - url: http://loki:3100/loki/api/v1/push
            external_labels:
              cluster: "prod"
    scrape_configs:
    - job_name: kubernetes
      kubernetes_sd_configs:
      - role: pod