This is a terraform setup:
resource "aws_cloudwatch_log_metric_filter" "account-query-time" {
name = "${local.name_prefix}-AccountQueryTime"
pattern = "{ $.message = \"AccountQuery_70fed564\" }"
log_group_name = yaddayadda
metric_transformation {
name = "AccountQueryTime"
namespace = "Accounts"
value = "$.time"
}
}
Logs have JSON objects like {"message": "AccountQuery_70fed564", "time": 320, "units", "microseconds"}
Relevant portion is pattern = "{ $.message = \"AccountQuery_70fed564\" }". Can I make sure the field exists as part of the pattern? Will the filter only pick fields that are valid for its metric transform?
I'd like to make sure that this metric will not add in messages that are missing the time field. The docs have NOT EXISTS but don't have EXISTS by itself.
Tried:
&& $.time&& $.time EXISTS&& !!$.time
Is it not necessary to check for the existence of a field? Seems safer to confirm that it is there before you go and add it to your metric...