datadog-agent icon indicating copy to clipboard operation
datadog-agent copied to clipboard

K8S pod logs are not tagged

Open calvinbui opened this issue 7 years ago • 2 comments

Describe what happened: Short-lived cronjob pods (less than 10 seconds) and deployment pods are sometimes not tagged correctly in Datadog.

In this example below, I have a cronjob that runs every 2 mins but only half of the pods have the correct tags such as "Pod Name" and other labels I'm setting. It is not specific to any node.

image

Incorrect: image

Correct: image

For deployments, logs may be tagged correctly for roughly ~12 log entries.

I have switched between the Docker socket and K8S File method of log collection and both have this issue. The Docker socket is worse and sometimes misses the logs completely.

Describe what you expected:

All logs to be captured and tagged correctly. We can miss issues that happen in production.

Steps to reproduce the issue:

Run a short-lived cronjob from Kubernetes and watch the logs coming in.

Additional environment details (Operating System, Cloud provider, etc):

  • Datadog Agent 6.14.1
  • Google Kubernetes Engine

Pod YAML

apiVersion: v1
kind: Pod
metadata:
  annotations:
    ad.datadoghq.com/snapshot.logs: '[{"source":"kubernetes","service":"campaigns"}]'
...
spec:
  containers:
  - name: snapshot

Environment variables:

DD_APM_ENABLED: "false"
DD_COLLECT_KUBERNETES_EVENTS: "false"
DD_EXCLUDE_PAUSE_CONTAINER: "false"
DD_KUBERNETES_POD_LABELS_AS_TAGS: '{"environment":"environment","process":"process","service":"service"}'
DD_LEADER_ELECTION: "false"
DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL: "true"
DD_LOGS_CONFIG_K8S_CONTAINER_USE_FILE: "true"
DD_LOGS_ENABLED: "true"
KUBERNETES: "true"

calvinbui avatar Oct 17 '19 03:10 calvinbui

i am experiencing the exact same issue! settings are almost identical...

---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: datadog-agent
  namespace: monitoring
spec:
  selector:
    matchLabels:
      app: datadog-agent
  template:
    metadata:
      labels:
        app: datadog-agent
      name: datadog-agent
    spec:
      serviceAccountName: datadog-agent
      containers:
      - image: datadog/agent:latest
        imagePullPolicy: Always
        name: datadog-agent
        ports:
          - containerPort: 8125
            ## Custom metrics via DogStatsD - uncomment this section to enable custom metrics collection
            ## Set DD_DOGSTATSD_NON_LOCAL_TRAFFIC to true to collect StatsD metrics from other containers.
            hostPort: 8125
            name: dogstatsdport
            protocol: UDP
          - containerPort: 8126
            ## Trace Collection (APM) - uncomment this section to enable APM
            hostPort: 8126
            name: traceport
            protocol: TCP
        env:
          - name: DD_API_KEY
            ## Kubernetes Secrets - uncomment this section to supply API Key with secrets
            valueFrom:
              secretKeyRef:
                name: datadog-secret
                key: api-key
          ## Set DD_SITE to datadoghq.eu to send your Agent data to the Datadog EU site
          - name: DD_SITE
            value: "datadoghq.com"
          ## logs
          - name: DD_LOGS_ENABLED
            value: "true"
          - name: "DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL"
            value: "true"
          - name: DD_AC_EXCLUDE
            value: "name:datadog-agent name:k8s.gcr.io/* name:quay.io/* name:gcr.io/stackdriver-agents/stackdriver-logging-agent"
          ## Set DD_DOGSTATSD_NON_LOCAL_TRAFFIC to true to allow StatsD collection.
          - name: DD_DOGSTATSD_NON_LOCAL_TRAFFIC
            value: "true"
          - name: DD_COLLECT_KUBERNETES_EVENTS
            value: "true"
          - name: DD_LEADER_ELECTION
            value: "true"
          - name: KUBERNETES
            value: "true"
          - name: DD_LOGS_CONFIG_K8S_CONTAINER_USE_FILE
            value: "true"
          - name: DD_KUBERNETES_KUBELET_HOST
            valueFrom:
              fieldRef:
                fieldPath: status.hostIP
          - name: DD_HEALTH_PORT
            value: "5555"
          - name: DD_KUBERNETES_POD_LABELS_AS_TAGS
            value: '{"app":"kube_label_app", "type":"kube_label_type"}'
          - name: SD_BACKEND
            value: "docker"
          - name: DD_APM_ENABLED
            value: "true"
        ## Note these are the minimum suggested values for requests and limits. The amount of resources required by the Agent varies depending on the number of checks, integrations, and features enabled.
        resources:
          requests:
            memory: "512Mi"
            cpu: "500m"
          limits:
            memory: "512Mi"
            cpu: "500m"
        livenessProbe:
          httpGet:
            path: /health
            port: 5555
          initialDelaySeconds: 15
          periodSeconds: 15
          timeoutSeconds: 5
          successThreshold: 1
          failureThreshold: 3
        volumeMounts:
          - name: dockersocket
            mountPath: /var/run/docker.sock
          - name: s6-run
            mountPath: /var/run/s6
          - name: logpodpath
            mountPath: /var/log/pods
          # ## Docker runtime directory, replace this path with your container runtime logs directory, or remove this configuration if `/var/log/pods` is not a symlink to any other directory.
          - name: pointdir
            mountPath: /opt/datadog-agent/run
          - name: logcontainerpath
            mountPath: /var/lib/docker/containers
          - name: procdir
            mountPath: /host/proc
            readOnly: true
          - name: cgroups
            mountPath: /host/sys/fs/cgroup
            readOnly: true
          - name: kms-config
            mountPath: /etc/datadog-agent/conf.d/kubernetes_state.d/auto_conf.yaml
            subPath: auto_conf.yaml
          - name: datadog-yaml
            mountPath: /etc/datadog-agent/datadog.yaml
            subPath: datadog.yaml
        livenessProbe:
          exec:
            command:
            - ./probe.sh
          initialDelaySeconds: 15
          periodSeconds: 5
      volumes:
        - name: dockersocket
          hostPath:
            path: /var/run/docker.sock
        - name: s6-run
          emptyDir: {}
        - hostPath:
            path: /proc
          name: procdir
        - hostPath:
            path: /var/log/pods
          name: logpodpath
        ## Docker runtime directory, replace this path with your container runtime logs directory, or remove this configuration if `/var/log/pods` is not a symlink to any other directory.
        - name: logcontainerpath
          hostPath:
            path: /var/lib/docker/containers
        - name: cgroups
          hostPath:
            path: /sys/fs/cgroup
        - name: kms-config
          configMap:
            name: dd-agent-config
            items:
            - key: kms-config
              path: auto_conf.yaml
        - name: datadog-yaml
          configMap:
            name: dd-agent-config
            items:
              - key: datadog-yaml
                path: datadog.yaml
        - name: pointdir
          hostPath:
            path: /var/run/datadog-agent

agent version is

Agent 6.15.1 - Commit: 44c5066 - Serialization version: 4.14.0 - Go version: go1.12.9

also another thing to note... DD_AC_EXCLUDE does not work

zbutt-muvaki avatar Dec 10 '19 17:12 zbutt-muvaki

@zbutt-muvaki datadog/agent-dev:6-15-1-logs fixed the issue.

calvinbui avatar Dec 18 '19 22:12 calvinbui