'Match regex not working for integer types - MQL GCP
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)]
Solution 1:[1]
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
Solution 2:[2]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Bharath |
| Solution 2 | Chandra Kiran Pasumarti |
