Elasticsearch/Transport.pm

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