-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preserve pre-existing index templates (#1900).
When opening an `EsMetricsStore`, it creates the index template if any of following: - the index template doesn't exist - `reporting/datastore.overwrite_existing_templates` option is `true` It will preserve existing template on all the other cases. It adds a new method for getting boolean configuration options. It logs a warning when an existing index template is being replaced. It highlights index template differences between the existing one (if any) and the configured one (according to rally.ini).
- Loading branch information
1 parent
d0aa512
commit d1e7004
Showing
8 changed files
with
370 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Licensed to Elasticsearch B.V. under one or more contributor | ||
# license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright | ||
# ownership. Elasticsearch B.V. licenses this file to you under | ||
# the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from typing import Callable, Protocol | ||
|
||
import pytest | ||
|
||
|
||
class Case(Protocol): | ||
"""Case represent the interface expected an instance passed to cases decorator is expected to implement.""" | ||
|
||
# case_id specifies the ID of the test case. | ||
case_id: str | ||
|
||
|
||
def cases(*cases: Case) -> Callable: | ||
"""cases defines a decorator wrapping pytest.mark.parametrize to run a test with multiple cases. | ||
Example of use: | ||
@dataclass | ||
class SumCase: | ||
id: str | ||
values: list[int] | ||
want: int | ||
@cases( | ||
MyCase("no_values", want=0) | ||
MyCase("2 values", values=[1,2] want=3), | ||
) | ||
def test_sum(case: MyCase): | ||
assert sum(*case.values) == case.want | ||
:param cases: sequence of cases | ||
:return: test method decorator | ||
""" | ||
return pytest.mark.parametrize(argnames="case", argvalues=cases, ids=lambda case: case.case_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Licensed to Elasticsearch B.V. under one or more contributor | ||
# license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright | ||
# ownership. Elasticsearch B.V. licenses this file to you under | ||
# the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
from __future__ import annotations | ||
|
||
import difflib | ||
import json | ||
import typing | ||
from collections import abc | ||
|
||
O = typing.Union[abc.Mapping, abc.Sequence, str, int, float, bool, None] | ||
|
||
|
||
_diff_methods = [] | ||
|
||
|
||
def diff(old, new: O, flat_dict=False) -> str: | ||
return "\n".join(difflib.ndiff(_dump(old, flat_dict=flat_dict), _dump(new, flat_dict=flat_dict))) | ||
|
||
|
||
def dump(o: O, flat_dict=False): | ||
return "\n".join(_dump(o, flat_dict=flat_dict)) | ||
|
||
|
||
def _dump(o: O, flat_dict=False) -> abc.Sequence[str]: | ||
if flat_dict: | ||
o = _flat_dict(o) | ||
return json.dumps(o, indent=2, sort_keys=True).splitlines() | ||
|
||
|
||
def _flat_dict(o: O) -> dict[str, str]: | ||
"""Given a JSON like object, it produces a key value flat dictionary of strings easy to read and compare. | ||
:param o: a JSON like object | ||
:return: a flat dictionary | ||
""" | ||
return dict(_visit_nested(o)) | ||
|
||
|
||
def _visit_nested(o: O) -> abc.Generator[tuple[str, str], None, None]: | ||
if isinstance(o, (str, bytes)): | ||
yield "", str(o) | ||
elif isinstance(o, abc.Mapping): | ||
for k1, v1 in o.items(): | ||
for k2, v2 in _visit_nested(v1): | ||
if k2: | ||
yield f"{k1}.{k2}", v2 | ||
else: | ||
yield k1, v2 | ||
elif isinstance(o, abc.Sequence): | ||
for k1, v1 in enumerate(o): | ||
for k2, v2 in _visit_nested(v1): | ||
if k2: | ||
yield f"{k1}.{k2}", v2 | ||
else: | ||
yield str(k1), v2 | ||
else: | ||
yield "", json.dumps(o) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.