简体   繁体   中英

Format double to string in MQL (Monitoring Query Language) in GCP

From the docs

format Format Int64, Double, or String as a String. Signature: format(Num, lit-String ) → String format(String, lit-String ) → String

The format function takes two required arguments: an Int, Double or String, and a String. The function formats the first argument as a string, using the format specified in the second String argument, and returns the result as a String.

I'm trying to convert a Double datatype to String and used

fetch k8s_container
| metric logging.googleapis.com/user/my-metric
| group_by 1d, mean(val())
| map
  add[
      log: concatenate("License expiring in", format(val(), ""))
  ]
| condition val() <= 30

I'm not able to figure out what the lit-String is and how to use it inside format function.

I figured it out. "lit-string" is the "%s" for string. For other datatypes we can use "%f" for floating point numbers, "%d" for integers and so on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM