Skip to content

Commit

Permalink
ajustes
Browse files Browse the repository at this point in the history
  • Loading branch information
engFelipeMonteiro committed Apr 11, 2022
1 parent cc3da7b commit 30d16e9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
38 changes: 21 additions & 17 deletions prometheus_client/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,12 +771,12 @@ def set_metric(self, df: pd.DataFrame):

def __init__(
self: T,
name: str = '',
documentation: str = '',
name: str,
documentation: str,
df: pd.DataFrame,
namespace: str = '',
subsystem: str = '',
unit: str = '',
df=None,
columns=None,
registry: Optional[CollectorRegistry] = REGISTRY,
tag='report',
Expand All @@ -786,11 +786,15 @@ def __init__(
Esta classe parte do pressuporto que a metrica é trocada com mais eficiencia do que ficar alterando apenas 1 valor
o calculo pode ser feito em outro lugar e passar apenas a estrutura completo pronto em DataFrame
"""
if df is None:
raise ValueError("df must be set")

self._name = _build_full_name(self._type, name, namespace, subsystem, unit)
if columns:
self._labelvalues = columns
else:
self._labelvalues = df.columns

self._labelnames = _validate_labelnames(self, self._labelvalues)
self._labelvalues = tuple(None or ())
self._kwargs: Dict[str, Any] = {}
Expand Down Expand Up @@ -837,20 +841,20 @@ def clear(self) -> None:
with self._lock:
self._metrics = {}

def _samples(self) -> Iterable[Sample]:
if self._is_parent():
return self._multi_samples()
else:
return self._child_samples()

def _multi_samples(self) -> Iterable[Sample]:
if 'pandas' not in vars(metrics._encoder):
with self._lock:
metrics = self._metrics.copy()
for labels, metric in metrics.items():
series_labels = list(zip(self._labelnames, labels))
for suffix, sample_labels, value, timestamp, exemplar in metric._samples():
yield Sample(suffix, dict(series_labels + list(sample_labels.items())), value, timestamp, exemplar)
# def _samples(self) -> Iterable[Sample]:
# if self._is_parent():
# return self._multi_samples()
# else:
# return self._child_samples()

# def _multi_samples(self) -> Iterable[Sample]:
# if 'pandas' not in vars(metrics._encoder):
# with self._lock:
# metrics = self._metrics.copy()
# for labels, metric in metrics.items():
# series_labels = list(zip(self._labelnames, labels))
# for suffix, sample_labels, value, timestamp, exemplar in metric._samples():
# yield Sample(suffix, dict(series_labels + list(sample_labels.items())), value, timestamp, exemplar)

def _child_samples(self) -> Iterable[Sample]: # pragma: no cover
raise NotImplementedError('_child_samples() must be implemented by %r' % self)
Expand Down
2 changes: 0 additions & 2 deletions tests/test_exposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,6 @@ def test_gauge_pandas_columns(self):
PandasGauge('report_pandas', 'metric description', df=df, columns= ['a', 'value'], registry=self.registry)
g2 = PandasGauge('report_panda2s', 'metric description2', df=df2, columns=['d', 'result'],value='result' ,registry=self.registry)


import pdb; pdb.set_trace()
self.assertEqual(
b'# HELP report_pandas metric description\n'
b'# TYPE report_pandas gauge\n'
Expand Down

0 comments on commit 30d16e9

Please sign in to comment.