0

i am trying to get logs from a single namespace through promtail and scrape_configs, but i am not getting results. I am installing in k8s with

helm install loki grafana/loki-stack -n loki-test -f ~/loki-stack-values.yml

and the contents of my values file are:

loki:
 enabled: true

promtail:
 enabled: true
 pipelineStages:
 - cri: {}
 - json:
  expressions:
   is_even: is_even
   level: level
   version: version
 scrape_configs:
 - job_name: kubernetes-pods
  kubernetes_sd_configs:
  - role: pod
  relabel_configs:
  - source_labels: [__meta_kubernetes_namespace]
   action: keep
   regex: mongodb-test
 # [...]

 - job_name: kubernetes-pods-app
  kubernetes_sd_configs:
  - role: pod
  relabel_configs:
  - source_labels: [__meta_kubernetes_namespace]
   action: keep
   regex: mongodb-test

grafana:
 enabled: true
 sidecar:
 datasources:
  enabled: true
 image:
 tag: 8.3.5

My expectation was that i will only get logs from the mongodb-test namespace, but i can view from any namespace present. Also tried with drop, but it did not do anything.

What should i do here? Thank you so much

happymatei
  • 113
  • 1
  • 12

2 Answers2

1

Using match statement to drop other namespaces under pipeline stages worked for me. In your case,

config:
  snippets:
    pipelineStages:
      - cri: {}
      - match:
          selector: '{namespace!~"mongodb-test"}'
          action: drop
    common:
      - action: replace
        source_labels:
          - __meta_kubernetes_namespace
        target_label: namespace
0

This is my solution to drop particular namespaces.

promtail:
  config:
    clients:
      - url: http://{{ .Release.Name }}:3100/loki/api/v1/push
    logLevel: info
    serverPort: 3101
    snippets:    
      pipelineStages:
      - drop:
          source:     "namespace"
          expression: "(kube-public|kube-system)"
  enabled: true
mikey
  • 1
  • 1