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
55f627d9
"test/test_neteng_routes.py" did not exist on "19a31026cf4d95791ee34f8a62409c337958e80c"
Commit
55f627d9
authored
1 year ago
by
Pelle Koster
Browse files
Options
Downloads
Patches
Plain Diff
small refactor of report-interface-errors
parent
5bf037af
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
brian_polling_manager/error_report/cli.py
+15
-5
15 additions, 5 deletions
brian_polling_manager/error_report/cli.py
test/error_report/test_error_report.py
+28
-15
28 additions, 15 deletions
test/error_report/test_error_report.py
with
43 additions
and
20 deletions
brian_polling_manager/error_report/cli.py
+
15
−
5
View file @
55f627d9
...
...
@@ -220,12 +220,19 @@ def select_error_fields(errors, mapping):
def
interface_errors
(
client
:
InfluxDBClient
,
interface_info
,
errors
,
exclusions
=
(),
raise_on_errors
=
False
error_points_today
,
error_points_yesterday
,
interface_info
,
errors
,
exclusions
=
(),
raise_on_errors
=
False
,
):
"""
Retrieves error counters from influx
:param client: InfluxDBClient for connecting to influx
:param error_points_today: todays errors as a return value of ``get_error_points``
:param error_points_yesterday: yesterdays errors as a return value of
``get_error_points``
:param interface_info: a dict of {(router, interface): info_dict} with interface
information coming from invprov (ie. the output from `get_relevant_interfaces`_)
:param errors: A dict of (input_data_field: result_field) for every error to report
...
...
@@ -236,11 +243,11 @@ def interface_errors(
"""
todays_data
=
{
key
:
select_error_fields
(
val
,
mapping
=
errors
)
for
key
,
val
in
get_
error_points
(
client
,
INFLUX_TIME_WINDOW_TODAY
)
.
items
()
for
key
,
val
in
error_points
_today
.
items
()
}
yesterdays_data
=
{
key
:
select_error_fields
(
val
,
mapping
=
errors
)
for
key
,
val
in
get_
error_points
(
client
,
INFLUX_TIME_WINDOW_YESTERDAY
)
.
items
()
for
key
,
val
in
error_points
_yesterday
.
items
()
}
result
=
{
"
interfaces
"
:
[],
"
excluded_interfaces
"
:
[]}
...
...
@@ -343,7 +350,10 @@ def main(config: dict):
with
client
:
logger
.
info
(
"
Retrieving error points from influxdb...
"
)
all_error_counters
=
interface_errors
(
client
,
error_points_today
=
get_error_points
(
client
,
INFLUX_TIME_WINDOW_TODAY
),
error_points_yesterday
=
get_error_points
(
client
,
INFLUX_TIME_WINDOW_YESTERDAY
),
interface_info
=
all_interfaces
,
errors
=
ERROR_FIELDS
,
exclusions
=
config
[
"
exclude-interfaces
"
],
...
...
This diff is collapsed.
Click to expand it.
test/error_report/test_error_report.py
+
28
−
15
View file @
55f627d9
...
...
@@ -44,6 +44,7 @@ def small_inventory():
@pytest.fixture
def
mock_influx_client
():
class
FakeInfluxClient
:
"""
Fake influx client, see `create_error_point` for usage how to set it up
...
...
@@ -52,8 +53,8 @@ def mock_influx_client():
INFLUX_ERROR_FIELDS
=
{
v
.
replace
(
"
-
"
,
"
_
"
):
k
for
k
,
v
in
ERROR_FIELDS
.
items
()}
def
__init__
(
self
)
->
None
:
self
.
today
=
[]
self
.
yesterday
=
[]
self
.
today
=
{}
self
.
yesterday
=
{}
def
__enter__
(
self
):
pass
...
...
@@ -65,26 +66,37 @@ def mock_influx_client():
converted_payload
=
{
self
.
INFLUX_ERROR_FIELDS
[
k
]:
v
for
k
,
v
in
payload
.
items
()
}
point
=
(
(
"
errors
"
,
{
"
hostname
"
:
hostname
,
"
interface_name
"
:
interface
}),
iter
([
converted_payload
]),
)
if
timestamp
==
"
today
"
:
return
self
.
today
.
append
(
point
)
if
timestamp
==
"
yesterday
"
:
return
self
.
yesterday
.
append
(
point
)
raise
ValueError
(
"'
timestamp
'
argument must be either
'
today
'
or
'
yesterday
'"
)
self
.
today
[(
hostname
,
interface
)]
=
converted_payload
elif
timestamp
==
"
yesterday
"
:
self
.
yesterday
[(
hostname
,
interface
)]
=
converted_payload
else
:
raise
ValueError
(
"'
timestamp
'
argument must be either
'
today
'
or
'
yesterday
'"
)
def
query
(
self
,
q
):
result
=
Mock
()
if
INFLUX_TIME_WINDOW_YESTERDAY
in
q
:
result
.
items
.
return_value
=
self
.
yesterday
result
.
items
.
return_value
=
self
.
points_as_influx
(
self
.
yesterday
)
else
:
result
.
items
.
return_value
=
self
.
today
result
.
items
.
return_value
=
self
.
points_as_influx
(
self
.
today
)
return
result
@staticmethod
def
points_as_influx
(
points
:
dict
):
return
[
(
(
"
errors
"
,
{
"
hostname
"
:
hostname
,
"
interface_name
"
:
interface
},
),
iter
([
errors
]),
)
for
(
hostname
,
interface
),
errors
in
points
.
items
()
]
return
FakeInfluxClient
()
...
...
@@ -115,7 +127,8 @@ def get_interface_errors(small_inventory, mock_influx_client):
def
_get_interface_errors
(
**
kwargs
):
defaults
=
{
"
client
"
:
mock_influx_client
,
"
error_points_today
"
:
mock_influx_client
.
today
,
"
error_points_yesterday
"
:
mock_influx_client
.
yesterday
,
"
interface_info
"
:
interfaces
,
"
errors
"
:
ERROR_FIELDS
,
}
...
...
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