x

[eBook Presented by AWS & Thundra] Mastering Observability on the Cloud 📖 Download:

Working with Thundra Alerts

Aug 4, 2020

                                    Working with Thundra Alerts

This is a guest blog post by Matt Billock, Staff Software Engineer at Thinkful/Chegg.

When things go wrong in serverless applications, up-to-date information is absolutely critical. While Thundra’s basic functionality provides a lot of visibility into your stack right out of the box, there are a few features that, when configured correctly, can help your integration go above and beyond. Thundra alerts are a powerful tool that lets you get to the source of the issue and monitor defined metrics with ease. In this article, we’ll dive deep into Thundra alerts, exploring how you can use Thundra’s powerful query language to gain fine-grain control over your serverless application’s behavior.

Setting the Stage

To explore Thundra alerts, we’ll make use of a small demonstration application that implements a simple calculator application using AWS Lambda and AWS SAM. The calculator application has only very basic error handling, and we’d like to build out error tracking so we can figure out when things are going wrong. On top of tracking errors, we’d like to start collecting statistics on which calculator functions are the most popular, information that will be valuable in driving future development.

The sample application is implemented in Node.js, and contains the following serverless functions:

  • serverlessAddFunction - Adds together two arguments.
  • serverlessSubtractFunction - Subtracts two arguments.
  • serverlessMultiplyFunction - Multiplies two arguments.
  • serverlessDivideFunction - Divides one argument by another. Returns an error if divide by zero occurs.

Once you’ve cloned the parent repository, go to the project folder and build the application to get started:

PS D:\dev\aws> cd serverless-calculator

PS D:\dev\aws\serverless-calculator> sam build

When the build has completed successfully, you can stand up a local API to test against. To do so, simply use the AWS SAM command provided:

PS D:\dev\aws\serverless-calculator> sam local start-api


Your Lambda function API endpoints are now available at http://127.0.0.1:3000. To contact the API, append the name of the operation you wish to perform to the end of the URL, and provide the arguments in a JSON body. Below is a sample set of parameters:

{
    "lhs":10,
    "rhs":0
}


Spend some time experimenting with the functionality provided, and feel free to expand it as needed. This project comes with the Thundra Lambda Layer already integrated, so instrumenting the application should be very straightforward. Simply enter your Thundra API key in the field provided in file template.yml, and you’re ready to go.

The true power of the Thundra platform is now available to you. With no code changes and only a few lines of YAML code, you’ve connected your serverless calculator with your Thundra dashboard. Start calling your Lambda functions and you’ll be able to see traces and invocation metrics recorded as they occur in the dashboard. Once this integration is confirmed, you’re ready to begin working with Thundra alerts.

Defining Alerts

Alerts in the Thundra platform are tools designed to notify developers when specific types of actions take place in the system. These actions can be as simple as logging a specific message upon completion of a registration, or as complex as an exception driven by a third-party failure. Alerts can thus be used for informational purposes, or they can signify cases of significant system errors leading to performance degradation. Alerts provide critical visibility into the state of your serverless functions when things go wrong.

When you receive an alert, you can acknowledge it in the Thundra dashboard, which takes you directly to the source of the issue for which you are hunting. Alerts can be set to occur as frequently or infrequently as you wish, and the easy-to-use wizard lets you tie the configured alerts into your critical reporting infrastructure. With careful application of queries and configurations, you can get all the information you need on the state of your application.

Queries

Queries are the core of Thundra alerts. They let you filter related objects in your application based on execution characteristics, rather than simply searching by name-based string. These queries produce lists of records that are then interpreted by the alerts functionality before being sent onward to the user. With queries, you can easily configure complex alerts in just a few mouse clicks.

You can build queries in the Thundra dashboard using the query helper. The query helper dynamically builds queries based upon user actions, which reduces the complexity of defining query strings for your alerts. Thundra has query helpers for five different kinds of objects:

  1. Functions - The function query helper lets you filter on the function properties, tags, and statistical performance of your Lambda functions.
  2. Invocations - The invocation query helper lets you filter your invocations on your application’s functional properties (such as error type), custom and resource tags, and statistical performance metrics for your invocations.
  3. Traces - The traces query helper filters your traces on trace properties or performance metrics. You can also query by unique trace.
  4. Operations - The operations query helper filters your operations according to specific operation properties as well as operation performance metrics.
  5. Logs - The log query helper allows you to filter your logs based on log-specific characteristics like name, level, and message.

Alerts on each of the types of objects above contain links to the query results that produced the alert, allowing you to fine-tune your queries based upon your application’s recorded actions. Using this functionality, you can create automated alerts when errors occur in your serverless functions, create statistics counters that alert you when no activity is detected, and more!

Configuring and Responding to Alerts

Thundra alerts require some straightforward configuration from the Thundra dashboard. Alerts are driven by queries, with one alert mapping to one query. You can configure how often queries are run against the data that Thundra has collected on your application—anywhere from once a minute to once a week. In addition to configuring query frequency, you can add a configurable throttle value, which lets you limit the number of notifications you receive by adding a delay between detection of an entry in the query and publication of the event.

Additionally, from within the configuration dialog you can easily connect your alerts to PagerDuty, EventBridge, Slack, or other tools so that they receive alerts at the frequency you have configured. Select your provider, and fill in the API connection information. Once you’ve done this, save the configured options for your alert, and it will be active in Thundra’s dashboard.

Moving Forward with Confidence

Thundra’s alerts are a powerful tool for ensuring your application’s integrity. Alerts let you filter on a number of different aspects of your serverless application’s behavior, tying multiple complex objects together behind a unifying query interface that is both easy to use and high-powered. With configurable alert frequencies and time-delay options, you can rely upon Thundra alerts to provide you with up-to-date information when things go wrong.