I'm having trouble wrapping my head around GCP Logs Based Metrics. I have the following messages being logged from a cloud function:
insertId: qwerty
jsonPayload:
accountId: 60da91d2-7391-4979-ba3b-4bfb31fa7777
message: Replay beginning. Event tally=1
metric: stashed-events-tally
tally: 5
labels:
execution_id: n2iwj3335agb
What I'd like to do is sum up the values in the tally
field. I've looked into logs based metrics and most of the examples I've seen seem to concern themselves with COUNTing the number of log messages that match the given filter. What I need to do is SUM the tally
value.
Here's what I have so far (I'm using terraform to deploy the logs based metric):
resource "google_logging_metric" "my_metric" {
name = "mymetric"
filter = "resource.type=cloud_function AND resource.labels.function_name=${google_cloudfunctions_function.function.name} AND jsonPayload.metric=stashed-events-tally"
metric_descriptor {
metric_kind = "DELTA"
value_type = "DISTRIBUTION"
display_name = "mymetric"
}
value_extractor = "EXTRACT(jsonPayload.tally)"
bucket_options {
linear_buckets {
num_finite_buckets = 10
width = 1
}
}
}
Do I have to do something specific to SUM those values up, or is that defined wherever the metric is consumed (e.g. on a monitoring dashboard)?
As I say, I'm having trouble wrapping my head around this.
When you instrument your code, you have 2 steps:
The Log-based metric simply converts a log in a metric.
Then, if you want to perform a sum (over a time window of course), you have to ask your dashboarding system to perform that operation, with Cloud Monitoring for instance