Skip to content

Instantly share code, notes, and snippets.

@mbutsko
Last active February 25, 2022 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbutsko/d84dffaf039825d1ed4237cbe36b9f58 to your computer and use it in GitHub Desktop.
Save mbutsko/d84dffaf039825d1ed4237cbe36b9f58 to your computer and use it in GitHub Desktop.

Redash as Guard Rails for Unexpected Conditions

Production is the best environment to learn things. These are tips to help us learn and grow from production data using Redash.

Using redash queries and alerts as a way to notify your team of unexpected conditions in production can be a great way to provide assurance that expectations are being met and/or error.

Redash can (but should not be) used as a safe guard for data integrity issues. Database constraints and model validations are the best way to go, but especially when thinking about heuristics as warning signs, this is not always possible.

Steps to Profit

  1. Create a Query. This query needs to return something comparable like a single aggregate scalar (like a count, average, min, max etc.) Redash can use queries with multiple rows, but when setting up an alert it will only look at the top row. Protip Add labels for your team and epic to make finding and discovery of queries easier.
  2. Ensure your query has a refresh schedule so that it will run on its own at whatever interval you need.
  3. Check your alert destination. Generally these are one per person; you can elect to send them to yourself for personal things, but this may be bad in the long run as it means there's a bus/lottery factor of 1.
  4. Create an Alert. Here you will select your query, alert condition, and customize the alert text if so required.

Tips

  • Always start with the alert in a triggered state to make sure notifications are working.
  • If the alarm message hits a group/team email (yey!) be sure that someone will respond to take action. Taking action might mean a production fix or altering the query for an unexpected condition, but it's not helpful if it triggers once and never gets resolved!
  • If your query refreshes daily or less, consider sending notification every time it runs, in case no one resolves the issue.
  • Do customize the template to include any instructions on how to investigate or resolve the issue.

Redash for Awesome CLI

⛔️ IMPORTANT: This step involves using urls which have an api key unique to you ** the query in the URL. Exposure of this API key to unauthorized users could easily be used outside of the org to look at our production data. Proceed with caution!!!

** Thanks to Taylor @ Seven Fifty for pointing out that this key is specific to the query and not the user, which represents far less risk. There is still an API key for the user, but that's separate from the one that's shown on the query page.

Steps to profit

  1. Create a Query.
  2. On your query, click the vertical ellipsis in the upper-right hand corner and click 'Show API Key'.
  3. CURL:
curl -s https://redash.pvfog.com/api/queries/[your query id here]/results.json?api_key=$REDASH_API_KEY | \
  jq .query_result.data

Tips

  • Pulling query results does not rerun your query; use refresh schedules (judiciously) to get fresh data.
  • You will get ALL of the results, so adding LIMITs to your queries is advised.
  • DO NOT SHARE THE COPIED URL as it contains your api key.

Redash for Dashboards

  1. Create some queries. Again, refresh schedules are often, just don't run queries that take 10 minutes every minute.
  2. Add one or more vizualizations.
  3. Create a dashboard
  4. Embed

Redash as a snippet library

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment