line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Starch::Plugin::Net::Statsd::Store; |
2
|
1
|
|
|
1
|
|
540
|
use 5.008001; |
|
1
|
|
|
|
|
12
|
|
3
|
1
|
|
|
1
|
|
6
|
use strictures 2; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
40
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
186
|
use Net::Statsd; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
7
|
1
|
|
|
1
|
|
5
|
use Types::Common::String -types; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
8
|
1
|
|
|
1
|
|
1943
|
use Time::HiRes qw( gettimeofday tv_interval ); |
|
1
|
|
|
|
|
1349
|
|
|
1
|
|
|
|
|
4
|
|
9
|
1
|
|
|
1
|
|
228
|
use Try::Tiny; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
65
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
6
|
use Moo::Role; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
12
|
1
|
|
|
1
|
|
383
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
with 'Starch::Plugin::ForStore'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has statsd_path => ( |
17
|
|
|
|
|
|
|
is => 'lazy', |
18
|
|
|
|
|
|
|
isa => NonEmptySimpleStr, |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
sub _build_statsd_path { |
21
|
4
|
|
|
4
|
|
48
|
my ($self) = @_; |
22
|
4
|
|
|
|
|
22
|
my $path = $self->short_store_class_name(); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Path sanitization stolen, and slightly modified, from the statsd source. |
25
|
4
|
|
|
|
|
136
|
$path =~ s{\s+}{_}g; |
26
|
4
|
|
|
|
|
12
|
$path =~ s{/}{-}g; |
27
|
4
|
|
|
|
|
10
|
$path =~ s{::}{-}g; |
28
|
4
|
|
|
|
|
12
|
$path =~ s{[^a-zA-Z_\-0-9\.]}{}g; |
29
|
|
|
|
|
|
|
|
30
|
4
|
|
|
|
|
67
|
return $path; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has statsd_full_path => ( |
34
|
|
|
|
|
|
|
is => 'lazy', |
35
|
|
|
|
|
|
|
isa => NonEmptySimpleStr, |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
sub _build_statsd_full_path { |
38
|
6
|
|
|
6
|
|
75
|
my ($self) = @_; |
39
|
6
|
|
|
|
|
135
|
return $self->manager->statsd_root_path() . '.' . $self->statsd_path(); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
foreach my $method (qw( set get remove )) { |
43
|
|
|
|
|
|
|
around $method => sub{ |
44
|
|
|
|
|
|
|
my ($orig, $self, @args) = @_; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
return $self->$orig( @args ) if $self->isa('Starch::Store::Layered'); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $path = $self->statsd_full_path() . '.' . $method; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my $start = [gettimeofday]; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my ($errored, $error); |
53
|
|
|
|
|
|
|
my $data = try { $self->$orig( @args ) } |
54
|
|
|
|
|
|
|
catch { ($errored, $error) = (1, $_) }; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $end = [gettimeofday]; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
if ($errored) { |
59
|
|
|
|
|
|
|
$path .= '-error'; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
elsif ($method eq 'get') { |
62
|
|
|
|
|
|
|
$path .= '-' . ($data ? 'hit' : 'miss'); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my $host = $self->manager->statsd_host(); |
66
|
|
|
|
|
|
|
local $Net::Statsd::HOST = $host if defined $host; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $port = $self->manager->statsd_port(); |
69
|
|
|
|
|
|
|
local $Net::Statsd::PORT = $port if defined $port; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Net::Statsd::timing( |
72
|
|
|
|
|
|
|
$path, |
73
|
|
|
|
|
|
|
tv_interval($start, $end) * 1000, |
74
|
|
|
|
|
|
|
$self->manager->statsd_sample_rate(), |
75
|
|
|
|
|
|
|
); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
die $error if $errored; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
return if $method ne 'get'; |
80
|
|
|
|
|
|
|
return $data; |
81
|
|
|
|
|
|
|
}; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |