Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to be notified on Google Cloud Function timeout?

I've enabled the notifications in Stackdriver and I'm getting notification e-mails for exceptions just fine.

The problem is that I don't get any notification for timeouts.

Is there any way to be notified when a Google Cloud Function is killed by timeout?

like image 815
José Ricardo Avatar asked Feb 28 '19 22:02

José Ricardo


People also ask

How do I set request timeout?

Click the Container tab. In the Request timeout field, enter the timeout value that you want to use in seconds. Use values ranging from 1 to 3600 seconds, or from 1 to 60 minutes. Click Create or Deploy.

How long can a cloud function run for?

60 minutes for HTTP functions. 10 minutes for event-driven functions.

What is the difference between on call and on request function?

onRequest creates a standard API endpoint, and you'll use whatever methods your client-side code normally uses to make. HTTP requests to interact with them. onCall creates a callable. Once you get used to them, onCall is less effort to write, but you don't have all the flexibility you might be used to.


2 Answers

Even though a timeout is not reported as an error, you can still set up a metric for timeout log entries, and then an alert on the metric exceeding a zero threshold.

  1. From the GCP console, go to the Stackdriver Logging viewer (/logs/viewer), and build a filter like this:
resource.type="cloud_function"
resource.labels.function_name="[YOUR_FUNCTION_NAME_HERE]"
"finished with status: 'timeout'"

The third line is a "contains" text filter. Timeout messages consistently contain this text. You can add other things or modify as needed.

  1. Click Create Metric. Give the metric a name like "Function timeouts", and make sure the type is counter. You can leave the optional fields blank. Submit the form, and you should be redirected to /logs/metrics.

  2. Under User-defined Metrics, you should see your new metric. Click the three-dot button on the right and select Create alert from metric.

  3. Give the alert policy a meaningful name. Under target, you may also get some red text about being unable to produce a line plot. Click the helpful link to switch the aligner to mean and the aggregator to none. Then under Configuration, set the condition to "is above," threshold to "0", and for "most recent value."

  4. Proceed with building the notification and documentation as desired. Make sure you add a notification channel so you get alerted. The UI should include hints on each field.

More detail is in the official documentation.

like image 81
Dom Zippilli Avatar answered Oct 28 '22 13:10

Dom Zippilli


  • Navigate to "Create alerting policy" using the search box at the top of the dashboard.
  • Under "What do you want to track?" click "Add Condition."
  • Configure the new condition like so:

enter image description here

  • Click "Add."
  • Click "Next."
  • Select a notification channel or create a new one.
  • I unchecked "Notify on incident resolution."
  • Click "Next."
  • Provide a descriptive alert name and optional documentation.
  • Click "Save."
  • Ensure that at the top of the policy you see the word "Enabled" along with a green checkmark.
like image 39
Nathan Arthur Avatar answered Oct 28 '22 14:10

Nathan Arthur