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
This commit is contained in:
Igor Degtiarov 2015-11-10 23:22:13 +02:00
parent 45b3cb66e5
commit 3116ecf1c2
8 changed files with 185 additions and 16 deletions

View File

@ -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)

View File

@ -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):

View File

@ -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"}
}
}
]
}

View File

@ -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"

View File

@ -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"}
}
}
]

View File

@ -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"

View File

@ -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)

View File

@ -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)