Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check-es-index-field-count.rb #112

Merged
merged 1 commit into from
Mar 1, 2018
Merged

Add check-es-index-field-count.rb #112

merged 1 commit into from
Mar 1, 2018

Conversation

huynt1979
Copy link
Contributor

@huynt1979 huynt1979 commented Feb 27, 2018

  • Add check-es-index-field-count.rb
  • Clean up rubocop warnings

Pull Request Checklist

#104

General

  • Update Changelog following the conventions laid out here

  • Update README with any necessary configuration snippets

  • Binstubs are created if needed

  • RuboCop passes

  • Existing tests pass

New Plugins

  • Tests

  • Add the plugin to the README

  • Does it have a complete header as outlined here

Purpose

This is a check to make sure we get alerts when the number of fields is approaching the targeted limit. Elasticsearch by defaults sets this limit to 1000. While there are certainly use cases when you may even need more than this, but in general it's an indicator your index is being too "flat". Hence you may want to review your mapping strategy. This check helps us know beforehand when the limit is being about to be reached so that you can have the proper action, for example, use another index or increase index.mapping.total_fields.limit setting.

Known Compatibility Issues

@huynt1979
Copy link
Contributor Author

Tested locally.
es_create_index

es_create_mapping

es_check_test

Copy link
Member

@majormoses majormoses left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks great, if you can address the comments we should be good to go.

@@ -161,9 +161,9 @@ def run
nodes_being_used = node_fs_stats['nodes'].values.select { |node| node['indices']['store']['size_in_bytes'] > 0 }
# TODO: come back and cleanup all these rubocop disables with a little refactor
# rubocop:disable Style/SingleLineBlockParams
used_in_bytes = nodes_being_used.map { |node| node['fs']['data'].map { |data| data['total_in_bytes'] - data['available_in_bytes'] }.flatten }.flatten.inject { |sum, x| sum + x } # rubocop:disable LineLength
# rubocop:disable LineLength
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you are not disabling rubocop inline you should then enable it when you are done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rubocop is complaining about line being too long here, hence the disable directive.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# rubocop:disable Metrics/LineLength on the same line.

class ESIndexFieldCount < Sensu::Plugin::Check::CLI
include ElasticsearchCommon

option :transport,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this being used anywhere do we need this? If support is not implemented then we should not include it.

long: '--transport TRANSPORT',
description: 'Transport to use to communicate with ES. Use "AWS" for signed AWS transports.'

option :region,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this being used anywhere do we need this? If support is not implemented then we should not include it.

@majormoses
Copy link
Member

For bonus points you could write an integration test, we currently spin up an ES6 container in travis and you could add creating an index with field mappings and use that to write a test against.

@huynt1979
Copy link
Contributor Author

@majormoses Integration test is added

#
# DEPENDENCIES:
# gem: sensu-plugin
# gem: aws_es_transport
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is clearly not being maintained anymore I think we should not include it, we are gonna rip that out from the checks in the somewhat near future.
cdunn/aws-es-transport#3

Use `_all` or empty string to perform the operation on all indices.
Accepts wildcards',
short: '-i INDEX',
long: '--indices INDEX'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should default to _all as I imagine most people want to check all indices.

end

def run
config[:index] = '_all' if config[:index].nil?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just default to it rather than embedding this logic?

@majormoses
Copy link
Member

Can you add the new check to the list of files in the readme?

@huynt1979
Copy link
Contributor Author

@majormoses Comments are addressed

Copy link
Member

@majormoses majormoses left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename the file to be indices as it supports multiple indices (default all)

@@ -161,9 +161,9 @@ def run
nodes_being_used = node_fs_stats['nodes'].values.select { |node| node['indices']['store']['size_in_bytes'] > 0 }
# TODO: come back and cleanup all these rubocop disables with a little refactor
# rubocop:disable Style/SingleLineBlockParams
used_in_bytes = nodes_being_used.map { |node| node['fs']['data'].map { |data| data['total_in_bytes'] - data['available_in_bytes'] }.flatten }.flatten.inject { |sum, x| sum + x } # rubocop:disable LineLength
# rubocop:disable LineLength
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# rubocop:disable Metrics/LineLength on the same line.

Clean up rubocop warnings

Add test for check-es-index-field-count

Add check-es-index-field-count to README
Copy link
Member

@majormoses majormoses left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@majormoses majormoses merged commit 3601b23 into sensu-plugins:master Mar 1, 2018
@majormoses
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants