| 1 | # OpenSearch::Client is an unofficial client for OpenSearch. | ||||||||||
| 2 | # It is derived from Search::Elasticsearch version 7.714 | ||||||||||
| 3 | # License details from that work are contained in the NOTICE | ||||||||||
| 4 | # file distributed with this work. | ||||||||||
| 5 | #----------------------------------------------------------------------- | ||||||||||
| 6 | # OpenSearch::Client | ||||||||||
| 7 | #----------------------------------------------------------------------- | ||||||||||
| 8 | # Copyright 2026 Mark Dootson | ||||||||||
| 9 | # | ||||||||||
| 10 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||
| 11 | # you may not use this file except in compliance with the License. | ||||||||||
| 12 | # You may obtain a copy of the License at | ||||||||||
| 13 | # | ||||||||||
| 14 | # http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||
| 15 | # | ||||||||||
| 16 | # Unless required by applicable law or agreed to in writing, software | ||||||||||
| 17 | # distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||
| 18 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||
| 19 | # See the License for the specific language governing permissions and | ||||||||||
| 20 | # limitations under the License. | ||||||||||
| 21 | |||||||||||
| 22 | package OpenSearch::Client::Transport; | ||||||||||
| 23 | 56 | $OpenSearch::Client::Transport::VERSION = '3.007011'; | |||||||||
| 24 | 56 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | |||||||||||
| 26 | 56 | ▶ | use URI(); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 56 | ▶ | use Time::HiRes qw(time); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | 56 | ▶ | use Try::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 56 | ▶ | use OpenSearch::Client::Util qw(upgrade_error); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | 56 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 31 | |||||||||||
| 32 | 56 | with 'OpenSearch::Client::Role::Is_Sync', | |||||||||
| 33 | 'OpenSearch::Client::Role::Transport'; | ||||||||||
| 34 | |||||||||||
| 35 | #=================================== | ||||||||||
| 36 | 160 | ▶ | sub perform_request { | ||||||||
|
Subroutine
perform_request: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 37 | #=================================== | ||||||||||
| 38 | 160 | my $self = shift; | |||||||||
| 39 | 160 | my $params = $self->tidy_request(@_); | |||||||||
| 40 | 160 | my $pool = $self->cxn_pool; | |||||||||
| 41 | 160 | my $logger = $self->logger; | |||||||||
| 42 | |||||||||||
| 43 | 160 | my ( $code, $response, $cxn, $error ); | |||||||||
| 44 | |||||||||||
| 45 | 160 | ▶ | try { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 46 | 160 | $cxn = $pool->next_cxn; | |||||||||
| 47 | 148 | my $start = time(); | |||||||||
| 48 | 148 | $logger->trace_request( $cxn, $params ); | |||||||||
| 49 | |||||||||||
| 50 | 148 | ( $code, $response ) = $cxn->perform_request($params); | |||||||||
| 51 | 114 | $pool->request_ok($cxn); | |||||||||
| 52 | 114 | $logger->trace_response( $cxn, $code, $response, time() - $start ); | |||||||||
| 53 | } | ||||||||||
| 54 | 46 | ▶ | catch { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 55 | 46 | $error = upgrade_error( | |||||||||
| 56 | $_, | ||||||||||
| 57 | { request => $params, | ||||||||||
| 58 | status_code => $code, | ||||||||||
| 59 | body => $response | ||||||||||
| 60 | } | ||||||||||
| 61 | ); | ||||||||||
| 62 | 160 | }; | |||||||||
| 63 | |||||||||||
| 64 | 160 | ▶ | if ($error) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | 46 | ▶ | if ( $pool->request_failed( $cxn, $error ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 19 | $logger->debugf( "[%s] %s", $cxn->stringify, "$error" ); | |||||||||
| 67 | 19 | $logger->info('Retrying request on a new cxn'); | |||||||||
| 68 | 19 | return $self->perform_request($params); | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 27 | $logger->trace_error( $cxn, $error ); | |||||||||
| 72 | 27 | ▶ | $error->is('NoNodes') | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | ? $logger->throw_critical($error) | ||||||||||
| 74 | : $logger->throw_error($error); | ||||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 114 | return $response; | |||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | 56 | 1; | |||||||||
| 81 | |||||||||||
| 82 | __END__ | ||||||||||