cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Issue with Validating Namespace from Cluster in Dynatrace API Using toRelationships.isCluster in entitySelector

vignesh179
Visitor

 

Hello,

I’m currently working with the Dynatrace API (v2) to retrieve namespace entity IDs that are associated with a specific Kubernetes cluster. The goal is to generate a deep link based on the namespace and cluster combination.

I’m using the following entitySelector query:

 

 

type(CLOUD_APPLICATION_NAMESPACE),entityName.equals("namespace_name"),toRelationships.isCluster(type(KUBERNETES_CLUSTER),entityName.equals("cluster_name"))

 

While this query works in theory, I’m encountering issues where the namespace is not being validated correctly against the cluster. Despite the namespace existing within the specified cluster, the API returns no entities, or I receive a 404 error stating that the namespace was not found in the cluster.

Here’s the relevant portion of my code for fetching the namespace entity ID:

 

def get_namespace_entity_id(namespace_name, cluster_name):
    url = f"{dynatrace_env}/api/v2/entities"
    headers = {
        "Authorization": f"Api-Token {api_token}"
    }

    params = {
        "entitySelector": (
            f"type(CLOUD_APPLICATION_NAMESPACE),entityName.equals(\"{namespace_name}\"),"
            f"toRelationships.isCluster(type(KUBERNETES_CLUSTER),entityName.equals(\"{cluster_name}\"))"
        )
    }

    response = requests.get(url, headers=headers, params=params)
    
    if response.status_code == 200:
        entities = response.json().get('entities', [])
        if entities:
            return entities[0]['entityId']  # Return the first matching entity ID
        else:
            return None  # No matching entity found
    else:
        print(f"Request failed with status code {response.status_code}")
        print("Response content:", response.text)
        return None

 

Even though I’ve specified the correct cluster and namespace names, the query doesn't seem to work as expected. Has anyone encountered this issue when using toRelationships.isCluster in entitySelector queries, and how can I resolve this to properly validate the namespace under the specified cluster?

Any help or insights would be appreciated!

3 REPLIES 3

Peter_Youssef
Champion

Hi @vignesh179 

You can verify the below points:

  • The created access token have the required scopes to fetch the entities from the monitoring tenant.
  • Ensure the token isn't expired.
  • Ensure that K8s monitored entities are properly monitored through the UI and you have access permissions to view it.
  • Ensure there are no monitoring problems issues on the K8s cluster itself.

KR, 

Peter.

Hi Peter,

Thank you for your suggestions. I have verified the following:

  1. The access token has the required scopes to fetch entities from the monitoring tenant.
  2. The token is not expired.
  3. The Kubernetes monitored entities are properly monitored through the UI, and I have the necessary access permissions to view them.
  4. There are no monitoring issues with the Kubernetes cluster itself.

Despite these checks, I'm still encountering the same issue. If you have any additional insights or troubleshooting steps, I would greatly appreciate your help.

Best regards,
Vignesh

Hi @Peter_Youssef 
This is my terminal error message,
curl : {"error":{"code":400,"message":"Constraints
violated.","constraintViolations":[{"path":"entitySelector","message":"Unknown predicate name
toRelationships.isCluster","parameterLocation":"QUERY","location":null}]}}

Featured Posts