0

I am trying to create an uptime check in Google Cloud Platform using the gcloud command line client. This is an example:

gcloud monitoring uptime create 'example uptime check' --resource-labels=host=...,project_id=... --resource-type=uptime-url --protocol=https --port=443 "--path=..." --request-method=get --validate-ssl=true --status-codes=200 --matcher-type=contains-string "--matcher-content=..." --period=5 --timeout=30 --user-labels=instance-group=production,instance-type=authentication,monitoring-type=uptime 

This generally works, i.e. the uptime check is created and no errors are reported. However, my user labels are silently ignored.

I believe that I am following the documentation (https://cloud.google.com/sdk/gcloud/reference/monitoring/uptime/create) correctly:

 --user-labels=[KEY=VALUE,…] List of label KEY=VALUE pairs to add. Keys must start with a lowercase character and contain only hyphens (-), underscores (_), lowercase characters, and numbers. Values must contain only hyphens (-), underscores (_), lowercase characters, and numbers. 

I have successfully added very similar user labels to compute instances, disks etc.

I have also tried to add user labels to existing uptime checks via gcloud monitoring uptime update, but that also did not work.

Update: I have created a bug report as suggested by Daniel t.: https://issuetracker.google.com/issues/393989630

1 Answer 1

0

I was able to reproduce this, and it appears to be a bug on gcloud sdk. Running it with debug mode and log-http shows the CLI is capturing the user-lables passed by user but it is not sending it to Cloud Monitoring API. As of Jan 30, 2025 with latest version of Google Cloud SDK 508.0.0. YOu can file bug here - https://cloud.google.com/sdk/docs/getting-support

Here the flags being captured accurately -

gcloud monitoring uptime create test-uptime --resource-labels=host=example.com,project_id=myproject --resource-type=uptime-url --protocol=https --port=443 --path=/status --request-method=get --validate-ssl=true --status-codes=200 --user-labels=environment=sandbox --period=15 --timeout=30 --log-http --verbosity=debug DEBUG: Running [gcloud.monitoring.uptime.create] with arguments: [--log-http: "true", --path: "/status", --period: "15", --port: "443", --protocol: "https", --request-method: "get", --resource-labels: "OrderedDict([('host', 'example.com'), ('project_id', 'myproject')])", --resource-type: "uptime-url", --status-codes: "[200]", --timeout: "30", --user-labels: "OrderedDict([('environment', 'sandbox')])", --validate-ssl: "True", --verbosity: "debug", DISPLAY_NAME: "test-uptime"] 

But --log-http shows the userLabels is not being sent to Monitoring API -

-- body start -- { "name": "projects/myproject/uptimeCheckConfigs/test-uptime-ABn9TbKDCj8", "displayName": "test-uptime", "monitoredResource": { "type": "uptime_url", "labels": { "host": "example.com", "project_id": "myproject" } }, "httpCheck": { "useSsl": true, "path": "/status", "port": 443, "validateSsl": true, "requestMethod": "GET", "acceptedResponseStatusCodes": [ { "statusValue": 200 } ] }, "period": "900s", "timeout": "30s", "checkerType": "STATIC_IP_CHECKERS" } 

One alternative is to use curl or similar tools to create the uptime checks by directly hitting the Cloud monitoring API. Here is a simple example shell script,

#!/bin/bash Project_id=your_gcp_project_id url="https://monitoring.googleapis.com/v3/projects/$Project_id/uptimeCheckConfigs?alt=json" body='{"displayName": "test-uptime", "httpCheck": {"acceptedResponseStatusCodes": [{"statusValue": 200}], "authInfo": {}, "contentType": "TYPE_UNSPECIFIED", "path": "/status", "port": 443, "requestMethod": "GET", "useSsl": true, "validateSsl": true}, "monitoredResource": {"labels": {"host": "example.com", "project_id": "$Project_id"}, "type": "uptime_url"}, "period": "900s", "timeout": "30s", "userLabels": {"environment": "sandbox"}}' token="$(gcloud auth print-access-token)" curl -i -X POST -H "content-type: application/json" -H "Authorization: Bearer $token" -d "${body}" $url 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.