09 Jan 2024 02:14 PM
Hi
I want to add these values filter and I want it to affect what is in the view
fetch dt.entity.service
| fields entity.name, managementZones = managementZones
| filter matchesValue(managementZones, "prod")
-------------------------------------------------------------
fetch dt.entity.service
| expand tags
| filter contains(tags, "prod")
The code that is displayed is
const processedResults: MetricResult[] = metricQuery.result[0].data.map(result => { return { "Service Name": result.dimensionMap["dt.entity.service.name"], "Service ID": result.dimensionMap["dt.entity.service"], "Tag": result.dimensionMap["dt.entity.service"], "Failure Rate": +result.values }; });
Is there something I can write instead of dt.entity.service ??
Solved! Go to Solution.
09 Jan 2024 02:46 PM
hi @yuval1983 ,
When I run these 2 queries independently, I don't get any errors on my side.
Are these two different requests? Can you provide us with a screenshot of your query with the visible error please?
09 Jan 2024 06:24 PM
Hi,
I want to filter the table by total of TAGS and ZONE, including a cut according to the filter below, instead of filtering only before the service name.
09 Jan 2024 07:34 PM
@yuval1983
To use these 2 filters in the same query, you may test :
fetch dt.entity.service
| fields entity.name, managementZones, tags
| filter matchesValue(managementZones, "prod")
| expand tags
| filter contains(tags, "prod")
09 Jan 2024 09:09 PM - edited 09 Jan 2024 09:16 PM
@gbaudart wrote:@yuval1983
To use these 2 filters in the same query, you may test :
fetch dt.entity.service
| fields entity.name, managementZones, tags
| filter matchesValue(managementZones, "prod")
| expand tags
| filter contains(tags, "prod")
Ok, I want to filter the results based on services and tags and display them in a window (table). The filter will look like this: services:test, tags:test2. Also, the Zone:prod .
----------------------------------------------
What should I replace in this setting?
"Zone": result.dimensionMap["dt.entity.service"],
"Tag": result.dimensionMap["dt.entity.service"],
------------------------------
import { metricsClient } from '@dynatrace-sdk/client-classic-environment-v2';
export default async function fetchMetricResults() {
const serviceSelection = $Service;
const metricKey = "builtin:service.errors.total.rate";
const config = {
metricSelector: buildQuery(serviceSelection, metricKey),
resolution: "Inf",
from: $dt_timeframe_from,
to: $dt_timeframe_to,
acceptType: "application/json; charset=utf-8"
};
if (config.metricSelector.length > 3500) {
return "Please select fewer services";
}
const metricQuery = await metricsClient.query(config);
const processedResults: MetricResult[] = metricQuery.result[0].data.map(result => {
return {
"Service Name": result.dimensionMap["dt.entity.service.name"],
"Service ID": result.dimensionMap["dt.entity.service"],
"Zone": result.dimensionMap["dt.entity.service"],
"Tag": result.dimensionMap["dt.entity.service"],
"Failure Rate": +result.values
};
});
return processedResults;
}
function buildQuery(inputs: string[], metricKey: string): string {
const filters = inputs.map(
input => `in("dt.entity.service", entitySelector("type(service), entityName.equals(~"${input}~")"))`
);
const filterString = filters.join(",");
return `${metricKey}:filter(or(${filterString})):splitBy("dt.entity.service"):sort(value(auto, descending)):names`;
}
11 Jan 2024 07:22 AM
HI,
I'm not looking for an error
I have created a dashboard and added filters for Service, Zone, and Tag. The filter for Service is working fine and the dashboard is being filtered accordingly when I select a service. However, when I try to filter by Zone or Tag, it doesn't work and doesn't display the required information on the dashboard.
I have checked the code and noticed that the following code is used for Service filtering:
"Service Name": result.dimensionMap["dt.entity.service.name"],
"Service ID": result.dimensionMap["dt.entity.service"]
But, I am not sure what code I should use for Zone and Tag filtering. I am not sure which "dt.xxx" I should use for Zone and Tag filtering or what I should configure in the code for filtering by Zone and Tag.
11 Jan 2024 08:00 AM
mz and tags are not Dynatrace entities. you will therefore not have an equivalent in dt.xxx. you have to find a workaround
11 Jan 2024 08:24 AM
oK
The classic bashboard I can do this filter there according to TAG
Why can't it be done here?
11 Jan 2024 08:33 AM
I'm not saying we can't filter on tags, just that there is no dt.xxx for tags.
When I want to filter on tags with Grail or the SDK, I generally use an EntitySelector.
However, I am not strong enough in SDK code to easily reformulate your "query"
11 Jan 2024 10:03 AM
HI
I was able to create the filter that I needed. Now, I just need to link it to the code inside the table, which I attached above. I'm not sure how to insert this filter into the table's view.
fetch dt.entity.service
| expand tags
| filter contains(tags, "Planning and stability")
| fields managementZones, tags
11 Jan 2024 10:15 AM
If you “simply” have to take the filter value.
I think, You may use the $FILTER variable :
$Tags_PlanningAndStability
11 Jan 2024 10:57 AM - edited 11 Jan 2024 10:57 AM
OK
Could you assist me in inserting a value into this code? I am having trouble inserting it in a way that it will filter rather than tag. Below is the code that I have mentioned earlier
import { metricsClient } from '@dynatrace-sdk/client-classic-environment-v2';
export default async function fetchMetricResults() {
const serviceSelection = $Service;
const metricKey = "builtin:service.errors.total.rate";
const config = {
metricSelector: buildQuery(serviceSelection, metricKey),
resolution: "Inf",
from: $dt_timeframe_from,
to: $dt_timeframe_to,
acceptType: "application/json; charset=utf-8"
};
if (config.metricSelector.length > 3500) {
return "Please select fewer services";
}
const metricQuery = await metricsClient.query(config);
const processedResults: MetricResult[] = metricQuery.result[0].data.map(result => {
return {
"Service Name": result.dimensionMap["dt.entity.service.name"],
"Service ID": result.dimensionMap["dt.entity.service"],
"Tag": xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
"Failure Rate": +result.values
};
});
return processedResults;
}
function buildQuery(inputs: string[], metricKey: string): string {
const filters = inputs.map(
input => `in("dt.entity.service", entitySelector("type(service), entityName.equals(~"${input}~")"))`
);
const filterString = filters.join(",");
return `${metricKey}:filter(or(${filterString})):splitBy("dt.entity.service"):sort(value(auto, descending)):names`;
}
11 Jan 2024 11:02 AM
Try this :
const processedResults: MetricResult[] = metricQuery.result[0].data.map(result => {
return {
"Service Name": result.dimensionMap["dt.entity.service.name"],
"Service ID": result.dimensionMap["dt.entity.service"],
"Tag": $Tags_PlanningAndStability,
"Failure Rate": +result.values
};
};
On the other hand, to improve the rereading of your code, you should indent it
11 Jan 2024 11:17 AM
There is progress now, and I can see the value. However, the filter doesn't really perform a filter like the service filter's function. It only shows what I mark inside the filter.
The classic dashboard where I make the change in the filter by filtering, so I see what service is inside that tag.
Thank you for your assistance and patience.
function buildQuery(inputs: string[], metricKey: string): string {
const filters = inputs.map(
input => `in("dt.entity.service", entitySelector("type(service), entityName.equals(~"${input}~")"))`
);
const filterString = filters.join(",");
return `${metricKey}:filter(or(${filterString})):splitBy("dt.entity.service"):sort(value(auto, descending)):names`;
}
12 Jan 2024 09:12 AM
Hi yuval1983,
I'm afraid I don't have idea for solution 😞 But I see you made a big progress with @gbaudart, nice work 👏
12 Jan 2024 10:14 AM
I was able to link a tag to the table, but you pointed out that the name of the service in the table is incorrect. I would like to display all the names under the same tag group. I need help figuring out how to do it.
15 Jan 2024 05:31 AM - edited 15 Jan 2024 05:33 AM
HI, @gbaudart
I need to know how to search for a desired service using tags.
Maybe I need to change something here?
serviceSelection
This is the code-
https://paste.ofcode.org/3863CCfHHf3qzWB2REYYAGA
Could you please tell me where I can find an index or a way to debug it?
15 Jan 2024 08:56 AM
Hi @yuval1983
In the EntitySelector command, you can filter with the desired tags like this:
input => `in("dt.entity.service", entitySelector("type(service), entityName.equals(~"${input}~"), tag("$TAG_VARIABLE")"))`
21 Jan 2024 07:02 AM - edited 21 Jan 2024 07:03 AM
Thank you for your assistance.
I have a new project and need to prioritize, but I will update you once I have more information. Thank you again for your help and prompt responses.