mozilla-services/bec-alerts

Name: bec-alerts

Owner: Mozilla Services

Description: null

Created: 2018-04-19 21:35:45.0

Updated: 2018-05-23 23:00:20.0

Pushed: 2018-05-24 17:31:21.0

Homepage: null

Size: 81

Language: Python

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Browser Error Collection Notifications

This is a prototype service that reads processed events from Sentry (exported via Amazon SQS) and evaluates several rules to determine if it should send email alerts.

Development Setup

Prerequisites:

Running the Processor

To run the processor and related services:

er-compose up
Simulating an Error

If you've set SIMULATE_SENTRY_DSN in your .env file properly, you can simulate sending an error to your running processor instance with the simulate_error command:

er-compose run processor bec-alerts simulate_error
Evaluating Triggers / Running Watcher

After you've processed an error, you can evaluate the configured alert triggers with the watcher:

er-compose run processor bec-alerts watcher --once --console-alerts --dry-run

You should see log output stating how many issues were evaluated, and messages logged to the console if any alerts were triggered. It may be useful to set the enabled property on the example triggers in bec_alerts/triggers.py, which will trigger alerts whenever a new event is seen or when new events that the user has not seen before are seen.

Running Tests

You can run the test suite using pytest in the processor container:

er-compose run processor pytest /app
Deployment

The service consists of a few AWS services and a Docker image that is intended to be run on EC2. The required AWS resources are:

AWS credentials are pulled from IAM. The region is provided by the AWS_DEFAULT_REGION environment variable.

The Docker image defined in Dockerfile is used to run two separate processes: the processor, and the watcher, described in the following sections.

The following environment variables are available for all processes:

| Name | Required? | Default | Description | | —- | ——— | ——- | ———– | | AWS_DEFAULT_REGION | :white_check_mark: | | Region for connecting to AWS | | DATABASE_URL | :white_check_mark: | | URL with connection data for the database. Typically a postgres URL of the form postgres://user:password@host/database_name. | | DJANGO_SECRET_KEY | :white_check_mark: | | Secret key for Django's cryptographic signing. We don't really use it but Django fails to start without it. Set to a secret, random string. | | SENTRY_DSN | :white_check_mark: | | DSN used to send errors to Sentry. | | AWS_CONNECT_TIMEOUT | :x: | 30 | Timeout for connecting to AWS | | AWS_READ_TIMEOUT | :x: | 30 | Timeout for reading a response from AWS | | LOG_FORMAT | :x: | mozlog | Format to output logs in. Use mozlog for mozlog-compatible logs, or compose for a human-readable format suited for docker-compose output. | | LOG_LEVEL | :x: | INFO | Minimum log level to output. One of CRITICAL, ERROR, WARNING, INFO, or DEBUG. |

Processor

Command: bec-alerts processor

Reads from SQS to fetch incoming events from Sentry, processes them, and saves the resulting data to Postgres. This process will launch and manage a pool of subprocesses for listening and processing data.

The following environment variables are available for the processor:

| Name | Required? | Default | Description | | —- | ——— | ——- | ———– | | SQS_QUEUE_URL | :x: | | URL of the queue to poll for events. If not provided, a queue will be created on startup with the default name sentry_errors. | | SQS_ENDPOINT_URL | :x: | | Endpoint URL for connection to AWS. Only required for local development. | | PROCESSOR_PROCESS_COUNT | :x: | System CPU count | Number of worker processes to start | | PROCESSOR_WORKER_MESSAGE_COUNT | :x: | 200 | Number of messages a worker should process before terminating; a new worker process is started to take its place. Workers may process slightly more messages than this number before shutting down due to message batching. |

Watcher

Command: bec-alerts watcher

Periodically checks for events that have been processed since the last run, and evaluates alert triggers to determine if we should send a notification to users. This process implements its own sleep timer.

The following environment variables are available for the watcher:

| Name | Required? | Default | Description | | —- | ——— | ——- | ———– | | SES_FROM_EMAIL | :white_check_mark: | notifications@sentry.prod.mozaws.net | Email to use in the From field for notifications | | DATADOG_COUNTER_NAME | :x: | bec-alerts.watcher.health | Name of the DogStatsD counter to increment for health checks. | | SES_VERIFY_EMAIL | :x: | False | If True, the watcher will attempt to verify the SES_VERIFY_EMAIL via API on startup. Should probably be False in production. | | WATCHER_SLEEP_DELAY | :x: | 300 | Seconds to wait between checking for new events and alert triggers | | SES_ENDPOINT_URL | :x: | | Endpoint URL for connection to AWS. Only required for local development. |

Monitoring
License

Browser Error Collection Notifications is licensed under the MPL 2.0. See the LICENSE file for details.

The file sentry/sqs_plugin.py is a fork of an official Sentry plugin provided by Sentry. It is covered under the Apache License, version 2.0. See the file's comments for details.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.