DQL
Questions about Dynatrace Query Language
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to retrieve data from another tenant and display in chart through DQL

Hillman
Helper

We have created some charts which display the data from another tenant. In gen2 version, it can be configured like this:

Hillman_0-1767062399659.png

When I try to convert the chart to gen3 version, I am not sure how to use DQL to achieve this. Any suggestions?

4 REPLIES 4

olga_wall
Helper

Hi Hillman,

I haven't done this myself yet but I think you can achieve this by querying the data from another tenant via API in a code tile on a gen3 dashboard.

Mohamed_Hamdy
DynaMight Leader
DynaMight Leader

Hi @Hillman ,

In Dynatrace 3rd Gen, a flexible approach to query data from another environment is to use a Dashboard/Notebook Code tile (external/remote environment data). The idea is to create a Platform Token in the remote environment with the required storage read scopes, store it in the local environment Credential Vault, and then call the remote query endpoint from the Code tile. You can use the sample below and simply replace the remote URL, Credential Vault, and adjust the DQL as needed.

import { credentialVaultClient } from "@dynatrace-sdk/client-classic-environment-v2";

async function fetchRemoteDql(credentialId, url, query) {
  const { token } = await credentialVaultClient.getCredentialsDetails({ id: credentialId });

  const response = await fetch(url, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      Accept: "application/json",
      Authorization: `Bearer ${token}`,
    },
    body: JSON.stringify({
      query,
      requestTimeoutMilliseconds: 60000,
      enablePreview: true,
    }),
  });

  if (!response.ok) throw new Error(`HTTP ${response.status} ${response.statusText}`);
  return (await response.json()).result;
}

export default async function () {
  const credentialId = "CREDENTIALS_VAULT-XXXXXXX"; // your vault entry on the *local* env
  const url =
    "https://XXXXXXXX.apps.dynatrace.com/platform/storage/query/v1/query:execute";
  const query = `
timeseries usage = avg(dt.host.cpu.usage), by: { dt.entity.host }
| fieldsAdd entityName(dt.entity.host)
| sort arrayAvg(usage) desc
| limit 20
  `.trim();

  return await fetchRemoteDql(credentialId, url, query);
}

Note: make sure the remote environment url is added to the allowlist if it is configured to limit external requests from the environment.

https://developer.dynatrace.com/develop/app-functions/allow-outbound-connections/

Regards,

Hamdy

 

Certified Dynatrace Professional | Certified Dynatrace Services Delivery - Observability & CloudOps | Dynatrace Partner - yourcompass.ca

Hi @Mohamed_Hamdy,

I have tried with the DQL but I have found that it throws the following error.

{
  "error": {
    "code": 540,
    "message": "Execution crashed.",
    "details": {
      "logs": "403: The requested credential details cannot be accessed by the current user or entity.\n    at CredentialVaultClient.getCredentialsDetails (file:///opt/sdk_modules/@dynatrace-sdk/client-classic-environment-v2@4/esm/index.js:6983:19)\n    at eventLoopTick (ext:core/01_core.js:177:7)\n    at async fetchRemoteDql (file:///script.ts:4:21)\n    at async default (file:///script.ts:34:10)\n",
      "type": "UNCAUGHT_EXCEPTION",
      "message": "Uncaught (in promise) 403: The requested credential details cannot be accessed by the current user or entity.",
      "details": {
        "lineNumber": 6983,
        "startColumn": 19,
        "stack": "403: The requested credential details cannot be accessed by the current user or entity.\n    at CredentialVaultClient.getCredentialsDetails (file:///opt/sdk_modules/@dynatrace-sdk/client-classic-environment-v2@4/esm/index.js:6983:19)\n    at eventLoopTick (ext:core/01_core.js:177:7)\n    at async fetchRemoteDql (file:///script.ts:4:21)\n    at async default (file:///script.ts:34:10)"
      }
    }
  }
}

 

Hello @Hillman ,

It looks like the failure is related to Credential Vault access (the code tile can’t read the credential)

Could you please confirm the following:

  1. Did you create a Platform token in the remote environment (not an Environment API access token)? If yes, what scopes/permissions are enabled on that token?

  2. How was the Credential Vault entry created on the local environment?

For more details on Platform Tokens, please refer to Dynatrace documentation: https://docs.dynatrace.com/docs/shortlink/platform-tokens

Certified Dynatrace Professional | Certified Dynatrace Services Delivery - Observability & CloudOps | Dynatrace Partner - yourcompass.ca

Featured Posts