lib/ForgeOps/Tracker/HistogramBucketer.pm

filter: Statementstmt 100% 14 / 14 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 95.2% 20 / 21 CC 3 SCAR 6.9
CC
3
Cov
100%
bucket_for
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.0
« lib/ForgeOps/Tracker/Reporter.pm ↑ Summary lib/ForgeOps/Tracker/DeliveryQueue.pm »
1 package ForgeOps::Tracker::HistogramBucketer;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # Buckets a single duration into one of a fixed set of latency-range labels, the building block
7 # PerformanceFlusher uses to accumulate an approximate distribution (not just count/sum/max)
8 # alongside every transaction bucket it already tallies. The server merges these counts across
9 # matching samples at read time and walks cumulative counts to approximate a percentile, accurate
10 # to the bucket width: this SDK never stores the raw duration list a true percentile would need.
11 # Ported from gems/forge_ops_tracker/lib/forge_ops_tracker/histogram_bucketer.rb.
12 #
13 # BOUNDARIES_MS is duplicated on the server side, in app/services/histogram_percentile.rb. Change
14 # one, change the other, or a released SDK version and the server it talks to would silently
15 # disagree about what each bucket label means.
16 1 ▶use constant BOUNDARIES_MS => (50, 100, 250, 500, 1000, 2500, 5000, 10000);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # Returns the label (a string) of the smallest boundary $duration_ms fits under, or "inf" for
19 # anything larger than the largest boundary. A string, not a number: this travels as a JSON object
20 # key once flushed, and JSON object keys are always strings.
21 14 ▶sub bucket_for {
Subroutine bucket_for: called CC=3 SCAR=11.0
Pod undocumented
22 14 my ($duration_ms) = @_;
23 14 for my $boundary (BOUNDARIES_MS) {
24 63 ▶ return "$boundary" if $duration_ms <= $boundary;
Branch: 1 branch
BranchTrueFalseTotal
if $duration_ms <= $boundary 12 51 63
25 }
26 2 return 'inf';
27 }
28  
29 1 1;
« lib/ForgeOps/Tracker/Reporter.pm ↑ Summary lib/ForgeOps/Tracker/DeliveryQueue.pm »