can't use metric.method as a filter field in alert definition?

546 views
Skip to first unread message

Karol Sokołowski

unread,
Feb 18, 2021, 7:00:27 AM2/18/21
to Google Stackdriver Discussion Forum
Hi All,

I'm trying to get an alert setup in TF in a following way:

resource "google_monitoring_alert_policy" "alert-policy-spanner-latency-high" {
  project      = var.project_id
  display_name = "Spanner latency high"
  combiner     = "OR"
  conditions {
    display_name = "Spanner latency high"
    condition_threshold {
      filter     = "metric.type=\"spanner.googleapis.com/api/request_latencies\" AND resource.type=\"spanner_instance\" AND metric.method!=\"CreateBackup\""
      duration   = "180s"
      comparison = "COMPARISON_GT"
      aggregations {
        alignment_period   = "60s"
        per_series_aligner = "ALIGN_PERCENTILE_50"
        group_by_fields = [ "metric.method" ]
      }
      trigger {
        count = 1
      }
      threshold_value = 5.0
    }
  }
  notification_channels = local.default_channel
}

and I'm getting a following err no matter what I try:

Error: Error updating AlertPolicy "projects/<project_name>/alertPolicies/<alert_id>": googleapi: Error 400: Field alert_policy.conditions[0].condition_threshold.filter had an invalid value of "metric.type="spanner.googleapis.com/api/request_latencies" AND resource.type="spanner_instance" AND metric.method!="CreateBackup"": The comparison operand: 'method' cannot be used with the prefix 'metric'.

what's absolutely strange is that in stackdriver GUI, I can click that filter extactly the way I want, it appears on the chart for alert, and even generates something that looks like a valid query:

fetch spanner_instance
| filter (metric.method != 'CreateBackup')
| align delta(1m)
| every 1m
| group_by [metric.method],
    [value_request_latencies_mean: mean(value.request_latencies)]

Can you advise on what I'm doing wrong when trying to use API/TF pls ? Greetings

Nie drukuj tej wiadomości, ani innych dokumentów, jeśli nie jest to konieczne. 

Operator Chmury Krajowej sp. z o. o. z siedzibą w Warszawie przy ul. Grzybowskiej 62, 00-844 Warszawa, zarejestrowana w Sądzie Rejonowym dla miasta stołecznego Warszawy w Warszawie, XII Wydział Gospodarczy Krajowego Rejestru Sądowego pod nr KRS 0000770202; NIP: 525-277-57-89 REGON: 382039032; kapitał zakładowy 120 000 000 PLN. Niniejsza wiadomość może zawierać poufną i prawnie zastrzeżoną korespondencję między naszą Spółką i Klientem. Jeżeli nie jesteście Państwo jej adresatem informujemy, że otrzymali ją Państwo omyłkowo oraz, że przeglądanie, rozpowszechnianie lub kopiowanie jest zabronione. W przypadku omyłkowego otrzymania niniejszej wiadomości, prosimy o niezwłoczne powiadomienie o tym nadawcy i trwałe usunięcie oryginału wiadomości wraz z ewentualnymi załącznikami.

Operator Chmury Krajowej sp. z o. o. with the registered office in Warsaw, ul. Grzybowska 62, 00-844 Warsaw, registered at the Capital City of Warsaw District Court in Warsaw, 12th Commercial Division of the National Court Register under KRS number 0000770202; Tax Identification Number (NIP): 525-277-57-89; REGON statistical number: 382039032; share capital: PLN 120,000,000.This message may contain a confidential and privileged communication between our Company and our Client. If you are not the intended recipient, you are hereby notified that you have received this message in error and that any use, dissemination, forwarding, or copying of this communication is strictly prohibited. If you have received this message by mistake, please notify the sender and delete the message permanently, including any attachments.

Summit Tuladhar

unread,
Feb 18, 2021, 7:43:34 AM2/18/21
to Karol Sokołowski, Syed Ashrafulla, Google Stackdriver Discussion Forum

--
© 2020 Google Inc. 1600 Amphitheatre Parkway, Mountain View, CA 94043
 
Email preferences: You received this email because you signed up for the Google Stackdriver Discussion Google Group (google-stackdr...@googlegroups.com) to participate in discussions with other members of the GoogleStackdriver community.
---
You received this message because you are subscribed to the Google Groups "Google Stackdriver Discussion Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-stackdriver-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-stackdriver-discussion/720ca7ea-8a43-4812-9f7a-c9586022c7d4n%40googlegroups.com.

Syed Ashrafulla

unread,
Feb 18, 2021, 8:29:49 AM2/18/21
to Summit Tuladhar, Karol Sokołowski, Google Stackdriver Discussion Forum
Correct, the appropriate syntax when using the form field query (conditionThreshold) is "metric.labels.method!='CreateBackup'". The monitoring query language dropped the extra ".labels" phrase.

Syed Ashrafulla

unread,
Feb 18, 2021, 8:32:15 AM2/18/21
to Summit Tuladhar, Karol Sokołowski, Google Stackdriver Discussion Forum
More details on what is allowed in the form field filter can be found in https://cloud.google.com/monitoring/api/v3/filters#filter_syntax.

Karol Sokołowski

unread,
Feb 18, 2021, 8:35:51 AM2/18/21
to Google Stackdriver Discussion Forum
Is there any way to acheive what I need = measure latency minus the backup set ? 

Karol Sokołowski

unread,
Feb 18, 2021, 8:48:33 AM2/18/21
to Google Stackdriver Discussion Forum
ah I see now, so using "metric.labels.method!='CreateBackup'". instead is working - would that be a gui bug (it generates it the way I provided first) ?
Reply all
Reply to author
Forward
0 new messages