1

I've created a couple alert policies using cloud console, but after exporting them and changing name (via Download JSON or gcloud CLI) I can't import them back.

Details below:

Payload (name fields are removed after export):

{
  "displayName": "somename",
  "conditions": [
    {
      "displayName": "somename",
      "conditionAbsent": {
        "aggregations": [
          {
            "alignmentPeriod": "300s",
            "crossSeriesReducer": "REDUCE_MEAN",
            "perSeriesAligner": "ALIGN_DELTA"
          }
        ],
        "duration": "300s",
        "filter": "metric.type=\"logging.googleapis.com/user/some-metric\""
      }
    }
  ],
  "combiner": "OR",
  "enabled": true,
  "notificationChannels": [
    "projects/my-prod-dod/notificationChannels/1962880049684990238",
    "projects/my-prod-dod/notificationChannels/9131919367771592634"
  ]
}

Command:

gcloud alpha monitoring policies create --policy-from-file alert.json

Error:

Field alert_policy.conditions[0].condition_absent.filter had an invalid value of "metric.type="logging.googleapis.com/user/some-metric"": must specify a restriction on "resource.type" in the filter

Metric type is:

enter image description here

Screenshot of alert policy: enter image description here

dzh
  • 286
  • 1
  • 19

1 Answers1

4

Adding additional filter like below solved the problem

"filter": "metric.type=\"logging.googleapis.com/user/celery-person\" resource.type=\"k8s_container\"",

Similar question: Use a Stackdriver resource group's ID in a GCP Deployment Manager configuration

dzh
  • 286
  • 1
  • 19