diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c666839..ba58e8b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,13 +6,8 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.7', '3.8', '3.9', '3.10'] - django-version: ['3.2', '4.0', '4.1'] - exclude: - - python-version: '3.7' - django-version: '4.0' - - python-version: '3.7' - django-version: '4.1' + python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] + django-version: ['3.2', '4.1', '4.2'] steps: - uses: actions/checkout@v2 @@ -22,10 +17,11 @@ jobs: with: python-version: ${{ matrix.python-version }} - - name: Install dependencies + - name: Install dependencies and package run: | python -m pip install --upgrade pip - pip install flake8 codecov + pip install -r requirements.txt + pip install django~=${{ matrix.django-version }} - name: Lint with flake8 run: | @@ -34,12 +30,6 @@ jobs: # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - name: Install Django ${{ matrix.django-version }} - run: pip install django==${{ matrix.django-version }} - - - name: Install package and dependencies - run: pip install -e . - - name: Run checks working-directory: ./tests/test_project/ run: python -Wd manage.py check @@ -58,4 +48,4 @@ jobs: coverage xml - name: Upload coverage to Codecov - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v3 diff --git a/CHANGELOG.md b/CHANGELOG.md index 04be75f..dd71256 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,13 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [1.6.0 - Unreleased] ### Added -- +- Support for Python 3.11 and Python 3.12 +- Support for Django 4.2 ### Changed -- +- Distinguish between errors and warnings on up-check +- Register built-in up-checks via the `monitor_up_check` signal ### Removed -- +- Support for Python 3.7 +- Support for Django 4.0 ## [1.5.0] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..5f34d6d --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,35 @@ +# Guidance on how to contribute + +> By submitting a pull request or filing a bug, issue, or feature request, +> you are agreeing to comply with this waiver of copyright interest. +> Details can be found in our [LICENSE](LICENSE). + + +There are two primary ways to help: + - Using the issue tracker, and + - Changing the code-base. + + +## Using the issue tracker + +Use the issue tracker to suggest feature requests, report bugs, and ask questions. +This is also a great way to connect with the developers of the project as well +as others who are interested in this solution. + +Use the issue tracker to find ways to contribute. Find a bug or a feature, mention in +the issue that you will take on that effort, then follow the _Changing the code-base_ +guidance below. + + +## Changing the code-base + +Generally speaking, you should fork this repository, make changes in your +own fork, and then submit a pull request. All new code should have associated +unit tests that validate implemented features and the presence or lack of defects. +Additionally, the code should follow any stylistic and architectural guidelines +prescribed by the project. In the absence of such guidelines, mimic the styles +and patterns in the existing code-base. + +### Contribution guidelines + - Your code should follow PEP 8 -- Style Guide for Python Code + - Your changes should be covered by unit-tests diff --git a/README.md b/README.md index 26721c0..27949bb 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ If your project uses an older version of Django, you can choose an older version | This Project | Python Version | Django Version | |--------------|----------------|----------------| +| 1.6.* | 3.8 - 3.12 | 3.2, 4.1, 4.2 | | 1.5.* | 3.7 - 3.10 | 3.2, 4.0, 4.1 | | 1.4.* | 3.7 - 3.10 | 3.2, 4.0 | | 1.3.* | 3.5 - 3.9 | 2.2, 3.1, 3.2 | diff --git a/anexia_monitoring/__init__.py b/anexia_monitoring/__init__.py index 40a96af..e69de29 100644 --- a/anexia_monitoring/__init__.py +++ b/anexia_monitoring/__init__.py @@ -1 +0,0 @@ -# -*- coding: utf-8 -*- diff --git a/anexia_monitoring/decorators.py b/anexia_monitoring/decorators.py index c5b0326..888d680 100644 --- a/anexia_monitoring/decorators.py +++ b/anexia_monitoring/decorators.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from django.conf import settings from django.http import HttpResponse diff --git a/anexia_monitoring/events.py b/anexia_monitoring/events.py index 9a3498a..b942a26 100644 --- a/anexia_monitoring/events.py +++ b/anexia_monitoring/events.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from django import dispatch monitor_up_check = dispatch.Signal() diff --git a/anexia_monitoring/urls.py b/anexia_monitoring/urls.py index cd482e1..d5552b1 100644 --- a/anexia_monitoring/urls.py +++ b/anexia_monitoring/urls.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from django.urls import include, re_path from .views import MonitorModulesView, MonitorUpView diff --git a/anexia_monitoring/views.py b/anexia_monitoring/views.py index 961f983..b0e9822 100644 --- a/anexia_monitoring/views.py +++ b/anexia_monitoring/views.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import asyncio import sys @@ -7,6 +6,7 @@ from django.http import JsonResponse, HttpResponse from django.contrib.auth import get_user_model from django.db import connections +from django.dispatch import receiver from django.views.generic import View from django.conf import settings @@ -101,19 +101,47 @@ class MonitorUpView(BaseView): @access_token_check def get(self, request, *args, **kwargs): - # Test database connections - if getattr(settings, 'ANX_MONITORING_TEST_DB_CONNECTIONS', True): - for connection_key in connections: - connections[connection_key].cursor() + response_contents = [] + response_status = 200 + + # Sends signal for health check implementations + up_check_results = monitor_up_check.send_robust(sender=None) + up_check_result_warnings = [ + r[1] for r in up_check_results + if isinstance(r[1], Exception) and getattr(r[1], "is_anx_monitoring_up_warning", False) + ] + up_check_result_errors = [ + r[1] + for r in up_check_results + if isinstance(r[1], Exception) and not getattr(r[1], "is_anx_monitoring_up_warning", False) + ] + + if not up_check_result_warnings and not up_check_result_errors: + response_contents.append("OK") + response_status = 200 + + for up_check_result_warning in up_check_result_warnings: + response_contents.append("WARNING: {}".format(str(up_check_result_warning) or "-")) + response_status = 200 + + for up_check_result_error in up_check_result_errors: + response_contents.append("ERROR: {}".format(str(up_check_result_error) or "-")) + response_status = 500 + + response = HttpResponse("\n".join(response_contents), content_type="text/plain", status=response_status) + self.add_access_control_headers(response) + return response - # Query for users - if getattr(settings, 'ANX_MONITORING_TEST_QUERY_USERS', True): - User = get_user_model() - User.objects.all().count() - # Registers signal for custom check - monitor_up_check.send(sender=None) +if getattr(settings, 'ANX_MONITORING_TEST_DB_CONNECTIONS', True): + @receiver(monitor_up_check) + def anx_monitoring_test_db_connections(sender, **kwargs): + for connection_key in connections: + connections[connection_key].cursor() - response = HttpResponse("OK", content_type="text/plain") - self.add_access_control_headers(response) - return response + +if getattr(settings, 'ANX_MONITORING_TEST_QUERY_USERS', True): + @receiver(monitor_up_check) + def anx_monitoring_test_query_users(sender, **kwargs): + user_model = get_user_model() + user_model.objects.all().count() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..3181290 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,6 @@ +[build-system] +requires = [ + "setuptools>=58", + "wheel", +] +build-backend = "setuptools.build_meta" diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..716b9d7 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,10 @@ +# Package and package dependencies +-e . + +# Development dependencies +django>=3.2.0 +flake8>=5.0 +codecov>=2.1 +setuptools>=42 +wheel>=0.37 +twine>=3.4 diff --git a/setup.py b/setup.py index 2f8be60..2309b2f 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Note: To use the 'upload' functionality of this file, you must: # $ pip install twine diff --git a/tests/test_project/test_project/tests.py b/tests/test_project/test_project/tests.py index e6ddc5c..c443322 100644 --- a/tests/test_project/test_project/tests.py +++ b/tests/test_project/test_project/tests.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from django.test import TestCase, Client from django.urls import reverse from django.conf import settings