Skip to content

Commit

Permalink
Merge pull request #13 from anexia-it/astocker/SIANXKE-349
Browse files Browse the repository at this point in the history
SIANXKE-349: Update supported versions
  • Loading branch information
nezhar committed Jun 12, 2024
2 parents a120ffc + 430bb9b commit 36acffb
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 40 deletions.
22 changes: 6 additions & 16 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: |
Expand All @@ -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
Expand All @@ -58,4 +48,4 @@ jobs:
coverage xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v3
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
35 changes: 35 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
1 change: 0 additions & 1 deletion anexia_monitoring/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# -*- coding: utf-8 -*-
1 change: 0 additions & 1 deletion anexia_monitoring/decorators.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from django.conf import settings
from django.http import HttpResponse

Expand Down
1 change: 0 additions & 1 deletion anexia_monitoring/events.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from django import dispatch

monitor_up_check = dispatch.Signal()
1 change: 0 additions & 1 deletion anexia_monitoring/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from django.urls import include, re_path

from .views import MonitorModulesView, MonitorUpView
Expand Down
56 changes: 42 additions & 14 deletions anexia_monitoring/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import asyncio
import sys

Expand All @@ -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

Expand Down Expand Up @@ -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()
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[build-system]
requires = [
"setuptools>=58",
"wheel",
]
build-backend = "setuptools.build_meta"
10 changes: 10 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

# Note: To use the 'upload' functionality of this file, you must:
# $ pip install twine

Expand Down
1 change: 0 additions & 1 deletion tests/test_project/test_project/tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from django.test import TestCase, Client
from django.urls import reverse
from django.conf import settings
Expand Down

0 comments on commit 36acffb

Please sign in to comment.