Skip to content

Commit

Permalink
PI-750 Set rate-limit and create alert for Sentry during bootstrap (#776
Browse files Browse the repository at this point in the history
)

* PI-750 Set rate-limit and create alert for Sentry during bootstrap

Based on the suggestion in this comment: getsentry/sentry#18904 (comment)

* Fix alert creation
  • Loading branch information
marcus-bcl committed Jan 26, 2023
1 parent 70ffbd5 commit 8c18a13
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions .github/workflows/bootstrap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,28 +179,27 @@ jobs:
echo "dsn=$dsn" >> $GITHUB_OUTPUT
echo "id=$id" >> $GITHUB_OUTPUT
- name: Set rate limit (10/minute)
run: |
curl -X PUT https://sentry.io/api/0/projects/ministryofjustice/${{ steps.project.outputs.slug }}/keys/${{ steps.client_key.outputs.id }}/ --fail \
-H 'Authorization: Bearer ${{ secrets.SENTRY_AUTH_TOKEN }}' \
-H 'Content-Type: application/json' \
-d '{"rateLimit":{"count":10,"window":60}}'
- name: Create alert
run: |
curl -X POST 'https://sentry.io/api/0/projects/ministryofjustice/${{ steps.project.outputs.slug }}/rules/?duplicateRule=true&wizardV3=true' --fail \
-H 'Authorization: Bearer ${{ secrets.SENTRY_AUTH_TOKEN }}' \
-H 'Content-Type: application/json' \
-d '{"conditions":[{"id":"sentry.rules.conditions.first_seen_event.FirstSeenEventCondition","name":"A new issue is created"},{"id":"sentry.rules.conditions.regression_event.RegressionEventCondition","name":"The issue changes state from resolved to unresolved"},{"id":"sentry.rules.conditions.reappeared_event.ReappearedEventCondition","name":"The issue changes state from ignored to unresolved"}],"filters":[],"actions":[{"workspace":"50134","id":"sentry.integrations.slack.notify_action.SlackNotifyServiceAction","channel":"probation-integration-notifications","channel_id":"C033HPR0W91","tags":"","name":"Send a notification to the MOJ Digital & Technology Slack workspace to probation-integration-notifications (optionally, an ID: C033HPR0W91) and show tags [] in notification"}],"actionMatch":"any","filterMatch":"all","frequency":5,"name":"New issues","dateCreated":"2023-01-23T12:03:42.969890Z","owner":"team:1611212","environment":null,"projects":["${{ steps.project.outputs.slug }}"]}'
- name: Store DSN as GitHub secret
run: gh secret set "$NAME" --body "$VALUE" --app actions
env:
NAME: ${{ steps.project_name.outputs.with_underscores }}_SENTRY_DSN
VALUE: ${{ steps.client_key.outputs.dsn }}
GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}

- name: Create issue for manual steps
# see https://github.com/getsentry/sentry/issues/18904
# see https://github.com/getsentry/sentry/issues/36968
run: |
gh issue create \
--title "${{ inputs.issue_number }} Complete Sentry setup for ${{ inputs.project_name }}" \
--body '
- [ ] Configure rate limiting to 10/minute: https://sentry.io/settings/ministryofjustice/projects/${{ steps.project.outputs.slug }}/keys/${{ steps.client_key.outputs.id }}
- [ ] Create a Slack alert: https://sentry.io/organizations/ministryofjustice/alerts/new/issue/?createFromDuplicate=true&duplicateRuleId=11530702&project=prison-case-notes-to-probation
> :memo: Note: the above link will duplicate an alert from `prison-case-notes-to-probation`. Make sure to update the Project to `${{ inputs.project_name }}` in the drop-down.' \
--label bootstrap
env:
GITHUB_TOKEN: ${{ github.token }}

sqs-queue-setup:
runs-on: ubuntu-latest
if: ${{ inputs.create_queue }}
Expand Down

0 comments on commit 8c18a13

Please sign in to comment.