0

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

screenshot of trigger

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:gcp screenshot

4
  • Do you have the cloud run job running in the us-central1? Did you try with global region? Commented Oct 4 at 21:05
  • Yes, everything is in the same region (us-central1)
    – Patrick
    Commented Oct 4 at 21:24
  • 1
    Did you activated the audit logs? Commented Oct 5 at 15:15
  • @guillaumeblaquiere if you have any other ideas, I'd be grateful to get this resolved
    – Patrick
    Commented Oct 22 at 15:23

3 Answers 3

1

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

enter image description here

I did it because the /Jobs.RunJob sounded odd for me!

2
  • Thanks! I was pretty sure I enabled Cloud Audit somewhere (and I'm able to search/filter the audit logs). I added "auditmanager.googleapis.com" to the enabled APIs in TF and changed the method filter to: google.cloud.run.v1.Jobs.RunJob (not v2 for some reason). Now it seems to work.
    – Patrick
    Commented Oct 7 at 20:05
  • I've been trying to get this to work, but google.cloud.run.v1.Jobs.RunJob works only as a trigger then the Job starts. Not when it finishes. For failed/success messages, methodName="/Jobs.RunJob" works in the Audit Logs, but not as a trigger. This is driving me nuts :(
    – Patrick
    Commented Oct 18 at 19:14
1

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.

1
  • Thanks! Seems Cloud Run Jobs still uses google.cloud.run.v1.Jobs.RunJob, not sure why not v2. /Jobs.RunJob was the methodName in the logs, not sure why I'm able to search/filter there but not trigger events. But it's working now.
    – Patrick
    Commented Oct 7 at 20:06
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.