Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

METRON-1283: Install Elasticsearch template as a part of the mpack startup scripts #817

Closed
wants to merge 9 commits into from
Expand Up @@ -48,6 +48,7 @@ def __init__(self, params):
self.__acl_configured = os.path.isfile(self.__params.indexing_acl_configured_flag_file)
self.__hbase_configured = os.path.isfile(self.__params.indexing_hbase_configured_flag_file)
self.__hbase_acl_configured = os.path.isfile(self.__params.indexing_hbase_acl_configured_flag_file)
self.__elasticsearch_template_installed = os.path.isfile(self.__params.elasticsearch_template_installed_flag_file)
self.__hdfs_perm_configured = os.path.isfile(self.__params.indexing_hdfs_perm_configured_flag_file)

def __get_topics(self):
Expand All @@ -72,6 +73,9 @@ def is_hbase_configured(self):
def is_hbase_acl_configured(self):
return self.__hbase_acl_configured

def is_elasticsearch_template_installed(self):
return self.__elasticsearch_template_installed

def set_configured(self):
metron_service.set_configured(self.__params.metron_user, self.__params.indexing_configured_flag_file, "Setting Indexing configured to True")

Expand All @@ -87,6 +91,9 @@ def set_acl_configured(self):
def set_hdfs_perm_configured(self):
metron_service.set_configured(self.__params.metron_user, self.__params.indexing_hdfs_perm_configured_flag_file, "Setting HDFS perm configured to True")

def set_elasticsearch_template_installed(self):
metron_service.set_configured(self.__params.metron_user, self.__params.elasticsearch_template_installed_flag_file, "Setting Elasticsearch template installed to True")

def create_hbase_tables(self):
Logger.info("Creating HBase Tables for indexing")
if self.__params.security_enabled:
Expand Down
Expand Up @@ -80,6 +80,13 @@ def start(self, env, upgrade_type=None):
from params import params
env.set_params(params)
self.configure(env)
# Install elasticsearch templates
try:
if not commands.is_elasticsearch_template_installed():
self.elasticsearch_template_install(env)
commands.set_elasticsearch_template_installed()
Copy link
Contributor

Choose a reason for hiding this comment

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

@anandsubbu said...

If the install fails the first time due to ES being down, then we WARN and move on. If ES service comes up later, the admin needs to install the templates subsequently by using 'Ambari -> Metron -> Service Actions -> Elasticsearch Template Install' option

I am reading the code differently. If we attempt to install the templates, but it fails because ES is down, then an exception is thrown and we never set the flag file. This is good because the next time we start indexing, it will again attempt to install the index templates. It will continue to attempt the index template install until that flag file is set. Only if the templates actually get installed will the flag file get set, which causes it to stop attempting the install. This is exactly what we want.

The only thing I would suggest is that we attempt the template install BEFORE starting the indexing topology.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you @nickwallen . Sure, done!

except:
Logger.warning("WARNING: Elasticsearch templates could not be installed. The Elasticsearch service is probably down.")
commands = IndexingCommands(params)
commands.start_indexing_topology(env)

Expand Down
Expand Up @@ -80,6 +80,7 @@
indexing_hbase_configured_flag_file = status_params.indexing_hbase_configured_flag_file
indexing_hbase_acl_configured_flag_file = status_params.indexing_hbase_acl_configured_flag_file
indexing_hdfs_perm_configured_flag_file = status_params.indexing_hdfs_perm_configured_flag_file
elasticsearch_template_installed_flag_file = status_params.elasticsearch_template_installed_flag_file
global_properties_template = config['configurations']['metron-env']['elasticsearch-properties']

# Elasticsearch hosts and port management
Expand Down
Expand Up @@ -74,6 +74,9 @@
indexing_hbase_configured_flag_file = metron_zookeeper_config_path + '/../metron_indexing_hbase_configured'
indexing_hbase_acl_configured_flag_file = metron_zookeeper_config_path + '/../metron_indexing_hbase_acl_configured'

# Elasticsearch
elasticsearch_template_installed_flag_file = metron_zookeeper_config_path + '/../metron_elasticsearch_template_installed_flag_file'

# REST
metron_rest_port = config['configurations']['metron-rest-env']['metron_rest_port']

Expand Down
8 changes: 0 additions & 8 deletions metron-deployment/roles/load_web_templates/tasks/main.yml
Expand Up @@ -15,14 +15,6 @@
# limitations under the License.
#
---
- name: Load ES Templates
command: >
curl -s -w "%{http_code}" -u admin:admin -H "X-Requested-By: ambari" -X POST -d '{ "RequestInfo": { "context": "Install ES Template from REST", "command": "ELASTICSEARCH_TEMPLATE_INSTALL"},"Requests/resource_filters": [{"service_name": "METRON","component_name": "METRON_INDEXING","hosts" : "{{ metron_hosts[0] }}"}]}' http://{{ groups.ambari_master[0] }}:{{ ambari_port }}/api/v1/clusters/{{ cluster_name }}/requests
args:
warn: off
register: result
failed_when: "result.rc != 0 or '202' not in result.stdout"

