DB Managment Transformer to use flavor and prefix

Change-Id: I72f430a948cc9122ee17581b37ca8b5f39928cc7
This commit is contained in:
Adrian Turjak 2020-07-20 13:11:24 +12:00
parent 0a0c7e12ef
commit 4fe7f644f8
3 changed files with 28 additions and 6 deletions

View File

@ -33,8 +33,8 @@ class FAKE_DATA:
# and one outside the window
tpre = p('2013-12-31T23:50:00')
flavor = '1'
flavor2 = '2'
flavor = 'c1.c1r1'
flavor2 = 'c1.c2r2'
FAKE_CONFIG = {
@ -601,7 +601,9 @@ class TestDatabaseManagementUpTimeTransformer(base.DistilTestCase):
result = xform.transform_usage('state', state, FAKE_DATA.t0,
FAKE_DATA.t1)
self.assertEqual({"d1.managment": 3600}, result)
management_service = "db." + FAKE_DATA.flavor
self.assertEqual({management_service: 3600}, result)
@mock.patch.object(
openstack, 'get_flavor_name',
@ -650,4 +652,6 @@ class TestDatabaseManagementUpTimeTransformer(base.DistilTestCase):
result = xform.transform_usage('state', state, FAKE_DATA.t0,
FAKE_DATA.t1)
self.assertEqual({"d1.managment": 1800}, result)
management_service = "db." + FAKE_DATA.flavor
self.assertEqual({management_service: 1800}, result)

View File

@ -188,6 +188,11 @@ class DatabaseUpTimeTransformer(UpTimeTransformer):
"""
Transformer to calculate uptime based on states,
which is broken apart into flavor at point in time.
Same as the normal instance uptime transformer, but the
status and flavor are pulled from different locations
in the metadata as database instance samples have a
different format.
"""
def _clean_entry(self, entry):
@ -214,11 +219,17 @@ class DatabaseManagementUpTimeTransformer(UpTimeTransformer):
"""
Transformer to calculate uptime based on states,
which is broken apart into flavor at point in time.
While this uses the base uptime logic, the service name
here needs to be a variant of the flavor prefixed with
a database specific value. In this case 'db.' which will
mean a flavor of 'c1.c1r2' will become 'db.c1.c1r2' for the
service in the usage sample.
"""
def _clean_entry(self, entry):
management_service_name = self.config.get(
'service_name', 'd1.management')
management_prefix = self.config.get(
'prefix', 'db.')
try:
timestamp = datetime.strptime(
@ -227,6 +238,11 @@ class DatabaseManagementUpTimeTransformer(UpTimeTransformer):
timestamp = datetime.strptime(
entry['timestamp'], constants.date_format_f)
flavor = openstack.get_flavor_name(
entry['metadata'].get('flavor.id'))
management_service_name = management_prefix + flavor
result = {
'status': entry['metadata'].get('status'),
'flavor': management_service_name,

View File

@ -38,6 +38,8 @@ databaseuptime:
- UPGRADE
- DETACH
databasemanagementuptime:
prefix: "db."
tracked_states:
- HEALTHY
- ACTIVE
- BLOCKED