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

Function _parse_nh_struct

prometheus_client/openmetrics/parser.py:308–338  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

306
307
308def _parse_nh_struct(text):
309 pattern = r'(\w+):\s*([^,}]+)'
310 re_spans = re.compile(r'(positive_spans|negative_spans):\[(\d+:\d+(,\d+:\d+)*)\]')
311 re_deltas = re.compile(r'(positive_deltas|negative_deltas):\[(-?\d+(?:,-?\d+)*)\]')
312
313 items = dict(re.findall(pattern, text))
314 span_matches = re_spans.findall(text)
315 deltas = dict(re_deltas.findall(text))
316
317 count_value = int(items['count'])
318 sum_value = int(items['sum'])
319 schema = int(items['schema'])
320 zero_threshold = float(items['zero_threshold'])
321 zero_count = int(items['zero_count'])
322
323 pos_spans = _compose_spans(span_matches, 'positive_spans')
324 neg_spans = _compose_spans(span_matches, 'negative_spans')
325 pos_deltas = _compose_deltas(deltas, 'positive_deltas')
326 neg_deltas = _compose_deltas(deltas, 'negative_deltas')
327
328 return NativeHistogram(
329 count_value=count_value,
330 sum_value=sum_value,
331 schema=schema,
332 zero_threshold=zero_threshold,
333 zero_count=zero_count,
334 pos_spans=pos_spans,
335 neg_spans=neg_spans,
336 pos_deltas=pos_deltas,
337 neg_deltas=neg_deltas
338 )
339
340
341def _compose_spans(span_matches, spans_name):

Callers 1

_parse_nh_sampleFunction · 0.85

Calls 3

_compose_spansFunction · 0.85
_compose_deltasFunction · 0.85
NativeHistogramClass · 0.85

Tested by

no test coverage detected