(name, documentation, typ, unit, samples)
| 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 |
no test coverage detected