Skip to content

Commit

Permalink
Fixes for metrics collected
Browse files Browse the repository at this point in the history
* Formatting fixed for metrics ending in `_millis`
* Format key names better by removing all non-alphanumeric characters
* Update the logic for determining the default ignore list so we do the
  smartest possible thing
  • Loading branch information
reyjrar committed Jul 20, 2023
1 parent ae85b16 commit 4b7252c
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions lib/App/ElasticSearch/Utilities/Metrics.pm
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,36 @@ the `_node/_local/stats` stats. Defaults to:
[qw(adaptive_selection)]
Plus ignores sections containing C<ingest>, C<ml>, C<transform> B<UNLESS> those
roles appear in the node's roles. Also, unless the node is tagged as a
C<data*> node, the following keys are ignored:
[qw(force_merge merges pressure recovery segments translog)]
=cut

has 'ignore' => (
is => 'lazy',
isa => ArrayRef[Str],
default => sub { [qw(adaptive_selection)] },
default => sub {
my ($self) = @_;

my %roles = map { $_ => 1 } @{ $self->node_details->{roles} };
my @ignore = qw(adaptive_selection);

# Easy roles and sections are the same
foreach my $section ( qw(ingest ml transform) ) {
push @ignore, $section
unless $roles{$section};
}

# Skip some sections if we're not a data node
if( ! grep { /^data/ } keys %roles ) {
push @ignore, qw(force_merge merges pressure recovery segments translog);
}

return \@ignore;
},
);

=attr node_details
Expand Down Expand Up @@ -292,7 +316,7 @@ sub collect_index_metrics {
# Figure out the Index Basename
my $index = $shard->{index} =~ s/[-_]\d{4}([.-])\d{2}\g{1}\d{2}(?:[-_.]\d+)?$//r;
next unless $index;
$index =~ s/\./_/g;
$index =~ s/[^a-zA-Z0-9]+/_/g;

my $type = $shard->{prirep} eq 'p' ? 'primary' : 'replica';

Expand Down Expand Up @@ -353,9 +377,9 @@ sub _stat_collector {

# Sanitize Key Name
my $key_name = $key;
$key_name =~ s/(?:time_)?in_millis/ms/;
$key_name =~ s/(?:_time)?(?:_in)?_millis/_ms/;
$key_name =~ s/(?:size_)?in_bytes/bytes/;
$key_name =~ s/\./_/g;
$key_name =~ s/[^a-zA-Z0-9]+/_/g;

if( is_hashref($ref->{$key}) ) {
# Recurse
Expand Down

0 comments on commit 4b7252c

Please sign in to comment.