Search code examples
google-cloud-platformstackdrivergoogle-cloud-stackdrivergoogle-cloud-logging

How do I compare a string field as a number in Google Stackdriver Logging advanced queries?


I tried

jsonPayload.elapsed_ms > 5000

and I'm clearly getting a lexicographical comparison of the character "5" because I only see results that are "6", "7", "8", "9" (see final number per line, after the "200"):

enter image description here

I tried

double(jsonPayload.elapsed_ms)>5000

as well but doesn't seem to be the right syntax.

There's a whole section on conversions here but no examples.


Solution

  • I am from the Cloud Logging team.

    Since the jsonPayload.elapsed_ms field is being logged as a string, the range comparison is evaluated lexicographically. Is it possible for you to log the field as a numeric type in the JSON payload?

    https://cloud.google.com/logging/docs/view/advanced-queries#values_conversions documents the auto-conversions when evaluating a filter expression. However, it is currently not supported to cast the logged values to a different type at query time.

    We plan to add support for this in the query language. Please follow and +1 the following public issue https://issuetracker.google.com/issues/140348005 for updates.