Promtail configuration to filter container logs

I need to filter out ingested docker logs by container name prefix. I already have labels that have a container name but cannot work out how to construct a match section to drop container names that don’t match a certain prefix: Here’s my config:


server:
http_listen_address: 0.0.0.0
http_listen_port: 9080

clients:

positions:
filename: d:/data/promtail/positions.yaml

scrape_configs:

  • job_name: containers
    static_configs:

    • targets:
      • localhost
        labels:
        job: containerlogs
        path: D:\ProgramData\docker\containers**.log

    pipeline_stages:

    • json:
      expressions:
      stream: stream
      attrs: attrs
      tag: attrs.tag
    • regex:
      expression: (?P<image_name>(?:[^|][^|])).(?P<container_name>(?:[^|][^|])).(?P<image_id>(?:[^|][^|])).(?P<container_id>(?:[^|][^|]))
      source: “tag”
    • labels:
      tag:
      stream:
      image_name:
      container_name:
      image_id:
      container_id:
    • match:
      selector: {container_name=~“uat+”}
      stages:
      - json:
      expressions:
      msg: message
      - output:
      source: msg