Skip to content

Commit

Permalink
Adds an action to create datadog downtimes (#53)
Browse files Browse the repository at this point in the history
This action will create a datadog downtime to mute monitors while an application is deploying.
  • Loading branch information
mike-carey authored Sep 13, 2024
1 parent 618c8a7 commit 6b79698
Show file tree
Hide file tree
Showing 16 changed files with 37,484 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/register-task-definition.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,59 @@ on:
type: string
required: false

# notify-datadog
notify-datadog:
description: 'Indicates if a datadog downtime should be posted'
type: boolean
default: false
allow-datadog-to-fail:
description: 'If true, will not fail the pipeline if the datadog downtime action fails'
type: boolean
default: true

datadog-scope:
description: 'The scope to which the downtime applies. Must follow the [common search syntax](https://docs.datadoghq.com/logs/explorer/search_syntax/)'
type: string
required: false
datadog-message:
description: 'A message to include with notifications for this downtime. Email notifications can be sent to specific users by using the same @username notation as events.'
type: string
required: false
datadog-monitor-tags:
description: 'A comma delimited list of monitor tags. For example, tags that are applied directly to monitors, not tags that are used in monitor queries (which are filtered by the scope parameter), to which the downtime applies. The resulting downtime applies to monitors that match all provided monitor tags. Setting monitor_tags to [*] configures the downtime to mute all monitors for the given scope.'
type: string
required: false
datadog-monitor-id:
description: 'ID of the monitor to prevent notifications.'
type: string
required: false
datadog-end:
description: 'ISO-8601 Datetime to end the downtime. Additionally, one can specify time from now as `XhXmXs`.'
type: string
required: false
datadog-start:
description: 'ISO-8601 Datetime to start the downtime. Additionally, one can specify time from now as `XhXmXs`.'
type: string
required: false

secrets:
aws-account-id:
description: 'The AWS account id that the ecr repository lives under'
required: true

# notify-slack
slack-webhook-url:
description: 'The webhook URL to send the slack notification to; requires notify-slack to be true'
required: false

# notify-datadog
datadog-api-key:
description: 'The secret API key to authenticate the request with'
required: false
datadog-app-key:
description: 'The app key to authenticate the request with (pairs with the api key)'
required: false

outputs:
revision-number:
description: 'The revision number of the task definition just published'
Expand Down Expand Up @@ -151,6 +195,20 @@ jobs:
version: ${{ inputs.version }}
slack-webhook-url: ${{ secrets.slack-webhook-url }}

- name: 'Notify datadog of deployment'
if: inputs.notify-datadog == true
uses: shopsmart/github-actions/actions/create-datadog-downtime@v3
with:
datadog-api-key: ${{ secrets.datadog-api-key }}
datadog-app-key: ${{ secrets.datadog-app-key }}
scope: ${{ inputs.datadog-scope }}
message: ${{ inputs.datadog-message }}
monitor-id: ${{ inputs.datadog-monitor-id }}
monitor-tags: ${{ inputs.datadog-monitor-tags }}
start: ${{ inputs.datadog-start }}
end: ${{ inputs.datadog-end }}
continue-on-error: ${{ inputs.allow-datadog-to-fail }}

- name: 'Download task-definition'
uses: actions/download-artifact@v3
with:
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/validate-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ jobs:
with:
fetch-depth: 0

- name: 'Checkout'
uses: actions/checkout@v2

- name: 'Setup node'
uses: actions/setup-node@v3
with:
node-version-file: actions/create-datadog-downtime/.nvmrc
cache: npm
cache-dependency-path: actions/create-datadog-downtime/package-lock.json

- name: 'Install dependencies'
run: npm ci
working-directory: actions/create-datadog-downtime

- name: 'Run pre-commit'
uses: pre-commit/[email protected]
with:
Expand All @@ -41,3 +55,29 @@ jobs:

- name: 'Run action tests'
run: bats -r actions/*/*.bats

node-tests:
name: 'Run node unit tests'
runs-on: ubuntu-latest
strategy:
matrix:
action:
- create-datadog-downtime
steps:
- name: 'Checkout'
uses: actions/checkout@v2

- name: 'Setup node'
uses: actions/setup-node@v3
with:
node-version-file: actions/${{ matrix.action }}/.nvmrc
cache: npm
cache-dependency-path: actions/${{ matrix.action }}/package-lock.json

- name: 'Install dependencies'
run: npm ci
working-directory: actions/${{ matrix.action }}

- name: 'Run tests'
run: npm test
working-directory: actions/${{ matrix.action }}
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,21 @@ repos:
args: [--allow-missing-credentials]
- id: detect-private-key
- id: end-of-file-fixer
exclude: ^.*/dist/.*$
- id: fix-byte-order-marker
- id: no-commit-to-branch
args: [--branch, main]
- id: pretty-format-json
args: [--autofix, --no-sort-keys, --indent=4]
- id: trailing-whitespace
exclude: ^.*/dist/.*$

- repo: local
hooks:
- id: build-create-datadog-downtime-dist
name: Build the create-datadog-downtime dist
entry: bash -c 'cd actions/create-datadog-downtime && npm run build'
language: system
verbose: true
files: ^actions/create-datadog-downtime/(src\/.*\.ts|jest\.config\.js|tsconfig\.json|package(-lock)?\.json)$
pass_filenames: false
127 changes: 127 additions & 0 deletions actions/create-datadog-downtime/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# For Github Actions, we keep the dist in the source code for GHA to download and use.
!dist/

## @see https://raw.githubusercontent.com/actions/checkout/main/.gitignore

tests/tmp
# __test__/_temp
lib/

## @see https://raw.githubusercontent.com/github/gitignore/master/Node.gitignore

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
# dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
1 change: 1 addition & 0 deletions actions/create-datadog-downtime/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20.17.0
42 changes: 42 additions & 0 deletions actions/create-datadog-downtime/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---

name: 'Post datadog downtime update'
description: 'Posts a downtime window update to Datadog'

inputs:
scope:
description: 'The scope to which the downtime applies. Must follow the [common search syntax](https://docs.datadoghq.com/logs/explorer/search_syntax/)'
required: true
message:
description: 'A message to include with notifications for this downtime. Email notifications can be sent to specific users by using the same @username notation as events.'
required: false
monitor-tags:
description: 'A comma delimited list of monitor tags. For example, tags that are applied directly to monitors, not tags that are used in monitor queries (which are filtered by the scope parameter), to which the downtime applies. The resulting downtime applies to monitors that match all provided monitor tags. Setting monitor_tags to [*] configures the downtime to mute all monitors for the given scope.'
required: false
monitor-id:
description: 'ID of the monitor to prevent notifications.'
required: false
end:
description: 'ISO-8601 Datetime to end the downtime. Additionally, one can specify time from now as `XhXmXs`.'
required: true
start:
description: 'ISO-8601 Datetime to start the downtime. Additionally, one can specify time from now as `XhXmXs`.'
required: false

# secrets
datadog-api-key:
description: 'The secret API key to authenticate the request with'
required: true
datadog-app-key:
description: 'The app key to authenticate the request with (pairs with the api key)'
required: true

outputs:
status-code:
description: 'The status code of the response provided by Datadog'
response:
description: 'The response body provided by Datadog'

runs:
using: 'node20'
main: dist/index.js
Loading

0 comments on commit 6b79698

Please sign in to comment.