From 30d16e914ef3411180c1a5e27efe26ef416cdd4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Monteiro=20J=C3=A1come?= Date: Mon, 11 Apr 2022 17:09:38 -0300 Subject: [PATCH] ajustes --- prometheus_client/metrics.py | 38 ++++++++++++++++++++---------------- tests/test_exposition.py | 2 -- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/prometheus_client/metrics.py b/prometheus_client/metrics.py index 738d2b45..0bca6b87 100644 --- a/prometheus_client/metrics.py +++ b/prometheus_client/metrics.py @@ -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', @@ -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] = {} @@ -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) diff --git a/tests/test_exposition.py b/tests/test_exposition.py index 338b61b1..3251d3c6 100644 --- a/tests/test_exposition.py +++ b/tests/test_exposition.py @@ -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'