blib/lib/Catalyst/Plugin/Statsd.pm

filter: Statementstmt 95.4% 42 / 44 Branchbran 44.4% 8 / 18 Conditioncond 42.8% 3 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 76.4% 65 / 85 CC 14 SCAR 19.4
CC
14
Cov
77%
__ANON__
13.3
__ANON__
8.7
statsd_metric_name_filter
2.0
CRAP 7.0
↑ Summary
1 package Catalyst::Plugin::Statsd;
2  
3 # ABSTRACT: Log Catalyst stats to statsd
4  
5 2 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use POSIX qw/ ceil /;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Ref::Util qw/ is_plain_arrayref /;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use experimental qw/ signatures /;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # RECOMMEND PREREQ: Ref::Util::XS
15  
16 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 requires qw/ log_stats /;
19  
20 2 our $VERSION = 'v0.10.1';
21  
22  
23 2 ▶sub statsd_client($c) {
Subroutine statsd_client: called CC=1 SCAR=0.0
Pod documented
24 2 return $c->req->env->{'psgix.monitor.statsd'};
25 }
26  
27  
28  
29 6 ▶sub statsd_metric_name_filter( $c, $stat ) {
Subroutine statsd_metric_name_filter: called CC=2 SCAR=7.0
Pod documented
30  
31 6 ▶ return "$stat" unless is_plain_arrayref($stat);
Branch: 1 branch
BranchTrueFalseTotal
unless Ref::Util::XS::is_plain_arrayref($stat) 0 6 6
32  
33 6 my $metric = "catalyst.stats." . $stat->[1] . ".time";
34 6 $metric =~ s/[^\w\-_]+/./g;
35  
36 6 return $metric;
37 }
38  
39 2 ▶around log_stats => sub ( $next, $c ) {
Subroutine __ANON__: called CC=8 SCAR=21.6
40  
41 2 ▶ state $config = $c->config->{'Plugin::Statsd'} // {};
Condition50%1/2
$c->config->{"Plugin::Statsd"} // {}
l!l
20
MC/DC0%0/1
$c->config->{"Plugin::Statsd"} // {}
$c->config->{"Plugin::Statsd"}
Truth table50%1/2
A
A= $c->config->{"Plugin::Statsd"}
Aresult
11
00
42  
43 2 ▶ if ( my $client = $c->statsd_client) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $client = $c->statsd_client) 2 0 2
44  
45 2 my $stat = [ -1, "catalyst.response.time", $c->stats->elapsed ];
46 2 ▶ my $metric = $c->statsd_metric_name_filter($stat) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $metric = $c->statsd_metric_name_filter($stat) or next 2 0 2
47  
48 2 $client->timing_ms( "catalyst.response.time",
49 ceil( $stat->[2] * 1000 ) );
50  
51 2 foreach my $stat ( $c->stats->report ) {
52  
53 4 ▶ my $metric = $c->statsd_metric_name_filter($stat) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $metric = $c->statsd_metric_name_filter($stat) or next 4 0 4
54 4 my $timing = ceil( $stat->[2] * 1000 );
55  
56 4 $client->timing_ms( $metric, $timing );
57  
58 }
59  
60 }
61  
62 2 ▶ my $disabled = $config->{disable_stats_report} // !$c->debug;
Condition50%1/2
$config->{"disable_stats_report"} // !$c->debug
l!l
20
MC/DC0%0/1
$config->{"disable_stats_report"} // !$c->debug
$config->{"disable_stats_report"}
Truth table50%1/2
A
A= $config->{"disable_stats_report"}
Aresult
11
00
63  
64 2 ▶ $c->$next unless $disabled;
Branch: 1 branch
BranchTrueFalseTotal
unless $disabled 1 1 2
65 2 };
66  
67 2 ▶around finalize => sub ( $next, $c ) {
Subroutine __ANON__: called CC=6 SCAR=25.9
68  
69 2 ▶ if (my $secure = $c->req->env->{'psgix.monitor.statsd_secure_set_add'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $secure = $c->req->env->{"psgix.monitor.statsd_secure_set_add"}) 2 0 2
70  
71 2 ▶ if ($c->can("sessionid") && (my $id = $c->sessionid)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($c->can('sessionid') and my $id = $c->sessionid) { } 2 0 2
elsif (my $options = $c->req->env->{'psgix.session.options'}) { } 0 0 0
Condition33%1/3
$c->can("sessionid") and my $id = $c->sessionid
!ll&&!rl&&r
002
MC/DC0%0/2
$c->can("sessionid") and my $id = $c->sessionid
$c->can("sessionid") my $id = $c->sessionid
Truth table33%1/3
A and B
A= $c->can("sessionid")B= my $id = $c->sessionid
ABresult
0X0
100
111
72 2 $secure->("catalyst.sessionid", "$id");
73 }
74 # Plack::Middleware::Session
75 elsif (my $options = $c->req->env->{'psgix.session.options'}) {
76 0 ▶ if (my $id = $options->{id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $id = $options->{"id"}) 0 0 0
77 0 $secure->("catalyst.sessionid", "$id");
78 }
79 }
80 }
81  
82 2 $c->$next();
83 2 };
84  
85  
86 2 1;
87  
88 __END__
↑ Summary