Skip to content
Snippets Groups Projects
Commit 96f6373b authored by geant-release-service's avatar geant-release-service
Browse files

Finished release 0.8.

parents 9564ef83 e516269f
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,9 @@
All notable changes to this project will be documented in this file.
## [0.8] - 2023-08-23
- Added cleanup of events for deleted checks so the GUI is usable
## [0.7] - 2022-10-19
- POL1-624: Allow supporting GTT as a GWS Direct ISP
......
MIT License
Copyright (c) 2023 GÉANT Vereniging
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
......@@ -100,6 +100,9 @@ def refresh(config, force=False):
}
jsonschema.validate(result, REFRESH_RESULT_SCHEMA) # sanity
# remove events for deleted checks, otherwise they stick around forever
sensu.clean_events(config['sensu'])
statsd_config = config.get('statsd', None)
if statsd_config:
for key, counts in result.items():
......
......@@ -5,6 +5,7 @@ import copy
import logging
import random
import requests
from datetime import datetime
logger = logging.getLogger(__name__)
......@@ -100,6 +101,38 @@ def checks_match(a, b) -> bool:
return True
def clean_events(params, namespace='default'):
logger.info('cleaning events for deleted checks')
url = random.choice(params['api-base'])
r = requests.get(f'{url}/api/core/v2/namespaces/{namespace}/events',
headers={'Authorization': f'Key {params["api-key"]}'})
r.raise_for_status()
events = r.json()
all_checks = load_all_checks(params, namespace)
check_names = {c['metadata']['name'] for c in all_checks}
with requests.Session() as session:
session.headers.update({'Authorization': f'Key {params["api-key"]}'})
for event in events:
if event['check']['metadata']['name'] not in check_names:
last_execution = event['check']['executed']
days_since_last_execution = (datetime.utcnow() - datetime.fromtimestamp(last_execution)).days
if days_since_last_execution <= 1:
continue
logger.info(f'deleting event for deleted check: '
f'{event["check"]["metadata"]["name"]}'
f' (last execution: {days_since_last_execution} days ago)')
r = session.delete(
f'{url}/api/core/v2/namespaces/{namespace}/events/'
f'{event["entity"]["metadata"]["name"]}/'
f'{event["check"]["metadata"]["name"]}')
r.raise_for_status()
class AbstractCheck(object):
"""
not explicitly using abc.ABC ... more readable than stacks of decorators
......@@ -230,7 +263,6 @@ def refresh(sensu_params, required_checks, current_checks):
:param current_checks: dict of {name:check_dict} from sensu
:return: dict with change counts
"""
# cf. main.REFRESH_RESULT_SCHEMA
result = {
'checks': len(current_checks),
......
......@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
setup(
name='brian-polling-manager',
version="0.7",
version="0.8",
author='GEANT',
author_email='swd@geant.org',
description='service for managing BRIAN polling checks',
......@@ -21,4 +21,6 @@ setup(
]
},
include_package_data=True,
license='MIT',
license_files=('LICENSE.txt',)
)
......@@ -171,6 +171,25 @@ def mocked_sensu():
r'.*sensu.+/api/core/v2/namespaces/[^\/]+/checks/[^\/]+$'),
callback=delete_check_callback)
def get_events_callback(request):
return 200, {}, _load_test_data('events.json')
# mocked api for returning all events
responses.add_callback(
method=responses.GET,
url=re.compile(r'.*sensu.+/api/core/v2/namespaces/[^\/]+/events$'),
callback=get_events_callback)
def delete_event_callback(request):
return 204, {}, ''
# mocked api for deleting an event
responses.add_callback(
method=responses.DELETE,
url=re.compile(
r'.*sensu.+/api/core/v2/namespaces/default/events/.*$'),
callback=delete_event_callback)
yield saved_sensu_checks
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
......@@ -2,6 +2,7 @@
envlist = py36
[flake8]
max-line-length = 120
exclude = venv,.tox
[testenv]
......@@ -12,7 +13,7 @@ deps =
commands =
coverage erase
coverage run --source brian_polling_manager -m py.test {posargs}
coverage run --source brian_polling_manager -m pytest {posargs}
coverage xml
coverage html
coverage report
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment