(samples, name)
| 399 | |
| 400 | |
| 401 | def _check_histogram(samples, name): |
| 402 | group = None |
| 403 | timestamp = None |
| 404 | |
| 405 | def do_checks(): |
| 406 | if bucket != float('+Inf'): |
| 407 | raise ValueError("+Inf bucket missing: " + name) |
| 408 | if count is not None and value != count: |
| 409 | raise ValueError("Count does not match +Inf value: " + name) |
| 410 | if has_sum and count is None: |
| 411 | raise ValueError("_count must be present if _sum is present: " + name) |
| 412 | if has_gsum and count is None: |
| 413 | raise ValueError("_gcount must be present if _gsum is present: " + name) |
| 414 | if not (has_sum or has_gsum) and count is not None: |
| 415 | raise ValueError("_sum/_gsum must be present if _count is present: " + name) |
| 416 | if has_negative_buckets and has_sum: |
| 417 | raise ValueError("Cannot have _sum with negative buckets: " + name) |
| 418 | if not has_negative_buckets and has_negative_gsum: |
| 419 | raise ValueError("Cannot have negative _gsum with non-negative buckets: " + name) |
| 420 | |
| 421 | for s in samples: |
| 422 | suffix = s.name[len(name):] |
| 423 | g = _group_for_sample(s, name, 'histogram') |
| 424 | if len(suffix) == 0: |
| 425 | continue |
| 426 | if g != group or s.timestamp != timestamp: |
| 427 | if group is not None: |
| 428 | do_checks() |
| 429 | count = None |
| 430 | bucket = None |
| 431 | has_negative_buckets = False |
| 432 | has_sum = False |
| 433 | has_gsum = False |
| 434 | has_negative_gsum = False |
| 435 | value = 0 |
| 436 | group = g |
| 437 | timestamp = s.timestamp |
| 438 | |
| 439 | if suffix == '_bucket': |
| 440 | b = float(s.labels['le']) |
| 441 | if b < 0: |
| 442 | has_negative_buckets = True |
| 443 | if bucket is not None and b <= bucket: |
| 444 | raise ValueError("Buckets out of order: " + name) |
| 445 | if s.value < value: |
| 446 | raise ValueError("Bucket values out of order: " + name) |
| 447 | bucket = b |
| 448 | value = s.value |
| 449 | elif suffix in ['_count', '_gcount']: |
| 450 | count = s.value |
| 451 | elif suffix in ['_sum']: |
| 452 | has_sum = True |
| 453 | elif suffix in ['_gsum']: |
| 454 | has_gsum = True |
| 455 | if s.value < 0: |
| 456 | has_negative_gsum = True |
| 457 | |
| 458 | if group is not None: |
no test coverage detected