Pulumi towards GCP: configure alert policy for uptime check

28 Views Asked by At

(Posted this question already on Pulumi's community Slack workspace without getting any attention so far.)

Using Pulumi towards GCP, I'm trying to set-up an uptime check and an alert policy connected to it. Tried to follow https://www.pulumi.com/ai/answers/bLDyceC28wpkQkapHCc9PL/setting-uptime-checks-in-google-cloud but that one seems very much incomplete and outdated.

So, after experimenting a little bit I ended up with:

const uptimeCheckConfigId = `my_uptime_check_config`;
    const uptimeCheckConfig = new gcp.monitoring.UptimeCheckConfig(
        uptimeCheckConfigId,
        {
            timeout: '20s',
            period: '60s',
            httpCheck: {
                path: '/health/status',
                port: 80,
            },
            monitoredResource: {
                labels: {
                    host: ....myUrl,
                },
                type: 'uptime_url',
            },
            displayName: `Uptime check`,
        },
        { provider },
    );

const myAlertPolicy = new gcp.monitoring.AlertPolicy(
        `my_uptime_alert_policy`,
        {
            notificationChannels: ...myChannelIds...,
            combiner: 'OR',

            conditions: [
                {
                    displayName: `Uptime check FAILED`,
                    conditionThreshold: {
                        aggregations: [
                            {
                                alignmentPeriod: '420s',
                                crossSeriesReducer: 'REDUCE_COUNT_FALSE',
                                groupByFields: [
                                    'resource.label.project_id',
                                    'resource.label.host',
                                ],
                                perSeriesAligner: 'ALIGN_NEXT_OLDER',
                            },
                        ],
                        comparison: 'COMPARISON_GT',
                        duration: '60s',
                        filter: `resource.type = "uptime_url" AND metric.type = "monitoring.googleapis.com/uptime_check/check_passed" AND resource.labels.check_id = "${uptimeCheckConfigId}"`,
                        thresholdValue: 1,
                        trigger: {
                            count: 1,
                        },
                    },
                },
            ],
            displayName: `Alert Policy check`,
        },
        { provider },
    );

However, I get

Error creating AlertPolicy: googleapi: Error 400: 
The supplied filter does not specify a valid combination of metric and monitored resource descriptors. 
The query will not return any time series.

I have a working example in a manually (= via GUI) created GCP project. I pretty much copied the alert policy from there. Only difference: It says metric.labels.check_id there instead of resource.labels.check_id. However, if I do the same in Pulumi, then the Uptime Check and the Alert Policy do not seem to be connected at all. It says "No policy connected". I'm pretty confused by this. Has anyone any clue?

0

There are 0 best solutions below