Match regex not working for integer types - MQL GCP

1k Views Asked by At

I am trying to match the response_code that are 4.*. But getting a Expected type 'String' but got 'Int'. in the MQL editor. I am able to match strings with regex, just the int doesn't work. Is there a way i could convert the metric type int to a string? Or am I doing it wrong?

fetch istio_canonical_service
| metric 'istio.io/service/client/request_count'
| filter (metric.response_code =~ '4.*')
| group_by 1m, [value_request_count_mean: mean(value.request_count)]
| every 1m
| group_by [metric.response_code],
    [value_request_count_mean_aggregate: aggregate(value_request_count_mean)]
2

There are 2 best solutions below

0
On BEST ANSWER

As per Chandra's answer above, the following workaround worked:

fetch istio_canonical_service
| metric 'istio.io/service/client/request_count'
| filter metric.response_code >= 400 
| filter metric.response_code < 500
| group_by 1m, [value_request_count_mean: mean(value.request_count)]
| every 1m
0
On

You can't match integers as you are doing for strings. If you want you can use AND operation.

Ex: metric.label.response_code>="400" AND metric.label.response_code<"500"

You can't convert metric type to string as the response codes are integers.