File Coverage

blib/lib/Search/Elasticsearch/Transport.pm
Criterion Covered Total %
statement 39 39 100.0
branch 6 6 100.0
condition n/a
subroutine 9 9 100.0
pod 1 1 100.0
total 55 55 100.0


line stmt bran cond sub pod time code
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             $Search::Elasticsearch::Transport::VERSION = '7.715';
7 55     55   28069 use Moo;
  55         139  
  55         380  
8              
9 55     55   18553 use URI();
  55         188  
  55         2454  
10 55     55   357 use Time::HiRes qw(time);
  55         115  
  55         809  
11 55     55   6376 use Try::Tiny;
  55         135  
  55         4245  
12 55     55   418 use Search::Elasticsearch::Util qw(upgrade_error);
  55         156  
  55         842  
13 55     55   16814 use namespace::clean;
  55         541  
  55         476  
14              
15             with 'Search::Elasticsearch::Role::Is_Sync',
16             'Search::Elasticsearch::Role::Transport';
17              
18             #===================================
19             sub perform_request {
20             #===================================
21 160     160 1 1128 my $self = shift;
22 160         553 my $params = $self->tidy_request(@_);
23 160         414 my $pool = $self->cxn_pool;
24 160         324 my $logger = $self->logger;
25              
26 160         272 my ( $code, $response, $cxn, $error );
27              
28             try {
29 160     160   10685 $cxn = $pool->next_cxn;
30 148         1068 my $start = time();
31 148         579 $logger->trace_request( $cxn, $params );
32              
33 148         10827 ( $code, $response ) = $cxn->perform_request($params);
34 114         465 $pool->request_ok($cxn);
35 114         702 $logger->trace_response( $cxn, $code, $response, time() - $start );
36             }
37             catch {
38 46     46   832 $error = upgrade_error(
39             $_,
40             { request => $params,
41             status_code => $code,
42             body => $response
43             }
44             );
45 160         1135 };
46              
47 160 100       6478 if ($error) {
48 46 100       194 if ( $pool->request_failed( $cxn, $error ) ) {
49 19         113 $logger->debugf( "[%s] %s", $cxn->stringify, "$error" );
50 19         721 $logger->info('Retrying request on a new cxn');
51 19         501 return $self->perform_request($params);
52             }
53              
54 27         141 $logger->trace_error( $cxn, $error );
55 27 100       1454 $error->is('NoNodes')
56             ? $logger->throw_critical($error)
57             : $logger->throw_error($error);
58             }
59              
60 114         636 return $response;
61             }
62              
63             1;
64              
65             #ABSTRACT: Provides interface between the client class and the Elasticsearch cluster
66              
67             __END__