From ef99a2cf4179237e74f90f22a5a62913563b4c48 Mon Sep 17 00:00:00 2001 From: Ishan Bhatt <39292911+AI-IshanBhatt@users.noreply.github.com> Date: Tue, 16 Jul 2024 17:32:26 +0200 Subject: [PATCH] Add an option to filter by challange in list command (#1865) --- esrally/metrics.py | 6 ++++++ esrally/rally.py | 6 ++++++ esrally/types.py | 1 + tests/metrics_test.py | 2 ++ 4 files changed, 15 insertions(+) diff --git a/esrally/metrics.py b/esrally/metrics.py index 03fe531e5..969743e0f 100644 --- a/esrally/metrics.py +++ b/esrally/metrics.py @@ -1623,6 +1623,9 @@ def _dry_run(self): def _id(self): return self.cfg.opts("system", "delete.id") + def _challenge(self): + return self.cfg.opts("system", "list.challenge", mandatory=False) + # Does not inherit from RaceStore as it is only a delegator with the same API. class CompositeRaceStore: @@ -1880,6 +1883,7 @@ def list(self): name = self._benchmark_name() from_date = self._from_date() to_date = self._to_date() + challenge = self._challenge() filters = [ { @@ -1911,6 +1915,8 @@ def list(self): query["query"]["bool"]["filter"].append( {"bool": {"should": [{"term": {"user-tags.benchmark-name": name}}, {"term": {"user-tags.name": name}}]}} ) + if challenge: + query["query"]["bool"]["filter"].append({"bool": {"should": [{"term": {"challenge": challenge}}]}}) result = self.client.search(index="%s*" % EsRaceStore.INDEX_PREFIX, body=query) hits = result["hits"]["total"] diff --git a/esrally/rally.py b/esrally/rally.py index 296d5de11..89d56dcd4 100644 --- a/esrally/rally.py +++ b/esrally/rally.py @@ -180,6 +180,11 @@ def add_track_source(subparser): type=valid_date, default=None, ) + list_parser.add_argument( + "--challenge", + help="Show only records from this challenge", + default=None, + ) add_track_source(list_parser) delete_parser = subparsers.add_parser("delete", help="Delete records") @@ -1098,6 +1103,7 @@ def dispatch_sub_command(arg_parser, args, cfg: types.Config): cfg.add(config.Scope.applicationOverride, "system", "list.races.benchmark_name", args.benchmark_name) cfg.add(config.Scope.applicationOverride, "system", "list.from_date", args.from_date) cfg.add(config.Scope.applicationOverride, "system", "list.to_date", args.to_date) + cfg.add(config.Scope.applicationOverride, "system", "list.challenge", args.challenge) configure_mechanic_params(args, cfg, command_requires_car=False) configure_track_params(arg_parser, args, cfg, command_requires_track=False) dispatch_list(cfg) diff --git a/esrally/types.py b/esrally/types.py index bb6e8c2b1..17f9ca393 100644 --- a/esrally/types.py +++ b/esrally/types.py @@ -89,6 +89,7 @@ "include.tasks", "indices", "install.id", + "list.challenge", "list.config.option", "list.from_date", "list.max_results", diff --git a/tests/metrics_test.py b/tests/metrics_test.py index adf9b1f18..524dd788a 100644 --- a/tests/metrics_test.py +++ b/tests/metrics_test.py @@ -1921,6 +1921,8 @@ def test_filter_race(self): assert len(self.race_store.list()) == 1 self.cfg.add(config.Scope.application, "system", "list.from_date", "20160131") assert len(self.race_store.list()) == 1 + self.cfg.add(config.Scope.application, "system", "list.challenge", t.default_challenge.name) + assert len(self.race_store.list()) == 1 def test_delete_race(self): self.cfg.add(config.Scope.application, "system", "delete.id", "0101")