Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add local AppInsights deployment #143

Merged
merged 3 commits into from Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env
Expand Up @@ -11,3 +11,9 @@ AZURITE_ACCOUNT=devstoreaccount1
AZURITE_KEY=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==
AZURITE_HOST=azurite:10000
AZURITE_SECURE=False

POSTGRES_USER=ascoderu
POSTGRES_PASSWORD=secretpassword
POSTGRES_DB=telemetry

APPINSIGHTS_INSTRUMENTATIONKEY=a314c6f7-776c-4e82-a677-8a3ecfb4669f
19 changes: 19 additions & 0 deletions docker-compose.yml
Expand Up @@ -4,6 +4,8 @@ x-shared-app-environment:
&shared-app-environment
QUEUE_BROKER_URL: pyamqp://guest:guest@rabbitmq
LOKOLE_LOG_LEVEL: ${LOKOLE_LOG_LEVEL}
LOKOLE_EMAIL_SERVER_APPINSIGHTS_KEY: ${APPINSIGHTS_INSTRUMENTATIONKEY}
LOKOLE_EMAIL_SERVER_APPINSIGHTS_HOST: http://appinsights

LOKOLE_STORAGE_PROVIDER: AZURE_BLOBS

Expand Down Expand Up @@ -61,6 +63,7 @@ services:
SERVER_WORKERS: ${SERVER_WORKERS}
TESTING_UI: "True"
depends_on:
- appinsights
- azurite

worker:
Expand All @@ -71,12 +74,28 @@ services:
CELERY_QUEUE_NAMES: all
QUEUE_WORKERS: ${QUEUE_WORKERS}
depends_on:
- appinsights
- azurite
- rabbitmq

rabbitmq:
image: rabbitmq:3.7.8-management

appinsights:
image: cwolff/appinsights-on-premises:0.0.9
depends_on:
- postgres
environment:
DATABASE_URL: "postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}"
APPINSIGHTS_INSTRUMENTATIONKEY: "${APPINSIGHTS_INSTRUMENTATIONKEY}"

postgres:
image: postgres:11-alpine
environment:
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}"
POSTGRES_USER: "${POSTGRES_USER}"
POSTGRES_DB: "${POSTGRES_DB}"

azurite:
image: arafato/azurite:2.6.5
environment:
Expand Down
1 change: 1 addition & 0 deletions makefile
Expand Up @@ -41,6 +41,7 @@ integration-tests:
./tests/integration/1-client-uploads-emails.sh && sleep 10s && \
./tests/integration/2-receive-email-for-client.sh && sleep 10s && \
./tests/integration/3-client-downloads-emails.sh && \
./tests/integration/assert.sh && \
rm -rf tests/files/end_to_end/test.out

stop:
Expand Down
1 change: 1 addition & 0 deletions opwen_email_server/config.py
Expand Up @@ -30,6 +30,7 @@
LOG_LEVEL = env('LOKOLE_LOG_LEVEL', 'INFO')

APPINSIGHTS_KEY = env('LOKOLE_EMAIL_SERVER_APPINSIGHTS_KEY')
APPINSIGHTS_HOST = env('LOKOLE_EMAIL_SERVER_APPINSIGHTS_HOST')

MAX_WIDTH_IMAGES = env.integer('MAX_WIDTH_EMAIL_IMAGES', 200)
MAX_HEIGHT_IMAGES = env.integer('MAX_HEIGHT_EMAIL_IMAGES', 200)
Expand Down
6 changes: 5 additions & 1 deletion opwen_email_server/utils/log.py
Expand Up @@ -19,6 +19,7 @@
from applicationinsights.logging import LoggingHandler
from cached_property import cached_property

from opwen_email_server.config import APPINSIGHTS_HOST
from opwen_email_server.config import APPINSIGHTS_KEY
from opwen_email_server.config import LOG_LEVEL
from opwen_email_server.constants.logging import SEPARATOR
Expand All @@ -32,7 +33,10 @@ def _create_telemetry_channel() -> Optional[TelemetryChannel]:
if not APPINSIGHTS_KEY:
return None

sender = AsynchronousSender()
if APPINSIGHTS_HOST:
sender = AsynchronousSender(APPINSIGHTS_HOST)
else:
sender = AsynchronousSender()
queue = AsynchronousQueue(sender)
context = TelemetryContext()
context.instrumentation_key = APPINSIGHTS_KEY
Expand Down
34 changes: 34 additions & 0 deletions tests/integration/assert.sh
@@ -0,0 +1,34 @@
#!/usr/bin/env bash

set -euo pipefail
out_dir="$(dirname "$0")/../files/end_to_end/test.out"
mkdir -p "${out_dir}"

num_emails_actual="$(wc -l "${out_dir}/emails.jsonl" | cut -d' ' -f1)"
num_emails_expected=1

if [[ "${num_emails_actual}" -ne "${num_emails_expected}" ]]; then
echo "Got ${num_emails_actual} emails but expected ${num_emails_expected}" >&2
exit 1
fi

sql_query() {
docker-compose exec postgres psql -Aqt -c "$1" -U ascoderu -d telemetry \
| tr -d -C '0-9'
}

num_exceptions="$(sql_query 'select count(*) from exceptions;')"
num_exceptions_expected=0

if [[ "${num_exceptions}" -ne "${num_exceptions_expected}" ]]; then
echo "Got ${num_exceptions} exceptions but expected ${num_exceptions_expected}" >&2
exit 2
fi

num_error_requests="$(sql_query 'select count(*) from requests where status_code != 200;')"
num_error_requests_expected=0

if [[ "${num_error_requests}" -ne "${num_error_requests_expected}" ]]; then
echo "Got ${num_error_requests} error requests but expected ${num_error_requests_expected}" >&2
exit 3
fi