From 1a81c607181ed2312ee7fe9cc91a0d2b481a0ab4 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 4 Oct 2012 16:41:24 +0200 Subject: [PATCH] Remove duration field in Counter This fixes bug #1039069 Change-Id: I17b5188d1cab08369599b1c936ab8d00b96dcf67 Signed-off-by: Julien Danjou --- ceilometer/compute/libvirt.py | 2 -- ceilometer/compute/notifications.py | 6 ---- ceilometer/counter.py | 3 -- ceilometer/image/glance.py | 2 -- ceilometer/image/notifications.py | 1 - ceilometer/meter.py | 1 - ceilometer/network/floatingip.py | 1 - ceilometer/network/notifications.py | 2 -- ceilometer/storage/impl_sqlalchemy.py | 1 - .../versions/002_remove_duration.py | 33 +++++++++++++++++++ ceilometer/storage/sqlalchemy/models.py | 1 - ceilometer/volume/notifications.py | 2 -- tests/api/v1/test_list_events.py | 2 -- tests/api/v1/test_list_projects.py | 4 --- tests/api/v1/test_list_resources.py | 8 ----- tests/api/v1/test_list_users.py | 4 --- tests/api/v1/test_max_resource_volume.py | 1 - tests/api/v1/test_sum_resource_volume.py | 1 - tests/compute/test_manager.py | 1 - tests/compute/test_nova_notifier.py | 1 - tests/image/test_notifications.py | 1 - tests/storage/test_impl_mongodb.py | 5 --- tests/storage/test_impl_sqlalchemy.py | 5 --- tests/test_meter.py | 2 -- tests/test_publish.py | 1 - tools/make_test_data.py | 1 - 26 files changed, 33 insertions(+), 59 deletions(-) create mode 100644 ceilometer/storage/sqlalchemy/migrate_repo/versions/002_remove_duration.py diff --git a/ceilometer/compute/libvirt.py b/ceilometer/compute/libvirt.py index 1ecf32f9b5..68695797ed 100644 --- a/ceilometer/compute/libvirt.py +++ b/ceilometer/compute/libvirt.py @@ -55,7 +55,6 @@ def make_counter_from_instance(instance, name, type, volume): project_id=instance.project_id, resource_id=instance.uuid, timestamp=timeutils.isotime(), - duration=None, resource_metadata=compute_instance.get_metadata_from_dbobject( instance), ) @@ -74,7 +73,6 @@ def make_vnic_counter(instance, name, type, volume, vnic_data): project_id=instance.project_id, resource_id=vnic_data['fref'], timestamp=timeutils.isotime(), - duration=None, resource_metadata=resource_metadata ) diff --git a/ceilometer/compute/notifications.py b/ceilometer/compute/notifications.py index a98bdd1585..45ca6a73da 100644 --- a/ceilometer/compute/notifications.py +++ b/ceilometer/compute/notifications.py @@ -75,7 +75,6 @@ class Instance(_Base): project_id=message['payload']['tenant_id'], resource_id=message['payload']['instance_id'], timestamp=message['timestamp'], - duration=0, resource_metadata=self.notification_to_metadata( message), ), @@ -94,7 +93,6 @@ class Memory(_Base): project_id=message['payload']['tenant_id'], resource_id=message['payload']['instance_id'], timestamp=message['timestamp'], - duration=0, resource_metadata=self.notification_to_metadata( message), ), @@ -113,7 +111,6 @@ class VCpus(_Base): project_id=message['payload']['tenant_id'], resource_id=message['payload']['instance_id'], timestamp=message['timestamp'], - duration=0, resource_metadata=self.notification_to_metadata( message), ), @@ -132,7 +129,6 @@ class RootDiskSize(_Base): project_id=message['payload']['tenant_id'], resource_id=message['payload']['instance_id'], timestamp=message['timestamp'], - duration=0, resource_metadata=self.notification_to_metadata( message), ), @@ -151,7 +147,6 @@ class EphemeralDiskSize(_Base): project_id=message['payload']['tenant_id'], resource_id=message['payload']['instance_id'], timestamp=message['timestamp'], - duration=0, resource_metadata=self.notification_to_metadata( message), ), @@ -174,7 +169,6 @@ class InstanceFlavor(_Base): project_id=message['payload']['tenant_id'], resource_id=message['payload']['instance_id'], timestamp=message['timestamp'], - duration=0, resource_metadata=self.notification_to_metadata( message), ) diff --git a/ceilometer/counter.py b/ceilometer/counter.py index a2405ffbfc..d9e539b57b 100644 --- a/ceilometer/counter.py +++ b/ceilometer/counter.py @@ -37,8 +37,6 @@ import collections # Project ID: the project ID # Resource ID: the resource ID # Timestamp: when the counter has been read -# Duration: duration in seconds determining how long the value is valid. -# adding this to timestamp give the end time of the counter # Resource metadata: various metadata Counter = collections.namedtuple('Counter', ' '.join(['source', @@ -49,7 +47,6 @@ Counter = collections.namedtuple('Counter', 'project_id', 'resource_id', 'timestamp', - 'duration', 'resource_metadata', ]) ) diff --git a/ceilometer/image/glance.py b/ceilometer/image/glance.py index 3b0421beca..75e545f007 100644 --- a/ceilometer/image/glance.py +++ b/ceilometer/image/glance.py @@ -99,7 +99,6 @@ class ImagePollster(_Base): project_id=image['owner'], resource_id=image['id'], timestamp=timeutils.isotime(), - duration=None, resource_metadata=self.extract_image_metadata(image), ) @@ -117,6 +116,5 @@ class ImageSizePollster(_Base): project_id=image['owner'], resource_id=image['id'], timestamp=timeutils.isotime(), - duration=None, resource_metadata=self.extract_image_metadata(image), ) diff --git a/ceilometer/image/notifications.py b/ceilometer/image/notifications.py index 5db93810a8..b9bcc3897e 100644 --- a/ceilometer/image/notifications.py +++ b/ceilometer/image/notifications.py @@ -67,7 +67,6 @@ class ImageBase(plugin.NotificationBase): user_id=user_id, project_id=project_id, timestamp=message['timestamp'], - duration=0, resource_metadata=metadata, ) diff --git a/ceilometer/meter.py b/ceilometer/meter.py index f415e915d2..90d829980b 100644 --- a/ceilometer/meter.py +++ b/ceilometer/meter.py @@ -89,7 +89,6 @@ def meter_message_from_counter(counter, secret): 'project_id': counter.project_id, 'resource_id': counter.resource_id, 'timestamp': counter.timestamp, - 'counter_duration': counter.duration, 'resource_metadata': counter.resource_metadata, 'message_id': str(uuid.uuid1()), } diff --git a/ceilometer/network/floatingip.py b/ceilometer/network/floatingip.py index fad3f7de99..bc2aa9e6d3 100644 --- a/ceilometer/network/floatingip.py +++ b/ceilometer/network/floatingip.py @@ -45,7 +45,6 @@ class FloatingIPPollster(plugin.CentralPollster): project_id=ip.project_id, resource_id=ip.id, timestamp=None, # FIXME(dhellmann): This needs to be now() - duration=None, resource_metadata={ 'address': ip.address, 'fixed_ip_id': ip.fixed_ip_id, diff --git a/ceilometer/network/notifications.py b/ceilometer/network/notifications.py index 6450b669ba..00a1845fe5 100644 --- a/ceilometer/network/notifications.py +++ b/ceilometer/network/notifications.py @@ -79,7 +79,6 @@ class NetworkNotificationBase(plugin.NotificationBase): project_id=message['payload']['tenant_id'], resource_id=message['payload']['id'], timestamp=message['timestamp'], - duration=None, resource_metadata=self.notification_to_metadata( message), ), @@ -91,7 +90,6 @@ class NetworkNotificationBase(plugin.NotificationBase): project_id=message['payload']['tenant_id'], resource_id='network', timestamp=message['timestamp'], - duration=None, resource_metadata=self.notification_to_metadata( message), ), diff --git a/ceilometer/storage/impl_sqlalchemy.py b/ceilometer/storage/impl_sqlalchemy.py index e3ff3f1301..14dc0084bd 100644 --- a/ceilometer/storage/impl_sqlalchemy.py +++ b/ceilometer/storage/impl_sqlalchemy.py @@ -166,7 +166,6 @@ class Connection(base.Connection): meter.user = user meter.timestamp = data['timestamp'] meter.resource_metadata = rmetadata - meter.counter_duration = data['counter_duration'] meter.counter_volume = data['counter_volume'] meter.message_signature = data['message_signature'] meter.message_id = data['message_id'] diff --git a/ceilometer/storage/sqlalchemy/migrate_repo/versions/002_remove_duration.py b/ceilometer/storage/sqlalchemy/migrate_repo/versions/002_remove_duration.py new file mode 100644 index 0000000000..1f1b9d056f --- /dev/null +++ b/ceilometer/storage/sqlalchemy/migrate_repo/versions/002_remove_duration.py @@ -0,0 +1,33 @@ +# -*- encoding: utf-8 -*- +# +# Author: Julien Danjou +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from sqlalchemy import * + +meta = MetaData() + + +def upgrade(migrate_engine): + meta.bind = migrate_engine + meter = Table('meter', meta, autoload=True) + duration = Column('counter_duration', Integer) + meter.drop_column(duration) + + +def downgrade(migrate_engine): + meta.bind = migrate_engine + meter = Table('meter', meta, autoload=True) + duration = Column('counter_duration', Integer) + meter.create_column(duration) diff --git a/ceilometer/storage/sqlalchemy/models.py b/ceilometer/storage/sqlalchemy/models.py index 99a7ee894c..00eb5b28c4 100644 --- a/ceilometer/storage/sqlalchemy/models.py +++ b/ceilometer/storage/sqlalchemy/models.py @@ -104,7 +104,6 @@ class Meter(Base): resource_metadata = Column(JSONEncodedDict) counter_type = Column(String(255)) counter_volume = Column(Integer) - counter_duration = Column(Integer) timestamp = Column(DateTime, default=timeutils.utcnow) message_signature = Column(String) message_id = Column(String) diff --git a/ceilometer/volume/notifications.py b/ceilometer/volume/notifications.py index 85ddb38f71..2b595a926d 100644 --- a/ceilometer/volume/notifications.py +++ b/ceilometer/volume/notifications.py @@ -77,7 +77,6 @@ class Volume(_Base): project_id=message['payload']['tenant_id'], resource_id=message['payload']['volume_id'], timestamp=message['timestamp'], - duration=None, resource_metadata=self.notification_to_metadata( message), ), @@ -96,7 +95,6 @@ class VolumeSize(_Base): project_id=message['payload']['tenant_id'], resource_id=message['payload']['volume_id'], timestamp=message['timestamp'], - duration=None, resource_metadata=self.notification_to_metadata( message), ), diff --git a/tests/api/v1/test_list_events.py b/tests/api/v1/test_list_events.py index 399d46f43d..befa636119 100644 --- a/tests/api/v1/test_list_events.py +++ b/tests/api/v1/test_list_events.py @@ -43,7 +43,6 @@ class TestListEvents(tests_api.TestBase): 'project1', 'resource-id', timestamp=datetime.datetime(2012, 7, 2, 10, 40), - duration=0, resource_metadata={'display_name': 'test-server', 'tag': 'self.counter', } @@ -62,7 +61,6 @@ class TestListEvents(tests_api.TestBase): 'project2', 'resource-id-alternate', timestamp=datetime.datetime(2012, 7, 2, 10, 41), - duration=0, resource_metadata={'display_name': 'test-server', 'tag': 'self.counter2', } diff --git a/tests/api/v1/test_list_projects.py b/tests/api/v1/test_list_projects.py index 51d3f5246e..af58fd3a8d 100644 --- a/tests/api/v1/test_list_projects.py +++ b/tests/api/v1/test_list_projects.py @@ -46,7 +46,6 @@ class TestListProjects(tests_api.TestBase): 'project-id', 'resource-id', timestamp=datetime.datetime(2012, 7, 2, 10, 40), - duration=0, resource_metadata={'display_name': 'test-server', 'tag': 'self.counter', } @@ -65,7 +64,6 @@ class TestListProjects(tests_api.TestBase): 'project-id2', 'resource-id-alternate', timestamp=datetime.datetime(2012, 7, 2, 10, 41), - duration=0, resource_metadata={'display_name': 'test-server', 'tag': 'self.counter2', } @@ -88,7 +86,6 @@ class TestListProjects(tests_api.TestBase): 'project-id', 'resource-id', timestamp=datetime.datetime(2012, 7, 2, 10, 40), - duration=0, resource_metadata={'display_name': 'test-server', 'tag': 'self.counter', } @@ -107,7 +104,6 @@ class TestListProjects(tests_api.TestBase): 'project-id2', 'resource-id-alternate', timestamp=datetime.datetime(2012, 7, 2, 10, 41), - duration=0, resource_metadata={'display_name': 'test-server', 'tag': 'self.counter2', } diff --git a/tests/api/v1/test_list_resources.py b/tests/api/v1/test_list_resources.py index 6b3f8850e5..70561a3e4d 100644 --- a/tests/api/v1/test_list_resources.py +++ b/tests/api/v1/test_list_resources.py @@ -46,7 +46,6 @@ class TestListResources(tests_api.TestBase): 'project-id', 'resource-id', timestamp=datetime.datetime(2012, 7, 2, 10, 40), - duration=0, resource_metadata={'display_name': 'test-server', 'tag': 'self.counter', } @@ -65,7 +64,6 @@ class TestListResources(tests_api.TestBase): 'project-id', 'resource-id-alternate', timestamp=datetime.datetime(2012, 7, 2, 10, 41), - duration=0, resource_metadata={'display_name': 'test-server', 'tag': 'self.counter2', } @@ -88,7 +86,6 @@ class TestListResources(tests_api.TestBase): 'project-id', 'resource-id', timestamp=datetime.datetime(2012, 7, 2, 10, 40), - duration=0, resource_metadata={'display_name': 'test-server', 'tag': 'self.counter', } @@ -107,7 +104,6 @@ class TestListResources(tests_api.TestBase): 'project-id', 'resource-id-alternate', timestamp=datetime.datetime(2012, 7, 2, 10, 41), - duration=0, resource_metadata={'display_name': 'test-server', 'tag': 'self.counter2', } @@ -131,7 +127,6 @@ class TestListResources(tests_api.TestBase): 'project-id', 'resource-id', timestamp=datetime.datetime(2012, 7, 2, 10, 40), - duration=0, resource_metadata={'display_name': 'test-server', 'tag': 'self.counter', } @@ -150,7 +145,6 @@ class TestListResources(tests_api.TestBase): 'project-id', 'resource-id-alternate', timestamp=datetime.datetime(2012, 7, 2, 10, 41), - duration=0, resource_metadata={'display_name': 'test-server', 'tag': 'self.counter2', } @@ -174,7 +168,6 @@ class TestListResources(tests_api.TestBase): 'project-id', 'resource-id', timestamp=datetime.datetime(2012, 7, 2, 10, 40), - duration=0, resource_metadata={'display_name': 'test-server', 'tag': 'self.counter', } @@ -193,7 +186,6 @@ class TestListResources(tests_api.TestBase): 'project-id2', 'resource-id-alternate', timestamp=datetime.datetime(2012, 7, 2, 10, 41), - duration=0, resource_metadata={'display_name': 'test-server', 'tag': 'self.counter2', } diff --git a/tests/api/v1/test_list_users.py b/tests/api/v1/test_list_users.py index 092275c308..4f79f574b2 100644 --- a/tests/api/v1/test_list_users.py +++ b/tests/api/v1/test_list_users.py @@ -46,7 +46,6 @@ class TestListUsers(tests_api.TestBase): 'project-id', 'resource-id', timestamp=datetime.datetime(2012, 7, 2, 10, 40), - duration=0, resource_metadata={'display_name': 'test-server', 'tag': 'self.counter', } @@ -65,7 +64,6 @@ class TestListUsers(tests_api.TestBase): 'project-id', 'resource-id-alternate', timestamp=datetime.datetime(2012, 7, 2, 10, 41), - duration=0, resource_metadata={'display_name': 'test-server', 'tag': 'self.counter2', } @@ -88,7 +86,6 @@ class TestListUsers(tests_api.TestBase): 'project-id', 'resource-id', timestamp=datetime.datetime(2012, 7, 2, 10, 40), - duration=0, resource_metadata={'display_name': 'test-server', 'tag': 'self.counter', } @@ -107,7 +104,6 @@ class TestListUsers(tests_api.TestBase): 'project-id', 'resource-id-alternate', timestamp=datetime.datetime(2012, 7, 2, 10, 41), - duration=0, resource_metadata={'display_name': 'test-server', 'tag': 'self.counter2', } diff --git a/tests/api/v1/test_max_resource_volume.py b/tests/api/v1/test_max_resource_volume.py index acd00cd425..2ddd42d5e9 100644 --- a/tests/api/v1/test_max_resource_volume.py +++ b/tests/api/v1/test_max_resource_volume.py @@ -55,7 +55,6 @@ class TestMaxResourceVolume(tests_api.TestBase): 'project1', 'resource-id', timestamp=datetime.datetime(2012, 9, 25, 10 + i, 30 + i), - duration=0, resource_metadata={'display_name': 'test-volume', 'tag': 'self.counter', } diff --git a/tests/api/v1/test_sum_resource_volume.py b/tests/api/v1/test_sum_resource_volume.py index 3d4a63faea..11d4199629 100644 --- a/tests/api/v1/test_sum_resource_volume.py +++ b/tests/api/v1/test_sum_resource_volume.py @@ -55,7 +55,6 @@ class TestSumResourceVolume(tests_api.TestBase): 'project1', 'resource-id', timestamp=datetime.datetime(2012, 9, 25, 10 + i, 30 + i), - duration=0, resource_metadata={'display_name': 'test-volume', 'tag': 'self.counter', } diff --git a/tests/compute/test_manager.py b/tests/compute/test_manager.py index f732a58f8c..09f39ad367 100644 --- a/tests/compute/test_manager.py +++ b/tests/compute/test_manager.py @@ -48,7 +48,6 @@ class TestRunTasks(base.TestCase): project_id='test', resource_id='test_run_tasks', timestamp=datetime.datetime.utcnow().isoformat(), - duration=0, resource_metadata={'name': 'Pollster', }, ) diff --git a/tests/compute/test_nova_notifier.py b/tests/compute/test_nova_notifier.py index 87974b4a04..e03c3ceebb 100644 --- a/tests/compute/test_nova_notifier.py +++ b/tests/compute/test_nova_notifier.py @@ -54,7 +54,6 @@ class TestNovaNotifier(base.TestCase): project_id='test', resource_id='test_run_tasks', timestamp=datetime.datetime.utcnow().isoformat(), - duration=0, resource_metadata={'name': 'Pollster', }, ) diff --git a/tests/image/test_notifications.py b/tests/image/test_notifications.py index e192016d3d..5eb74da5cd 100644 --- a/tests/image/test_notifications.py +++ b/tests/image/test_notifications.py @@ -49,7 +49,6 @@ class TestNotification(unittest.TestCase): self.assertEqual(c.volume, 42) self.assertEqual(c.resource_id, utils.fake_uuid('c')) self.assertEqual(c.timestamp, NOW) - self.assertEqual(c.duration, 0) metadata = c.resource_metadata self.assertEquals(metadata.get('event_type'), u'image.send') self.assertEquals(metadata.get('host'), u'images.example.com') diff --git a/tests/storage/test_impl_mongodb.py b/tests/storage/test_impl_mongodb.py index 38f232d1de..95aa707a75 100644 --- a/tests/storage/test_impl_mongodb.py +++ b/tests/storage/test_impl_mongodb.py @@ -110,7 +110,6 @@ class MongoDBEngineTestBase(unittest.TestCase): 'project-id', 'resource-id', timestamp=datetime.datetime(2012, 7, 2, 10, 40), - duration=0, resource_metadata={'display_name': 'test-server', 'tag': 'self.counter', } @@ -128,7 +127,6 @@ class MongoDBEngineTestBase(unittest.TestCase): 'project-id', 'resource-id-alternate', timestamp=datetime.datetime(2012, 7, 2, 10, 41), - duration=0, resource_metadata={'display_name': 'test-server', 'tag': 'self.counter2', } @@ -146,7 +144,6 @@ class MongoDBEngineTestBase(unittest.TestCase): 'project-id', 'resource-id-alternate', timestamp=datetime.datetime(2012, 7, 2, 10, 41), - duration=0, resource_metadata={'display_name': 'test-server', 'tag': 'self.counter3', } @@ -165,7 +162,6 @@ class MongoDBEngineTestBase(unittest.TestCase): 'project-id-%s' % i, 'resource-id-%s' % i, timestamp=datetime.datetime(2012, 7, 2, 10, 40 + i), - duration=0, resource_metadata={'display_name': 'test-server', 'tag': 'counter-%s' % i, } @@ -486,7 +482,6 @@ class TestGetEventInterval(MongoDBEngineTestBase): 'project-id', 'resource-id', timestamp=t, - duration=0, resource_metadata={'display_name': 'test-server', } ) diff --git a/tests/storage/test_impl_sqlalchemy.py b/tests/storage/test_impl_sqlalchemy.py index e3eea48449..fcddf06a87 100644 --- a/tests/storage/test_impl_sqlalchemy.py +++ b/tests/storage/test_impl_sqlalchemy.py @@ -87,7 +87,6 @@ class SQLAlchemyEngineTestBase(unittest.TestCase): project_id='project-id', resource_id='resource-id', timestamp=datetime.datetime(2012, 7, 2, 10, 40), - duration=0, resource_metadata={'display_name': 'test-server', 'tag': 'self.counter', } @@ -106,7 +105,6 @@ class SQLAlchemyEngineTestBase(unittest.TestCase): project_id='project-id', resource_id='resource-id-alternate', timestamp=datetime.datetime(2012, 7, 2, 10, 41), - duration=0, resource_metadata={'display_name': 'test-server', 'tag': 'self.counter2', } @@ -125,7 +123,6 @@ class SQLAlchemyEngineTestBase(unittest.TestCase): project_id='project-id', resource_id='resource-id-alternate', timestamp=datetime.datetime(2012, 7, 2, 10, 41), - duration=0, resource_metadata={'display_name': 'test-server', 'tag': 'self.counter3', } @@ -145,7 +142,6 @@ class SQLAlchemyEngineTestBase(unittest.TestCase): 'project-id-%s' % i, 'resource-id-%s' % i, timestamp=datetime.datetime(2012, 7, 2, 10, 40 + i), - duration=0, resource_metadata={'display_name': 'test-server', 'tag': 'counter-%s' % i, } @@ -408,7 +404,6 @@ class TestGetEventInterval(SQLAlchemyEngineTestBase): '1', '111', timestamp=t, - duration=0, resource_metadata={'display_name': 'test-server', } ) diff --git a/tests/test_meter.py b/tests/test_meter.py index 418f4d7588..64fae5ebc2 100644 --- a/tests/test_meter.py +++ b/tests/test_meter.py @@ -107,7 +107,6 @@ TEST_COUNTER = counter.Counter(source='src', project_id='project', resource_id=2, timestamp='today', - duration=3, resource_metadata={'key': 'value'}, ) @@ -161,7 +160,6 @@ def test_meter_message_from_counter_field(): name_map = {'name': 'counter_name', 'type': 'counter_type', 'volume': 'counter_volume', - 'duration': 'counter_duration', } for f in TEST_COUNTER._fields: msg_f = name_map.get(f, f) diff --git a/tests/test_publish.py b/tests/test_publish.py index 1f4d972ec7..b02d109331 100644 --- a/tests/test_publish.py +++ b/tests/test_publish.py @@ -38,7 +38,6 @@ class TestPublish(base.TestCase): project_id='test', resource_id='test_run_tasks', timestamp=datetime.datetime.utcnow().isoformat(), - duration=0, resource_metadata={'name': 'TestPublish', }, ) diff --git a/tools/make_test_data.py b/tools/make_test_data.py index 81be5f3888..fa082a456d 100755 --- a/tools/make_test_data.py +++ b/tools/make_test_data.py @@ -121,7 +121,6 @@ def main(): project_id=args.project, resource_id=args.resource, timestamp=timestamp, - duration=0, resource_metadata={}, ) data = meter.meter_message_from_counter(c)