From 3116ecf1c2c1fcbc2d8a790787753dadd2522618 Mon Sep 17 00:00:00 2001 From: Igor Degtiarov Date: Tue, 10 Nov 2015 23:22:13 +0200 Subject: [PATCH] Extend samples list benchmarks for Ceilometer Existing benchmarks for samples list query are updated via new context and adding new configured query parameters. It allow to find a weak places in requesting Ceilometer data and extend count of scenarios which use in Ceilometer. Change-Id: If2c780ab6cf9a3bdfb339e9b96b34d909ff17f28 --- .../openstack/scenarios/ceilometer/samples.py | 36 +++++++++++++-- .../openstack/scenarios/ceilometer/utils.py | 13 ++++-- .../ceilometer/list-matched-samples.json | 41 +++++++++++++++++ .../ceilometer/list-matched-samples.yaml | 35 ++++++++++++++ .../scenarios/ceilometer/list-samples.json | 8 +++- .../scenarios/ceilometer/list-samples.yaml | 8 +++- .../scenarios/ceilometer/test_samples.py | 46 +++++++++++++++++-- .../scenarios/ceilometer/test_utils.py | 14 +++++- 8 files changed, 185 insertions(+), 16 deletions(-) create mode 100644 samples/tasks/scenarios/ceilometer/list-matched-samples.json create mode 100644 samples/tasks/scenarios/ceilometer/list-matched-samples.yaml diff --git a/rally/plugins/openstack/scenarios/ceilometer/samples.py b/rally/plugins/openstack/scenarios/ceilometer/samples.py index ed41c543..31232892 100644 --- a/rally/plugins/openstack/scenarios/ceilometer/samples.py +++ b/rally/plugins/openstack/scenarios/ceilometer/samples.py @@ -24,9 +24,37 @@ class CeilometerSamples(ceiloutils.CeilometerScenario): @validation.required_services(consts.Service.CEILOMETER) @validation.required_openstack(users=True) @scenario.configure() - def list_samples(self): - """Fetch all samples. + def list_matched_samples(self, filter_by_resource_id=False, + filter_by_project_id=False, + filter_by_user_id=False, + metadata_query=None, limit=None): + """Get list of samples that matched fields from context and args. - This scenario fetches list of all samples. + :param filter_by_user_id: flag for query by user_id + :param filter_by_project_id: flag for query by project_id + :param filter_by_resource_id: flag for query by resource_id + :param metadata_query: dict with metadata fields and values for query + :param limit: count of samples in response """ - self._list_samples() + query = self._make_general_query(filter_by_project_id, + filter_by_user_id, + filter_by_resource_id, + metadata_query) + self._list_samples(query, limit) + + @validation.required_services(consts.Service.CEILOMETER) + @validation.required_openstack(users=True) + @scenario.configure() + def list_samples(self, metadata_query=None, limit=None): + """Fetch all available queries for list sample request. + + :param metadata_query: dict with metadata fields and values for query + :param limit: count of samples in response + """ + self.list_matched_samples(filter_by_project_id=True) + self.list_matched_samples(filter_by_user_id=True) + self.list_matched_samples(filter_by_resource_id=True) + if metadata_query: + self.list_matched_samples(metadata_query=metadata_query) + if limit: + self.list_matched_samples(limit=limit) diff --git a/rally/plugins/openstack/scenarios/ceilometer/utils.py b/rally/plugins/openstack/scenarios/ceilometer/utils.py index 1739c8d6..cbdd766c 100644 --- a/rally/plugins/openstack/scenarios/ceilometer/utils.py +++ b/rally/plugins/openstack/scenarios/ceilometer/utils.py @@ -303,13 +303,18 @@ class CeilometerScenario(scenario.OpenStackScenario): return self.admin_clients("ceilometer").trait_descriptions.list( event_type) - @atomic.action_timer("ceilometer.list_samples") - def _list_samples(self): + def _list_samples(self, query=None, limit=None): """List all Samples. - :returns: list of all samples + :param query: optional param that specify query + :param limit: optional param for maximum number of samples returned + :returns: list of samples """ - return self.clients("ceilometer").samples.list() + key = self._make_profiler_key("ceilometer.list_samples", query, + limit) + with atomic.ActionTimer(self, key): + return self.clients("ceilometer").samples.list(q=query, + limit=limit) @atomic.action_timer("ceilometer.get_resource") def _get_resource(self, resource_id): diff --git a/samples/tasks/scenarios/ceilometer/list-matched-samples.json b/samples/tasks/scenarios/ceilometer/list-matched-samples.json new file mode 100644 index 00000000..259ef408 --- /dev/null +++ b/samples/tasks/scenarios/ceilometer/list-matched-samples.json @@ -0,0 +1,41 @@ +{ + "CeilometerSamples.list_matched_samples": [ + { + "runner": { + "type": "constant", + "times": 10, + "concurrency": 2 + }, + "context": { + "users": { + "tenants": 2, + "users_per_tenant": 2 + }, + "ceilometer": { + "counter_name": "cpu_util", + "counter_type": "gauge", + "counter_unit": "instance", + "counter_volume": 1.0, + "resources_per_tenant": 100, + "samples_per_resource": 100, + "timestamp_interval": 60, + "metadata_list": [ + {"status": "active", "name": "fake_resource", + "deleted": "False", + "created_at": "2015-09-04T12:34:19.000000"}, + {"status": "not_active", "name": "fake_resource_1", + "deleted": "False", + "created_at": "2015-09-10T06:55:12.000000"} + ] + } + }, + "args":{ + "filter_by_user_id": true, + "filter_by_project_id": true, + "filter_by_resource_id": true, + "limit": 50, + "metadata_query": {"status": "not_active"} + } + } + ] +} \ No newline at end of file diff --git a/samples/tasks/scenarios/ceilometer/list-matched-samples.yaml b/samples/tasks/scenarios/ceilometer/list-matched-samples.yaml new file mode 100644 index 00000000..1ff7c229 --- /dev/null +++ b/samples/tasks/scenarios/ceilometer/list-matched-samples.yaml @@ -0,0 +1,35 @@ +--- + CeilometerSamples.list_matched_samples: + - + runner: + type: "constant" + times: 10 + concurrency: 2 + context: + users: + tenants: 2 + users_per_tenant: 2 + ceilometer: + counter_name: "cpu_util" + counter_type: "gauge" + counter_unit: "instance" + counter_volume: 1.0 + resources_per_tenant: 100 + samples_per_resource: 100 + timestamp_interval: 60 + metadata_list: + - status: "active" + name: "fake_resource" + deleted: "False" + created_at: "2015-09-04T12:34:19.000000" + - status: "not_active" + name: "fake_resource_1" + deleted: "False" + created_at: "2015-09-10T06:55:12.000000" + args: + limit: 50 + filter_by_user_id: true + filter_by_project_id: true + filter_by_resource_id: true + metadata_query: + status: "not_active" diff --git a/samples/tasks/scenarios/ceilometer/list-samples.json b/samples/tasks/scenarios/ceilometer/list-samples.json index 49f7d09f..82b82ebc 100644 --- a/samples/tasks/scenarios/ceilometer/list-samples.json +++ b/samples/tasks/scenarios/ceilometer/list-samples.json @@ -16,8 +16,8 @@ "counter_type": "gauge", "counter_unit": "instance", "counter_volume": 1.0, - "resources_per_tenant": 3, - "samples_per_resource": 3, + "resources_per_tenant": 100, + "samples_per_resource": 100, "timestamp_interval": 60, "metadata_list": [ {"status": "active", "name": "fake_resource", @@ -28,6 +28,10 @@ "created_at": "2015-09-10T06:55:12.000000"} ] } + }, + "args":{ + "limit": 50, + "metadata_query": {"status": "not_active"} } } ] diff --git a/samples/tasks/scenarios/ceilometer/list-samples.yaml b/samples/tasks/scenarios/ceilometer/list-samples.yaml index 22d4186c..5c020d84 100644 --- a/samples/tasks/scenarios/ceilometer/list-samples.yaml +++ b/samples/tasks/scenarios/ceilometer/list-samples.yaml @@ -14,8 +14,8 @@ counter_type: "gauge" counter_unit: "instance" counter_volume: 1.0 - resources_per_tenant: 3 - samples_per_resource: 3 + resources_per_tenant: 100 + samples_per_resource: 100 timestamp_interval: 60 metadata_list: - status: "active" @@ -26,3 +26,7 @@ name: "fake_resource_1" deleted: "False" created_at: "2015-09-10T06:55:12.000000" + args: + limit: 50 + metadata_query: + status: "not_active" diff --git a/tests/unit/plugins/openstack/scenarios/ceilometer/test_samples.py b/tests/unit/plugins/openstack/scenarios/ceilometer/test_samples.py index 1be88a33..09c97a1d 100644 --- a/tests/unit/plugins/openstack/scenarios/ceilometer/test_samples.py +++ b/tests/unit/plugins/openstack/scenarios/ceilometer/test_samples.py @@ -19,8 +19,48 @@ from tests.unit import test class CeilometerSamplesTestCase(test.ScenarioTestCase): - def test_list_samples(self): + + def test_all_list_samples(self): + scenario = samples.CeilometerSamples(self.context) + scenario.list_matched_samples = mock.MagicMock() + metadata_query = {"a": "test"} + limit = 10 + scenario.list_samples(metadata_query, limit) + scenario.list_matched_samples.assert_any_call(limit=10) + scenario.list_matched_samples.assert_any_call( + metadata_query=metadata_query) + scenario.list_matched_samples.assert_any_call( + filter_by_resource_id=True) + scenario.list_matched_samples.assert_any_call( + filter_by_user_id=True) + scenario.list_matched_samples.assert_any_call( + filter_by_project_id=True) + + def test_list_samples_without_limit_and_metadata(self): + scenario = samples.CeilometerSamples(self.context) + scenario.list_matched_samples = mock.MagicMock() + scenario.list_samples() + expected_call_args_list = [ + mock.call(filter_by_project_id=True), + mock.call(filter_by_user_id=True), + mock.call(filter_by_resource_id=True) + ] + self.assertSequenceEqual(expected_call_args_list, + scenario.list_matched_samples.call_args_list) + + def test_list_matched_samples(self): scenario = samples.CeilometerSamples(self.context) scenario._list_samples = mock.MagicMock() - scenario.list_samples() - scenario._list_samples.assert_called_once_with() + context = {"user": {"tenant_id": "fake", "id": "fake_id"}, + "tenant": {"id": "fake_id", + "resources": ["fake_resource"]}} + scenario.context = context + metadata_query = {"a": "test"} + limit = 10 + scenario.list_matched_samples(True, True, True, metadata_query, limit) + scenario._list_samples.assert_called_once_with( + [{"field": "user_id", "value": "fake_id", "op": "eq"}, + {"field": "project_id", "value": "fake_id", "op": "eq"}, + {"field": "resource_id", "value": "fake_resource", "op": "eq"}, + {"field": "metadata.a", "value": "test", "op": "eq"}], + 10) diff --git a/tests/unit/plugins/openstack/scenarios/ceilometer/test_utils.py b/tests/unit/plugins/openstack/scenarios/ceilometer/test_utils.py index eeaab407..ed37b5b3 100644 --- a/tests/unit/plugins/openstack/scenarios/ceilometer/test_utils.py +++ b/tests/unit/plugins/openstack/scenarios/ceilometer/test_utils.py @@ -222,10 +222,22 @@ class CeilometerScenarioTestCase(test.ScenarioTestCase): self.assertEqual( self.scenario._list_samples(), self.clients("ceilometer").samples.list.return_value) - self.clients("ceilometer").samples.list.assert_called_once_with() + self.clients("ceilometer").samples.list.assert_called_once_with( + q=None, limit=None) self._test_atomic_action_timer(self.scenario.atomic_actions(), "ceilometer.list_samples") + def test__list_samples_with_query(self): + self.assertEqual( + self.scenario._list_samples(query=[{"field": "user_id", + "volume": "fake_id"}], + limit=10), + self.clients("ceilometer").samples.list.return_value) + self.clients("ceilometer").samples.list.assert_called_once_with( + q=[{"field": "user_id", "volume": "fake_id"}], limit=10) + self._test_atomic_action_timer(self.scenario.atomic_actions(), + "ceilometer.list_samples:limit&user_id") + def test__get_resource(self): self.assertEqual(self.scenario._get_resource("fake-resource-id"), self.clients("ceilometer").resources.get.return_value)