| 1 | package Punk::Observe::Health; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Punk::Observe (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Punk::Observe::Store (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Punk::Observe::Target (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use File::Raw::JSON (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Fetch; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | our $VERSION = $Punk::Observe::VERSION; | |||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | M_OK => 'punk.health.ok', | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | M_MS => 'punk.health.ms', | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # The store's budgets default to 500,000 when left unset. A STRING, not | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # `1 << 62`, because a perl with 32-bit integers does not have that number and | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # would quietly pass something else; the store parses nanosecond-width decimals | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # everywhere already. | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | ▶ | use constant NO_CEILING => '4611686018427387904'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # Every query here is one this file wrote, and every one of them is an | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # aggregate over the window - so none can be answered by stopping part way. An | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # uptime band that stops mid-window reports a service as up because the scan | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # ran out, which is the one reading this page must never give. It is also what | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # keeps the page cheap: a chunk that truncates is never cached, so a query left | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # on the default ceiling has its busiest chunk rescanned on every poll. | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 15 | ▶ | sub _read { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 15 | my ($store, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | 15 | push @args, limit => NO_CEILING, hard_max => NO_CEILING, | |||||||||||||||||||||||||||||||||||||||||||||
| 36 | max_rows => NO_CEILING; | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 15 | ▶ | return $store->can('cached_query') | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | ? $store->cached_query(@args) | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | : $store->query(@args); | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 519 | ▶ | sub _rec { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rec: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 519 | my ($t, $name, $value, $attrs) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | 519 | return { t => $t, kind => 1, body => $name, value => $value + 0, | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | severity => 0, span_kind => 0, status => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | trace_hi => 0, trace_lo => 0, span_id => 0, parent_id => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | attrs => $attrs }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 172 | ▶ | sub points { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
points: called CC=22 SCAR=31.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 172 | my ($target, $status, $body, $now, $rtt_ms) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 52 | 172 | ▶ | $now = Punk::Observe::now_ns() unless defined $now; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 172 | my @recs; | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 172 | ▶ | push @recs, _rec($now, M_MS, 0 + sprintf('%.3f', $rtt_ms), | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $rtt_ms and $status
MC/DC100%2/2
defined $rtt_ms and $status
defined $rtt_ms
$status
Truth table100%3/3
A and B
A= defined $rtt_msB= $status
| |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | { target => $target }) | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | if defined $rtt_ms && $status; | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 172 | ▶ | if (!defined $status || !$status) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $status and $status
MC/DC50%1/2
defined $status and $status
defined $status
$status
Truth table66%2/3
A and B
A= defined $statusB= $status
| |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 8 | push @recs, _rec($now, M_OK, 0, | |||||||||||||||||||||||||||||||||||||||||||||
| 61 | { target => $target, state => 'unreachable' }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 8 | return (\@recs, 'error'); | |||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 164 | my $doc = eval { File::Raw::JSON::file_json_decode($body) }; | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | 164 | ▶ | if (!$doc || ref $doc ne 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $doc or ref $doc ne "HASH"
MC/DC50%1/2
not $doc or ref $doc ne "HASH"
not $doc
ref $doc ne "HASH"
Truth table66%2/3
not(A) or B
A= not $docB= ref $doc ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | push @recs, _rec($now, M_OK, 0, | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | { target => $target, state => 'unknown' }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | return (\@recs, 'error'); | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 163 | ▶ | my $ready = (defined $doc->{status} && $doc->{status} eq 'ok') ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $doc->{"status"} and $doc->{"status"} eq "ok"
MC/DC50%1/2
defined $doc->{"status"} and $doc->{"status"} eq "ok"
defined $doc->{"status"}
$doc->{"status"} eq "ok"
Truth table66%2/3
A and B
A= defined $doc->{"status"}B= $doc->{"status"} eq "ok"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 163 | ▶ | $ready = 0 if $status >= 500; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 163 | ▶ | push @recs, _rec($now, M_OK, $ready, | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | { target => $target, | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | state => ($ready ? 'ready' : 'unready') }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 163 | my $checks = $doc->{checks}; | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | 163 | ▶ | return (\@recs, $ready ? 'ok' : 'error') | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
ref $checks eq "HASH" and %$checks
MC/DC50%1/2
ref $checks eq "HASH" and %$checks
ref $checks eq "HASH"
%$checks
Truth table66%2/3
A and B
A= ref $checks eq "HASH"B= %$checks
| |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | unless ref $checks eq 'HASH' && %$checks; | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 161 | for my $name (sort keys %$checks) { | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | 174 | my $c = $checks->{$name}; | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | 174 | ▶ | next unless ref $c eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 174 | my $labels = { target => $target, check => $name }; | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 174 | ▶ | if ($c->{skipped}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | $labels->{skipped} = 'true'; | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | push @recs, _rec($now, M_OK, 0, $labels); | |||||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 173 | ▶ | push @recs, _rec($now, M_OK, ($c->{ok} ? 1 : 0), $labels); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | push @recs, _rec($now, M_MS, ($c->{ms} || 0) + 0, $labels) | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 173 | ▶ | if defined $c->{ms}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$c->{'ms'} || 0
MC/DC0%0/1
$c->{'ms'} || 0
$c->{'ms'}
Truth table50%1/2
A
A= $c->{'ms'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 161 | ▶ | return (\@recs, $ready ? 'ok' : 'error'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 8 | ▶ | sub poll { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
poll: called CC=8 SCAR=21.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 8 | my ($target, %opt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 103 | 8 | ▶ | my $now = $opt{now} || Punk::Observe::now_ns(); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$opt{'now'} || Punk::Observe::now_ns()
MC/DC0%0/2
$opt{'now'} || Punk::Observe::now_ns()
$opt{'now'}
Punk::Observe::now_ns()
Truth table33%1/3
A || B
A= $opt{'now'}B= Punk::Observe::now_ns()
| |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 8 | my $url = $target->{url}; | |||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 8 | my $t = Punk::Observe::Target::check($url, $opt{allow}); | |||||||||||||||||||||||||||||||||||||||||||||
| 107 | 8 | ▶ | return (points($target->{name}, 0, '', $now))[0] unless $t->{ok}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 3 | ▶ | my $timeout = ($target->{timeout_ms} || 5000) / 1000; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$target->{'timeout_ms'} || 5000
MC/DC100%1/1
$target->{'timeout_ms'} || 5000
$target->{'timeout_ms'}
Truth table100%2/2
A
A= $target->{'timeout_ms'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 3 | my ($status, $body) = (0, ''); | |||||||||||||||||||||||||||||||||||||||||||||
| 111 | 3 | require Time::HiRes; | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | 3 | my $t0 = Time::HiRes::time(); | |||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 3 | eval { | |||||||||||||||||||||||||||||||||||||||||||||
| 115 | 3 | my $ua = $opt{ua}; | |||||||||||||||||||||||||||||||||||||||||||||
| 116 | 3 | ▶ | unless ($ua) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | $ua = Fetch->new(timeout => $timeout, | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | ($opt{loop} ? (loop => $opt{loop}) : ())); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 3 | my $res = $ua->get($url)->get; | |||||||||||||||||||||||||||||||||||||||||||||
| 121 | 2 | ▶ | if ($res) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 2 | $status = $res->status; | |||||||||||||||||||||||||||||||||||||||||||||
| 123 | 2 | $body = $res->content; | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | 2 | ▶ | $body = '' unless defined $body; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 3 | my $rtt_ms = (Time::HiRes::time() - $t0) * 1000; | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | 3 | return (points($target->{name}, $status, $body, $now, $rtt_ms))[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 6 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=10 SCAR=25.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 6 | my (%opt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | 6 | ▶ | my $db = $opt{db} or return []; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 6 | ▶ | my $tenant = defined $opt{tenant} ? $opt{tenant} : 'default'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 6 | ▶ | my $now = $opt{now} || Punk::Observe::now_ns(); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$opt{'now'} || Punk::Observe::now_ns()
MC/DC0%0/2
$opt{'now'} || Punk::Observe::now_ns()
$opt{'now'}
Punk::Observe::now_ns()
Truth table66%2/3
A || B
A= $opt{'now'}B= Punk::Observe::now_ns()
| |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 6 | require Punk::Observe::Config; | |||||||||||||||||||||||||||||||||||||||||||||
| 139 | 6 | my $targets = Punk::Observe::Config::health_targets($db, $tenant); | |||||||||||||||||||||||||||||||||||||||||||||
| 140 | 6 | ▶ | return [] unless ref $targets eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 6 | my $ua = $opt{ua}; | |||||||||||||||||||||||||||||||||||||||||||||
| 143 | 6 | ▶ | if (!$ua && $opt{loop}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $ua and $opt{"loop"}
MC/DC0%0/2
not $ua and $opt{"loop"}
not $ua
$opt{"loop"}
Truth table66%2/3
not(A) and B
A= not $uaB= $opt{"loop"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | eval { require Fetch; $ua = Fetch->new(loop => $opt{loop}); 1 }; | |||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 6 | my @recs; | |||||||||||||||||||||||||||||||||||||||||||||
| 148 | 6 | for my $t (@$targets) { | |||||||||||||||||||||||||||||||||||||||||||||
| 149 | 2 | ▶ | next unless $t->{enabled}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | my $r = eval { poll($t, ua => $ua, allow => $opt{allow}, now => $now) }; | |||||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | ▶ | push @recs, @$r if ref $r eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 6 | return \@recs; | |||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 5 | ▶ | sub run_and_store { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_and_store: called CC=7 SCAR=21.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 5 | my (%opt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 158 | 5 | ▶ | my $store = $opt{store} or return 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 5 | my $recs = run(%opt); | |||||||||||||||||||||||||||||||||||||||||||||
| 160 | 5 | ▶ | return 0 unless @$recs; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 1 | require Punk::Observe::WAL; | |||||||||||||||||||||||||||||||||||||||||||||
| 163 | 1 | my $r = Punk::Observe::WAL::append($store->wal_path, $recs, 1, '200000000'); | |||||||||||||||||||||||||||||||||||||||||||||
| 164 | 1 | ▶ | return 0 unless $r && $r->{ok} && $r->{frames}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$r and $r->{"ok"} and $r->{"frames"}
$r and $r->{"ok"}
MC/DC0%0/3
$r and $r->{"ok"} and $r->{"frames"}
$r
$r->{"ok"}
$r->{"frames"}
Truth table25%1/4
A and B and C
A= $rB= $r->{"ok"}C= $r->{"frames"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 1 | ▶ | $store->seal_if_full($r->{bytes} || 0); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$r->{'bytes'} || 0
MC/DC0%0/1
$r->{'bytes'} || 0
$r->{'bytes'}
Truth table50%1/2
A
A= $r->{'bytes'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 1 | return scalar @$recs; | |||||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 3 | ▶ | sub page_vars { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
page_vars: called CC=43 SCAR=42.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 3 | my (%opt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 171 | 3 | my $store = $opt{store}; | |||||||||||||||||||||||||||||||||||||||||||||
| 172 | 3 | my $db = $opt{db}; | |||||||||||||||||||||||||||||||||||||||||||||
| 173 | 3 | ▶ | my $tenant = defined $opt{tenant} ? $opt{tenant} : 'default'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 3 | ▶ | my $now = $opt{now} || Punk::Observe::now_ns(); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$opt{'now'} || Punk::Observe::now_ns()
MC/DC0%0/2
$opt{'now'} || Punk::Observe::now_ns()
$opt{'now'}
Punk::Observe::now_ns()
Truth table33%1/3
A || B
A= $opt{'now'}B= Punk::Observe::now_ns()
| |||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 3 | ▶ | my $window = $opt{window_ns} || 3_600 * 1_000_000_000; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opt{'window_ns'} || 3600000000000
MC/DC0%0/1
$opt{'window_ns'} || 3600000000000
$opt{'window_ns'}
Truth table50%1/2
A
A= $opt{'window_ns'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 3 | my $from = Punk::Observe::Store::nsub($now, $window); | |||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||
| 178 | my $targets = $db | ||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 3 | ▶ | ? eval { require Punk::Observe::Config; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 3 | Punk::Observe::Config::health_targets($db, $tenant) } | |||||||||||||||||||||||||||||||||||||||||||||
| 181 | : undef; | ||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 3 | ▶ | $targets = [] unless ref $targets eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 3 | my @out; | |||||||||||||||||||||||||||||||||||||||||||||
| 185 | 3 | for my $t (@$targets) { | |||||||||||||||||||||||||||||||||||||||||||||
| 186 | my $row = { | ||||||||||||||||||||||||||||||||||||||||||||||
| 187 | name => $t->{name}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 188 | url => $t->{url}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 189 | every_s => int(($t->{every_ns} || 60_000_000_000) / 1_000_000_000), | ||||||||||||||||||||||||||||||||||||||||||||||
| 190 | timeout_ms => $t->{timeout_ms} || 5000, | ||||||||||||||||||||||||||||||||||||||||||||||
| 191 | enabled => ($t->{enabled} ? 1 : 0), | ||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 6 | ▶ | state => ($t->{enabled} ? 'never polled' : 'disabled'), | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%2/4
$t->{'every_ns'} || 60000000000
$t->{'timeout_ms'} || 5000
MC/DC0%0/1
$t->{'every_ns'} || 60000000000
$t->{'every_ns'}
MC/DC0%0/1
$t->{'timeout_ms'} || 5000
$t->{'timeout_ms'}
Truth table50%1/2
A
A= $t->{'every_ns'}
Truth table50%1/2
A
A= $t->{'timeout_ms'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 193 | ok => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 194 | held => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 195 | held_min => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 196 | checks => [], | ||||||||||||||||||||||||||||||||||||||||||||||
| 197 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 6 | push @out, $row; | |||||||||||||||||||||||||||||||||||||||||||||
| 199 | 6 | ▶ | next unless $store && $t->{enabled}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$store and $t->{"enabled"}
MC/DC0%0/2
$store and $t->{"enabled"}
$store
$t->{"enabled"}
Truth table33%1/3
A and B
A= $storeB= $t->{"enabled"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 6 | ▶ | my $secs = int(($t->{every_ns} || 60_000_000_000) / 1_000_000_000) || 60; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
int(($t->{'every_ns'} || 60000000000) / 1000000000) || 60
$t->{'every_ns'} || 60000000000
MC/DC0%0/1
int(($t->{'every_ns'} || 60000000000) / 1000000000) || 60
$t->{'every_ns'}
Truth table50%1/2
A
A= $t->{'every_ns'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 202 | my $q = sprintf('metric %s | where target == "%s" | bucket(%ds) min by check', | ||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 6 | M_OK, $t->{name}, $secs); | |||||||||||||||||||||||||||||||||||||||||||||
| 204 | 6 | my $res = eval { _read($store, $q, from => $from, to => $now) }; | |||||||||||||||||||||||||||||||||||||||||||||
| 205 | 6 | ▶ | next unless $res && $res->{ok} && ref $res->{series} eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$res and $res->{"ok"} and ref $res->{"series"} eq "ARRAY"
$res and $res->{"ok"}
MC/DC0%0/3
$res and $res->{"ok"} and ref $res->{"series"} eq "ARRAY"
$res
$res->{"ok"}
ref $res->{"series"} eq "ARRAY"
Truth table25%1/4
A and B and C
A= $resB= $res->{"ok"}C= ref $res->{"series"} eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 6 | for my $s (@{ $res->{series} }) { | |||||||||||||||||||||||||||||||||||||||||||||
| 208 | 9 | ▶ | my @pts = @{ $s->{points} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$s->{'points'} || []
MC/DC0%0/1
$s->{'points'} || []
$s->{'points'}
Truth table50%1/2
A
A= $s->{'points'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 9 | ▶ | next unless @pts; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 9 | @pts = sort { Punk::Observe::Store::ncmp($a->[0], $b->[0]) } @pts; | |||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 9 | my $last = $pts[-1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 213 | 9 | ▶ | my $val = ($last->[1] || 0) >= 1 ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$last->[1] || 0
MC/DC100%1/1
$last->[1] || 0
$last->[1]
Truth table100%2/2
A
A= $last->[1]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 9 | my $since = $last->[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 216 | 9 | my $walked = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 217 | 9 | for my $p (reverse @pts) { | |||||||||||||||||||||||||||||||||||||||||||||
| 218 | 178 | ▶ | last if ((($p->[1] || 0) >= 1) ? 1 : 0) != $val; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%2/2
$p->[1] || 0
MC/DC100%1/1
$p->[1] || 0
$p->[1]
Truth table100%2/2
A
A= $p->[1]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 176 | $since = $p->[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 220 | 176 | $walked++; | |||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 9 | my $held = Punk::Observe::Store::nsub($now, $since); | |||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 9 | ▶ | my $capped = ($walked >= scalar @pts) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 9 | ▶ | my $key = defined $s->{key} ? $s->{key} : ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 9 | ▶ | if (!length $key) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 4 | $row->{ok} = $val; | |||||||||||||||||||||||||||||||||||||||||||||
| 229 | 4 | $row->{held} = $held; | |||||||||||||||||||||||||||||||||||||||||||||
| 230 | 4 | $row->{held_min} = $capped; | |||||||||||||||||||||||||||||||||||||||||||||
| 231 | 4 | ▶ | $row->{state} = $val ? 'ready' : 'not ready'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 233 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 5 | ▶ | push @{ $row->{checks} }, { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 235 | name => $key, | ||||||||||||||||||||||||||||||||||||||||||||||
| 236 | ok => $val, | ||||||||||||||||||||||||||||||||||||||||||||||
| 237 | state => ($val ? 'ok' : 'failing'), | ||||||||||||||||||||||||||||||||||||||||||||||
| 238 | held => $held, | ||||||||||||||||||||||||||||||||||||||||||||||
| 239 | held_min => $capped, | ||||||||||||||||||||||||||||||||||||||||||||||
| 240 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 1 | @{ $row->{checks} } = sort { $a->{name} cmp $b->{name} } | |||||||||||||||||||||||||||||||||||||||||||||
| 244 | 6 | @{ $row->{checks} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||
| 246 | my $qm = sprintf('metric %s | where target == "%s" | bucket(%ds) max by check', | ||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 6 | M_MS, $t->{name}, $secs); | |||||||||||||||||||||||||||||||||||||||||||||
| 248 | 6 | my $ms = eval { _read($store, $qm, from => $from, to => $now) }; | |||||||||||||||||||||||||||||||||||||||||||||
| 249 | 6 | ▶ | if ($ms && $ms->{ok} && ref $ms->{series} eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$ms and $ms->{"ok"} and ref $ms->{"series"} eq "ARRAY"
$ms and $ms->{"ok"}
MC/DC0%0/3
$ms and $ms->{"ok"} and ref $ms->{"series"} eq "ARRAY"
$ms
$ms->{"ok"}
ref $ms->{"series"} eq "ARRAY"
Truth table25%1/4
A and B and C
A= $msB= $ms->{"ok"}C= ref $ms->{"series"} eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 6 | my %by_check; | |||||||||||||||||||||||||||||||||||||||||||||
| 251 | 6 | for my $s (@{ $ms->{series} }) { | |||||||||||||||||||||||||||||||||||||||||||||
| 252 | 135 | my @pts = sort { Punk::Observe::Store::ncmp($a->[0], $b->[0]) } | |||||||||||||||||||||||||||||||||||||||||||||
| 253 | 5 | ▶ | @{ $s->{points} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$s->{'points'} || []
MC/DC0%0/1
$s->{'points'} || []
$s->{'points'}
Truth table50%1/2
A
A= $s->{'points'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 5 | ▶ | next unless @pts; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 5 | ▶ | my $key = defined $s->{key} ? $s->{key} : ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 5 | ▶ | my $val = sprintf('%.2f', $pts[-1][1] || 0); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$pts[-1][1] || 0
MC/DC0%0/1
$pts[-1][1] || 0
$pts[-1][1]
Truth table50%1/2
A
A= $pts[-1][1]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | if (!length $key) { $row->{ms} = $val } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 5 | else { $by_check{$key} = $val } | |||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 6 | for my $c (@{ $row->{checks} }) { | |||||||||||||||||||||||||||||||||||||||||||||
| 261 | $c->{ms} = $by_check{ $c->{name} } | ||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 5 | ▶ | if exists $by_check{ $c->{name} }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 3 | return \@out; | |||||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 2 | my $UP_BUCKETS = 120; # across the window, whatever it is | |||||||||||||||||||||||||||||||||||||||||||||
| 270 | 2 | my $UP_MIN_NS = 30 * 1_000_000_000; | |||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 3 | ▶ | sub _up_bucket_ns { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_up_bucket_ns: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 3 | my ($from, $to) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 274 | 3 | my $span = Punk::Observe::Store::nsub($to, $from); | |||||||||||||||||||||||||||||||||||||||||||||
| 275 | 3 | my $each = int(($span + 0) / $UP_BUCKETS); | |||||||||||||||||||||||||||||||||||||||||||||
| 276 | 3 | ▶ | $each = $UP_MIN_NS if $each < $UP_MIN_NS; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 3 | ▶ | my $secs = int($each / 1_000_000_000) || 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
int $each / 1000000000 || 1
MC/DC0%0/1
int $each / 1000000000 || 1
int $each / 1000000000
Truth table50%1/2
A
A= int $each / 1000000000
| |||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 3 | return $secs; | |||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 5 | ▶ | sub uptime_events { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
uptime_events: called CC=21 SCAR=33.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 5 | my (%opt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 283 | 5 | ▶ | my $store = $opt{store} or return []; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 4 | my ($from, $to) = @opt{qw(from to)}; | |||||||||||||||||||||||||||||||||||||||||||||
| 285 | 4 | ▶ | return [] unless defined $from && defined $to; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $from and defined $to
MC/DC50%1/2
defined $from and defined $to
defined $from
defined $to
Truth table66%2/3
A and B
A= defined $fromB= defined $to
| |||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 3 | my $secs = _up_bucket_ns($from, $to); | |||||||||||||||||||||||||||||||||||||||||||||
| 288 | 3 | my $res = eval { | |||||||||||||||||||||||||||||||||||||||||||||
| 289 | 3 | _read($store, 'metric ' . M_OK . " | bucket(${secs}s) min by target, check", | |||||||||||||||||||||||||||||||||||||||||||||
| 290 | from => $from, to => $to) | ||||||||||||||||||||||||||||||||||||||||||||||
| 291 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 3 | ▶ | return [] unless $res && $res->{ok} && ($res->{shape} || '') eq 'buckets'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition37%3/8
$res and $res->{"ok"} and ($res->{"shape"} || "") eq "buckets"
$res and $res->{"ok"}
$res->{'shape'} || ''
MC/DC0%0/3
$res and $res->{"ok"} and ($res->{"shape"} || "") eq "buckets"
$res
$res->{"ok"}
$res->{'shape'}
Truth table25%1/4
A and B and C
A= $resB= $res->{"ok"}C= $res->{'shape'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 3 | my @ev; | |||||||||||||||||||||||||||||||||||||||||||||
| 295 | 3 | ▶ | for my $ser (@{ $res->{series} || [] }) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$res->{'series'} || []
MC/DC0%0/1
$res->{'series'} || []
$res->{'series'}
Truth table50%1/2
A
A= $res->{'series'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 6 | ▶ | my ($target, $check) = split /\x1f/, ($ser->{key} // ''), 2; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ser->{"key"} // ""
MC/DC0%0/1
$ser->{"key"} // ""
$ser->{"key"}
Truth table50%1/2
A
A= $ser->{"key"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 6 | ▶ | next unless defined $target && length $target; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $target and length $target
MC/DC0%0/2
defined $target and length $target
defined $target
length $target
Truth table33%1/3
A and B
A= defined $targetB= length $target
| |||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 6 | ▶ | my $label = (defined $check && length $check) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $check and length $check
MC/DC50%1/2
defined $check and length $check
defined $check
length $check
Truth table66%2/3
A and B
A= defined $checkB= length $check
| |||||||||||||||||||||||||||||||||||||||||||||||
| 299 | ? "$target \x{203a} $check" : $target; | ||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 60 | ▶ | my @pts = sort { length($a->[0]) <=> length($b->[0]) | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
length $Punk::Observe::Health::a->[0] <=> length $Punk::Observe::Health::b->[0] || $Punk::Observe::Health::a->[0] cmp $Punk::Observe::Health::b->[0]
MC/DC0%0/2
length $Punk::Observe::Health::a->[0] <=> length $Punk::Observe::Health::b->[0] || $Punk::Observe::Health::a->[0] cmp $Punk::Observe::Health::b->[0]
length $Punk::Observe::Health::a->[0] <=> length $Punk::Observe::Health::b->[0]
$Punk::Observe::Health::a->[0] cmp $Punk::Observe::Health::b->[0]
Truth table33%1/3
A || B
A= length $Punk::Observe::Health::a->[0] <=> length $Punk::Observe::Health::b->[0]B= $Punk::Observe::Health::a->[0] cmp $Punk::Observe::Health::b->[0]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 6 | ▶ | || $a->[0] cmp $b->[0] } @{ $ser->{points} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ser->{'points'} || []
MC/DC0%0/1
$ser->{'points'} || []
$ser->{'points'}
Truth table50%1/2
A
A= $ser->{'points'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 6 | my $last = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 304 | 6 | for my $p (@pts) { | |||||||||||||||||||||||||||||||||||||||||||||
| 305 | 36 | ▶ | my $state = (($p->[1] // 0) >= 1) ? 'up' : 'down'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$p->[1] // 0
MC/DC0%0/1
$p->[1] // 0
$p->[1]
Truth table50%1/2
A
A= $p->[1]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 36 | ▶ | next if $state eq $last; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 9 | push @ev, { series => $label, at => "$p->[0]", to => $state }; | |||||||||||||||||||||||||||||||||||||||||||||
| 308 | 9 | $last = $state; | |||||||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 3 | return \@ev; | |||||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | sub _plugin_state { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_plugin_state: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | my ($class) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | require Punk::Plugin::Observe; | |||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | my $st = Punk::Plugin::Observe->state_for($class) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 318 | or Carp::croak("Punk::Observe::Health: no Observe plugin state for " | ||||||||||||||||||||||||||||||||||||||||||||||
| 319 | . "$class - is the worker running the same application " | ||||||||||||||||||||||||||||||||||||||||||||||
| 320 | . "class as the server?"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | return $st; | |||||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | ▶ | sub health_job { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
health_job: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | my ($job, $class) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | my $st = _plugin_state($class); | |||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | my $q = $job->queue_object; | |||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | my $owner = 0 + $$; | |||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | return { skipped => 'lock' } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 331 | unless $q->lock('observe.health', 60, owner => $owner); | ||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | my $n = eval { run_and_store( | |||||||||||||||||||||||||||||||||||||||||||||
| 334 | db => $st->{db}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 335 | store => Punk::Plugin::Observe::store_for( | ||||||||||||||||||||||||||||||||||||||||||||||
| 336 | $st, $st->{tenant}{fixed} || 'default'), | ||||||||||||||||||||||||||||||||||||||||||||||
| 337 | allow => $st->{opts}{health_allow}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | ) }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$st->{'tenant'}{'fixed'} || 'default'
MC/DC0%0/1
$st->{'tenant'}{'fixed'} || 'default'
$st->{'tenant'}{'fixed'}
Truth table0%0/2
A
A= $st->{'tenant'}{'fixed'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | my $err = $@; | |||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | $q->unlock('observe.health', $owner) if $q->can('unlock'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | die $err if $err; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | return { points => $n || 0 }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$n || 0
MC/DC0%0/1
$n || 0
$n
Truth table0%0/2
A
A= $n
| |||||||||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 5 | ▶ | sub cron_task { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cron_task: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 5 | my (%opt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 347 | 5 | my $db = $opt{db}; | |||||||||||||||||||||||||||||||||||||||||||||
| 348 | 5 | my $store = $opt{store}; | |||||||||||||||||||||||||||||||||||||||||||||
| 349 | 5 | my $owner = $opt{owner}; | |||||||||||||||||||||||||||||||||||||||||||||
| 350 | 5 | ▶ | $owner = $$ unless defined $owner && $owner =~ /\A[0-9]+\z/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $owner and $owner =~ /\A[0-9]+\z/
MC/DC100%2/2
defined $owner and $owner =~ /\A[0-9]+\z/
defined $owner
$owner =~ /\A[0-9]+\z/
Truth table100%3/3
A and B
A= defined $ownerB= $owner =~ /\A[0-9]+\z/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 5 | ▶ | my $lease = $opt{lease_seconds} || 30; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opt{'lease_seconds'} || 30
MC/DC0%0/1
$opt{'lease_seconds'} || 30
$opt{'lease_seconds'}
Truth table50%1/2
A
A= $opt{'lease_seconds'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 6 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=20.6
| |||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 6 | my ($q) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 355 | 6 | ▶ | return 0 unless $q && $db && $store; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$q and $db and $store
$q and $db
MC/DC0%0/3
$q and $db and $store
$q
$db
$store
Truth table25%1/4
A and B and C
A= $qB= $dbC= $store
| |||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 6 | ▶ | return 0 unless $q->lock('leader', $lease, owner => $owner); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 5 | my $n = eval { | |||||||||||||||||||||||||||||||||||||||||||||
| 360 | run_and_store(db => $db, store => $store, | ||||||||||||||||||||||||||||||||||||||||||||||
| 361 | tenant => $opt{tenant}, allow => $opt{allow}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 5 | loop => $opt{loop}, ua => $opt{ua}); | |||||||||||||||||||||||||||||||||||||||||||||
| 363 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 5 | my $err = $@; | |||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 5 | $q->renew_lock('leader', $owner, $lease); | |||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 5 | ▶ | die $err if $err; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 5 | ▶ | return $n || 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$n || 0
MC/DC0%0/1
$n || 0
$n
Truth table50%1/2
A
A= $n
| |||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 5 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||
| 375 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||