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

Support data streams in create-track #1531

Merged
merged 18 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions esrally/rally.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,15 @@ def add_track_source(subparser):
create_track_parser.add_argument(
"--indices",
type=non_empty_list,
required=True,
required=False,
help="Comma-separated list of indices to include in the track",
)
create_track_parser.add_argument(
"--datastreams",
type=non_empty_list,
required=False,
help="Comma-separated list of data-streams to include in the track",
)
create_track_parser.add_argument(
"--target-hosts",
default="",
Expand Down Expand Up @@ -987,9 +993,18 @@ def dispatch_sub_command(arg_parser, args, cfg):
cfg.add(config.Scope.applicationOverride, "generator", "output.path", args.output_path)
generate(cfg)
elif sub_command == "create-track":
cfg.add(config.Scope.applicationOverride, "generator", "indices", args.indices)
cfg.add(config.Scope.applicationOverride, "generator", "output.path", args.output_path)
cfg.add(config.Scope.applicationOverride, "track", "track.name", args.track)
if args.datastreams is not None and args.indices is None:
pquentin marked this conversation as resolved.
Show resolved Hide resolved
cfg.add(config.Scope.applicationOverride, "generator", "indices", "*")
cfg.add(config.Scope.applicationOverride, "generator", "datastreams", args.datastreams)
cfg.add(config.Scope.applicationOverride, "generator", "output.path", args.output_path)
cfg.add(config.Scope.applicationOverride, "track", "track.name", args.track)
elif args.indices is not None:
cfg.add(config.Scope.applicationOverride, "generator", "indices", args.indices)
cfg.add(config.Scope.applicationOverride, "generator", "datastreams", args.datastreams)
cfg.add(config.Scope.applicationOverride, "generator", "output.path", args.output_path)
cfg.add(config.Scope.applicationOverride, "track", "track.name", args.track)
else:
raise exceptions.SystemSetupError("Following arguments are required: --indices or specify --datastream ", sub_command)
configure_connection_params(arg_parser, args, cfg)

tracker.create_track(cfg)
Expand Down Expand Up @@ -1043,7 +1058,6 @@ def main():
if args.subcommand is None:
arg_parser.print_help()
sys.exit(0)

console.init(quiet=args.quiet)
console.println(BANNER)

Expand Down
30 changes: 28 additions & 2 deletions esrally/tracker/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,19 @@ def update_index_setting_parameters(settings):
settings[s] = param.format(orig=orig_value)


allowed_list_hidden_indices = [
gizas marked this conversation as resolved.
Show resolved Hide resolved
".ds-metrics-kubernetes",
".ds-metrics-system",
".ds-metrics-elastic_agent",
".ds-logs-kubernetes",
".ds-logs-elastic_agent",
]


def is_valid(index_name):
if len(index_name) == 0:
return False, "Index name is empty"
if index_name.startswith("."):
if index_name.startswith(".") and not index_name.startswith(tuple(allowed_list_hidden_indices)):
pquentin marked this conversation as resolved.
Show resolved Hide resolved
return False, f"Index [{index_name}] is hidden"
return True, None

Expand All @@ -65,7 +74,7 @@ def extract_index_mapping_and_settings(client, index_pattern):
results = {}
logger = logging.getLogger(__name__)
# the response might contain multiple indices if a wildcard was provided
response = client.indices.get(index=index_pattern)
response = client.indices.get(index=index_pattern, params={"expand_wildcards": "all"})
for index, details in response.items():
valid, reason = is_valid(index)
if valid:
Expand Down Expand Up @@ -104,3 +113,20 @@ def extract(client, outdir, index_pattern):
}
)
return results


def datastreamextract(client, datastream_pattern):
pquentin marked this conversation as resolved.
Show resolved Hide resolved
"""
Calls Elasticsearch client get_data_stream function to retrieve list of indexes
:param client: Elasticsearch client
:param index_pattern: name of datastream
pquentin marked this conversation as resolved.
Show resolved Hide resolved
:return: index creation dictionary
pquentin marked this conversation as resolved.
Show resolved Hide resolved
"""
results = []
# the response might contain multiple indices if a wildcard was provided
params_defined = {"expand_wildcards": "all", "filter_path": "data_streams.name"}
results_datastreams = client.indices.get_data_stream(name=datastream_pattern, params=params_defined)

for indices in results_datastreams["data_streams"]:
pquentin marked this conversation as resolved.
Show resolved Hide resolved
results.append(indices.get("name"))
return results
24 changes: 22 additions & 2 deletions esrally/tracker/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ def process_template(templates_path, template_filename, template_vars, output_pa
f.write(template.render(template_vars))


def extract_indexes_from_datastreams(client, datastreams_to_extract):
pquentin marked this conversation as resolved.
Show resolved Hide resolved
indices = []
# first extract index metadata (which is cheap) and defer extracting data to reduce the potential for
# errors due to invalid index names late in the process.
for datastream_name in datastreams_to_extract:
try:
indices += index.datastreamextract(client, datastream_name)
except ElasticsearchException:
logging.getLogger(__name__).exception("Failed to extract indexes from datastream [%s]", datastream_name)

return indices


def extract_mappings_and_corpora(client, output_path, indices_to_extract):
indices = []
corpora = []
Expand Down Expand Up @@ -63,8 +76,7 @@ def create_track(cfg):
root_path = cfg.opts("generator", "output.path")
target_hosts = cfg.opts("client", "hosts")
client_options = cfg.opts("client", "options")

logger.info("Creating track [%s] matching indices [%s]", track_name, indices)
datastreams = cfg.opts("generator", "datastreams")

client = EsClientFactory(
hosts=target_hosts.all_hosts[opts.TargetHosts.DEFAULT], client_options=client_options.all_client_options[opts.TargetHosts.DEFAULT]
Expand All @@ -76,6 +88,14 @@ def create_track(cfg):
output_path = os.path.abspath(os.path.join(io.normalize_path(root_path), track_name))
io.ensure_dir(output_path)

if datastreams is None:
logger.info("Creating track [%s] matching indices [%s]", track_name, indices)
else:
logger.info("Creating track [%s] matching datastreams [%s]", track_name, datastreams)
extracted_indices = extract_indexes_from_datastreams(client, datastreams)
indices = extracted_indices
console.info(f"##### List datastreams to extract [{indices}]", logger=logger)
pquentin marked this conversation as resolved.
Show resolved Hide resolved

indices, corpora = extract_mappings_and_corpora(client, output_path, indices)
if len(indices) == 0:
raise RuntimeError("Failed to extract any indices for track!")
Expand Down