I was trying to make a dynamic promql query in GCP metrics to get the difference between pod restart count based on the time selected from the time selector box(underlined in the image).
The logic is to obtain the restart count back in time and subtract it from restart count now:
sum by(pod_name) (
kubernetes_io:container_restart_count
-
kubernetes_io:container_restart_count offset ${__interval}
)
I tried running these queries individually to validate them and both these queries
sum by(pod_name)(kubernetes_io:container_restart_count)
and
sum by(pod_name)(kubernetes_io:container_restart_count offset ${__interval})
gave the same output, for range selected to be last 1hr
, but they shouldn’t have cause the second query uses offset ${__interval}
while the fist one doesn’t.
But in grafana when I ran this using $__range
value, the second query
sum by(pod_name)(pod_restart_count offset ${__range})
was able to give us pod restart count for 1hr
back in time.
Any solutions/workarounds on how to get the same result in GCP using or without using ${__interval}
?
4