Capture Alerting Metric details in Alert Name/Rule Name

Hello Everyone,

Was hoping if I could get some assistance on this specific query.

I am trying to fetch value of “metadata.label.user.app” and pass it within Custom Labels

[ var=‘C’ labels={metadata.label.user.app=app, metric.name=value_received_bytes_count_count} value=1 ], [ var=‘B’ labels={metadata.label.user.app=app, metric.name=value_received_bytes_count_count} value=35 ]

I’ve tried using

{{ $labels.metadata.label.user.app }} but that’s not passing any value.

Was hoping if someone could assist

Regards

@Rohan

Maybe try this?

{{ $values.B0.Labels.metadata.label.user.app }}

Thanks @grant2 ,

Tried that - i am still getting “no value” , I’ve tried using {{ $labels.app }} in the past for the info where value was saved in “app” field - This time since the value is in “metadata.label.user.app” it’s unable to capture value.

image

Can you (just for test purposes) create a label that does not have dots in the name and see if that works?

This info below is from our resident expert @melori.arellano in another post, but may be applicable here…

Examples for specific situations like . . .

When a label has dots in the name

If you have a label like netflow.ipv4_dst_addr with a value of 192.168.1.1, you might find that your alert template just shows the raw template (which is what happens if there’s an error in the evaluation).

If you’re using a classic condition, here’s an example of using the go index function:

{{ index $values.B0.Labels “netflow.ipv4_dst_addr” }}

Screen Shot 2022-08-15 at 6 15 21 PM

if your alert has two or more conditions or an expression, then you can use the $labels variable:
{{ index $labels “netflow.ipv4_dst_addr” }}

Screen Shot 2022-08-15 at 6 11 25 PM

Hi @grant2 ,

Please find below screenshots from another Alert - which was setup using Prometheus as a Datasource - which worked fine with {{ $labels.queue }}

image

The issue i am experiencing with has Google Cloud Monitoring Datasource. that’s where i have fields with “dots”

In both cases i’ve used Reduce and Maths to split alerts. However, one is behaving differently at the time of capturing values from Labels.

Just checking,

Has anyone found a solution to this?

Regards,

@Rohan can you try something like this? I used a dummy test datasource and gave it one of your test labels with dots in the name. Then, I set the value of metadata.label.user.app to slack.

Then I set the custom label to a value of {{index $labels "metadata.label.user.app"}}

My default notification policy is email. To test that the label is working. I created a rule to route alerts with metadata.label.user.app=slack to my slack contact point overriding the default:

1 Like

Thanks @melori.arellano, the Rule is working for a Math expression -
However for Classic condition where it says “{{ index $values.B0.Labels “netflow.ipv4_dst_addr” }}” based on the example shared by @grant2 - I have two queries and an Expression which is a Classic condition

[ var=‘C0’ metric=‘abcd’ labels={metadata.label.user.app=abcd, metric.name=value_received_bytes_count_count} value=3 ], [ var=‘C1’ metric=‘abcd-2’ labels={metadata.label.user.app=abcd-2, metric.name=value_received_bytes_count_count} value=3 ], [ var=‘C2’ metric=‘abcd-3’ labels={metadata.label.user.app=abcd-3, metric.name=value_received_bytes_count_count} value=2 ], [ var=‘C3’ metric=‘abcd-4’ labels={metadata.label.user.app=abcd-4, metric.name=value_received_bytes_count_count} value=3 ], [ var=‘C4’ metric=‘abcd-5’ labels={metadata.label.user.app=abcd-5, metric.name=value_received_bytes_count_count} value=3 ], [ var=‘C5’ metric=‘abcd-6’ labels={metadata.label.user.app=abcd-6, metric.name=value_received_bytes_count_count} value=3 ], [ var=‘C6’ metric=‘abcd-7’ labels={metadata.label.user.app=abcd-7, metric.name=value_received_bytes_count_count} value=2 ], [ var=‘C7’ metric=‘abcd-8’ labels={metadata.label.user.app=abcd-8, metric.name=value_received_bytes_count_count} value=2 ]

image

Tried 2nd Approach too of using: {{ index $labels “metadata.user.label.app” }} but it returns blank

Expectation is to capture all the labels within the label instead of just one.

@melori.arellano - whenever you get a chance would appreciate if you could look that there’s something i’ve missed?

Data source i am using is “Google Cloud Monitoring”