GCP Eventarc for specific log entry

234 views Asked by At

While GCP allows event arc execution, or trigger for a number of different services\methods\log types, is there any way to execute based on text output in the logs.
Eg. can an eventarc trigger be created to executed on an error, with a certain error message protoPayload.serviceData.jobCompletedEvent.job.jobStatus.additionalErrors.message='Failed due to value 0'

1

There are 1 answers

0
Romin On BEST ANSWER

From what I understand -- you are trying to invoke some custom logic based on the generation of a certain error message.

While directly -- you cannot have an EventArc Trigger for a custom payload, there is one way that you can do that:

  1. Create a Log-based Alert. You can use the above pattern for search for logs from the Logs Explorer and then create a log-based alert based on that. Check out the documentation for the same. Ensure that the Destination Channel for this Log-based Alert is a Cloud Pub/Sub topic. This is important.
  2. You can now create an EventArc Trigger on the above Cloud Pub/Sub topic and provide the destination service to invoke.

Check out this excellent blog post that highlights various ways to configure EventArc filters.

Note: The above is required if you want to go to the EventArc way. From the Log-based Alerts, you can directly just write it to a Pub/Sub topic or even a custom Webhook and you wouldn't need to route it via the EventArc service.