Skip to content

Commit

Permalink
Merge pull request #1298 from metacpan/haarg/es-config-consistency
Browse files Browse the repository at this point in the history
Always use type coercion to construct Search::Elasticsearch object
  • Loading branch information
haarg authored Oct 24, 2024
2 parents 11b7ebb + b575361 commit e134d2c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
6 changes: 4 additions & 2 deletions lib/MetaCPAN/Script/Snapshot.pm
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ has snap_name => (
has host => (
is => 'ro',
isa => Str,
default =>
sub { MetaCPAN::Server::Config::config()->{elasticsearch_servers} },
default => sub {
my $self = shift;
return $self->es->transport->cxn_pool->cxns->[0]->uri;
},
documentation => 'ES host, defaults to: http://localhost:9200',
);

Expand Down
4 changes: 3 additions & 1 deletion metacpan_server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ git: /usr/bin/git
cpan: /CPAN
secret: "the stone roses"
level: info
elasticsearch_servers: http://elasticsearch:9200
elasticsearch_servers:
client: '2_0::Direct'
nodes: http://elasticsearch:9200
minion_dsn: "postgresql://metacpan:t00lchain@pghost:5432/minion_queue"
port: 5000

Expand Down
4 changes: 3 additions & 1 deletion metacpan_server_testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ level: warn
port: 5000
source_base: var/t/tmp/source

elasticsearch_servers: http://elasticsearch_test:9200
elasticsearch_servers:
client: '2_0::Direct'
nodes: http://elasticsearch_test:9200

logger:
class: Log::Log4perl::Appender::Screen
Expand Down
3 changes: 1 addition & 2 deletions t/lib/MetaCPAN/Server/Test.pm
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ sub app {

sub model {
my $c = MetaCPAN::Server::Config::config();
MetaCPAN::Model->new(
es => { nodes => [ $c->{elasticsearch_servers} ] } );
MetaCPAN::Model->new( es => $c->{elasticsearch_servers} );
}

1;
Expand Down
13 changes: 7 additions & 6 deletions t/lib/MetaCPAN/TestServer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ use MetaCPAN::Server ();
use MetaCPAN::Server::Config ();
use MetaCPAN::TestHelpers qw( fakecpan_dir );
use MetaCPAN::Types::TypeTiny qw( HashRef Path );
use MooseX::Types::ElasticSearch qw( ES );
use Search::Elasticsearch ();
use Test::More;

has es_client => (
is => 'ro',
does => 'Search::Elasticsearch::Role::Client',
isa => ES,
coerce => 1,
lazy => 1,
builder => '_build_es_client',
);
Expand Down Expand Up @@ -64,14 +66,13 @@ sub _build_config {
sub _build_es_client {
my $self = shift;

my $es = Search::Elasticsearch->new(
nodes => MetaCPAN::Server::Config::config()->{elasticsearch_servers},
( $ENV{ES_TRACE} ? ( trace_to => [ 'File', 'es.log' ] ) : () )
);
my $es = ES->coerce(
MetaCPAN::Server::Config::config()->{elasticsearch_servers}, );

ok( $es, 'got ElasticSearch object' );
ok( $es, 'got Search::Elasticsearch object' );

note( Test::More::explain( { 'Elasticsearch info' => $es->info } ) );

return $es;
}

Expand Down

0 comments on commit e134d2c

Please sign in to comment.