Skip to content

Commit

Permalink
fixes / optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
akpw committed Aug 11, 2024
1 parent 3811e71 commit ef471d9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions mktxp/datasource/base_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class BaseDSProcessor:
'''

@staticmethod
def trimmed_records(router_entry, *, router_records = None, metric_labels = None, add_router_id = True, translation_table = None):
def trimmed_records(router_entry, *, router_records = None, metric_labels = None, add_router_id = True, translation_table = None, translate_if_no_value = True):
metric_labels = metric_labels or []
router_records = router_records or []
translation_table = translation_table or {}
Expand All @@ -36,7 +36,8 @@ def trimmed_records(router_entry, *, router_records = None, metric_labels = None

# translate fields if needed
for key, func in translation_table.items():
translated_record[key] = func(translated_record.get(key))
if translate_if_no_value or translated_record.get(key) is not None:
translated_record[key] = func(translated_record.get(key))
labeled_records.append(translated_record)
return labeled_records

Expand Down
6 changes: 3 additions & 3 deletions mktxp/datasource/health_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class HealthMetricsDataSource:
''' Health Metrics data provider
'''
@staticmethod
def metric_records(router_entry, *, metric_labels = None, translation_table = None):
def metric_records(router_entry, *, metric_labels = None, translation_table = None, translate_if_no_value = False):
if metric_labels is None:
metric_labels = []
try:
Expand All @@ -34,8 +34,8 @@ def metric_records(router_entry, *, metric_labels = None, translation_table = No
val = record.get('value', None)
record[name] = val

return BaseDSProcessor.trimmed_records(router_entry, router_records = health_records,
metric_labels = metric_labels, translation_table = translation_table)
return BaseDSProcessor.trimmed_records(router_entry, router_records = health_records, metric_labels = metric_labels,
translation_table = translation_table, translate_if_no_value = translate_if_no_value)
except Exception as exc:
print(f'Error getting system health info from router {router_entry.router_name}@{router_entry.config_entry.hostname}: {exc}')
return None

0 comments on commit ef471d9

Please sign in to comment.