10000 ajust format · engFelipeMonteiro/client_python@ee89a43 · GitHub
[go: up one dir, main page]

Skip to content

Commit ee89a43

Browse files
ajust format
Signed-off-by: Felipe Monteiro Jácome <fmj1988@gmail.com>
1 parent 5fd0520 commit ee89a43

File tree

2 files changed

+30
-31
lines changed

2 files changed

+30
-31
lines changed

prometheus_client/metrics.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from threading import Lock
21
import time
32
import types
3+
from threading import Lock
44
from typing import (
55
Any, Callable, Dict, Iterable, Optional, Sequence, Type, TypeVar, Union,
66
)
@@ -758,7 +758,7 @@ def __repr__(self):
758758

759759
def generate_pandas_report(self):
760760
def make_str(row):
761-
return f"""{self._name}({','.join([ f'{col}="{row[col]}" ' for col in self._labelnames if col not in [self._value, self._tag]])}) {row[self._value]} {chr(10)}"""
761+
return f"""{self._name}{{{','.join([ f'{col}="{row[col]}" ' for col in self._labelnames if col not in [self._value, self._tag]])}}} {row[self._value]} {chr(10)}"""
762762
with self._lock:
763763
self._metrics[self._tag] = self._metrics.apply(make_str, axis=1)
764764
# self._metrics
@@ -784,7 +784,7 @@ def __init__(
784784
registry: Optional[CollectorRegistry] = REGISTRY,
785785
tag: str = 'report',
786786
value: str = 'value'
787-
) -> None:
787+
) -> None:
788788
"""
789789
Esta classe parte do pressuporto que a metrica é trocada com mais eficiencia do que ficar alterando apenas 1 valor
790790
o calculo pode ser feito em outro lugar e passar apenas a estrutura completo pronto em DataFrame

tests/test_exposition.py

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from http.server import BaseHTTPRequestHandler, HTTPServer
2+
import pandas as pd
3+
import pytest
24
import threading
35
import time
46
import unittest
57

6-
import pandas as pd
7-
import pytest
8-
98
from prometheus_client import (
109
CollectorRegistry, CONTENT_TYPE_LATEST, core, Counter, delete_from_gateway,
1110
Enum, Gauge, generate_latest, Histogram, Info, instance_ip_grouping_key,
@@ -208,37 +207,37 @@ def test_gauge_pandas(self):
208207
df2 = pd.DataFrame({'c': [1.1, 2.2, 3.3, 4.4], 'd': [5.1, 6.2, 7.3, 8.4], 'value': [5, 6, 7, 8]})
209208
PandasGauge('report_pandas', 'metric description', df=df, columns=['a', 'b', 'value'], registry=self.registry)
210209
g2 = PandasGauge('report_panda2s', 'metric description2', df=df2, registry=self.registry)
211-
210+
212211
self.assertEqual(
213212
b'# HELP report_pandas metric description\n'
214213
b'# TYPE report_pandas gauge\n'
215-
b'report_pandas(a="1.1" ,b="5.1" ) 1.0 \n'
216-
b'report_pandas(a="2.2" ,b="6.2" ) 2.0 \n'
217-
b'report_pandas(a="3.3" ,b="7.3" ) 3.0 \n'
218-
b'report_pandas(a="4.4" ,b="8.4" ) 4.0 \n'
214+
b'report_pandas{a="1.1" ,b="5.1" } 1.0 \n'
215+
b'report_pandas{a="2.2" ,b="6.2" } 2.0 \n'
216+
b'report_pandas{a="3.3" ,b="7.3" } 3.0 \n'
217+
b'report_pandas{a="4.4" ,b="8.4" } 4.0 \n'
219218
b'# HELP report_panda2s metric description2\n'
220219
b'# TYPE report_panda2s gauge\n'
221-
b'report_panda2s(c="1.1" ,d="5.1" ) 5.0 \n'
222-
b'report_panda2s(c="2.2" ,d="6.2" ) 6.0 \n'
223-
b'report_panda2s(c="3.3" ,d="7.3" ) 7.0 \n'
224-
b'report_panda2s(c="4.4" ,d="8.4" ) 8.0 \n',
220+
b'report_panda2s{c="1.1" ,d="5.1" } 5.0 \n'
221+
b'report_panda2s{c="2.2" ,d="6.2" } 6.0 \n'
222+
b'report_panda2s{c="3.3" ,d="7.3" } 7.0 \n'
223+
b'report_panda2s{c="4.4" ,d="8.4" } 8.0 \n',
225224
generate_latest(self.registry)
226225
)
227226

228227
g2.set_metric(df2)
229228
self.assertEqual(
230229
b'# HELP report_pandas metric description\n'
231230
b'# TYPE report_pandas gauge\n'
232-
b'report_pandas(a="1.1" ,b="5.1" ) 1.0 \n'
233-
b'report_pandas(a="2.2" ,b="6.2" ) 2.0 \n'
234-
b'report_pandas(a="3.3" ,b="7.3" ) 3.0 \n'
235-
b'report_pandas(a="4.4" ,b="8.4" ) 4.0 \n'
231+
b'report_pandas{a="1.1" ,b="5.1" } 1.0 \n'
232+
b'report_pandas{a="2.2" ,b="6.2" } 2.0 \n'
233+
b'report_pandas{a="3.3" ,b="7.3" } 3.0 \n'
234+
b'report_pandas{a="4.4" ,b="8.4" } 4.0 \n'
236235
b'# HELP report_panda2s metric description2\n'
237236
b'# TYPE report_panda2s gauge\n'
238-
b'report_panda2s(c="1.1" ,d="5.1" ) 5 \n'
239-
b'report_panda2s(c="2.2" ,d="6.2" ) 6 \n'
240-
b'report_panda2s(c="3.3" ,d="7.3" ) 7 \n'
241-
b'report_panda2s(c="4.4" ,d="8.4" ) 8 \n',
237+
b'report_panda2s{c="1.1" ,d="5.1" } 5 \n'
238+
b'report_panda2s{c="2.2" ,d="6.2" } 6 \n'
239+
b'report_panda2s{c="3.3" ,d="7.3" } 7 \n'
240+
b'report_panda2s{c="4.4" ,d="8.4" } 8 \n',
242241
generate_latest(self.registry)
243242
)
244243

@@ -261,16 +260,16 @@ def test_gauge_pandas_columns(self):
261260
self.assertEqual(
262261
b'# HELP report_pandas metric description\n'
263262
b'# TYPE report_pandas gauge\n'
264-
b'report_pandas(a="1.1" ) 1.0 \n'
265-
b'report_pandas(a="2.2" ) 2.0 \n'
266-
b'report_pandas(a="3.3" ) 3.0 \n'
267-
b'report_pandas(a="4.4" ) 4.0 \n'
263+
b'report_pandas{a="1.1" } 1.0 \n'
264+
b'report_pandas{a="2.2" } 2.0 \n'
265+
b'report_pandas{a="3.3" } 3.0 \n'
266+
b'report_pandas{a="4.4" } 4.0 \n'
268267
b'# HELP report_panda2s metric description2\n'
269268
b'# TYPE report_panda2s gauge\n'
270-
b'report_panda2s(d="5.1" ) 5.0 \n'
271-
b'report_panda2s(d="6.2" ) 6.0 \n'
272-
b'report_panda2s(d="7.3" ) 7.0 \n'
273-
b'report_panda2s(d="8.4" ) 8.0 \n',
269+
b'report_panda2s{d="5.1" } 5.0 \n'
270+
b'report_panda2s{d="6.2" } 6.0 \n'
271+
b'report_panda2s{d="7.3" } 7.0 \n'
272+
b'report_panda2s{d="8.4" } 8.0 \n',
274273
generate_latest(self.registry)
275274
)
276275

0 commit comments

Comments
 (0)
0