question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

StackdriverStatsExporter: k8s namespace and container name missing

See original GitHub issue

What version of OpenCensus are you using?

0.19.1

What JVM are you using (java -version)?

openjdk version “1.8.0_181” OpenJDK Runtime Environment (build 1.8.0_181-8u181-b13-0ubuntu0.16.04.1-b13) OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)

What did you do?

I’m using StackdriverStatsExporter.createAndRegister() in an application running on GKE (1.10.11-gke.1).

What did you expect to see?

I expect all the labels for k8s_container to be populated, see https://cloud.google.com/monitoring/api/resources#tag_k8s_container

What did you see instead?

The following labels are empty:

  • namespace_name
  • container_name

This makes it very hard to differentiate metrics between multiple applications running within the same GCP project.

Is there a workaround for this?

It would help a lot if it would be possible to set global tags which are appended to all metrics automatically.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
mwuertingercommented, Apr 10, 2019

We’re now using the following code to get the MonitoredResource:

    MonitoredResource getMonitoredResource(String containerName) {
        try {
            MonitoredResource.Builder builder = MonitoredResource.newBuilder();
            builder.setType("k8s_container");

            builder.putLabels("container_name", containerName);

            String gcpProjectId = MetadataConfig.getProjectId();
            if (gcpProjectId != null) {
                builder.putLabels("project_id", gcpProjectId);
            }

            String zone = MetadataConfig.getZone();
            if (zone != null) {
                builder.putLabels("location", zone);
            }

            String clusterName = MetadataConfig.getClusterName();
            if (clusterName != null) {
                builder.putLabels("cluster_name", clusterName);
            }

            String namespace = System.getenv("KUBERNETES_NAMESPACE");
            if (namespace != null) {
                builder.putLabels("namespace_name", namespace);
            }

            String hostname = InetAddress.getLocalHost().getHostName();
            builder.putLabels("pod_name", hostname);

            return builder.build();
        } catch (Exception e) {
            log.error("Unable to determine MonitoredResource, falling back to default", e);
            return null;
        }
    }

We set the namespace via downward API and just set the container name to the service name within the application. This works fine for our needs right now.

Thanks for your help. We can close this issue.

0reactions
songy23commented, Apr 10, 2019

Thanks @mwuertinger for confirmation. Closing this for now, feel free to reopen if you have any follow-up questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Kubernetes best practices: Specifying Namespaces in YAML
Managing your active Namespace​​ Out of the box, your active namespace is the “default” namespace. Unless you specify a Namespace in the YAML, ......
Read more >
Namespaces Walkthrough - Kubernetes
We have created a deployment whose replica size is 2 that is running the pod called snowflake with a basic container that serves...
Read more >
Kubernetes Log collection - Datadog Docs
The pointerdir is used to store a file with a pointer to all the containers that the Agent is collecting logs from. This...
Read more >
Projects and Kubernetes Namespaces with Rancher
From the Name combo box, search for a user or group that you want to assign project access. Note: You can only search...
Read more >
Troubleshoot Container insights - Azure Monitor
When you configure monitoring of your Azure Kubernetes Service (AKS) ... --namespace=kube-system NAME DESIRED CURRENT READY UP-TO-DATE ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found