Remove duration field in Counter

This fixes bug #1039069

Change-Id: I17b5188d1cab08369599b1c936ab8d00b96dcf67
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2012-10-04 16:41:24 +02:00
parent f1ecbcc829
commit 1a81c60718
26 changed files with 33 additions and 59 deletions

View File

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

View File

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

View File

@ -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',
])
)

View File

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

View File

@ -67,7 +67,6 @@ class ImageBase(plugin.NotificationBase):
user_id=user_id,
project_id=project_id,
timestamp=message['timestamp'],
duration=0,
resource_metadata=metadata,
)

View File

@ -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()),
}

View File

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

View File

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

View File

@ -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']

View File

@ -0,0 +1,33 @@
# -*- encoding: utf-8 -*-
#
# Author: Julien Danjou <julien@danjou.info>
#
# 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)

View File

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

View File

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

View File

@ -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',
}

View File

@ -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',
}

View File

@ -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',
}

View File

@ -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',
}

View File

@ -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',
}

View File

@ -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',
}

View File

@ -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',
},
)

View File

@ -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',
},
)

View File

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

View File

@ -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',
}
)

View File

@ -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',
}
)

View File

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

View File

@ -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',
},
)

View File

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