From d95d09b947dbb4fc3012e635bccc2c1c42707b6e Mon Sep 17 00:00:00 2001 From: James Person Date: Thu, 28 Mar 2024 16:41:07 -0400 Subject: [PATCH 1/3] Bug: "Test Site" Banner on Production Error Pages (#3573) * Add error handlers for other standard error pages * Add error handlers for other standard error pages * Reset file upload timeout to 30s. Oops. --- backend/audit/validators.py | 10 +++++++--- backend/config/error_handlers.py | 23 ++++++++++++++++++++++- backend/config/urls.py | 3 +++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/backend/audit/validators.py b/backend/audit/validators.py index 79dc69184a..317b5d7bad 100644 --- a/backend/audit/validators.py +++ b/backend/audit/validators.py @@ -380,6 +380,8 @@ def validate_file_size(file, max_file_size_mb): def _scan_file(file): + error_message = "We were unable to complete a security inspection of the file, please try again or contact support for assistance." + try: return requests.post( settings.AV_SCAN_URL, @@ -387,10 +389,12 @@ def _scan_file(file): data={"name": file.name}, timeout=30, ) + # Common upload issues get their own messages. These messages display as form errors. + # Allow other errors to be raised and either caught elsewhere or passed to a 400 page. except requests.exceptions.ConnectionError: - raise ValidationError( - "We were unable to complete a security inspection of the file, please try again or contact support for assistance." - ) + raise ValidationError(f"Connection error. {error_message}") + except requests.exceptions.ReadTimeout: + raise ValidationError(f"Read timed out. {error_message}") @newrelic_timing_metric("validate_file_infection") diff --git a/backend/config/error_handlers.py b/backend/config/error_handlers.py index d02e7e06e2..c7ca707e26 100644 --- a/backend/config/error_handlers.py +++ b/backend/config/error_handlers.py @@ -1,8 +1,29 @@ from django.shortcuts import render +def handler404(request, exception, template_name="404.html"): + """ + Custom handler for 404. Ensures the 404 template loads with proper context (environment, login info, OMB values). + """ + return render(request, template_name, {}, status=404) + + +def handler403(request, exception, template_name="403.html"): + """ + Custom handler for 403. Ensures the 403 template loads with proper context (environment, login info, OMB values). + """ + return render(request, template_name, {}, status=403) + + def handler500(request, template_name="500.html"): """ Custom handler for 500s. Ensures the 500 template loads with proper context (environment, login info, OMB values). """ - return render(request, template_name, {}) + return render(request, template_name, {}, status=500) + + +def handler400(request, exception, template_name="400.html"): + """ + Custom handler for 400. Ensures the 400 template loads with proper context (environment, login info, OMB values). + """ + return render(request, template_name, {}, status=400) diff --git a/backend/config/urls.py b/backend/config/urls.py index 9ab9d939cb..3e065f25e0 100644 --- a/backend/config/urls.py +++ b/backend/config/urls.py @@ -18,7 +18,10 @@ renderer_classes=[JSONOpenAPIRenderer], ) +handler404 = "config.error_handlers.handler404" +handler403 = "config.error_handlers.handler403" handler500 = "config.error_handlers.handler500" +handler400 = "config.error_handlers.handler400" urlpatterns = [ path("api/schema.json", schema_view), From aff3338ff27498371b73957e1e8e92497c1adaea Mon Sep 17 00:00:00 2001 From: Tim Ballard <1425377+timoballard@users.noreply.github.com> Date: Thu, 28 Mar 2024 16:16:17 -0500 Subject: [PATCH 2/3] back to 8 (#3579) --- backend/manifests/vars/vars-production.yml | 2 +- terraform/production/production.tf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/manifests/vars/vars-production.yml b/backend/manifests/vars/vars-production.yml index 0c97b4642c..733090b91f 100644 --- a/backend/manifests/vars/vars-production.yml +++ b/backend/manifests/vars/vars-production.yml @@ -4,4 +4,4 @@ cf_env_name: PRODUCTION env_name: prod service_name: production endpoint: app.fac.gov -instances: 16 +instances: 8 diff --git a/terraform/production/production.tf b/terraform/production/production.tf index 1f756affbc..ee233b2826 100644 --- a/terraform/production/production.tf +++ b/terraform/production/production.tf @@ -3,7 +3,7 @@ module "production" { cf_space_name = "production" new_relic_license_key = var.new_relic_license_key pgrst_jwt_secret = var.pgrst_jwt_secret - clamav_instances = 16 + clamav_instances = 8 database_plan = "xlarge-gp-psql-redundant" postgrest_instances = 4 json_params = jsonencode( From b890d7d2d65ca7c18c1426cd877cf544ba290d15 Mon Sep 17 00:00:00 2001 From: Dan Swick <2365503+danswick@users.noreply.github.com> Date: Thu, 28 Mar 2024 15:51:11 -0700 Subject: [PATCH 3/3] Double the app startup timeout to see if that fixes prod deploys with Very Many instances (#3581) * double the app startup timeout to see if that fixes prod deploys with Very Many instances * try setting CLI env var instead * back to 16 so we can test the actual timeout * Update bin/ops/deploy.sh --- backend/manifests/vars/vars-production.yml | 2 +- bin/ops/deploy.sh | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/manifests/vars/vars-production.yml b/backend/manifests/vars/vars-production.yml index 733090b91f..0c97b4642c 100644 --- a/backend/manifests/vars/vars-production.yml +++ b/backend/manifests/vars/vars-production.yml @@ -4,4 +4,4 @@ cf_env_name: PRODUCTION env_name: prod service_name: production endpoint: app.fac.gov -instances: 8 +instances: 16 diff --git a/bin/ops/deploy.sh b/bin/ops/deploy.sh index c4ef507a7b..6c7a5c4463 100755 --- a/bin/ops/deploy.sh +++ b/bin/ops/deploy.sh @@ -18,6 +18,8 @@ before_sha=$(echo "${before_data}"|xargs|cut -d'}' -f1|cut -d':' -f3|xargs) echo "Before SHA: ${before_sha}" echo "cf comand on next line:" echo cf push -f backend/manifests/manifest-fac.yml --vars-file backend/manifests/vars/vars-"${cfspace}".yml --strategy rolling +# https://docs.cloudfoundry.org/devguide/deploy-apps/large-app-deploy.html#considerations +export CF_STARTUP_TIMEOUT=10 cf push -f backend/manifests/manifest-fac.yml --vars-file backend/manifests/vars/vars-"${cfspace}".yml --strategy rolling after_data=$(cf curl "/v3/apps/${appguid}/relationships/current_droplet") echo "After data: ${after_data}"