Skip to content

Commit

Permalink
fix elasticsearch index widget (#639)
Browse files Browse the repository at this point in the history
  • Loading branch information
ebattat authored Aug 5, 2023
1 parent 6f111a4 commit 2464e6a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,14 @@ def delete_index_ids_between_dates(self, index: str, start_datetime: datetime =
raise Exception('Empty parameters: index/ start_datetime/ end_datetime')

@logger_time_stamp
def get_all_result_index(self):
def get_all_indexes(self):
"""
This method returns sorted elasticsearch indexes that contains results
This method returns sorted elasticsearch indexes
@return:
"""
index_results = []
indexes = []
# Fetch all indices
indices = self.__es.cat.indices(format="json")
for index in indices:
if 'results' in index['index']:
index_results.append(index['index'])
return sorted(index_results)
indexes.append(index['index'])
return sorted(indexes)
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,22 @@ def get_elastic_index():
"""
return elastic_index

def get_perfci_indexes(self):
"""
This method returns sorted perfci elasticsearch indexes that contains 'results' or 'status'
@return:
"""
# Use list comprehension to filter strings containing 'result' or 'status'
return [item for item in self.__elasticsearch.get_all_indexes() if 'result' in item or 'status' in item]

def index_dropdown(self):
"""
index dropdown widget
@return:
"""
dropdown = widgets.Dropdown(
options=self.__elasticsearch.get_all_result_index(),
value=self.__elasticsearch.get_all_result_index()[0],
options=self.get_perfci_indexes(),
value=self.get_perfci_indexes()[0],
description='Choose INDEX & DATES:',
style={'description_width': 'initial'},
layout=widgets.Layout(width='500px')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ def test_get_delete_ids_elasticsearch_last_day():
assert len(elastic.get_index_ids_between_dates(index=TEST_INDEX_NAME, start_datetime=day_before_timestamp, end_datetime=current_timestamp)) == 0


def test_get_all_result_index():
def test_get_all_indexes():
"""
This method gets all result index
This method gets all indexes
@return:
"""
elastic = ElasticSearchOperations(es_host=test_environment_variable.get('elasticsearch', ''),
es_port=test_environment_variable.get('elasticsearch_port', ''),
es_user=test_environment_variable.get('elasticsearch_user', ''),
es_password=test_environment_variable.get('elasticsearch_password', ''))
assert len(elastic.get_all_result_index()) > 1
assert len(elastic.get_all_indexes()) > 1

0 comments on commit 2464e6a

Please sign in to comment.