Reputation: 8083
I set up a Terraform google_cloudfunctions2_function
with the following trigger config:
event_trigger {
trigger_region = var.region
event_type = "google.cloud.audit.log.v1.written"
retry_policy = "RETRY_POLICY_RETRY"
service_account_email = google_service_account.event.email
event_filters {
attribute = "serviceName"
value = "run.googleapis.com"
}
event_filters {
attribute = "methodName"
value = "/Jobs.RunJob"
}
...
If I query the Cloud Logs for:
protoPayload.serviceName="run.googleapis.com"
protoPayload.methodName="/Jobs.RunJob"
I can see the events there, but they're not triggering my Cloud Function. Roles are all there:
- roles/eventarc.eventReceiver
- roles/run.invoker
- roles/cloudfunctions.invoker
What am I doing wrong?
What's odd is that this is all v1
in my Audit Logs. The job is created as google_cloud_run_v2_job
in Terraform and I explicitly added execution_environment = "EXECUTION_ENVIRONMENT_GEN2"
, but still v1.
In the Cloud Logs, I can find/filter by those parameters for the events I want to use as a trigger:
Upvotes: 0
Views: 365
Reputation: 8083
I can't believe it is that difficult to trigger something when a Cloud Run Job is done! There should be a simple event already on PubSub just like Cloud Build.
None of the Eventarc methods worked and we subscribed to paid Google Cloud support to get this resolved. The answer is a Log Sink with the following filter:
resource.type = cloud_run_job
protoPayload.status.message =~ Execution.*.has completed successfully
With PubSub as destination.
Upvotes: 0
Reputation: 419
Make sure that methodName is in the correct format:
Try changing the methodName from /Jobs.RunJob to google.cloud.run.v2.Jobs.RunJob
Updated trigger config:
event_filters {
attribute = "methodName"
value = "google.cloud.run.v2.Jobs.RunJob"
}
Check with Google Cloud Logs Explorer to see if Cloud Run Jobs are being logged under v2 or v1 methods. Otherwise, use google.cloud.run.v1.Jobs.RunJob as the method name in the event filter.
Upvotes: 1
Reputation: 75970
In addition to my comment (you have to activate the audit logs to get this event with eventarc), I manually defined an eventarc trigger on the UI and I didn't get the same config as you
I did it because the /Jobs.RunJob sounded odd for me!
Upvotes: 1