Elasticsearch/Transport.pm

filter: Statementstmt 100% 43 / 43 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 100% 59 / 59 CC 4 SCAR 6.9
CC
4
Cov
100%
perform_request
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.0
« Elasticsearch/Role/CxnPool/Static.pm ↑ Summary Elasticsearch/Logger/LogAny.pm »
1 # Licensed to Elasticsearch B.V under one or more agreements.
2 # Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3 # See the LICENSE file in the project root for more information
4  
5 package Search::Elasticsearch::Transport;
6 55 $Search::Elasticsearch::Transport::VERSION = '7.30_1'; # TRIAL
7  
8 55 $Search::Elasticsearch::Transport::VERSION = '7.301';
9 55 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 55 ▶use URI();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 55 ▶use Time::HiRes qw(time);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 55 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 55 ▶use Search::Elasticsearch::Util qw(upgrade_error);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 55 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 55 with 'Search::Elasticsearch::Role::Is_Sync',
18 'Search::Elasticsearch::Role::Transport';
19  
20 #===================================
21 sub perform_request {
22 #===================================
23 160 ▶ my $self = shift;
Subroutine perform_request: called CC=4 SCAR=13.9
Pod documented
24 160 my $params = $self->tidy_request(@_);
25 160 my $pool = $self->cxn_pool;
26 160 my $logger = $self->logger;
27  
28 160 my ( $code, $response, $cxn, $error );
29  
30 try {
31 160 ▶ $cxn = $pool->next_cxn;
Subroutine __ANON__: called CC=1 SCAR=0.0
32 148 my $start = time();
33 148 $logger->trace_request( $cxn, $params );
34  
35 148 ( $code, $response ) = $cxn->perform_request($params);
36 114 $pool->request_ok($cxn);
37 114 $logger->trace_response( $cxn, $code, $response, time() - $start );
38 }
39 catch {
40 46 ▶ $error = upgrade_error(
Subroutine __ANON__: called CC=1 SCAR=0.0
41 $_,
42 { request => $params,
43 status_code => $code,
44 body => $response
45 }
46 );
47 160 };
48  
49 160 ▶ if ($error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 46 114 160
50 46 ▶ if ( $pool->request_failed( $cxn, $error ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pool->request_failed($cxn, $error)) 19 27 46
51 19 $logger->debugf( "[%s] %s", $cxn->stringify, "$error" );
52 19 $logger->info('Retrying request on a new cxn');
53 19 return $self->perform_request($params);
54 }
55  
56 27 $logger->trace_error( $cxn, $error );
57 27 ▶ $error->is('NoNodes')
Branch: 1 branch
BranchTrueFalseTotal
$error->is('NoNodes') ? : 12 15 27
58 ? $logger->throw_critical($error)
59 : $logger->throw_error($error);
60 }
61  
62 114 return $response;
63 }
64  
65 55 1;
66  
67 #ABSTRACT: Provides interface between the client class and the Elasticsearch cluster
68  
69 __END__
« Elasticsearch/Role/CxnPool/Static.pm ↑ Summary Elasticsearch/Logger/LogAny.pm »