From c347c9930f736cae19b1fcad67a22eefd1537b57 Mon Sep 17 00:00:00 2001 From: Ashley Felton Date: Tue, 5 Dec 2023 07:51:03 +0800 Subject: [PATCH 1/8] Move sfm/fields.py into forms.py --- ibms_project/ibms/forms.py | 1 - ibms_project/sfm/fields.py | 14 -------------- ibms_project/sfm/forms.py | 18 +++++++++++++++--- 3 files changed, 15 insertions(+), 18 deletions(-) delete mode 100644 ibms_project/sfm/fields.py diff --git a/ibms_project/ibms/forms.py b/ibms_project/ibms/forms.py index 24100fb..e561dee 100644 --- a/ibms_project/ibms/forms.py +++ b/ibms_project/ibms/forms.py @@ -1,5 +1,4 @@ from django import forms -#from django.db.utils import ProgrammingError from crispy_forms.helper import FormHelper from crispy_forms.layout import Submit, Layout, HTML, Div from ibms.models import ( diff --git a/ibms_project/sfm/fields.py b/ibms_project/sfm/fields.py deleted file mode 100644 index 2944065..0000000 --- a/ibms_project/sfm/fields.py +++ /dev/null @@ -1,14 +0,0 @@ -#fields.py -from django import forms - -class QtrModelChoiceField(forms.ModelChoiceField): - def label_from_instance(self, obj): - return obj.description - -class SFMMetricModelChoiceField(forms.ModelChoiceField): - def label_from_instance(self, obj): - return obj.metricID - -class SFMCostCentreModelChoiceField(forms.ModelChoiceField): - def label_from_instance(self, obj): - return str(obj) diff --git a/ibms_project/sfm/forms.py b/ibms_project/sfm/forms.py index f4468e3..d5ef793 100644 --- a/ibms_project/sfm/forms.py +++ b/ibms_project/sfm/forms.py @@ -3,9 +3,21 @@ from ibms.forms import HelperForm from sfm.models import Quarter, CostCentre, SFMMetric, FinancialYear, MeasurementValue, REGION_CHOICES -from sfm.fields import ( - QtrModelChoiceField, SFMMetricModelChoiceField, SFMCostCentreModelChoiceField, -) + + +class QtrModelChoiceField(forms.ModelChoiceField): + def label_from_instance(self, obj): + return obj.description + + +class SFMMetricModelChoiceField(forms.ModelChoiceField): + def label_from_instance(self, obj): + return obj.metricID + + +class SFMCostCentreModelChoiceField(forms.ModelChoiceField): + def label_from_instance(self, obj): + return str(obj) class OutputEntryForm(HelperForm): From 5228727197857c759549ca8d524829157f087a38 Mon Sep 17 00:00:00 2001 From: Ashley Felton Date: Tue, 5 Dec 2023 08:06:51 +0800 Subject: [PATCH 2/8] Update dj-database-url. --- poetry.lock | 11 ++++++----- pyproject.toml | 10 +++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/poetry.lock b/poetry.lock index 68f3b91..d803415 100644 --- a/poetry.lock +++ b/poetry.lock @@ -315,17 +315,18 @@ files = [ [[package]] name = "dj-database-url" -version = "1.0.0" +version = "2.1.0" description = "Use Database URLs in your Django Application." optional = false python-versions = "*" files = [ - {file = "dj-database-url-1.0.0.tar.gz", hash = "sha256:ccf3e8718f75ddd147a1e212fca88eecdaa721759ee48e38b485481c77bca3dc"}, - {file = "dj_database_url-1.0.0-py3-none-any.whl", hash = "sha256:cd354a3b7a9136d78d64c17b2aec369e2ae5616fbca6bfbe435ef15bb372ce39"}, + {file = "dj-database-url-2.1.0.tar.gz", hash = "sha256:f2042cefe1086e539c9da39fad5ad7f61173bf79665e69bf7e4de55fa88b135f"}, + {file = "dj_database_url-2.1.0-py3-none-any.whl", hash = "sha256:04bc34b248d4c21aaa13e4ab419ae6575ef5f10f3df735ce7da97722caa356e0"}, ] [package.dependencies] -Django = ">3.2" +Django = ">=3.2" +typing-extensions = ">=3.10.0.0" [[package]] name = "django" @@ -1102,4 +1103,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = ">=3.10,<3.11" -content-hash = "9c25ce793e7877be7e6745b346d04a40f147634f14cb9c14d7c60cb003de9693" +content-hash = "3ebe2ba5527c07925dc981690c245f1fcbfc126f7285466ee4416d00a06d638c" diff --git a/pyproject.toml b/pyproject.toml index c8b662a..12c86b4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "ibms" -version = "2.8.2" +version = "2.8.3" description = "Integrated Business Management System corporate application" authors = ["Ashley Felton "] license = "Apache-2.0" @@ -12,13 +12,13 @@ psycopg2 = "2.9.9" dbca-utils = "1.1.6" django-extensions = "3.2.3" python-dotenv = "1.0.0" -dj-database-url = "1.0.0" +dj-database-url = "2.1.0" gunicorn = "21.2.0" django-crispy-forms = "2.0" crispy-bootstrap5 = "0.7" -xlrd = "2.0.1" -xlutils = "2.0.0" -xlwt = "1.3.0" +xlrd = "2.0.1" # TODO: deprecate +xlutils = "2.0.0" # TODO: deprecate +xlwt = "1.3.0" # TODO: deprecate openpyxl = "3.1.2" webtemplate-dbca = "1.6.0" whitenoise = {version = "6.6.0", extras = ["brotli"]} From 1a74cb368439f5b473d7380b761cd9236af7345d Mon Sep 17 00:00:00 2001 From: Ashley Felton Date: Mon, 11 Dec 2023 07:47:19 +0800 Subject: [PATCH 3/8] Set terminationGracePeriodSeconds value. --- kustomize/base/deployment.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/kustomize/base/deployment.yaml b/kustomize/base/deployment.yaml index e454646..5f8f515 100644 --- a/kustomize/base/deployment.yaml +++ b/kustomize/base/deployment.yaml @@ -61,3 +61,4 @@ spec: - ALL readOnlyRootFilesystem: false restartPolicy: Always + terminationGracePeriodSeconds: 180 From db28234743723b7fc3b3d5b12a2ab1284c972aac Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Dec 2023 06:14:31 +0000 Subject: [PATCH 4/8] Bump actions/setup-python from 4 to 5 Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4 to 5. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v4...v5) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index cf930bd..c780822 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -30,7 +30,7 @@ jobs: - name: Check out repository uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 id: setup-python with: python-version: '3.9' From e656346b5bbcfb72a8ba79b8dd9fb23107f2e04c Mon Sep 17 00:00:00 2001 From: Ashley Felton Date: Mon, 11 Dec 2023 15:13:00 +0800 Subject: [PATCH 5/8] Added sentry-sdk to project. --- Dockerfile | 2 +- ibms_project/settings.py | 16 ++++++++++++++ poetry.lock | 48 +++++++++++++++++++++++++++++++++++++++- pyproject.toml | 1 + 4 files changed, 65 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 36677b7..77e7091 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ RUN apt-get update -y \ # Install Python libs using Poetry. FROM builder_base_ibms as python_libs_ibms WORKDIR /app -ARG POETRY_VERSION=1.6.1 +ARG POETRY_VERSION=1.7.1 RUN pip install poetry=="${POETRY_VERSION}" COPY poetry.lock pyproject.toml ./ RUN poetry config virtualenvs.create false \ diff --git a/ibms_project/settings.py b/ibms_project/settings.py index e5de0b8..08a9ba2 100644 --- a/ibms_project/settings.py +++ b/ibms_project/settings.py @@ -176,3 +176,19 @@ # django-crispy-forms config CRISPY_ALLOWED_TEMPLATE_PACKS = 'bootstrap5' CRISPY_TEMPLATE_PACK = 'bootstrap5' + +# Sentry settings +SENTRY_DSN = env('SENTRY_DSN', None) +SENTRY_SAMPLE_RATE = env('SENTRY_SAMPLE_RATE', 1.0) # Error sampling rate +SENTRY_TRANSACTION_SAMPLE_RATE = env('SENTRY_TRANSACTION_SAMPLE_RATE', 0.0) # Transaction sampling +SENTRY_ENVIRONMENT = env('SENTRY_ENVIRONMENT', None) +if SENTRY_DSN and SENTRY_ENVIRONMENT: + import sentry_sdk + + sentry_sdk.init( + dsn=SENTRY_DSN, + sample_rate=SENTRY_SAMPLE_RATE, + traces_sample_rate=SENTRY_TRANSACTION_SAMPLE_RATE, + environment=SENTRY_ENVIRONMENT, + release=APPLICATION_VERSION_NO, + ) diff --git a/poetry.lock b/poetry.lock index d803415..122072b 100644 --- a/poetry.lock +++ b/poetry.lock @@ -878,6 +878,52 @@ urllib3 = ">=1.21.1,<3" socks = ["PySocks (>=1.5.6,!=1.5.7)"] use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] +[[package]] +name = "sentry-sdk" +version = "1.38.0" +description = "Python client for Sentry (https://sentry.io)" +optional = false +python-versions = "*" +files = [ + {file = "sentry-sdk-1.38.0.tar.gz", hash = "sha256:8feab81de6bbf64f53279b085bd3820e3e737403b0a0d9317f73a2c3374ae359"}, + {file = "sentry_sdk-1.38.0-py2.py3-none-any.whl", hash = "sha256:0017fa73b8ae2d4e57fd2522ee3df30453715b29d2692142793ec5d5f90b94a6"}, +] + +[package.dependencies] +certifi = "*" +django = {version = ">=1.8", optional = true, markers = "extra == \"django\""} +urllib3 = {version = ">=1.26.11", markers = "python_version >= \"3.6\""} + +[package.extras] +aiohttp = ["aiohttp (>=3.5)"] +arq = ["arq (>=0.23)"] +asyncpg = ["asyncpg (>=0.23)"] +beam = ["apache-beam (>=2.12)"] +bottle = ["bottle (>=0.12.13)"] +celery = ["celery (>=3)"] +chalice = ["chalice (>=1.16.0)"] +clickhouse-driver = ["clickhouse-driver (>=0.2.0)"] +django = ["django (>=1.8)"] +falcon = ["falcon (>=1.4)"] +fastapi = ["fastapi (>=0.79.0)"] +flask = ["blinker (>=1.1)", "flask (>=0.11)", "markupsafe"] +grpcio = ["grpcio (>=1.21.1)"] +httpx = ["httpx (>=0.16.0)"] +huey = ["huey (>=2)"] +loguru = ["loguru (>=0.5)"] +opentelemetry = ["opentelemetry-distro (>=0.35b0)"] +opentelemetry-experimental = ["opentelemetry-distro (>=0.40b0,<1.0)", "opentelemetry-instrumentation-aiohttp-client (>=0.40b0,<1.0)", "opentelemetry-instrumentation-django (>=0.40b0,<1.0)", "opentelemetry-instrumentation-fastapi (>=0.40b0,<1.0)", "opentelemetry-instrumentation-flask (>=0.40b0,<1.0)", "opentelemetry-instrumentation-requests (>=0.40b0,<1.0)", "opentelemetry-instrumentation-sqlite3 (>=0.40b0,<1.0)", "opentelemetry-instrumentation-urllib (>=0.40b0,<1.0)"] +pure-eval = ["asttokens", "executing", "pure-eval"] +pymongo = ["pymongo (>=3.1)"] +pyspark = ["pyspark (>=2.4.4)"] +quart = ["blinker (>=1.1)", "quart (>=0.16.1)"] +rq = ["rq (>=0.6)"] +sanic = ["sanic (>=0.8)"] +sqlalchemy = ["sqlalchemy (>=1.2)"] +starlette = ["starlette (>=0.19.1)"] +starlite = ["starlite (>=1.48)"] +tornado = ["tornado (>=5)"] + [[package]] name = "setuptools" version = "69.0.2" @@ -1103,4 +1149,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = ">=3.10,<3.11" -content-hash = "3ebe2ba5527c07925dc981690c245f1fcbfc126f7285466ee4416d00a06d638c" +content-hash = "aae5fa76c2791da7f7e1f68f2d5eed6d83d240983155641a69226807576bc1ac" diff --git a/pyproject.toml b/pyproject.toml index 12c86b4..92f6552 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,6 +24,7 @@ webtemplate-dbca = "1.6.0" whitenoise = {version = "6.6.0", extras = ["brotli"]} mixer = "7.2.2" tomli = "2.0.1" +sentry-sdk = {version = "1.38.0", extras = ["django"]} [tool.poetry.group.dev.dependencies] ipython = "^8.10.0" From 6e715b7a67aacc2e5f75fe901c6edca777607e10 Mon Sep 17 00:00:00 2001 From: Ashley Felton Date: Mon, 11 Dec 2023 15:19:26 +0800 Subject: [PATCH 6/8] Run poetry update. --- poetry.lock | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/poetry.lock b/poetry.lock index 122072b..5f61758 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.5.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. [[package]] name = "asgiref" @@ -467,13 +467,13 @@ tornado = ["tornado (>=0.2)"] [[package]] name = "identify" -version = "2.5.32" +version = "2.5.33" description = "File identification library for Python" optional = false python-versions = ">=3.8" files = [ - {file = "identify-2.5.32-py2.py3-none-any.whl", hash = "sha256:0b7656ef6cba81664b783352c73f8c24b39cf82f926f78f4550eda928e5e0545"}, - {file = "identify-2.5.32.tar.gz", hash = "sha256:5d9979348ec1a21c768ae07e0a652924538e8bce67313a73cb0f681cf08ba407"}, + {file = "identify-2.5.33-py2.py3-none-any.whl", hash = "sha256:d40ce5fcd762817627670da8a7d8d8e65f24342d14539c59488dc603bf662e34"}, + {file = "identify-2.5.33.tar.gz", hash = "sha256:161558f9fe4559e1557e1bff323e8631f6a0e4837f7497767c1782832f16b62d"}, ] [package.extras] @@ -662,13 +662,13 @@ ptyprocess = ">=0.5" [[package]] name = "platformdirs" -version = "4.0.0" +version = "4.1.0" description = "A small Python package for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." optional = false -python-versions = ">=3.7" +python-versions = ">=3.8" files = [ - {file = "platformdirs-4.0.0-py3-none-any.whl", hash = "sha256:118c954d7e949b35437270383a3f2531e99dd93cf7ce4dc8340d3356d30f173b"}, - {file = "platformdirs-4.0.0.tar.gz", hash = "sha256:cb633b2bcf10c51af60beb0ab06d2f1d69064b43abf4c185ca6b28865f3f9731"}, + {file = "platformdirs-4.1.0-py3-none-any.whl", hash = "sha256:11c8f37bcca40db96d8144522d925583bdb7a31f7b0e37e3ed4318400a8e2380"}, + {file = "platformdirs-4.1.0.tar.gz", hash = "sha256:906d548203468492d432bcb294d4bc2fff751bf84971fbb2c10918cc206ee420"}, ] [package.extras] @@ -677,13 +677,13 @@ test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.4)", "pytest-co [[package]] name = "pre-commit" -version = "3.5.0" +version = "3.6.0" description = "A framework for managing and maintaining multi-language pre-commit hooks." optional = false -python-versions = ">=3.8" +python-versions = ">=3.9" files = [ - {file = "pre_commit-3.5.0-py2.py3-none-any.whl", hash = "sha256:841dc9aef25daba9a0238cd27984041fa0467b4199fc4852e27950664919f660"}, - {file = "pre_commit-3.5.0.tar.gz", hash = "sha256:5804465c675b659b0862f07907f96295d490822a450c4c40e747d0b1c6ebcb32"}, + {file = "pre_commit-3.6.0-py2.py3-none-any.whl", hash = "sha256:c255039ef399049a5544b6ce13d135caba8f2c28c3b4033277a788f434308376"}, + {file = "pre_commit-3.6.0.tar.gz", hash = "sha256:d30bad9abf165f7785c15a21a1f46da7d0677cb00ee7ff4c579fd38922efe15d"}, ] [package.dependencies] @@ -1014,13 +1014,13 @@ test = ["argcomplete (>=3.0.3)", "mypy (>=1.7.0)", "pre-commit", "pytest (>=7.0, [[package]] name = "typing-extensions" -version = "4.8.0" +version = "4.9.0" description = "Backported and Experimental Type Hints for Python 3.8+" optional = false python-versions = ">=3.8" files = [ - {file = "typing_extensions-4.8.0-py3-none-any.whl", hash = "sha256:8f92fc8806f9a6b641eaa5318da32b44d401efaac0f6678c9bc448ba3605faa0"}, - {file = "typing_extensions-4.8.0.tar.gz", hash = "sha256:df8e4339e9cb77357558cbdbceca33c303714cf861d1eef15e1070055ae8b7ef"}, + {file = "typing_extensions-4.9.0-py3-none-any.whl", hash = "sha256:af72aea155e91adfc61c3ae9e0e342dbc0cba726d6cba4b6c72c1f34e47291cd"}, + {file = "typing_extensions-4.9.0.tar.gz", hash = "sha256:23478f88c37f27d76ac8aee6c905017a143b0b1b886c3c9f66bc2fd94f9f5783"}, ] [[package]] @@ -1041,13 +1041,13 @@ zstd = ["zstandard (>=0.18.0)"] [[package]] name = "virtualenv" -version = "20.24.7" +version = "20.25.0" description = "Virtual Python Environment builder" optional = false python-versions = ">=3.7" files = [ - {file = "virtualenv-20.24.7-py3-none-any.whl", hash = "sha256:a18b3fd0314ca59a2e9f4b556819ed07183b3e9a3702ecfe213f593d44f7b3fd"}, - {file = "virtualenv-20.24.7.tar.gz", hash = "sha256:69050ffb42419c91f6c1284a7b24e0475d793447e35929b488bf6a0aade39353"}, + {file = "virtualenv-20.25.0-py3-none-any.whl", hash = "sha256:4238949c5ffe6876362d9c0180fc6c3a824a7b12b80604eeb8085f2ed7460de3"}, + {file = "virtualenv-20.25.0.tar.gz", hash = "sha256:bf51c0d9c7dd63ea8e44086fa1e4fb1093a31e963b86959257378aef020e1f1b"}, ] [package.dependencies] From 390551e9af0bd4043de782ea5bd6ea1f7acc5e0a Mon Sep 17 00:00:00 2001 From: Ashley Felton Date: Tue, 12 Dec 2023 08:37:35 +0800 Subject: [PATCH 7/8] Update tagged image in prod overlay. --- kustomize/overlays/prod/kustomization.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kustomize/overlays/prod/kustomization.yaml b/kustomize/overlays/prod/kustomization.yaml index 83e76ff..0da408b 100644 --- a/kustomize/overlays/prod/kustomization.yaml +++ b/kustomize/overlays/prod/kustomization.yaml @@ -16,7 +16,7 @@ labels: variant: prod images: - name: ghcr.io/dbca-wa/ibms - newTag: 2.8.2 + newTag: 2.8.3 patches: - path: deployment_patch.yaml - path: service_patch.yaml From 4388e98ba073d41b0e9547d18c978c0e4cd3afa5 Mon Sep 17 00:00:00 2001 From: Ashley Felton Date: Tue, 12 Dec 2023 10:25:52 +0800 Subject: [PATCH 8/8] Added Sentry environment vars to deployment overlays. --- kustomize/overlays/prod/deployment_patch.yaml | 17 +++++++++++++++++ kustomize/overlays/uat/deployment_patch.yaml | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/kustomize/overlays/prod/deployment_patch.yaml b/kustomize/overlays/prod/deployment_patch.yaml index 386ca53..07cf5e1 100644 --- a/kustomize/overlays/prod/deployment_patch.yaml +++ b/kustomize/overlays/prod/deployment_patch.yaml @@ -29,3 +29,20 @@ spec: secretKeyRef: name: ibms-env-prod key: SECRET_KEY + - name: SENTRY_DSN + valueFrom: + secretKeyRef: + name: ibms-env-prod + key: SENTRY_DSN + - name: SENTRY_SAMPLE_RATE + valueFrom: + secretKeyRef: + name: ibms-env-prod + key: SENTRY_SAMPLE_RATE + - name: SENTRY_TRANSACTION_SAMPLE_RATE + valueFrom: + secretKeyRef: + name: ibms-env-prod + key: SENTRY_TRANSACTION_SAMPLE_RATE + - name: SENTRY_ENVIRONMENT + value: "prod" diff --git a/kustomize/overlays/uat/deployment_patch.yaml b/kustomize/overlays/uat/deployment_patch.yaml index fe0ebd8..c5b315c 100644 --- a/kustomize/overlays/uat/deployment_patch.yaml +++ b/kustomize/overlays/uat/deployment_patch.yaml @@ -28,3 +28,20 @@ spec: secretKeyRef: name: ibms-env-uat key: SECRET_KEY + - name: SENTRY_DSN + valueFrom: + secretKeyRef: + name: ibms-env-uat + key: SENTRY_DSN + - name: SENTRY_SAMPLE_RATE + valueFrom: + secretKeyRef: + name: ibms-env-uat + key: SENTRY_SAMPLE_RATE + - name: SENTRY_TRANSACTION_SAMPLE_RATE + valueFrom: + secretKeyRef: + name: ibms-env-uat + key: SENTRY_TRANSACTION_SAMPLE_RATE + - name: SENTRY_ENVIRONMENT + value: "uat"