MCPcopy Index your code
hub / github.com/prometheus/client_python / test_restrict

Method test_restrict

tests/test_multiprocess.py:361–388  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

359 self.assertEqual(metrics['h'].samples, expected_histogram)
360
361 def test_restrict(self):
362 pid = 0
363 values.ValueClass = MultiProcessValue(lambda: pid)
364 labels = {i: i for i in 'abcd'}
365
366 def add_label(key, value):
367 l = labels.copy()
368 l[key] = value
369 return l
370
371 c = Counter('c', 'help', labelnames=labels.keys(), registry=None)
372 g = Gauge('g', 'help', labelnames=labels.keys(), registry=None)
373
374 c.labels(**labels).inc(1)
375 g.labels(**labels).set(1)
376
377 pid = 1
378
379 c.labels(**labels).inc(1)
380 g.labels(**labels).set(1)
381
382 metrics = {m.name: m for m in self.registry.restricted_registry(['c_total']).collect()}
383
384 self.assertEqual(metrics.keys(), {'c'})
385
386 self.assertEqual(
387 metrics['c'].samples, [Sample('c_total', labels, 2.0)]
388 )
389
390 def test_collect_preserves_help(self):
391 pid = 0

Callers

nothing calls this directly

Calls 10

MultiProcessValueFunction · 0.90
CounterClass · 0.90
GaugeClass · 0.85
SampleClass · 0.85
keysMethod · 0.80
restricted_registryMethod · 0.80
incMethod · 0.45
labelsMethod · 0.45
setMethod · 0.45
collectMethod · 0.45

Tested by

no test coverage detected