Skip to content

Commit

Permalink
resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
gabelton committed Jun 5, 2024
2 parents 770a446 + 583f453 commit b9f9798
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 70 deletions.
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
web: python migrate.py && python manage.py load_defaults && opentelemetry-instrument gunicorn -b 0.0.0.0:$PORT demodjango.wsgi:application
web: python migrate.py && python manage.py load_defaults && gunicorn -b 0.0.0.0:$PORT demodjango.wsgi:application
celery-worker: celery --app demodjango.celery worker --task-events --loglevel INFO
celery-beat: celery --app demodjango.celery beat --loglevel INFO
check: python manage.py check
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,16 @@ After installing the dependencies, run `playwright install` to install the brows
Run the test suite with `./smoke_tests.sh` to test against your local running environment.

You can target deployed environments with `./smoke_tests.sh <environment>`.


## Running the application with docker-compose

docker-compose will run several services as part of the demodjango application.
These are defined in the docker-compose.yml file.

```
docker-compose build
docker-compose up
```


18 changes: 1 addition & 17 deletions app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
REDIS = 'redis'
S3 = 's3'
SERVER_TIME = 'server_time'
SQLITE = 'sqlite3'
HTTP_CONNECTION = 'http'

ALL_CHECKS = {
Expand All @@ -41,7 +40,6 @@
REDIS: 'Redis',
S3: 'S3 Bucket',
SERVER_TIME: 'Server Time',
SQLITE: 'SQLite3',
HTTP_CONNECTION: 'HTTP Checks',
}

Expand All @@ -58,7 +56,7 @@ def index(request):
"headers": dict(request.headers),
})

status_check_results = [server_time_check(), git_information(), sqlite_check()]
status_check_results = [server_time_check(), git_information()]

optional_checks: Dict[str, Callable] = {
POSTGRES_RDS: postgres_rds_check,
Expand Down Expand Up @@ -117,20 +115,6 @@ def postgres_aurora_check():
return render_connection_info(addon_type, False, str(e))


def sqlite_check():
addon_type = ALL_CHECKS[SQLITE]
try:
db_name = "default"
if RDS_POSTGRES_CREDENTIALS:
db_name = "sqlite"

with connections[db_name].cursor() as c:
c.execute('SELECT SQLITE_VERSION()')
return render_connection_info(addon_type, True, c.fetchone()[0])
except Exception as e:
return render_connection_info(addon_type, False, str(e))


def redis_check():
addon_type = ALL_CHECKS[REDIS]
try:
Expand Down
2 changes: 1 addition & 1 deletion app/views/report.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<strong>{{ report.summary }}: {% if report.success %}success{% else %}failure{% endif %}</strong>
{{ report.summary }}: {% if report.success %}success{% else %}failure{% endif %}
{% for error in report.errors %}
{{ error }}
{% endfor %}
6 changes: 1 addition & 5 deletions demodjango/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,7 @@
DATABASES = {
"default": dj_database_url.config(
default=database_url_from_env("RDS_POSTGRES_CREDENTIALS")
),
"sqlite": {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': sqlite_db_root / "demodjango.sqlite3",
}
)
}
else:
DATABASES = {
Expand Down
2 changes: 0 additions & 2 deletions demodjango/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
import os

from django.core.wsgi import get_wsgi_application
from opentelemetry.instrumentation.wsgi import OpenTelemetryMiddleware

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'demodjango.settings')

application = get_wsgi_application()
application = OpenTelemetryMiddleware(application)
10 changes: 2 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ services:
S3_BUCKET_NAME: test-bucket
AWS_ACCESS_KEY_ID: access-key-id
AWS_SECRET_ACCESS_KEY: secret-access-key
OTEL_EXPORTER_OTLP_ENDPOINT: 'http://otel:4317'
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: 'http://otel:4317'
GIT_COMMIT: "3x4mp13"
GIT_BRANCH: "example-branch"
GIT_TAG: "3.2.1"
Expand All @@ -41,12 +39,6 @@ services:
- redis
- s3
- opensearch
- otel

otel:
image: public.ecr.aws/aws-observability/aws-otel-collector:v0.17.0
environment:
AWS_REGION: eu-west-2

celery-worker:
build:
Expand Down Expand Up @@ -122,3 +114,5 @@ services:
environment:
'discovery.type': single-node
'plugins.security.disabled': true
OPENSEARCH_INITIAL_ADMIN_PASSWORD: P4ssword-does-not-matter

