Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
brian-polling-manager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
geant-swd
brian
brian-polling-manager
Commits
cd6d0838
Commit
cd6d0838
authored
1 year ago
by
Bjarke Madsen
Browse files
Options
Downloads
Patches
Plain Diff
cleanup events for deleted checks
parent
29dece4c
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
brian_polling_manager/main.py
+3
-0
3 additions, 0 deletions
brian_polling_manager/main.py
brian_polling_manager/sensu.py
+33
-1
33 additions, 1 deletion
brian_polling_manager/sensu.py
tox.ini
+2
-1
2 additions, 1 deletion
tox.ini
with
38 additions
and
2 deletions
brian_polling_manager/main.py
+
3
−
0
View file @
cd6d0838
...
...
@@ -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
():
...
...
This diff is collapsed.
Click to expand it.
brian_polling_manager/sensu.py
+
33
−
1
View file @
cd6d0838
...
...
@@ -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
),
...
...
This diff is collapsed.
Click to expand it.
tox.ini
+
2
−
1
View file @
cd6d0838
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment