blib/lib/Message/Passing/Output/Search/Elasticsearch.pm

filter: Statementstmt 56.7% 21 / 37 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 40.0% 4 / 10 Podpod 100% 1 / 1 totaltotal 44.0% 26 / 59 CC 5 SCAR 24.0
CC
5
Cov
46%
consume
30.0
__ANON__
2.0
__ANON__
2.0
CRAP 11.1
↑ Summary
1 package Message::Passing::Output::Search::Elasticsearch;
2 3 $Message::Passing::Output::Search::Elasticsearch::VERSION = '0.005';
3 # ABSTRACT: index messages in Elasticsearch
4  
5 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 use MooX::Types::MooseLike::Base
7 3 ▶ qw( Str ArrayRef HashRef CodeRef is_CodeRef AnyOf ConsumerOf InstanceOf );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 ▶use Search::Elasticsearch::Async;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Promises backend => ['AnyEvent'];
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 with 'Message::Passing::Role::Output';
13  
14  
15  
16 has es_params => (
17 is => 'ro',
18 isa => HashRef,
19 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
20 3 );
21  
22  
23 has es => (
24 is => 'ro',
25 lazy => 1,
26 isa => ConsumerOf ['Search::Elasticsearch::Role::Client'],
27 0 ▶ builder => sub {
Subroutine _build_es: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
28 0 my $self = shift;
29 0 return Search::Elasticsearch::Async->new( %{ $self->es_params } );
30 },
31 3 );
32  
33  
34 has es_bulk_params => (
35 is => 'ro',
36 isa => HashRef,
37 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
38 3 );
39  
40  
41 has es_bulk => (
42 is => 'ro',
43 lazy => 1,
44 isa => ConsumerOf [
45 'Search::Elasticsearch::Client::6_0::Role::Bulk',
46 'Search::Elasticsearch::Role::Is_Async'
47 ],
48 0 ▶ builder => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
49 0 my $self = shift;
50 0 return $self->es->bulk_helper( %{ $self->es_bulk_params } );
51 },
52 3 );
53  
54  
55 3 has type => (
56 is => 'ro',
57 required => 1,
58 isa => AnyOf [ Str, CodeRef ],
59 );
60  
61  
62 3 has index_name => (
63 is => 'ro',
64 required => 1,
65 isa => AnyOf [ Str, CodeRef ],
66 );
67  
68  
69 0 ▶sub consume {
Subroutine consume: not called CC=5 SCAR=34.0
Pod documented
70 0 my ( $self, $data ) = @_;
71 return
72 0 ▶ unless defined $data && ref $data eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data and ref $data eq "HASH" 0 0 0
Condition0%0/3
defined $data and ref $data eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $data and ref $data eq "HASH"
defined $data ref $data eq "HASH"
Truth table0%0/3
A and B
A= defined $dataB= ref $data eq "HASH"
ABresult
0X0
100
111
73  
74 #if ( my $epochtime = delete $data->{epochtime} ) {
75 #$date = DateTime->from_epoch(epoch => $epochtime);
76 #}
77 #$date ||= DateTime->from_epoch(epoch => time());
78  
79 0 ▶ my $type =
Branch: 1 branch
BranchTrueFalseTotal
is_CodeRef($self->type) ? : 0 0 0
80 is_CodeRef( $self->type )
81 ? $self->type->($data)
82 : $self->type;
83 0 ▶ my $index_name =
Branch: 1 branch
BranchTrueFalseTotal
is_CodeRef($self->index_name) ? : 0 0 0
84 is_CodeRef( $self->index_name )
85 ? $self->index_name->($data)
86 : $self->index_name;
87  
88 #$self->_indexes->{$index_name} = 1;
89 # my $to_queue = {
90 # '@timestamp' => to_ISO8601DateTimeStr($date),
91 # '@tags' => [],
92 # '@type' => $type,
93 # '@source_host' => delete( $data->{hostname} ) || 'none',
94 # '@message' => exists( $data->{message} )
95 # ? delete( $data->{message} )
96 # : encode_json($data),
97 # '@fields' => $data,
98 # exists( $data->{uuid} ) ? ( id => delete( $data->{uuid} ) ) : (),
99 # };
100 0 $self->es_bulk->index(
101 { index => $index_name,
102 type => $type,
103 source => $data,
104 }
105 );
106 }
107  
108 3 1;
109  
110 __END__
↑ Summary