Skip to content

Commit

Permalink
Fix rally-annotations index creation (#1747)
Browse files Browse the repository at this point in the history
The `rally-annotations` index settings body template lacks `index`
attribute. Also, upgraded Python Elasticsearch client is more strict 
when evaluating `body` parameter in index `create` method. This
breaks `rally-annotations` index creation in Elasticsearch metric
store.

This commit fixes `rally-annotations` index creation adopting the
approach from other Rally indices which all use index templates.
  • Loading branch information
gbanasiak committed Jul 13, 2023
1 parent 01f3c25 commit 7d913f7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
12 changes: 8 additions & 4 deletions esrally/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ def delete_by_query(self, index, body):
return self.guarded(self._client.delete_by_query, index=index, body=body)

def delete(self, index, id):
# ignore 404 status code (NotFoundError) when index does not exist
return self.guarded(self._client.delete, index=index, id=id, ignore=404)

def get_index(self, name):
return self.guarded(self._client.indices.get, name=name)

def create_index(self, index, body=None):
return self.guarded(self._client.indices.create, index=index, body=body, ignore=400)
def create_index(self, index):
# ignore 400 status code (BadRequestError) when index already exists
return self.guarded(self._client.indices.create, index=index, ignore=400)

def exists(self, index):
return self.guarded(self._client.indices.exists, index=index)
Expand All @@ -94,6 +96,7 @@ def search(self, index, body):
def guarded(self, target, *args, **kwargs):
# pylint: disable=import-outside-toplevel
import elasticsearch
import elasticsearch.helpers
from elastic_transport import ApiError, TransportError

max_execution_count = 10
Expand Down Expand Up @@ -1773,8 +1776,9 @@ def _at_midnight(race_timestamp):
)
else:
if not self.client.exists(index="rally-annotations"):
body = self.index_template_provider.annotations_template()
self.client.create_index(index="rally-annotations", body=body)
# create or overwrite template on index creation
self.client.put_template("rally-annotations", self.index_template_provider.annotations_template())
self.client.create_index(index="rally-annotations")
self.client.index(
index="rally-annotations",
id=annotation_id,
Expand Down
4 changes: 3 additions & 1 deletion esrally/resources/annotation-template.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"index_patterns": ["rally-annotations"],
"settings": {
"number_of_shards": 1
"index":{
}
},
"mappings": {
"dynamic_templates": [
Expand Down
5 changes: 5 additions & 0 deletions tests/metrics_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2607,6 +2607,7 @@ def test_primary_and_replica_shard_count_specified_index_template_update(self):
_index_template_provider = metrics.IndexTemplateProvider(self.cfg)

templates = [
_index_template_provider.annotations_template(),
_index_template_provider.metrics_template(),
_index_template_provider.races_template(),
_index_template_provider.results_template(),
Expand All @@ -2627,6 +2628,7 @@ def test_primary_shard_count_specified_index_template_update(self):
_index_template_provider = metrics.IndexTemplateProvider(self.cfg)

templates = [
_index_template_provider.annotations_template(),
_index_template_provider.metrics_template(),
_index_template_provider.races_template(),
_index_template_provider.results_template(),
Expand All @@ -2649,6 +2651,7 @@ def test_replica_shard_count_specified_index_template_update(self):
_index_template_provider = metrics.IndexTemplateProvider(self.cfg)

templates = [
_index_template_provider.annotations_template(),
_index_template_provider.metrics_template(),
_index_template_provider.races_template(),
_index_template_provider.results_template(),
Expand All @@ -2672,6 +2675,7 @@ def test_primary_shard_count_less_than_one(self):
with pytest.raises(exceptions.SystemSetupError) as ctx:
# pylint: disable=unused-variable
templates = [
_index_template_provider.annotations_template(),
_index_template_provider.metrics_template(),
_index_template_provider.races_template(),
_index_template_provider.results_template(),
Expand All @@ -2693,6 +2697,7 @@ def test_primary_and_replica_shard_counts_passed_as_strings(self):
_index_template_provider = metrics.IndexTemplateProvider(self.cfg)

templates = [
_index_template_provider.annotations_template(),
_index_template_provider.metrics_template(),
_index_template_provider.races_template(),
_index_template_provider.results_template(),
Expand Down

0 comments on commit 7d913f7

Please sign in to comment.