diff --git a/.craft.yml b/.craft.yml new file mode 100644 index 0000000..37c861b --- /dev/null +++ b/.craft.yml @@ -0,0 +1,15 @@ +minVersion: "0.10.0" +github: + owner: getsentry + repo: onpremise +releaseBranchPrefix: releases +changelogPolicy: none +artifactProvider: + name: none +statusProvider: + name: github + config: + contexts: + - 'continuous-integration/travis-ci/push' +targets: + - name: github diff --git a/.env b/.env index 008cb10..60a9f66 100644 --- a/.env +++ b/.env @@ -1,2 +1,4 @@ COMPOSE_PROJECT_NAME=sentry_onpremise SENTRY_EVENT_RETENTION_DAYS=90 +SENTRY_VERSION=20.6.0 +SYMBOLICATOR_VERSION=bc041908c8259a0fd28d84f3f0b12daa066b49f6 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..b08ddb0 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,39 @@ +name: release +on: + repository_dispatch: + types: [release] + schedule: + # We want the release to be at 10 or 11am Pacific Time + # We also make this an hour after all others such as Sentry, + # Snuba, and Relay to make sure their releases finish. + - cron: '0 18 15 * *' +jobs: + release: + runs-on: ubuntu-latest + name: "Release a new version" + steps: + - id: calver + if: ${{ !github.event.client_payload.version }} + run: echo "::set-output name=version::$(date +'%y.%-m.0')" + - uses: actions/checkout@v2 + - uses: getsentry/craft@master + if: ${{ !github.event.client_payload.skip_prepare }} + with: + action: prepare + version: ${{ github.event.client_payload.version || steps.calver.outputs.version }} + env: + DRY_RUN: ${{ github.event.client_payload.dry_run }} + GIT_COMMITTER_NAME: getsentry-bot + GIT_AUTHOR_NAME: getsentry-bot + EMAIL: bot@getsentry.com + - uses: getsentry/craft@master + with: + action: publish + version: ${{ github.event.client_payload.version || steps.calver.outputs.version }} + keep_branch: '--keep-branch' + no_merge: '--no-merge' + env: + DRY_RUN: ${{ github.event.client_payload.dry_run }} + GIT_COMMITTER_NAME: getsentry-bot + GIT_AUTHOR_NAME: getsentry-bot + EMAIL: bot@getsentry.com diff --git a/.gitignore b/.gitignore index 77b24eb..5931ebe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,79 +1,81 @@ # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class # C extensions *.so # Distribution / packaging .Python env/ build/ develop-eggs/ dist/ downloads/ eggs/ .eggs/ lib/ lib64/ parts/ sdist/ var/ *.egg-info/ .installed.cfg *.egg # PyInstaller # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest *.spec # Installer logs pip-log.txt pip-delete-this-directory.txt sentry_install_log*.txt # Unit test / coverage reports htmlcov/ .tox/ .coverage .coverage.* .cache nosetests.xml coverage.xml *.cover .hypothesis/ # Translations *.mo *.pot # Django stuff: *.log local_settings.py # Sphinx documentation docs/_build/ # PyBuilder target/ # Ipython Notebook .ipynb_checkpoints # pyenv .python-version # https://docs.docker.com/compose/extends/ docker-compose.override.yml *.tar data/ .vscode/tags # custom Sentry config sentry/sentry.conf.py sentry/config.yml +sentry/*.bak sentry/requirements.txt +relay/credentials.json diff --git a/.travis.yml b/.travis.yml index 8ec590d..761d998 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,22 @@ language: bash services: docker env: - DOCKER_COMPOSE_VERSION=1.24.1 before_install: - sudo rm /usr/local/bin/docker-compose - curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose - chmod +x docker-compose - sudo mv docker-compose /usr/local/bin script: - ./install.sh - docker-compose run --rm web createuser --superuser --email test@example.com --password test123TEST - docker-compose up -d - timeout 60 bash -c 'until $(curl -Isf -o /dev/null http://localhost:9000); do printf '.'; sleep 0.5; done' - ./test.sh + +after_failure: + - docker-compose ps + - docker-compose logs diff --git a/LICENSE b/LICENSE index 274ed3e..cd8936f 100644 --- a/LICENSE +++ b/LICENSE @@ -1,104 +1,104 @@ Business Source License 1.1 Parameters Licensor: Functional Software, Inc. Licensed Work: Sentry The Licensed Work is (c) 2019 Functional Software, Inc. Additional Use Grant: You may make use of the Licensed Work, provided that you do not use the Licensed Work for an Application Monitoring Service. An "Application Monitoring Service" is a commercial offering that allows third parties (other than your employees and contractors) to access the functionality of the Licensed Work so that such third parties directly benefit from the error-reporting or application monitoring features of the Licensed Work. -Change Date: 2023-03-01 +Change Date: 2023-06-01 Change License: Apache License, Version 2.0 For information about alternative licensing arrangements for the Software, please visit: https://sentry.io/pricing/ Notice The Business Source License (this document, or the "License") is not an Open Source license. However, the Licensed Work will eventually be made available under an Open Source License, as stated in this License. License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved. "Business Source License" is a trademark of MariaDB Corporation Ab. ----------------------------------------------------------------------------- Business Source License 1.1 Terms The Licensor hereby grants you the right to copy, modify, create derivative works, redistribute, and make non-production use of the Licensed Work. The Licensor may make an Additional Use Grant, above, permitting limited production use. Effective on the Change Date, or the fourth anniversary of the first publicly available distribution of a specific version of the Licensed Work under this License, whichever comes first, the Licensor hereby grants you rights under the terms of the Change License, and the rights granted in the paragraph above terminate. If your use of the Licensed Work does not comply with the requirements currently in effect as described in this License, you must purchase a commercial license from the Licensor, its affiliated entities, or authorized resellers, or you must refrain from using the Licensed Work. All copies of the original and modified Licensed Work, and derivative works of the Licensed Work, are subject to this License. This License applies separately for each version of the Licensed Work and the Change Date may vary for each version of the Licensed Work released by Licensor. You must conspicuously display this License on each original or modified copy of the Licensed Work. If you receive the Licensed Work in original or modified form from a third party, the terms and conditions set forth in this License apply to your use of that work. Any use of the Licensed Work in violation of this License will automatically terminate your rights under this License for the current and all other versions of the Licensed Work. This License does not grant you any right in any trademark or logo of Licensor or its affiliates (provided that you may use a trademark or logo of Licensor as expressly required by this License). TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND TITLE. MariaDB hereby grants you permission to use this License’s text to license your works, and to refer to it using the trademark "Business Source License", as long as you comply with the Covenants of Licensor below. Covenants of Licensor In consideration of the right to use this License’s text and the "Business Source License" name and trademark, Licensor covenants to MariaDB, and to all other recipients of the licensed work to be provided by Licensor: 1. To specify as the Change License the GPL Version 2.0 or any later version, or a license that is compatible with GPL Version 2.0 or a later version, where "compatible" means that software provided under the Change License can be included in a program with software provided under GPL Version 2.0 or a later version. Licensor may specify additional Change Licenses without limitation. 2. To either: (a) specify an additional grant of rights to use that does not impose any additional restriction on the right granted in this License, as the Additional Use Grant; or (b) insert the text "None". 3. To specify a Change Date. 4. Not to modify this License in any other way. diff --git a/README.md b/README.md index 87cde9f..ec79d51 100644 --- a/README.md +++ b/README.md @@ -1,73 +1,66 @@ -# Sentry 10 On-Premise [![Build Status][build-status-image]][build-status-url] +# Sentry 20.6.0 On-Premise [![Build Status][build-status-image]][build-status-url] Official bootstrap for running your own [Sentry](https://sentry.io/) with [Docker](https://www.docker.com/). ## Requirements * Docker 17.05.0+ - * Compose 1.19.0+ + * Compose 1.23.0+ ## Minimum Hardware Requirements: * You need at least 2400MB RAM ## Setup To get started with all the defaults, simply clone the repo and run `./install.sh` in your local check-out. There may need to be modifications to the included example config files (`sentry/config.example.yml` and `sentry/sentry.conf.example.py`) to accommodate your needs or your environment (such as adding GitHub credentials). If you want to perform these, do them before you run the install script and copy them without the `.example` extensions in the name (such as `sentry/sentry.conf.py`) before running the `install.sh` script. The recommended way to customize your configuration is using the files below, in that order: * `config.yml` * `sentry.conf.py` * `.env` w/ environment variables We currently support a very minimal set of environment variables to promote other means of configuration. If you have any issues or questions, our [Community Forum](https://forum.sentry.io/c/on-premise) is at your service! Everytime you run the install script, it will generate a log file, `sentry_install_log-.txt` with the output. Sharing these logs would help people diagnose any issues you might be having. ## Versioning -We continously push the Docker image for each commit made into [Sentry](https://github.com/getsentry/sentry), and other services such as [Snuba](https://github.com/getsentry/snuba) or [Symbolicator](https://github.com/getsentry/symbolicator) to [our Docker Hub](https://hub.docker.com/u/getsentry) and tag the latest version on master as `:latest`. This is also usually what we have on sentry.io and what the install script uses. You can use a custom Sentry image, such as a modified version that you have built on your own, or simply a specific commit hash by setting the `SENTRY_IMAGE` environment variable to that image name before running `./install.sh`: - -```shell -SENTRY_IMAGE=getsentry/sentry:10 ./install.sh -``` +If you want to install a specific release of Sentry, use the tags/releases on this repo. -or +We continously push the Docker image for each commit made into [Sentry](https://github.com/getsentry/sentry), and other services such as [Snuba](https://github.com/getsentry/snuba) or [Symbolicator](https://github.com/getsentry/symbolicator) to [our Docker Hub](https://hub.docker.com/u/getsentry) and tag the latest version on master as `:latest`. This is also usually what we have on sentry.io and what the install script uses. You can use a custom Sentry image, such as a modified version that you have built on your own, or simply a specific commit hash by setting the `SENTRY_IMAGE` environment variable to that image name before running `./install.sh`: ```shell SENTRY_IMAGE=getsentry/sentry:83b1380 ./install.sh ``` -If you want to use different or specific images for other services, you may create a `docker-compose.overrides.yaml` file in the repo and override the `image` field for the corresponding services. - -We strongly recommend keeping the `latest` tags for all, if you are using this repository directly. We also recommend using specific commit tags if you are consuming any of our Docker images in an environment that needs consistent deploys such as [a Helm chart](https://github.com/helm/charts/tree/master/stable/sentry). +Note that this may not work for all commit SHAs as this repository evolves with Sentry and its satellite projects. It is highly recommended to check out a version of this repository that is close to the timestamp of the Sentry commit you are installing. ## Event Retention Sentry comes with a cleanup cron job that prunes events older than `90 days` by default. If you want to change that, you can change the `SENTRY_EVENT_RETENTION_DAYS` environment variable in `.env` or simply override it in your environment. If you do not want the cleanup cron, you can remove the `sentry-cleanup` service from the `docker-compose.yml`file. ## Securing Sentry with SSL/TLS If you'd like to protect your Sentry install with SSL/TLS, there are fantastic SSL/TLS proxies like [HAProxy](http://www.haproxy.org/) and [Nginx](http://nginx.org/). You'll likely want to add this service to your `docker-compose.yml` file. ## Updating Sentry _You need to be on at least Sentry 9.1.2 to be able to upgrade automatically to the latest version. If you are not, upgrade to 9.1.2 first by checking out the [9.1.2 tag](https://github.com/getsentry/onpremise/tree/9.1.2) on this repo._ The included `install.sh` script is meant to be idempotent and to bring you to the latest version. What this means is you can and should run `install.sh` to upgrade to the latest version available. Remember that the output of the script will be stored in a log file, `sentry_install_log-.txt`, which you may share for diagnosis if anything goes wrong. ## Resources - * [Documentation](https://docs.sentry.io/server/) + * [Documentation](https://docs.sentry.io/development/server/) * [Bug Tracker](https://github.com/getsentry/onpremise/issues) - * [Forums](https://forum.sentry.io/c/on-premise) - * [Discord](https://discord.gg/mg5V76F) (Sentry Community, #sentry-server) + * [Community Forums](https://forum.sentry.io/c/on-premise) [build-status-image]: https://api.travis-ci.com/getsentry/onpremise.svg?branch=master [build-status-url]: https://travis-ci.com/getsentry/onpremise diff --git a/docker-compose.yml b/docker-compose.yml index 821279f..027ece9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,120 +1,158 @@ version: '3.4' x-restart-policy: &restart_policy restart: unless-stopped x-sentry-defaults: &sentry_defaults << : *restart_policy build: context: ./sentry args: - SENTRY_IMAGE + - SENTRY_VERSION image: sentry-onpremise-local depends_on: - redis - memcached - snuba-api - snuba-consumer + - snuba-outcomes-consumer + - snuba-sessions-consumer - snuba-replacer - symbolicator environment: + SENTRY_CONF: '/etc/sentry' SNUBA: 'http://snuba-api:1218' volumes: - 'sentry-data:/data' + - './sentry:/etc/sentry' x-snuba-defaults: &snuba_defaults << : *restart_policy depends_on: - redis - clickhouse - image: 'getsentry/snuba:latest' + image: 'getsentry/snuba:$SENTRY_VERSION' environment: SNUBA_SETTINGS: docker CLICKHOUSE_HOST: clickhouse REDIS_HOST: redis - # TODO: Remove these after getsentry/snuba#353 UWSGI_MAX_REQUESTS: '10000' UWSGI_DISABLE_LOGGING: 'true' - UWSGI_ENABLE_THREADS: 'true' - UWSGI_DIE_ON_TERM: 'true' - UWSGI_NEED_APP: 'true' - UWSGI_IGNORE_SIGPIPE: 'true' - UWSGI_IGNORE_WRITE_ERRORS: 'true' - UWSGI_DISABLE_WRITE_EXCEPTION: 'true' services: memcached: << : *restart_policy image: 'memcached:1.5-alpine' redis: << : *restart_policy image: 'redis:5.0-alpine' volumes: - 'sentry-redis:/data' clickhouse: << : *restart_policy - image: 'yandex/clickhouse-server:19.11' + image: 'yandex/clickhouse-server:19.17' ulimits: nofile: soft: 262144 hard: 262144 volumes: - 'sentry-clickhouse:/var/lib/clickhouse' + - 'sentry-clickhouse-log:/var/log/clickhouse-server' snuba-api: << : *snuba_defaults + # Kafka consumer responsible for feeding events into Clickhouse snuba-consumer: << : *snuba_defaults - command: consumer --auto-offset-reset=latest --max-batch-time-ms 750 + command: consumer --storage events --auto-offset-reset=latest --max-batch-time-ms 750 + # Kafka consumer responsible for feeding outcomes into Clickhouse + # Use --auto-offset-reset=earliest to recover up to 7 days of TSDB data + # since we did not do a proper migration + snuba-outcomes-consumer: + << : *snuba_defaults + command: consumer --storage outcomes_raw --auto-offset-reset=earliest --max-batch-time-ms 750 + # Kafka consumer responsible for feeding session data into Clickhouse + snuba-sessions-consumer: + << : *snuba_defaults + command: consumer --storage sessions_raw --auto-offset-reset=latest --max-batch-time-ms 750 snuba-replacer: << : *snuba_defaults - command: replacer --auto-offset-reset=latest --max-batch-size 3 + command: replacer --storage events --auto-offset-reset=latest --max-batch-size 3 snuba-cleanup: << : *snuba_defaults image: snuba-cleanup-onpremise-local build: context: ./cron args: - BASE_IMAGE: 'getsentry/snuba:latest' + BASE_IMAGE: 'getsentry/snuba:$SENTRY_VERSION' command: '"*/5 * * * * gosu snuba snuba cleanup --dry-run False"' symbolicator: << : *restart_policy - image: 'getsentry/symbolicator:latest' + image: 'getsentry/symbolicator:$SYMBOLICATOR_VERSION' volumes: - 'sentry-symbolicator:/data' command: run symbolicator-cleanup: + << : *restart_policy image: symbolicator-cleanup-onpremise-local build: context: ./cron args: - BASE_IMAGE: 'getsentry/symbolicator:latest' + BASE_IMAGE: 'getsentry/symbolicator:$SYMBOLICATOR_VERSION' command: '"55 23 * * * gosu symbolicator symbolicator cleanup"' volumes: - 'sentry-symbolicator:/data' web: << : *sentry_defaults - ports: - - '9000:9000/tcp' cron: << : *sentry_defaults command: run cron worker: << : *sentry_defaults command: run worker + ingest-consumer: + << : *sentry_defaults + command: run ingest-consumer --all-consumer-types post-process-forwarder: << : *sentry_defaults # Increase `--commit-batch-size 1` below to deal with high-load environments. command: run post-process-forwarder --commit-batch-size 1 sentry-cleanup: << : *sentry_defaults image: sentry-cleanup-onpremise-local build: context: ./cron args: BASE_IMAGE: 'sentry-onpremise-local' command: '"0 0 * * * gosu sentry sentry cleanup --days $SENTRY_EVENT_RETENTION_DAYS"' + nginx: + << : *restart_policy + ports: + - '9000:80/tcp' + image: 'nginx:1.16' + volumes: + - type: bind + read_only: true + source: ./nginx + target: /etc/nginx + depends_on: + - web + - relay + relay: + << : *restart_policy + image: 'getsentry/relay:$SENTRY_VERSION' + volumes: + - type: bind + read_only: true + source: ./relay + target: /work/.relay + depends_on: + - kafka + - redis volumes: sentry-data: external: true sentry-redis: external: true sentry-clickhouse: external: true sentry-symbolicator: external: true + sentry-secrets: + sentry-clickhouse-log: diff --git a/install.sh b/install.sh index a4f87db..de42d01 100755 --- a/install.sh +++ b/install.sh @@ -1,171 +1,263 @@ #!/usr/bin/env bash set -e dc="docker-compose --no-ansi" dcr="$dc run --rm" # Thanks to https://unix.stackexchange.com/a/145654/108960 log_file="sentry_install_log-`date +'%Y-%m-%d_%H-%M-%S'`.txt" exec &> >(tee -a "$log_file") MIN_DOCKER_VERSION='17.05.0' MIN_COMPOSE_VERSION='1.23.0' MIN_RAM=2400 # MB SENTRY_CONFIG_PY='sentry/sentry.conf.py' SENTRY_CONFIG_YML='sentry/config.yml' +RELAY_CONFIG_YML='relay/config.yml' +RELAY_CREDENTIALS_JSON='relay/credentials.json' SENTRY_EXTRA_REQUIREMENTS='sentry/requirements.txt' DID_CLEAN_UP=0 # the cleanup function will be the exit point cleanup () { if [ "$DID_CLEAN_UP" -eq 1 ]; then return 0; fi echo "Cleaning up..." $dc stop &> /dev/null DID_CLEAN_UP=1 } trap cleanup ERR INT TERM echo "Checking minimum requirements..." DOCKER_VERSION=$(docker version --format '{{.Server.Version}}') COMPOSE_VERSION=$($dc --version | sed 's/docker-compose version \(.\{1,\}\),.*/\1/') RAM_AVAILABLE_IN_DOCKER=$(docker run --rm busybox free -m 2>/dev/null | awk '/Mem/ {print $2}'); # Compare dot-separated strings - function below is inspired by https://stackoverflow.com/a/37939589/808368 function ver () { echo "$@" | awk -F. '{ printf("%d%03d%03d", $1,$2,$3); }'; } # Thanks to https://stackoverflow.com/a/25123013/90297 for the quick `sed` pattern function ensure_file_from_example { if [ -f "$1" ]; then echo "$1 already exists, skipped creation." else echo "Creating $1..." cp -n $(echo "$1" | sed 's/\.[^.]*$/.example&/') "$1" fi } if [ $(ver $DOCKER_VERSION) -lt $(ver $MIN_DOCKER_VERSION) ]; then echo "FAIL: Expected minimum Docker version to be $MIN_DOCKER_VERSION but found $DOCKER_VERSION" exit 1 fi if [ $(ver $COMPOSE_VERSION) -lt $(ver $MIN_COMPOSE_VERSION) ]; then echo "FAIL: Expected minimum docker-compose version to be $MIN_COMPOSE_VERSION but found $COMPOSE_VERSION" exit 1 fi if [ "$RAM_AVAILABLE_IN_DOCKER" -lt "$MIN_RAM" ]; then echo "FAIL: Expected minimum RAM available to Docker to be $MIN_RAM MB but found $RAM_AVAILABLE_IN_DOCKER MB" exit 1 fi -#SSE4.2 required by Clickhouse (https://clickhouse.yandex/docs/en/operations/requirements/) -SUPPORTS_SSE42=$(docker run --rm busybox grep -c sse4_2 /proc/cpuinfo || :); -if (($SUPPORTS_SSE42 == 0)); then +#SSE4.2 required by Clickhouse (https://clickhouse.yandex/docs/en/operations/requirements/) +# On KVM, cpuinfo could falsely not report SSE 4.2 support, so skip the check. https://github.com/ClickHouse/ClickHouse/issues/20#issuecomment-226849297 +IS_KVM=$(docker run --rm busybox grep -c 'Common KVM processor' /proc/cpuinfo || :) +if (($IS_KVM == 0)); then + SUPPORTS_SSE42=$(docker run --rm busybox grep -c sse4_2 /proc/cpuinfo || :) + if (($SUPPORTS_SSE42 == 0)); then echo "FAIL: The CPU your machine is running on does not support the SSE 4.2 instruction set, which is required for one of the services Sentry uses (Clickhouse). See https://git.io/JvLDt for more info." exit 1 + fi fi # Clean up old stuff and ensure nothing is working while we install/update # This is for older versions of on-premise: $dc -p onpremise down --rmi local --remove-orphans # This is for newer versions $dc down --rmi local --remove-orphans echo "" echo "Creating volumes for persistent storage..." echo "Created $(docker volume create --name=sentry-data)." echo "Created $(docker volume create --name=sentry-redis)." echo "Created $(docker volume create --name=sentry-clickhouse)." echo "Created $(docker volume create --name=sentry-symbolicator)." echo "" ensure_file_from_example $SENTRY_CONFIG_PY ensure_file_from_example $SENTRY_CONFIG_YML ensure_file_from_example $SENTRY_EXTRA_REQUIREMENTS if grep -xq "system.secret-key: '!!changeme!!'" $SENTRY_CONFIG_YML ; then echo "" echo "Generating secret key..." # This is to escape the secret key to be used in sed below # Note the need to set LC_ALL=C due to BSD tr and sed always trying to decode # whatever is passed to them. Kudos to https://stackoverflow.com/a/23584470/90297 SECRET_KEY=$(export LC_ALL=C; head /dev/urandom | tr -dc "a-z0-9@#%^&*(-_=+)" | head -c 50 | sed -e 's/[\/&]/\\&/g') sed -i -e 's/^system.secret-key:.*$/system.secret-key: '"'$SECRET_KEY'"'/' $SENTRY_CONFIG_YML echo "Secret key written to $SENTRY_CONFIG_YML" fi +replace_tsdb() { + if ( + [ -f "$SENTRY_CONFIG_PY" ] && + ! grep -xq 'SENTRY_TSDB = "sentry.tsdb.redissnuba.RedisSnubaTSDB"' "$SENTRY_CONFIG_PY" + ); then + tsdb_settings="SENTRY_TSDB = \"sentry.tsdb.redissnuba.RedisSnubaTSDB\" + +# Automatic switchover 90 days after $(date). Can be removed afterwards. +SENTRY_TSDB_OPTIONS = {\"switchover_timestamp\": $(date +%s) + (90 * 24 * 3600)}" + + if grep -q 'SENTRY_TSDB_OPTIONS = ' "$SENTRY_CONFIG_PY"; then + echo "Not attempting automatic TSDB migration due to presence of SENTRY_TSDB_OPTIONS" + else + echo "Attempting to automatically migrate to new TSDB" + # Escape newlines for sed + tsdb_settings="${tsdb_settings//$'\n'/\\n}" + cp "$SENTRY_CONFIG_PY" "$SENTRY_CONFIG_PY.bak" + sed -i -e "s/^SENTRY_TSDB = .*$/${tsdb_settings}/g" "$SENTRY_CONFIG_PY" || true + + if grep -xq 'SENTRY_TSDB = "sentry.tsdb.redissnuba.RedisSnubaTSDB"' "$SENTRY_CONFIG_PY"; then + echo "Migrated TSDB to Snuba. Old configuration file backed up to $SENTRY_CONFIG_PY.bak" + return + fi + + echo "Failed to automatically migrate TSDB. Reverting..." + mv "$SENTRY_CONFIG_PY.bak" "$SENTRY_CONFIG_PY" + echo "$SENTRY_CONFIG_PY restored from backup." + fi + + echo "WARN: Your Sentry configuration uses a legacy data store for time-series data. Remove the options SENTRY_TSDB and SENTRY_TSDB_OPTIONS from $SENTRY_CONFIG_PY and add:" + echo "" + echo "$tsdb_settings" + echo "" + echo "For more information please refer to https://github.com/getsentry/onpremise/pull/430" + fi +} + +replace_tsdb + +echo "" +echo "Fetching and updating Docker images..." +echo "" +# We tag locally built images with an '-onpremise-local' suffix. docker-compose pull tries to pull these too and +# shows a 404 error on the console which is confusing and unnecessary. To overcome this, we add the stderr>stdout +# redirection below and pass it through grep, ignoring all lines having this '-onpremise-local' suffix. +$dc pull -q --ignore-pull-failures 2>&1 | grep -v -- -onpremise-local || true + +if [ -z "$SENTRY_IMAGE" ]; then + docker pull getsentry/sentry:${SENTRY_VERSION:-latest} +else + # We may not have the set image on the repo (local images) so allow fails + docker pull $SENTRY_IMAGE || true; +fi + echo "" echo "Building and tagging Docker images..." echo "" # Build the sentry onpremise image first as it is needed for the cron image -$dc pull --ignore-pull-failures -docker pull ${SENTRY_IMAGE:-getsentry/sentry:latest} $dc build --force-rm web $dc build --force-rm --parallel echo "" echo "Docker images built." -echo "Bootstrapping Snuba..." -# `bootstrap` is for fresh installs, and `migrate` is for existing installs -# Running them both for both cases is harmless so we blindly run them + +ZOOKEEPER_LOG_FILE_COUNT=$($dcr zookeeper bash -c 'ls 2>/dev/null -Ubad1 -- /var/lib/zookeeper/log/version-2/* | wc -l | tr -d '[:space:]'') +ZOOKEEPER_SNAPSHOT_FILE_COUNT=$($dcr zookeeper bash -c 'ls 2>/dev/null -Ubad1 -- /var/lib/zookeeper/data/version-2/* | wc -l | tr -d '[:space:]'') +# This is a workaround for a ZK upgrade bug: https://issues.apache.org/jira/browse/ZOOKEEPER-3056 +if [ "$ZOOKEEPER_LOG_FILE_COUNT" -gt "0" ] && [ "$ZOOKEEPER_SNAPSHOT_FILE_COUNT" -eq "0" ]; then + $dcr -v $(pwd)/zookeeper:/temp zookeeper bash -c 'cp /temp/snapshot.0 /var/lib/zookeeper/data/version-2/snapshot.0' + $dc run -d -e ZOOKEEPER_SNAPSHOT_TRUST_EMPTY=true zookeeper +fi + + +echo "Bootstrapping and migrating Snuba..." $dcr snuba-api bootstrap --force -$dcr snuba-api migrate echo "" # Very naively check whether there's an existing sentry-postgres volume and the PG version in it if [[ $(docker volume ls -q --filter name=sentry-postgres) && $(docker run --rm -v sentry-postgres:/db busybox cat /db/PG_VERSION 2>/dev/null) == "9.5" ]]; then docker volume rm sentry-postgres-new || true # If this is Postgres 9.5 data, start upgrading it to 9.6 in a new volume docker run --rm \ -v sentry-postgres:/var/lib/postgresql/9.5/data \ -v sentry-postgres-new:/var/lib/postgresql/9.6/data \ tianon/postgres-upgrade:9.5-to-9.6 # Get rid of the old volume as we'll rename the new one to that docker volume rm sentry-postgres docker volume create --name sentry-postgres # There's no rename volume in Docker so copy the contents from old to new name # Also append the `host all all all trust` line as `tianon/postgres-upgrade:9.5-to-9.6` # doesn't do that automatically. docker run --rm -v sentry-postgres-new:/from -v sentry-postgres:/to alpine ash -c \ "cd /from ; cp -av . /to ; echo 'host all all all trust' >> /to/pg_hba.conf" # Finally, remove the new old volume as we are all in sentry-postgres now docker volume rm sentry-postgres-new fi echo "" echo "Setting up database..." if [ $CI ]; then $dcr web upgrade --noinput echo "" echo "Did not prompt for user creation due to non-interactive shell." echo "Run the following command to create one yourself (recommended):" echo "" echo " docker-compose run --rm web createuser" echo "" else $dcr web upgrade fi SENTRY_DATA_NEEDS_MIGRATION=$(docker run --rm -v sentry-data:/data alpine ash -c "[ ! -d '/data/files' ] && ls -A1x /data | wc -l || true") if [ "$SENTRY_DATA_NEEDS_MIGRATION" ]; then echo "Migrating file storage..." # Use the web (Sentry) image so the file owners are kept as sentry:sentry # The `\"` escape pattern is to make this compatible w/ Git Bash on Windows. See #329. $dcr --entrypoint \"/bin/bash\" web -c \ "mkdir -p /tmp/files; mv /data/* /tmp/files/; mv /tmp/files /data/files; chown -R sentry:sentry /data" fi + +if [ ! -f "$RELAY_CREDENTIALS_JSON" ]; then + echo "" + echo "Generating Relay credentials..." + + # We need the ugly hack below as `relay generate credentials` tries to read the config and the credentials + # even with the `--stdout` and `--overwrite` flags and then errors out when the credentials file exists but + # not valid JSON. We hit this case as we redirect output to the same config folder, creating an empty + # credentials file before relay runs. + $dcr --no-deps -v $(pwd)/$RELAY_CONFIG_YML:/tmp/config.yml relay --config /tmp credentials generate --stdout > "$RELAY_CREDENTIALS_JSON" + echo "Relay credentials written to $RELAY_CREDENTIALS_JSON" +fi + +RELAY_CREDENTIALS=$(sed -n 's/^.*"public_key"[[:space:]]*:[[:space:]]*"\([a-zA-Z0-9_-]\{1,\}\)".*$/\1/p' "$RELAY_CREDENTIALS_JSON") +if [ -z "$RELAY_CREDENTIALS" ]; then + >&2 echo "FAIL: Cannot read credentials back from $RELAY_CREDENTIALS_JSON." + >&2 echo " Please ensure this file is readable and contains valid credentials." + >&2 echo "" + exit 1 +fi + +if ! grep -q "\"$RELAY_CREDENTIALS\"" "$SENTRY_CONFIG_PY"; then + echo "SENTRY_RELAY_WHITELIST_PK = (SENTRY_RELAY_WHITELIST_PK or []) + ([\"$RELAY_CREDENTIALS\"])" >> "$SENTRY_CONFIG_PY" + echo "Relay public key written to $SENTRY_CONFIG_PY" + echo "" +fi + cleanup echo "" echo "----------------" echo "You're all done! Run the following command to get Sentry running:" echo "" echo " docker-compose up -d" echo "" diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..84027d4 --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,73 @@ +user nginx; +worker_processes 1; + +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; + + +events { + worker_connections 1024; +} + + +http { + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + sendfile on; + tcp_nopush on; + tcp_nodelay on; + reset_timedout_connection on; + + keepalive_timeout 75s; + + gzip off; + server_tokens off; + + server_names_hash_bucket_size 64; + types_hash_max_size 2048; + types_hash_bucket_size 64; + client_max_body_size 100m; + + proxy_http_version 1.1; + proxy_redirect off; + proxy_buffering off; + proxy_next_upstream error timeout invalid_header http_502 http_503 non_idempotent; + proxy_next_upstream_tries 2; + + # Remove the Connection header if the client sends it, + # it could be "close" to close a keepalive connection + proxy_set_header Connection ''; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Request-Id $request_id; + proxy_read_timeout 30s; + proxy_send_timeout 5s; + + upstream relay { + server relay:3000; + } + + upstream sentry { + server web:9000; + } + + server { + listen 80; + + location /api/store/ { + proxy_pass http://relay; + } + location ~ ^/api/[1-9]\d*/ { + proxy_pass http://relay; + } + location / { + proxy_pass http://sentry; + } + } +} diff --git a/relay/config.yml b/relay/config.yml new file mode 100644 index 0000000..da00363 --- /dev/null +++ b/relay/config.yml @@ -0,0 +1,13 @@ +--- +relay: + upstream: "http://web:9000/" + host: 0.0.0.0 + port: 3000 +logging: + level: WARN +processing: + enabled: true + kafka_config: + - {name: "bootstrap.servers", value: "kafka:9092"} + - {name: "message.max.bytes", value: 50000000} #50MB or bust + redis: redis://redis:6379 diff --git a/scripts/bump-version.sh b/scripts/bump-version.sh new file mode 100644 index 0000000..081af99 --- /dev/null +++ b/scripts/bump-version.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -eu + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +cd $SCRIPT_DIR/.. + +OLD_VERSION="$1" +NEW_VERSION="$2" + +SYMBOLICATOR_VERSION=$(curl -sSL 'https://api.github.com/repos/getsentry/symbolicator/git/refs/heads/master' | grep -Po '(?<=\"sha\": \")([a-f0-9]{5,40})(?=\",?)') + +sed -i -e "s/^SYMBOLICATOR_VERSION=.*\$/SYMBOLICATOR_VERSION=$SYMBOLICATOR_VERSION/" .env +sed -i -e "s/^SENTRY_VERSION=.*\$/SENTRY_VERSION=$NEW_VERSION/" .env +sed -i -e "s/^\# Sentry .* On-Premise/# Sentry $NEW_VERSION On-Premise/" README.md + +echo "New version: $NEW_VERSION" +echo "New Symbolicator version: $SYMBOLICATOR_VERSION" diff --git a/sentry/.dockerignore b/sentry/.dockerignore new file mode 100644 index 0000000..693a7e0 --- /dev/null +++ b/sentry/.dockerignore @@ -0,0 +1,5 @@ +# Ignore everything +* + +# Only allow requirements.txt +!/requirements.txt diff --git a/sentry/Dockerfile b/sentry/Dockerfile index 032f340..406830e 100644 --- a/sentry/Dockerfile +++ b/sentry/Dockerfile @@ -1,18 +1,8 @@ +ARG SENTRY_VERSION=latest ARG SENTRY_IMAGE -FROM ${SENTRY_IMAGE:-getsentry/sentry:latest} +FROM ${SENTRY_IMAGE:-getsentry/sentry:$SENTRY_VERSION} -WORKDIR /usr/src/sentry - -# Add WORKDIR to PYTHONPATH so local python files don't need to be installed -ENV PYTHONPATH /usr/src/sentry COPY . /usr/src/sentry # Hook for installing additional plugins -RUN if [ -s requirements.txt ]; then pip install -r requirements.txt; fi - -# Hook for installing a local app as an addon -RUN if [ -s setup.py ]; then pip install -e .; fi - -# Hook for staging in custom configs -RUN if [ -s sentry.conf.py ]; then cp sentry.conf.py $SENTRY_CONF/; fi \ - && if [ -s config.yml ]; then cp config.yml $SENTRY_CONF/; fi +RUN if [ -s /usr/src/sentry/requirements.txt ]; then pip install -r /usr/src/sentry/requirements.txt; fi diff --git a/sentry/config.example.yml b/sentry/config.example.yml index ad237d9..b75e911 100644 --- a/sentry/config.example.yml +++ b/sentry/config.example.yml @@ -1,91 +1,101 @@ # While a lot of configuration in Sentry can be changed via the UI, for all # new-style config (as of 8.0) you can also declare values here in this file # to enforce defaults or to ensure they cannot be changed via the UI. For more # information see the Sentry documentation. ############### # Mail Server # ############### # mail.backend: 'smtp' # Use dummy if you want to disable email entirely mail.host: 'smtp' # mail.port: 25 # mail.username: '' # mail.password: '' # mail.use-tls: false # The email address to send on behalf of # mail.from: 'root@localhost' # If you'd like to configure email replies, enable this. # mail.enable-replies: true # When email-replies are enabled, this value is used in the Reply-To header # mail.reply-hostname: '' # If you're using mailgun for inbound mail, set your API key and configure a # route to forward to /api/hooks/mailgun/inbound/ # Also don't forget to set `mail.enable-replies: true` above. # mail.mailgun-api-key: '' ################### # System Settings # ################### -# If this file ever becomes compromised, it's important to regenerate your a new key +# If this file ever becomes compromised, it's important to generate a new key. # Changing this value will result in all current sessions being invalidated. # A new key can be generated with `$ sentry config generate-secret-key` system.secret-key: '!!changeme!!' # The ``redis.clusters`` setting is used, unsurprisingly, to configure Redis # clusters. These clusters can be then referred to by name when configuring # backends such as the cache, digests, or TSDB backend. # redis.clusters: # default: # hosts: # 0: # host: 127.0.0.1 # port: 6379 ################ # File storage # ################ # Uploaded media uses these `filestore` settings. The available # backends are either `filesystem` or `s3`. filestore.backend: 'filesystem' filestore.options: location: '/data/files' dsym.cache-path: '/data/dsym-cache' releasefile.cache-path: '/data/releasefile-cache' # filestore.backend: 's3' # filestore.options: # access_key: 'AKIXXXXXX' # secret_key: 'XXXXXXX' # bucket_name: 's3-bucket-name' system.internal-url-prefix: 'http://web:9000' symbolicator.enabled: true symbolicator.options: url: "http://symbolicator:3021" transaction-events.force-disable-internal-project: true ###################### # GitHub Integration # ###################### # github-app.id: GITHUB_APP_ID # github-app.name: 'GITHUB_APP_NAME' # github-app.webhook-secret: 'GITHUB_WEBHOOK_SECRET' # Use only if configured in GitHub # github-app.client-id: 'GITHUB_CLIENT_ID' # github-app.client-secret: 'GITHUB_CLIENT_SECRET' # github-app.private-key: | # -----BEGIN RSA PRIVATE KEY----- # privatekeyprivatekeyprivatekeyprivatekey # privatekeyprivatekeyprivatekeyprivatekey # privatekeyprivatekeyprivatekeyprivatekey # privatekeyprivatekeyprivatekeyprivatekey # privatekeyprivatekeyprivatekeyprivatekey # -----END RSA PRIVATE KEY----- + +##################### +# Slack Integration # +##################### + +# Refer to https://forum.sentry.io/t/how-to-configure-slack-in-your-on-prem-sentry/3463 for setup instructions. + +# slack.client-id: <'client id'> +# slack.client-secret: +# slack.verification-token: \ No newline at end of file diff --git a/sentry/sentry.conf.example.py b/sentry/sentry.conf.example.py index a9fe034..05862cb 100644 --- a/sentry/sentry.conf.example.py +++ b/sentry/sentry.conf.example.py @@ -1,222 +1,237 @@ # This file is just Python, with a touch of Django which means # you can inherit and tweak settings to your hearts content. from sentry.conf.server import * # NOQA DATABASES = { "default": { "ENGINE": "sentry.db.postgres", "NAME": "postgres", "USER": "postgres", "PASSWORD": "", "HOST": "postgres", "PORT": "", } } # You should not change this setting after your database has been created # unless you have altered all schemas first SENTRY_USE_BIG_INTS = True # If you're expecting any kind of real traffic on Sentry, we highly recommend # configuring the CACHES and Redis settings ########### # General # ########### # Instruct Sentry that this install intends to be run by a single organization # and thus various UI optimizations should be enabled. SENTRY_SINGLE_ORGANIZATION = True -SENTRY_OPTIONS["system.event-retention-days"] = int(env('SENTRY_EVENT_RETENTION_DAYS', '90')) +SENTRY_OPTIONS["system.event-retention-days"] = int( + env('SENTRY_EVENT_RETENTION_DAYS', '90') +) ######### # Redis # ######### # Generic Redis configuration used as defaults for various things including: # Buffers, Quotas, TSDB SENTRY_OPTIONS["redis.clusters"] = { "default": { "hosts": {0: {"host": "redis", "password": "", "port": "6379", "db": "0"}} } } ######### # Queue # ######### # See https://docs.getsentry.com/on-premise/server/queue/ for more # information on configuring your queue broker and workers. Sentry relies # on a Python framework called Celery to manage queues. rabbitmq_host = None if rabbitmq_host: BROKER_URL = "amqp://{username}:{password}@{host}/{vhost}".format( username="guest", password="guest", host=rabbitmq_host, vhost="/" ) else: BROKER_URL = "redis://:{password}@{host}:{port}/{db}".format( **SENTRY_OPTIONS["redis.clusters"]["default"]["hosts"][0] ) ######### # Cache # ######### # Sentry currently utilizes two separate mechanisms. While CACHES is not a # requirement, it will optimize several high throughput patterns. CACHES = { "default": { "BACKEND": "django.core.cache.backends.memcached.MemcachedCache", "LOCATION": ["memcached:11211"], "TIMEOUT": 3600, } } # A primary cache is required for things such as processing events SENTRY_CACHE = "sentry.cache.redis.RedisCache" DEFAULT_KAFKA_OPTIONS = { "bootstrap.servers": "kafka:9092", "message.max.bytes": 50000000, "socket.timeout.ms": 1000, } SENTRY_EVENTSTREAM = "sentry.eventstream.kafka.KafkaEventStream" SENTRY_EVENTSTREAM_OPTIONS = {"producer_configuration": DEFAULT_KAFKA_OPTIONS} KAFKA_CLUSTERS["default"] = DEFAULT_KAFKA_OPTIONS ############### # Rate Limits # ############### # Rate limits apply to notification handlers and are enforced per-project # automatically. SENTRY_RATELIMITER = "sentry.ratelimits.redis.RedisRateLimiter" ################## # Update Buffers # ################## # Buffers (combined with queueing) act as an intermediate layer between the # database and the storage API. They will greatly improve efficiency on large # numbers of the same events being sent to the API in a short amount of time. # (read: if you send any kind of real data to Sentry, you should enable buffers) SENTRY_BUFFER = "sentry.buffer.redis.RedisBuffer" ########## # Quotas # ########## # Quotas allow you to rate limit individual projects or the Sentry install as # a whole. SENTRY_QUOTAS = "sentry.quotas.redis.RedisQuota" ######## # TSDB # ######## # The TSDB is used for building charts as well as making things like per-rate # alerts possible. SENTRY_TSDB = "sentry.tsdb.redissnuba.RedisSnubaTSDB" ######### # SNUBA # ######### SENTRY_SEARCH = "sentry.search.snuba.EventsDatasetSnubaSearchBackend" SENTRY_SEARCH_OPTIONS = {} SENTRY_TAGSTORE_OPTIONS = {} ########### # Digests # ########### # The digest backend powers notification summaries. SENTRY_DIGESTS = "sentry.digests.backends.redis.RedisBackend" ############## # Web Server # ############## SENTRY_WEB_HOST = "0.0.0.0" SENTRY_WEB_PORT = 9000 SENTRY_WEB_OPTIONS = { - "http": "%s:%s" % (SENTRY_WEB_HOST, SENTRY_WEB_PORT), - "protocol": "uwsgi", - # This is needed to prevent https://git.io/fj7Lw - "uwsgi-socket": None, + # These ase for proper HTTP/1.1 support from uWSGI + # Without these it doesn't do keep-alives causing + # issues with Relay's direct requests. "http-keepalive": True, "http-chunked-input": True, + # the number of web workers + 'workers': 3, + # Turn off memory reporting "memory-report": False, - # 'workers': 3, # the number of web workers + # Some stuff so uwsgi will cycle workers sensibly + 'max-requests': 100000, + 'max-requests-delta': 500, + 'max-worker-lifetime': 86400, + # Duplicate options from sentry default just so we don't get + # bit by sentry changing a default value that we depend on. + 'thunder-lock': True, + 'log-x-forwarded-for': False, + 'buffer-size': 32768, + 'limit-post': 209715200, + 'disable-logging': True, + 'reload-on-rss': 600, + 'ignore-sigpipe': True, + 'ignore-write-errors': True, + 'disable-write-exception': True, } ########### # SSL/TLS # ########### # If you're using a reverse SSL proxy, you should enable the X-Forwarded-Proto # header and enable the settings below # SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') # SESSION_COOKIE_SECURE = True # CSRF_COOKIE_SECURE = True # SOCIAL_AUTH_REDIRECT_IS_HTTPS = True # End of SSL/TLS settings ############ # Features # ############ SENTRY_FEATURES["projects:sample-events"] = False SENTRY_FEATURES.update( { feature: True for feature in ( "organizations:discover", "organizations:events", - "organizations:discover-basic", - "organizations:discover-query", - "organizations:events-v2", "organizations:global-views", "organizations:integrations-issue-basic", "organizations:integrations-issue-sync", "organizations:invite-members", "organizations:sso-basic", "organizations:sso-rippling", "organizations:sso-saml2", "projects:custom-inbound-filters", "projects:data-forwarding", "projects:discard-groups", "projects:plugins", "projects:rate-limits", "projects:servicehooks", ) } ) ###################### # GitHub Integration # ###################### GITHUB_EXTENDED_PERMISSIONS = ['repo'] ######################### # Bitbucket Integration # ######################## # BITBUCKET_CONSUMER_KEY = 'YOUR_BITBUCKET_CONSUMER_KEY' # BITBUCKET_CONSUMER_SECRET = 'YOUR_BITBUCKET_CONSUMER_SECRET' diff --git a/zookeeper/snapshot.0 b/zookeeper/snapshot.0 new file mode 100644 index 0000000..3e6deee Binary files /dev/null and b/zookeeper/snapshot.0 differ