Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

k8sattributes: labels not attached to metrics from instrumented java process #34292

Closed
marcoboi opened this issue Jul 29, 2024 · 4 comments
Closed
Labels
help wanted Extra attention is needed needs triage New item requiring triage processor/k8sattributes k8s Attributes processor

Comments

@marcoboi
Copy link

Component(s)

processor/k8sattributes

Describe the issue you're reporting

Setup
I have an Otel-instrumented application sending metrics to an Otel Collector instance.
I've set up k8sattributes processor to enrich the metrics.
Metrics are then pushed into prometheus and consumed in Grafana.

Problem framing
I'm expecting the metrics from the instrumented application to carry the extra labels provided by k8sattributes.
The metrics i consume from Grafana do not have any k8s-related attributes attached to them, for instance:

process_runtime_jvm_memory_limit_bytes{
  instance="simple-java-app.simple-java-app-2-58fc45bbd7-mckvm.simple-java-app-2",
  job="simple-java-app-2",
  pool="CodeHeap 'non-profiled nmethods'",
  type="non_heap"
}

Configuration

apiVersion: opentelemetry.io/v1beta1
kind: OpenTelemetryCollector
metadata:
  name: "agent-collector"
spec:
  mode: daemonset
  tolerations:
    - operator: Exists
  replicas: 1
  resources:
    limits:
      memory: 500Mi
  containers:
    - env:
        - name: KUBE_NODE_NAME
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: spec.nodeName

  config:
    receivers:
      otlp:
        protocols:
          grpc:
            endpoint: 0.0.0.0:4317
          http:
            endpoint: 0.0.0.0:4318

    processors:
      k8sattributes:
        auth_type: serviceAccount
        passthrough: false
        filter:
          node_from_env_var: KUBE_NODE_NAME

    exporters:
      otlphttp/metrics:
        endpoint: http://{{ .Release.Name }}-prometheus-server:9090/api/v1/otlp
        tls:
          insecure: true
      debug/metrics:
        verbosity: detailed
    service:
      pipelines:
        metrics:
          receivers: [ otlp ]
          processors: [ k8sattributes ]
          exporters: [ otlphttp/metrics, debug/metrics ]
@marcoboi marcoboi added the needs triage New item requiring triage label Jul 29, 2024
@github-actions github-actions bot added the processor/k8sattributes k8s Attributes processor label Jul 29, 2024
Copy link
Contributor

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@marcoboi marcoboi reopened this Jul 30, 2024
@github-actions github-actions bot added the help wanted Extra attention is needed label Jul 30, 2024
@marcoboi
Copy link
Author

See related discussion in this thread.

@TylerHelmuth
Copy link
Member

Seems to be a duplicate of #34075

@TylerHelmuth TylerHelmuth closed this as not planned Won't fix, can't repro, duplicate, stale Aug 6, 2024
@marcoboi
Copy link
Author

marcoboi commented Aug 7, 2024

While not exactly a duplicate, the solution for this issue is the same as for #34075.
Namely, the attributes extracted from Otel need to be re-mapped to a format that can be understood by Prometheus.

This can be done using the following processor block in the Otel Collector pipeline:

      transform:
        metric_statements:
          - context: datapoint
            statements:
              - set(attributes["namespace"], resource.attributes["k8s.namespace.name"])
              - set(attributes["container"], resource.attributes["k8s.container.name"])
              - set(attributes["pod"], resource.attributes["k8s.pod.name"])
              - set(attributes["pod_id"], resource.attributes["k8s.pod.uid"])
              - set(attributes["node"], resource.attributes["k8s.node.name"])
              - set(attributes["app"], resource.attributes["k8s-app"])

You can check #34075 for more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed needs triage New item requiring triage processor/k8sattributes k8s Attributes processor
Projects
None yet
Development

No branches or pull requests

2 participants