Skip to content

Commit

Permalink
Fix cgroup jobmetric formatter to always return properly formatted
Browse files Browse the repository at this point in the history
strings, add typing to specify, instead of casting this higher in the
stack.
  • Loading branch information
dannon committed Feb 21, 2024
1 parent d770aa0 commit 404001c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/galaxy/job_metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def raw_to_dictifiable(raw_metric: RawMetric) -> DictifiableMetric:
safety = DEFAULT_SAFETY
return DictifiableMetric(
title,
str(value),
value,
str(metric_value),
metric_name,
metric_plugin,
Expand Down
8 changes: 4 additions & 4 deletions lib/galaxy/job_metrics/instrumenters/cgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,18 @@


class CgroupPluginFormatter(formatting.JobMetricFormatter):
def format(self, key, value):
def format(self, key: str, value: Any) -> formatting.FormattedMetric:
title = TITLES.get(key, key)
if key in CONVERSION:
return title, CONVERSION[key](value)
return formatting.FormattedMetric(title, CONVERSION[key](value))
elif key.endswith("_bytes"):
try:
return title, nice_size(value)
return formatting.FormattedMetric(title, nice_size(value))
except ValueError:
pass
elif isinstance(value, (decimal.Decimal, numbers.Integral, numbers.Real)) and value == int(value):
value = int(value)
return title, value
return formatting.FormattedMetric(title, str(value))


class CgroupPlugin(InstrumentPlugin):
Expand Down

0 comments on commit 404001c

Please sign in to comment.