2 changes: 1 addition & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ python manage.py migrate --database sqlite
python manage.py migrate --database aurora
python manage.py load_defaults

OTEL_PROPAGATORS=xray OTEL_PYTHON_ID_GENERATOR=xray OTEL_SERVICE_NAME=your-service-name OTEL_TRACES_EXPORTER=console,otlp OTEL_METRICS_EXPORTER=console,otlp opentelemetry-instrument gunicorn -b 0.0.0.0:8080 demodjango.wsgi:application
gunicorn -b 0.0.0.0:8080 demodjango.wsgi:application
21 changes: 5 additions & 16 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ django-log-formatter-asim = "^0.0.4"
django-requestlogs = "^0.8"
gunicorn = "^22.0.0"
opensearch-py = "^2.4.2"
opentelemetry-distro = "^0.43b0"
opentelemetry-exporter-otlp = "^1.22.0"
opentelemetry-instrumentation-wsgi = "^0.43b0"
opentelemetry-propagator-aws-xray = "^1.0.1"
opentelemetry-sdk-extension-aws = "^2.0.1"
pip-tools = "^7.3.0"
psycopg2-binary = "^2.9.9"
python-dotenv = "^1.0.0"
Expand All @@ -32,7 +27,7 @@ requests = "^2.31.0"
tenacity = "^8.2.3"
whitenoise = "^6.6.0"
normality = "^2.5.0"
jinja2 = "^3.1.3"
jinja2 = "^3.1.4"
django-celery-beat = "^2.5.0"
sentry-sdk = "^1.42.0"
pytest-env = "^1.1.3"
Expand Down
2 changes: 1 addition & 1 deletion smoke_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ case "${target}" in
host="http://localhost:8080"
;;
*)
host="https://v2.demodjango.${target}.uktrade.digital/"
host="https://internal.${target}.demodjango.uktrade.digital/"
;;
esac

Expand Down
4 changes: 2 additions & 2 deletions tests/app/check/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def test_rendering_a_successful_report():

output = report.render()

assert "<strong>Report Title: success</strong>\n\n" == output
assert "Report Title: success\n\n" == output


def test_rendering_an_unsuccessful_report():
Expand All @@ -17,6 +17,6 @@ def test_rendering_an_unsuccessful_report():

output = report.render()

assert '<strong>Report Title: failure</strong>' in output
assert 'Report Title: failure' in output
assert 'Something went wrong!' in output
assert 'And something else went wrong!' in output
15 changes: 5 additions & 10 deletions tests/smoke/test_landing_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
from app.views import (
ALL_CHECKS,
CELERY,
BEAT,
GIT_INFORMATION,
OPENSEARCH,
POSTGRES_AURORA,
POSTGRES_RDS,
REDIS,
S3,
SERVER_TIME,
SQLITE,
HTTP_CONNECTION,
)

Expand All @@ -32,18 +31,10 @@ def test_page_loads_with_title_and_has_success_ticks(page: Page):
page.get_by_test_id(slugify(ALL_CHECKS[GIT_INFORMATION]))
).to_have_text(re.compile(STATUS_SUCCESS))

expect(
page.get_by_test_id(slugify(ALL_CHECKS[SQLITE]))
).to_have_text(re.compile(STATUS_SUCCESS))

expect(
page.get_by_test_id(slugify(ALL_CHECKS[POSTGRES_RDS]))
).to_have_text(re.compile(STATUS_SUCCESS))

expect(
page.get_by_test_id(slugify(ALL_CHECKS[POSTGRES_AURORA]))
).to_have_text(re.compile(STATUS_SUCCESS))

expect(
page.get_by_test_id(slugify(ALL_CHECKS[REDIS]))
).to_have_text(re.compile(STATUS_SUCCESS))
Expand All @@ -60,6 +51,10 @@ def test_page_loads_with_title_and_has_success_ticks(page: Page):
page.get_by_test_id(slugify(ALL_CHECKS[CELERY]))
).to_have_text(re.compile(STATUS_SUCCESS))

expect(
page.get_by_test_id(slugify(ALL_CHECKS[BEAT]))
).to_have_text(re.compile(STATUS_SUCCESS))

expect(
page.get_by_test_id(slugify(ALL_CHECKS[HTTP_CONNECTION]))
).to_have_text(re.compile(STATUS_SUCCESS))

0 comments on commit b9f9798

Please sign in to comment.