|
16 | 16 | package io.micrometer.prometheusmetrics;
|
17 | 17 |
|
18 | 18 | import io.micrometer.core.Issue;
|
| 19 | +import io.micrometer.core.instrument.LongTaskTimer.Sample; |
19 | 20 | import io.micrometer.core.instrument.Timer;
|
20 | 21 | import io.micrometer.core.instrument.*;
|
21 | 22 | import io.micrometer.core.instrument.binder.BaseUnits;
|
@@ -583,12 +584,231 @@ void timerSumAndMaxHaveCorrectBaseUnit_whenPercentileHistogramEnabled() {
|
583 | 584 | }
|
584 | 585 |
|
585 | 586 | @Test
|
586 |
| - void scrapeWithLongTaskTimer() { |
587 |
| - LongTaskTimer.builder("my.long.task.timer").register(registry); |
588 |
| - assertThat(registry.scrape()).contains("my_long_task_timer_seconds_max") |
589 |
| - // since Prometheus client 1.x, suffix _active_count => _count |
590 |
| - .contains("my_long_task_timer_seconds_count") |
591 |
| - .contains("my_long_task_timer_seconds_sum"); |
| 587 | + @Issue("#4988") |
| 588 | + void longTaskTimerRecordingsSchouldBeCorrect() { |
| 589 | + LongTaskTimer ltt = LongTaskTimer.builder("test.ltt").publishPercentileHistogram().register(registry); |
| 590 | + |
| 591 | + String result = registry.scrape(); |
| 592 | + // since Prometheus client 1.x, suffix _active_count => _gcount and _sum => _gsum |
| 593 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"120.0\"} 0\n"); |
| 594 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"7200.0\"} 0\n"); |
| 595 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"+Inf\"} 0\n"); |
| 596 | + assertThat(result).contains("test_ltt_seconds_gcount 0\n"); |
| 597 | + assertThat(result).contains("test_ltt_seconds_gsum 0.0\n"); |
| 598 | + assertThat(result).contains("test_ltt_seconds_max 0.0\n"); |
| 599 | + |
| 600 | + // A task started |
| 601 | + Sample sample = ltt.start(); |
| 602 | + clock.add(150, TimeUnit.SECONDS); |
| 603 | + result = registry.scrape(); |
| 604 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"120.0\"} 0\n"); |
| 605 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"137.438953471\"} 0\n"); |
| 606 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"160.345445716\"} 1\n"); |
| 607 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"7200.0\"} 1\n"); |
| 608 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"+Inf\"} 1\n"); |
| 609 | + assertThat(result).contains("test_ltt_seconds_gcount 1\n"); |
| 610 | + assertThat(result).contains("test_ltt_seconds_gsum 150.0\n"); |
| 611 | + assertThat(result).contains("test_ltt_seconds_max 150.0\n"); |
| 612 | + |
| 613 | + // After a while another scrape happens, the task is still in progress... |
| 614 | + clock.add(20, TimeUnit.SECONDS); |
| 615 | + result = registry.scrape(); |
| 616 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"120.0\"} 0\n"); |
| 617 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"137.438953471\"} 0\n"); |
| 618 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"160.345445716\"} 0\n"); |
| 619 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"183.251937961\"} 1\n"); |
| 620 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"7200.0\"} 1\n"); |
| 621 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"+Inf\"} 1\n"); |
| 622 | + assertThat(result).contains("test_ltt_seconds_gcount 1\n"); |
| 623 | + assertThat(result).contains("test_ltt_seconds_gsum 170.0\n"); |
| 624 | + assertThat(result).contains("test_ltt_seconds_max 170.0\n"); |
| 625 | + |
| 626 | + // Another task started |
| 627 | + Sample sample2 = ltt.start(); |
| 628 | + clock.add(10, TimeUnit.SECONDS); |
| 629 | + result = registry.scrape(); |
| 630 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"120.0\"} 1\n"); |
| 631 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"137.438953471\"} 1\n"); |
| 632 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"160.345445716\"} 1\n"); |
| 633 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"183.251937961\"} 2\n"); |
| 634 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"7200.0\"} 2\n"); |
| 635 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"+Inf\"} 2\n"); |
| 636 | + assertThat(result).contains("test_ltt_seconds_gcount 2\n"); |
| 637 | + assertThat(result).contains("test_ltt_seconds_gsum 190.0\n"); |
| 638 | + assertThat(result).contains("test_ltt_seconds_max 180.0\n"); |
| 639 | + |
| 640 | + sample2.stop(); |
| 641 | + |
| 642 | + // After the second task stopped |
| 643 | + clock.add(1, TimeUnit.SECONDS); |
| 644 | + result = registry.scrape(); |
| 645 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"120.0\"} 0\n"); |
| 646 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"137.438953471\"} 0\n"); |
| 647 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"160.345445716\"} 0\n"); |
| 648 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"183.251937961\"} 1\n"); |
| 649 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"7200.0\"} 1\n"); |
| 650 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"+Inf\"} 1\n"); |
| 651 | + assertThat(result).contains("test_ltt_seconds_gcount 1\n"); |
| 652 | + assertThat(result).contains("test_ltt_seconds_gsum 181.0\n"); |
| 653 | + assertThat(result).contains("test_ltt_seconds_max 181.0\n"); |
| 654 | + |
| 655 | + sample.stop(); |
| 656 | + |
| 657 | + // After the first task stopped |
| 658 | + clock.add(10, TimeUnit.SECONDS); |
| 659 | + result = registry.scrape(); |
| 660 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"120.0\"} 0\n"); |
| 661 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"7200.0\"} 0\n"); |
| 662 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"+Inf\"} 0\n"); |
| 663 | + assertThat(result).contains("test_ltt_seconds_gcount 0\n"); |
| 664 | + assertThat(result).contains("test_ltt_seconds_gsum 0.0\n"); |
| 665 | + assertThat(result).contains("test_ltt_seconds_max 0.0\n"); |
| 666 | + } |
| 667 | + |
| 668 | + @Test |
| 669 | + @Issue("#4988") |
| 670 | + void longTaskTimerInfBucketShouldBeCorrect() { |
| 671 | + LongTaskTimer ltt = LongTaskTimer.builder("test.ltt").publishPercentileHistogram().register(registry); |
| 672 | + |
| 673 | + String result = registry.scrape(); |
| 674 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"120.0\"} 0\n"); |
| 675 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"7200.0\"} 0\n"); |
| 676 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"+Inf\"} 0\n"); |
| 677 | + assertThat(result).contains("test_ltt_seconds_gcount 0\n"); |
| 678 | + assertThat(result).contains("test_ltt_seconds_gsum 0.0\n"); |
| 679 | + assertThat(result).contains("test_ltt_seconds_max 0.0\n"); |
| 680 | + |
| 681 | + // A task started |
| 682 | + Sample sample = ltt.start(); |
| 683 | + clock.add(7000, TimeUnit.SECONDS); |
| 684 | + result = registry.scrape(); |
| 685 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"120.0\"} 0\n"); |
| 686 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"5864.062014805\"} 0\n"); |
| 687 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"7200.0\"} 1\n"); |
| 688 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"+Inf\"} 1\n"); |
| 689 | + assertThat(result).contains("test_ltt_seconds_gcount 1\n"); |
| 690 | + assertThat(result).contains("test_ltt_seconds_gsum 7000.0\n"); |
| 691 | + assertThat(result).contains("test_ltt_seconds_max 7000.0\n"); |
| 692 | + |
| 693 | + // After a while another scrape happens, the task is still in progress... |
| 694 | + // Now the task is in the +Inf bucket |
| 695 | + clock.add(500, TimeUnit.SECONDS); |
| 696 | + result = registry.scrape(); |
| 697 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"120.0\"} 0\n"); |
| 698 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"5864.062014805\"} 0\n"); |
| 699 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"7200.0\"} 0\n"); |
| 700 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"+Inf\"} 1\n"); |
| 701 | + assertThat(result).contains("test_ltt_seconds_gcount 1\n"); |
| 702 | + assertThat(result).contains("test_ltt_seconds_gsum 7500.0\n"); |
| 703 | + assertThat(result).contains("test_ltt_seconds_max 7500.0\n"); |
| 704 | + |
| 705 | + // Another task started |
| 706 | + Sample sample2 = ltt.start(); |
| 707 | + clock.add(500, TimeUnit.SECONDS); |
| 708 | + result = registry.scrape(); |
| 709 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"120.0\"} 0\n"); |
| 710 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"458.129844906\"} 0\n"); |
| 711 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"549.755813887\"} 1\n"); |
| 712 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"5864.062014805\"} 1\n"); |
| 713 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"7200.0\"} 1\n"); |
| 714 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"+Inf\"} 2\n"); |
| 715 | + assertThat(result).contains("test_ltt_seconds_gcount 2\n"); |
| 716 | + assertThat(result).contains("test_ltt_seconds_gsum 8500.0\n"); |
| 717 | + assertThat(result).contains("test_ltt_seconds_max 8000.0\n"); |
| 718 | + |
| 719 | + sample2.stop(); |
| 720 | + |
| 721 | + // After the second task stopped |
| 722 | + clock.add(500, TimeUnit.SECONDS); |
| 723 | + result = registry.scrape(); |
| 724 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"120.0\"} 0\n"); |
| 725 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"458.129844906\"} 0\n"); |
| 726 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"549.755813887\"} 0\n"); |
| 727 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"5864.062014805\"} 0\n"); |
| 728 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"7200.0\"} 0\n"); |
| 729 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"+Inf\"} 1\n"); |
| 730 | + assertThat(result).contains("test_ltt_seconds_gcount 1\n"); |
| 731 | + assertThat(result).contains("test_ltt_seconds_gsum 8500.0\n"); |
| 732 | + assertThat(result).contains("test_ltt_seconds_max 8500.0\n"); |
| 733 | + |
| 734 | + sample.stop(); |
| 735 | + |
| 736 | + // After the first task stopped |
| 737 | + result = registry.scrape(); |
| 738 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"120.0\"} 0\n"); |
| 739 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"7200.0\"} 0\n"); |
| 740 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"+Inf\"} 0\n"); |
| 741 | + assertThat(result).contains("test_ltt_seconds_gcount 0\n"); |
| 742 | + assertThat(result).contains("test_ltt_seconds_gsum 0.0\n"); |
| 743 | + assertThat(result).contains("test_ltt_seconds_max 0.0\n"); |
| 744 | + } |
| 745 | + |
| 746 | + @Test |
| 747 | + @Issue("#4988") |
| 748 | + void nonTelescopicLongTaskTimerRecordingsShouldBeCorrect() { |
| 749 | + LongTaskTimer ltt = LongTaskTimer.builder("test.ltt").publishPercentileHistogram().register(registry); |
| 750 | + |
| 751 | + String result = registry.scrape(); |
| 752 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"120.0\"} 0\n"); |
| 753 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"7200.0\"} 0\n"); |
| 754 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"+Inf\"} 0\n"); |
| 755 | + assertThat(result).contains("test_ltt_seconds_gcount 0\n"); |
| 756 | + assertThat(result).contains("test_ltt_seconds_gsum 0.0\n"); |
| 757 | + assertThat(result).contains("test_ltt_seconds_max 0.0\n"); |
| 758 | + |
| 759 | + // A task started |
| 760 | + Sample sample = ltt.start(); |
| 761 | + clock.add(200, TimeUnit.SECONDS); |
| 762 | + result = registry.scrape(); |
| 763 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"120.0\"} 0\n"); |
| 764 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"183.251937961\"} 0\n"); |
| 765 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"206.158430206\"} 1\n"); |
| 766 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"7200.0\"} 1\n"); |
| 767 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"+Inf\"} 1\n"); |
| 768 | + assertThat(result).contains("test_ltt_seconds_gcount 1\n"); |
| 769 | + assertThat(result).contains("test_ltt_seconds_gsum 200.0\n"); |
| 770 | + assertThat(result).contains("test_ltt_seconds_max 200.0\n"); |
| 771 | + |
| 772 | + // A second task started before the first stopped |
| 773 | + Sample sample2 = ltt.start(); |
| 774 | + // The first task stopped |
| 775 | + sample.stop(); |
| 776 | + |
| 777 | + clock.add(100, TimeUnit.SECONDS); |
| 778 | + result = registry.scrape(); |
| 779 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"120.0\"} 1\n"); |
| 780 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"7200.0\"} 1\n"); |
| 781 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"+Inf\"} 1\n"); |
| 782 | + assertThat(result).contains("test_ltt_seconds_gcount 1\n"); |
| 783 | + assertThat(result).contains("test_ltt_seconds_gsum 100.0\n"); |
| 784 | + assertThat(result).contains("test_ltt_seconds_max 100.0\n"); |
| 785 | + |
| 786 | + // The second task stopped |
| 787 | + sample2.stop(); |
| 788 | + |
| 789 | + // A third task started after the first and second stopped |
| 790 | + Sample sample3 = ltt.start(); |
| 791 | + clock.add(300, TimeUnit.SECONDS); |
| 792 | + result = registry.scrape(); |
| 793 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"120.0\"} 0\n"); |
| 794 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"274.877906944\"} 0\n"); |
| 795 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"366.503875925\"} 1\n"); |
| 796 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"7200.0\"} 1\n"); |
| 797 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"+Inf\"} 1\n"); |
| 798 | + assertThat(result).contains("test_ltt_seconds_gcount 1\n"); |
| 799 | + assertThat(result).contains("test_ltt_seconds_gsum 300.0\n"); |
| 800 | + assertThat(result).contains("test_ltt_seconds_max 300.0\n"); |
| 801 | + |
| 802 | + // The third task stopped |
| 803 | + sample3.stop(); |
| 804 | + |
| 805 | + result = registry.scrape(); |
| 806 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"120.0\"} 0\n"); |
| 807 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"7200.0\"} 0\n"); |
| 808 | + assertThat(result).contains("test_ltt_seconds_bucket{le=\"+Inf\"} 0\n"); |
| 809 | + assertThat(result).contains("test_ltt_seconds_gcount 0\n"); |
| 810 | + assertThat(result).contains("test_ltt_seconds_gsum 0.0\n"); |
| 811 | + assertThat(result).contains("test_ltt_seconds_max 0.0\n"); |
592 | 812 | }
|
593 | 813 |
|
594 | 814 | @Issue("#2087")
|
|
0 commit comments