Google Cloud Run Integration
Collect Google Cloud Run service deployments (via audit logs and a Pub/Sub push subscription), transform them to CDEvents.
- Cloud Run records every create, update and delete of a service in its admin activity audit logs.
- A logging sink routes these entries to Pub/Sub, which pushes them to cdviz-collector.
- cdviz-collector transforms them to
serviceCDEvents. Without a Pub/Sub push endpoint, poll the Cloud Run Admin API instead.
| From event | CDEvents |
|---|---|
| Services.CreateService | service.deployed |
| Services.UpdateService / ReplaceService | service.upgraded |
| Services.DeleteService | service.removed |
How It Works
Cloud Run has no event topic of its own: service changes are only visible in Cloud Audit Logs. A logging sink routes the admin activity entries of run.googleapis.com to a Pub/Sub topic. A push subscription on that topic sends them to the cdviz-collector webhook source.
The transformer maps protoPayload.methodName to a CDEvent:
methodName | CDEvent Type |
|---|---|
...Services.CreateService | service.deployed |
...Services.UpdateService, ReplaceService | service.upgraded |
...Services.DeleteService | service.removed |
When the response of the change carries a container image, subject.content.artifactId is set to its PURL (pkg:oci/...@sha256:...). It is the same PURL as the artifact.published event of Artifact Registry, so a deployment links to the image it runs.
service.rolledback is not emitted: the audit log does not tell a traffic revert from a regular update, so every update is service.upgraded.
Configuration
Setting Up cdviz-collector
[sources.gcp_cloudrun_webhook]
enabled = true
transformer_refs = ["gcp_cloudrun_webhook"]
[sources.gcp_cloudrun_webhook.extractor]
type = "webhook"
id = "000-gcp-cloudrun" # used as part of the webhook's url
[remote.transformers-community]
type = "github://cdviz-dev/transformers-community"
[transformers]
gcp_cloudrun_webhook = { type = "vrl", template_rfile = "transformers-community:///gcp_cloudrun_webhook/to_v0_5.vrl" }For more details on remote transformers, see the Transformers documentation.
Setting Up Google Cloud
- Create a Cloud Logging sink on the Cloud Run audit logs, with a Pub/Sub topic as destination. Filter:
resource.type="cloud_run_revision" AND logName:"cloudaudit.googleapis.com%2Factivity" - Create a push subscription on that topic, with the endpoint
https://your-collector-url/webhook/000-gcp-cloudrun.
Poll the Cloud Run Admin API
Use polling when Pub/Sub cannot reach the collector. The gcp_cloudrun_rest_api transformer reads the responses of services.list.
A poll is a snapshot of the current state: every poll reports every service as service.deployed. An unchanged service produces an identical event, which the database deduplicates. Only a new revision or image produces a new event. Polling cannot tell upgraded, removed or rolledback apart: use the audit logs for that, or run both.
[sources.gcp_cloudrun_rest_services]
enabled = true
transformer_refs = ["gcp_cloudrun_rest_services"]
[sources.gcp_cloudrun_rest_services.extractor]
type = "http_polling"
polling_interval = "5m"
parser = "json"
driver_vrl = """
project = "myproject"
location = "us-central1"
reqs = []
if .response == null {
reqs = [{ "url": "https://run.googleapis.com/v2/projects/" + project + "/locations/" + location + "/services", "route": "both" }]
} else {
next_token = to_string(.response.body.nextPageToken) ?? ""
if next_token != "" {
reqs = [{ "url": string!(.request.url), "query": {"pageToken": next_token}, "route": "both" }]
}
}
.requests = reqs
"""
[sources.gcp_cloudrun_rest_services.extractor.headers]
authorization = { type = "secret", value_file = "/secrets/gcp_token", prefix = "Bearer " }
[transformers]
gcp_cloudrun_rest_services = { type = "vrl", template_rfile = "transformers-community:///gcp_cloudrun_rest_api/services_to_v0_5.vrl" }Set project and location. The polling identity needs run.services.list on the project and location (role roles/run.viewer or broader).
Access token refresh
The http_polling source has no built-in Google OAuth2 or service account token refresh. Keep /secrets/gcp_token filled with a valid access token from an external process, for example a cron job or a sidecar that runs gcloud auth print-access-token > /secrets/gcp_token.