Skip to content

Commit

Permalink
Merge pull request #17520 from dannon/fix-metrics-api
Browse files Browse the repository at this point in the history
Stringify cgroups metrics formatted value return
  • Loading branch information
dannon authored Feb 21, 2024
2 parents c6fa453 + 027e1ac commit 2dd5477
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
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
7 changes: 0 additions & 7 deletions lib/galaxy/job_metrics/instrumenters/hostname.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,14 @@
import logging

from . import InstrumentPlugin
from .. import formatting

log = logging.getLogger(__name__)


class HostnameFormatter(formatting.JobMetricFormatter):
def format(self, key, value):
return key, value


class HostnamePlugin(InstrumentPlugin):
"""Gather hostname"""

plugin_type = "hostname"
formatter = HostnameFormatter()

def __init__(self, **kwargs):
pass
Expand Down
5 changes: 3 additions & 2 deletions lib/galaxy/job_metrics/instrumenters/meminfo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""The module describes the ``meminfo`` job metrics plugin."""

import re
from typing import Any

from galaxy import util
from . import InstrumentPlugin
Expand All @@ -14,9 +15,9 @@


class MemInfoFormatter(formatting.JobMetricFormatter):
def format(self, key, value):
def format(self, key: str, value: Any) -> formatting.FormattedMetric:
title = MEMINFO_TITLES.get(key, key)
return title, util.nice_size(value * 1000) # kB = *1000, KB = *1024 - wikipedia
return formatting.FormattedMetric(title, util.nice_size(value * 1000)) # kB = *1000, KB = *1024 - wikipedia


class MemInfoPlugin(InstrumentPlugin):
Expand Down

0 comments on commit 2dd5477

Please sign in to comment.