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

Add these values

yuval1983
Organizer

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 ??

 

 

 

 

 

 

19 REPLIES 19

gbaudart
DynaMight Champion
DynaMight Champion

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?

Observability Consultant - Dynatrace Associate Certified

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.

 

 

yuval1983_0-1704824461503.png

 

gbaudart
DynaMight Champion
DynaMight Champion

@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")

 

Observability Consultant - Dynatrace Associate Certified


@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")

 

 

 

 

yuval1983_0-1704834659168.png

yuval1983_1-1704834747815.png

 

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`;
}

HI,

 I'm not looking for an error

yuval1983_0-1704957294747.png

 

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.

 

 

gbaudart
DynaMight Champion
DynaMight Champion

mz and tags are not Dynatrace entities. you will therefore not have an equivalent in dt.xxx. you have to find a workaround

Observability Consultant - Dynatrace Associate Certified

oK

The classic bashboard I can do this filter there according to TAG

Why can't it be done here?

 

 

yuval1983_0-1704961280352.png

 

 

gbaudart
DynaMight Champion
DynaMight Champion

 

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"

Observability Consultant - Dynatrace Associate Certified

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

yuval1983_0-1704967248386.png

 

gbaudart
DynaMight Champion
DynaMight Champion

If you “simply” have to take the filter value.
I think, You may use the $FILTER variable :

$Tags_PlanningAndStability

 

Observability Consultant - Dynatrace Associate Certified

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`;
}

gbaudart
DynaMight Champion
DynaMight Champion

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

Observability Consultant - Dynatrace Associate Certified

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.

 

 

yuval1983_0-1704971590598.png

 

 

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`;
}

hi @Pawel_Zalewski 

 

Maybe you have a solution ?:)

Hi yuval1983,

I'm afraid I don't have idea for solution 😞 But I see you made a big progress with @gbaudart, nice work 👏

"The lions does not ally with the coyotes"

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.

yuval1983_1-1705054426836.png

 

yuval1983_0-1705054415081.png

 

 

 

 

HI, @gbaudart 

 

I need to know how to search for a desired service using tags.

Maybe I need to change something here?

serviceSelection 

yuval1983_1-1705296788554.png

 

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?

 

 

gbaudart
DynaMight Champion
DynaMight Champion

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")"))`
Observability Consultant - Dynatrace Associate Certified

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.

Featured Posts