- name: Load Kibana Dashboard
command: >
curl -s -w "%{http_code}" -u admin:admin -H "X-Requested-By: ambari" -X POST -d '{ "RequestInfo": { "context": "Install Kibana Dashboard from REST", "command": "LOAD_TEMPLATE"},"Requests/resource_filters": [{"service_name": "KIBANA","component_name": "KIBANA_MASTER","hosts" : "{{ kibana_hosts[0] }}"}]}' http://{{ groups.ambari_master[0] }}:{{ ambari_port }}/api/v1/clusters/{{ cluster_name }}/requests
Expand Down
17 changes: 16 additions & 1 deletion metron-platform/metron-elasticsearch/README.md
Expand Up @@ -2,7 +2,7 @@

## Introduction

Elasticsearch can be used as the real-time portion of the datastore resulting from [metron-indexing](../metron-indexing.README.md).
Elasticsearch can be used as the real-time portion of the datastore resulting from [metron-indexing](../metron-indexing/README.md).

## Properties

Expand Down Expand Up @@ -81,3 +81,18 @@ curl -XPUT "http://${ELASTICSEARCH}:9200/${SENSOR}_index*/_mapping/${SENSOR}_doc
'
rm ${SENSOR}.template
```

## Installing Elasticsearch Templates

The stock set of Elasticsearch templates for bro, snort, yaf, error index and meta index are installed automatically during the first time install and startup of Metron Indexing service.

Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of saying 'in the rare case', it might be better to say:

"It is possible that Elasticsearch is not available when the Metron Indexing Service starts the Elasticsearch topology, in that case the Elasticsearch templates will not be installed."

Also, this doesn't document the scenarios you have been describing fully.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reworded per your suggestion.

I believe the README section covers the current behavior with my change. If you are talking about the scenarios noted in the PR description, then these are captured in the existing ES README under the section Using Metron with Elasticsearch 2.x. Please let me know which specific scenario you are referring to and I would be happy to include them.

Copy link
Contributor

Choose a reason for hiding this comment

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

#817 (comment)
#817 (review)

My impression from these comments is that automatic installation could still possibly happen. That is what I'm referring to as being missing. I may be confused though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah okay, this comment and review is the same scenario described in the README as:

It is possible that Elasticsearch service is not available when the Metron Indexing Service startup, in that case the Elasticsearch template will not be installed. For such a scenario, an Admin can install the template manually from the Ambari UI by following the below flow:

Ambari UI -> Services -> Metron -> Service Actions -> Elasticsearch Template Install

Copy link
Contributor

Choose a reason for hiding this comment

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

So I am def. confused. I don't see how "It will try again next time X happens" as the same as Go and do it manually in ambari

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, let me try to explain more using examples:

Scenario 1 - Happy Path

  • Fresh install
  • ES service up and running
  • When the Indexing service comes up, it also installs the ES templates
  • Admin can start ingesting into sensors, launch alerts UI and everything works

Scenario 2 - ES service down

  • Fresh install
  • For some reason, the ES service is down when the Indexing service is coming up
  • We log a warning message in the Ambari install logs, and the Indexing service starts up fine.
  • Once the ES service issue is resolved, the Admin needs to install the ES templates manually before s/he can start ingesting into sensors. This can be done in two ways:
  1. Using the Ambari UI -> Services -> Metron -> Service Actions -> Elasticsearch Template Install
  2. By stopping the Metron Indexing service from Ambari UI, and starting it again so that it can trigger the piece of code to install the template.

Now, from a documentation perspective, point 2 above is counter intuitive IMHO, since it would not make sense to ask the Admin to stop/start Indexing service in order to have the ES template installed. I have hence documented only the first option--which is also the same way it is done presently.

Let me know if this helps clarify.

Copy link
Contributor

Choose a reason for hiding this comment

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

But, if that is the way it works, and is what will happen, you should documented it. If it doesn't make sense enough to document, then change the behavior.

We have people all over the user's list with issues understanding what is going on with things.

"Oh, the doc doesn't say it but we do try to install automatically next time or if you .... " isn't right.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough, added both methods in the latest doc change.

It is possible that Elasticsearch service is not available when the Metron Indexing Service startup, in that case the Elasticsearch template will not be installed.

For such a scenario, an Admin can have the template installed in two ways:

_Method 1_ - Manually from the Ambari UI by following the flow:
Ambari UI -> Services -> Metron -> Service Actions -> Elasticsearch Template Install

_Method 2_ - Stop the Metron Indexing service, and start it again from Ambari UI. Note that the Metron Indexing service tracks if it has successfully installed the Elasticsearch templates, and will attempt to do so each time it is Started until successful.

> Note: If you have made any customization to your index templates, then installing Elasticsearch templates afresh will lead to overwriting your existing changes. Please exercise caution.