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

Function build_metric

prometheus_client/openmetrics/parser.py:484–505  ·  view source on GitHub ↗
(name, documentation, typ, unit, samples)

Source from the content-addressed store, hash-verified

482 }
483
484 def build_metric(name, documentation, typ, unit, samples):
485 if typ is None:
486 typ = 'unknown'
487 for suffix in set(type_suffixes.get(typ, []) + [""]):
488 if name + suffix in seen_names:
489 raise ValueError("Clashing name: " + name + suffix)
490 seen_names.add(name + suffix)
491 if documentation is None:
492 documentation = ''
493 if unit is None:
494 unit = ''
495 if unit and not name.endswith("_" + unit):
496 raise ValueError("Unit does not match metric name: " + name)
497 if unit and typ in ['info', 'stateset']:
498 raise ValueError("Units not allowed for this metric type: " + name)
499 if typ in ['histogram', 'gaugehistogram']:
500 _check_histogram(samples, name)
501 _validate_metric_name(name)
502 metric = Metric(name, documentation, typ, unit)
503 # TODO: check labelvalues are valid utf8
504 metric.samples = samples
505 return metric
506
507 is_nh = False
508 typ = None

Callers 1

Calls 5

_check_histogramFunction · 0.85
_validate_metric_nameFunction · 0.85
MetricClass · 0.85
getMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected