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

Function _compose_spans

prometheus_client/openmetrics/parser.py:341–365  ·  view source on GitHub ↗

Takes a list of span matches (expected to be a list of tuples) and a string (the expected span list name) and processes the list so that the values extracted from the span matches can be used to compose a tuple of BucketSpan objects

(span_matches, spans_name)

Source from the content-addressed store, hash-verified

339
340
341def _compose_spans(span_matches, spans_name):
342 """Takes a list of span matches (expected to be a list of tuples) and a string
343 (the expected span list name) and processes the list so that the values extracted
344 from the span matches can be used to compose a tuple of BucketSpan objects"""
345 spans = {}
346 for match in span_matches:
347 # Extract the key from the match (first element of the tuple).
348 key = match[0]
349 # Extract the value from the match (second element of the tuple).
350 # Split the value string by commas to get individual pairs,
351 # split each pair by ':' to get start and end, and convert them to integers.
352 value = [tuple(map(int, pair.split(':'))) for pair in match[1].split(',')]
353 # Store the processed value in the spans dictionary with the key.
354 spans[key] = value
355 if spans_name not in spans:
356 return None
357 out_spans = []
358 # Iterate over each start and end tuple in the list of tuples for the specified spans_name.
359 for start, end in spans[spans_name]:
360 # Compose a BucketSpan object with the start and end values
361 # and append it to the out_spans list.
362 out_spans.append(BucketSpan(start, end))
363 # Convert to tuple
364 out_spans_tuple = tuple(out_spans)
365 return out_spans_tuple
366
367
368def _compose_deltas(deltas, deltas_name):

Callers 1

_parse_nh_structFunction · 0.85

Calls 2

mapFunction · 0.85
BucketSpanClass · 0.85

Tested by

no test coverage detected