Skip to content

Commit 82f59e3

Browse files
ajust '"' in metric
lint
1 parent c6eb213 commit 82f59e3

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

prometheus_client/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
write_to_textfile,
1212
)
1313
from .gc_collector import GC_COLLECTOR, GCCollector
14-
from .metrics import Counter, Enum, Gauge, Histogram, Info, Summary, PandasGauge
14+
from .metrics import Counter, Enum, Gauge, Histogram, Info, PandasGauge, Summary
1515
from .metrics_core import Metric
1616
from .platform_collector import PLATFORM_COLLECTOR, PlatformCollector
1717
from .process_collector import PROCESS_COLLECTOR, ProcessCollector

prometheus_client/metrics.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from threading import Lock
22
import time
33
import types
4+
import pandas as pd
45
from typing import (
56
Any, Callable, Dict, Iterable, Optional, Sequence, Type, TypeVar, Union,
67
)
@@ -15,7 +16,7 @@
1516
from .samples import Exemplar, Sample
1617
from .utils import floatToGoString, INF
1718

18-
import pandas as pd
19+
1920

2021
T = TypeVar('T', bound='MetricWrapperBase')
2122
F = TypeVar("F", bound=Callable[..., Any])
@@ -271,7 +272,7 @@ def _metric_init(self) -> None:
271272
self._labelvalues)
272273
self._created = time.time()
273274

274-
def inc(self, amount: float = 1, exemplar: Optional[Dict[str, str]] = None) -> None:
275+
def inc(self, amount: float=1, exemplar: Optional[Dict[str, str]] = None) -> None:
275276
"""Increment counter by the given amount."""
276277
self._raise_if_not_observable()
277278
if amount < 0:
@@ -755,7 +756,7 @@ def __repr__(self):
755756

756757
def generate_pandas_report(self):
757758
def make_str(row):
758-
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)}"""
759+
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)}"""
759760
with self._lock:
760761
self._metrics[self._tag] = self._metrics.apply(make_str, axis=1)
761762
# self._metrics

tests/test_exposition.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
import unittest
55

66
import pytest
7+
import pandas as pd
78

89
from prometheus_client import (
910
CollectorRegistry, CONTENT_TYPE_LATEST, core, Counter, delete_from_gateway,
1011
Enum, Gauge, generate_latest, Histogram, Info, instance_ip_grouping_key,
11-
Metric, push_to_gateway, pushadd_to_gateway, Summary, PandasGauge
12+
Metric, PandasGauge, push_to_gateway, pushadd_to_gateway, Summary
1213
)
1314
from prometheus_client.core import GaugeHistogramMetricFamily, Timestamp
1415
from prometheus_client.exposition import (
1516
basic_auth_handler, default_handler, MetricsHandler,
1617
passthrough_redirect_handler,
1718
)
1819

19-
import pandas as pd
2020

2121
class TestGenerateText(unittest.TestCase):
2222
def setUp(self):
@@ -204,8 +204,8 @@ def test_gauge_pandas(self):
204204
ou
205205
PandasGauge('report_pandas', 'metric description', df=df, columns=['columnn01', 'column02'], registry=self.registry)
206206
"""
207-
df = pd.DataFrame({'a': [1.1,2.2,3.3,4.4], 'b':[5.1,6.2,7.3,8.4], 'value': [1,2,3,4]})
208-
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]})
207+
df = pd.DataFrame({'a': [1.1, 2.2, 3.3, 4.4], 'b':[5.1, 6.2, 7.3, 8.4], 'value': [1, 2, 3, 4]})
208+
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]})
209209
PandasGauge('report_pandas', 'metric description', df=df, columns= ['a', 'b', 'value'], registry=self.registry)
210210
g2 = PandasGauge('report_panda2s', 'metric description2', df=df2, registry=self.registry)
211211

@@ -223,7 +223,7 @@ def test_gauge_pandas(self):
223223
b'report_panda2s(c=3.3 ,d=7.3 ) 7.0 \n'
224224
b'report_panda2s(c=4.4 ,d=8.4 ) 8.0 \n',
225225
generate_latest(self.registry)
226-
)
226+
)
227227

228228
g2.set_metric(df2)
229229
self.assertEqual(
@@ -240,7 +240,7 @@ def test_gauge_pandas(self):
240240
b'report_panda2s(c=3.3 ,d=7.3 ) 7 \n'
241241
b'report_panda2s(c=4.4 ,d=8.4 ) 8 \n',
242242
generate_latest(self.registry)
243-
)
243+
)
244244

245245
def test_gauge_pandas_columns(self):
246246
"""
@@ -253,8 +253,8 @@ def test_gauge_pandas_columns(self):
253253
ou
254254
PandasGauge('report_pandas', 'metric description', df=df, columns=['columnn01', 'column02'], registry=self.registry)
255255
"""
256-
df = pd.DataFrame({'a': [1.1,2.2,3.3,4.4], 'b':[5.1,6.2,7.3,8.4], 'value': [1,2,3,4]})
257-
df2 = pd.DataFrame({'c': [1.1,2.2,3.3,4.4], 'd':[5.1,6.2,7.3,8.4], 'result': [5,6,7,8]})
256+
df = pd.DataFrame({'a': [1.1, 2.2, 3.3, 4.4], 'b':[5.1, 6.2, 7.3, 8.4], 'value': [1, 2, 3, 4]})
257+
df2 = pd.DataFrame({'c': [1.1, 2.2, 3.3, 4.4], 'd':[5.1, 6.2, 7.3, 8.4], 'result': [5, 6, 7, 8]})
258258
PandasGauge('report_pandas', 'metric description', df=df, columns= ['a', 'value'], registry=self.registry)
259259
g2 = PandasGauge('report_panda2s', 'metric description2', df=df2, columns=['d', 'result'],value='result' ,registry=self.registry)
260260

@@ -272,7 +272,7 @@ def test_gauge_pandas_columns(self):
272272
b'report_panda2s(d=7.3 ) 7.0 \n'
273273
b'report_panda2s(d=8.4 ) 8.0 \n',
274274
generate_latest(self.registry)
275-
)
275+
)
276276

277277
class TestPushGateway(unittest.TestCase):
278278
def setUp(self):

tests/test_registry.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import pytest
2+
import pandas as pd
13
from prometheus_client.registry import CollectorRegistry
24
from prometheus_client.metrics import Gauge, PandasGauge, PandasGauge
3-
import pandas as pd
45

56
def test_collector_registry_init():
67
registry = CollectorRegistry()
@@ -10,7 +11,7 @@ def test_collector_registry_init():
1011
assert str(type(registry._lock)) == "<class '_thread.lock'>"
1112
assert registry._target_info == None
1213

13-
import pytest
14+
1415
@pytest.mark.skip('wip')
1516
def test_collector_registry_gauge():
1617
registry = CollectorRegistry()

0 commit comments

Comments
 (0)