diff --git a/distil/tests/unit/transformer/test_conversion.py b/distil/tests/unit/transformer/test_conversion.py index 76a3f66..f8b6e9c 100644 --- a/distil/tests/unit/transformer/test_conversion.py +++ b/distil/tests/unit/transformer/test_conversion.py @@ -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) diff --git a/distil/transformer/conversion.py b/distil/transformer/conversion.py index 9863d9b..fd62ad9 100644 --- a/distil/transformer/conversion.py +++ b/distil/transformer/conversion.py @@ -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, diff --git a/etc/transformer.yaml.sample b/etc/transformer.yaml.sample index 4eecf77..415cfa4 100644 --- a/etc/transformer.yaml.sample +++ b/etc/transformer.yaml.sample @@ -38,6 +38,8 @@ databaseuptime: - UPGRADE - DETACH databasemanagementuptime: + prefix: "db." + tracked_states: - HEALTHY - ACTIVE - BLOCKED