def test_create_filters_from_mixed_included_tasks(self): from esrally.track import track filters = loader.filters_from_included_tasks( ["force-merge", "type:search"]) self.assertListEqual([ track.TaskOpNameFilter("force-merge"), track.TaskOpTypeFilter("search") ], filters)
def filters_from_included_tasks(included_tasks): filters = [] if included_tasks: for t in included_tasks: spec = t.split(":") if len(spec) == 1: filters.append(track.TaskNameFilter(spec[0])) elif len(spec) == 2: if spec[0] == "type": filters.append(track.TaskOpTypeFilter(spec[1])) else: raise exceptions.SystemSetupError("Invalid format for included tasks: [%s]. Expected [type] but got [%s]." % (t, spec[0])) else: raise exceptions.SystemSetupError("Invalid format for included tasks: [%s]" % t) return filters
def test_task_op_type_filter(self): f = track.TaskOpTypeFilter( track.OperationType.CreateIndex.to_hyphenated_string()) self.assertTrue(f.matches(self.create_index_task())) self.assertFalse(f.matches(self.search_task()))
def test_filters_tasks(self): from esrally.track import track track_specification = { "short-description": "short description for unit test", "description": "longer description of this track for unit test", "indices": [{ "name": "test-index", "auto-managed": False }], "operations": [ { "name": "index-1", "operation-type": "index" }, { "name": "index-2", "operation-type": "index" }, { "name": "index-3", "operation-type": "index" }, { "name": "node-stats", "operation-type": "node-stats" }, { "name": "cluster-stats", "operation-type": "custom-operation-type" }, { "name": "match-all", "operation-type": "search", "body": { "query": { "match_all": {} } } }, ], "challenges": [{ "name": "default-challenge", "description": "Default challenge", "schedule": [{ "parallel": { "tasks": [ { "operation": "index-1", }, { "operation": "index-2", }, { "operation": "index-3", }, { "operation": "match-all", }, ] } }, { "operation": "node-stats" }, { "operation": "match-all" }, { "operation": "cluster-stats" }] }] } reader = loader.TrackSpecificationReader() full_track = reader("unittest", track_specification, "/mappings") self.assertEqual(4, len(full_track.challenges[0].schedule)) filtered = loader.filter_included_tasks( full_track, [ track.TaskOpNameFilter("index-3"), track.TaskOpTypeFilter("search"), # Filtering should also work for non-core operation types. track.TaskOpTypeFilter("custom-operation-type") ]) schedule = filtered.challenges[0].schedule self.assertEqual(3, len(schedule)) self.assertEqual(["index-3", "match-all"], [t.operation.name for t in schedule[0].tasks]) self.assertEqual("match-all", schedule[1].operation.name) self.assertEqual("cluster-stats", schedule[2].operation.name)
def post_process_for_index_auto_management(t, expected_cluster_health): auto_managed_indices = any([index.auto_managed for index in t.indices]) # spare users this warning for our default tracks if auto_managed_indices and t.name not in DEFAULT_TRACKS: console.warn("Track [%s] uses index auto-management which will be removed soon. Please add [delete-index] and [create-index] " "tasks at the beginning of each relevant challenge and turn off index auto-management for each index. For details " "please see the migration guide in the docs." % t.name) if auto_managed_indices or len(t.templates) > 0: for challenge in t.challenges: tasks = [] # TODO: Remove the index settings element. We can do this much better now with the create-index operation. create_index_params = {"include-in-reporting": False} if challenge.index_settings: if t.name not in DEFAULT_TRACKS: console.warn("Track [%s] defines the deprecated property 'index-settings'. Please create indices explicitly with " "[create-index] and the respective index settings there instead." % t.name) create_index_params["settings"] = challenge.index_settings if len(t.templates) > 0: # check if the user has defined a create index template operation user_creates_templates = any(task.matches(track.TaskOpTypeFilter(track.OperationType.CreateIndexTemplate.name)) for task in challenge.schedule) # We attempt to still do this automatically but issue a warning so that the user will create it themselves. if not user_creates_templates: console.warn("Track [%s] defines %d index template(s) but soon Rally will not create them implicitly anymore. Please " "add [delete-index-template] and [create-index-template] tasks at the beginning of the challenge %s." % (t.name, len(t.templates), challenge.name), logger=logger) tasks.append(track.Task(name="auto-delete-index-templates", operation=track.Operation(name="auto-delete-index-templates", operation_type=track.OperationType.DeleteIndexTemplate.name, params={ "include-in-reporting": False, "only-if-exists": True }))) tasks.append(track.Task(name="auto-create-index-templates", operation=track.Operation(name="auto-create-index-templates", operation_type=track.OperationType.CreateIndexTemplate.name, params=create_index_params.copy()))) if auto_managed_indices: tasks.append(track.Task(name="auto-delete-indices", operation=track.Operation(name="auto-delete-indices", operation_type=track.OperationType.DeleteIndex.name, params={ "include-in-reporting": False, "only-if-exists": True }))) tasks.append(track.Task(name="auto-create-indices", operation=track.Operation(name="auto-create-indices", operation_type=track.OperationType.CreateIndex.name, params=create_index_params.copy()))) # check if the user has already defined a cluster-health operation user_checks_cluster_health = any(task.matches(track.TaskOpTypeFilter(track.OperationType.ClusterHealth.name)) for task in challenge.schedule) if expected_cluster_health != "skip" and not user_checks_cluster_health: tasks.append(track.Task(name="auto-check-cluster-health", operation=track.Operation(name="auto-check-cluster-health", operation_type=track.OperationType.ClusterHealth.name, params={ "include-in-reporting": False, "request-params": { "wait_for_status": expected_cluster_health } }))) challenge.prepend_tasks(tasks) return t else: return t