From df49d4d2c45d3dbcd2e6791524b0c5812430105e Mon Sep 17 00:00:00 2001 From: Grzegorz Banasiak Date: Mon, 8 Jan 2024 13:28:39 +0100 Subject: [PATCH] Override serverless cluster version (#1818) Make Rally report `serverless` version instead of dummy `8.11.0` version when run against Elastic Serverless clusters. With `serverless` version, Rally track branch selection defaults to `master`. --- docs/serverless.rst | 2 +- esrally/client/factory.py | 6 ++++-- esrally/driver/driver.py | 12 ++++++++---- esrally/driver/runner.py | 5 +++-- tests/driver/driver_test.py | 4 ++-- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/docs/serverless.rst b/docs/serverless.rst index 7e9ea4200..005f18ac7 100644 --- a/docs/serverless.rst +++ b/docs/serverless.rst @@ -42,7 +42,7 @@ The Serverless detection and the skip manifests through the following messages o [INFO] Race id is [d9d82d3f-dd74-4af0-90ea-8bdd449c824c] [INFO] Detected Elasticsearch Serverless mode with operator=[False]. [INFO] Excluding [check-cluster-health], [force-merge], [wait-until-merges-finish], [index-stats], [node-stats] as challenge [append-no-conflicts] is run on serverless. - [INFO] Racing on track [geonames], challenge [append-no-conflicts] and car ['external'] with version [8.11.0]. + [INFO] Racing on track [geonames], challenge [append-no-conflicts] and car ['external'] with version [serverless]. [..] The automatic skip does not apply to the following tasks: diff --git a/esrally/client/factory.py b/esrally/client/factory.py index c18c99261..4a4c0179f 100644 --- a/esrally/client/factory.py +++ b/esrally/client/factory.py @@ -349,13 +349,15 @@ def cluster_distribution_version(hosts, client_options, client_factory=EsClientF version = es.info()["version"] version_build_flavor = version.get("build_flavor", "oss") - # build hash will only be available for serverless if the client has operator privs + # if build hash is not available default to build flavor version_build_hash = version.get("build_hash", version_build_flavor) - # version number does not exist for serverless + # if version number is not available default to build flavor version_number = version.get("number", version_build_flavor) serverless_operator = False if versions.is_serverless(version_build_flavor): + # overwrite static serverless version number + version_number = "serverless" authentication_info = es.perform_request(method="GET", path="/_security/_authenticate") serverless_operator = authentication_info.body.get("operator", False) diff --git a/esrally/driver/driver.py b/esrally/driver/driver.py index 25a2e604e..4c6f6d562 100644 --- a/esrally/driver/driver.py +++ b/esrally/driver/driver.py @@ -724,10 +724,14 @@ def prepare_benchmark(self, t): else: self.wait_for_rest_api(es_clients) self.driver_actor.cluster_details = self.retrieve_cluster_info(es_clients) - if serverless_mode and serverless_operator: - build_hash = self.retrieve_build_hash_from_nodes_info(es_clients) - self.logger.info("Retrieved actual build hash [%s] from serverless cluster.", build_hash) - self.driver_actor.cluster_details["version"]["build_hash"] = build_hash + if serverless_mode: + # overwrite static serverless version number + self.driver_actor.cluster_details["version"]["number"] = "serverless" + if serverless_operator: + # overwrite build hash if running as operator + build_hash = self.retrieve_build_hash_from_nodes_info(es_clients) + self.logger.info("Retrieved actual build hash [%s] from serverless cluster.", build_hash) + self.driver_actor.cluster_details["version"]["build_hash"] = build_hash # Avoid issuing any requests to the target cluster when static responses are enabled. The results # are not useful and attempts to connect to a non-existing cluster just lead to exception traces in logs. diff --git a/esrally/driver/runner.py b/esrally/driver/runner.py index 6f51c94a4..38791324f 100644 --- a/esrally/driver/runner.py +++ b/esrally/driver/runner.py @@ -35,6 +35,7 @@ import ijson from esrally import exceptions, track +from esrally.utils import convert from esrally.utils.versions import Version # Mapping from operation type to specific runner @@ -175,8 +176,8 @@ def __init__(self, *args, config=None, **kwargs): self.serverless_mode = False self.serverless_operator = False if config: - self.serverless_mode = config.opts("driver", "serverless.mode", mandatory=False, default_value=False) - self.serverless_operator = config.opts("driver", "serverless.operator", mandatory=False, default_value=False) + self.serverless_mode = convert.to_bool(config.opts("driver", "serverless.mode", mandatory=False, default_value=False)) + self.serverless_operator = convert.to_bool(config.opts("driver", "serverless.operator", mandatory=False, default_value=False)) async def __aenter__(self): return self diff --git a/tests/driver/driver_test.py b/tests/driver/driver_test.py index 0cd363ba3..0af8a80c5 100644 --- a/tests/driver/driver_test.py +++ b/tests/driver/driver_test.py @@ -197,13 +197,13 @@ def test_prepare_serverless_benchmark(self, mock_method): d = driver.Driver(driver_actor, self.cfg, es_client_factory_class=self.StaticServerlessClientFactory) d.prepare_benchmark(t=self.track) - # was build hash determined correctly? + # was build hash and version determined correctly? assert driver_actor.cluster_details == { "name": "serverless", "cluster_name": "serverless", "cluster_uuid": "4bbPT0Z6SsuODSz_vG1umA", "version": { - "number": "8.10.0", + "number": "serverless", # <--- THIS "build_flavor": "serverless", "build_type": "docker", "build_hash": "5f626ea4014dc029b8ae3f0bca06944975bf2d80", # <--- THIS