network: do not emit counter on exists event, fix resource id

We only emit resource counters like "network.create" when the event is not
something like "network.exists", and we now emit it on the resource itself,
not on 'network'.

This fixes bug #1062949

Change-Id: Id36bc3818107bf7b806096b7aee670d7b18215a4
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2012-10-08 12:04:33 +02:00
parent 4a82b98ca7
commit f3e7d2a611
3 changed files with 38 additions and 38 deletions

View File

@ -70,8 +70,8 @@ class NetworkNotificationBase(plugin.NotificationBase):
def process_notification(self, message): def process_notification(self, message):
LOG.info('network notification %r', message) LOG.info('network notification %r', message)
message['payload'] = message['payload'][self.resource_name] message['payload'] = message['payload'][self.resource_name]
return [ metadata = self.notification_to_metadata(message)
counter.Counter(source='?', yield counter.Counter(source='?',
name=self.resource_name, name=self.resource_name,
type=counter.TYPE_GAUGE, type=counter.TYPE_GAUGE,
volume=1, volume=1,
@ -79,21 +79,21 @@ class NetworkNotificationBase(plugin.NotificationBase):
project_id=message['payload']['tenant_id'], project_id=message['payload']['tenant_id'],
resource_id=message['payload']['id'], resource_id=message['payload']['id'],
timestamp=message['timestamp'], timestamp=message['timestamp'],
resource_metadata=self.notification_to_metadata( resource_metadata=metadata,
message), )
),
counter.Counter(source='?', network_counter_name = message['event_type'].rpartition('.')[0]
name=message['event_type'].rpartition('.')[0], if network_counter_name != self.resource_name:
yield counter.Counter(source='?',
name=network_counter_name,
type=counter.TYPE_GAUGE, type=counter.TYPE_GAUGE,
volume=1, volume=1,
user_id=message['_context_user_id'], user_id=message['_context_user_id'],
project_id=message['payload']['tenant_id'], project_id=message['payload']['tenant_id'],
resource_id='network', resource_id=message['payload']['id'],
timestamp=message['timestamp'], timestamp=message['timestamp'],
resource_metadata=self.notification_to_metadata( resource_metadata=metadata,
message), )
),
]
class Network(NetworkNotificationBase): class Network(NetworkNotificationBase):

View File

@ -62,17 +62,17 @@ Network (Quantum)
Name Type Volume Resource Note Name Type Volume Resource Note
======================== ========== ======= ======== ======================================================= ======================== ========== ======= ======== =======================================================
network Gauge 1 netw ID Duration of network network Gauge 1 netw ID Duration of network
network.create Gauge 1 network network.create Gauge 1 netw ID
network.update Gauge 1 network network.update Gauge 1 netw ID
network.exists Gauge 1 network network.exists Gauge 1 netw ID
subnet Gauge 1 subnt ID Duration of subnet subnet Gauge 1 subnt ID Duration of subnet
subnet.create Gauge 1 network subnet.create Gauge 1 subnt ID
subnet.update Gauge 1 network subnet.update Gauge 1 subnt ID
subnet.exists Gauge 1 network subnet.exists Gauge 1 subnt ID
port Gauge 1 port ID Duration of port port Gauge 1 port ID Duration of port
port.create Gauge 1 network port.create Gauge 1 port ID
port.update Gauge 1 network port.update Gauge 1 port ID
port.exists Gauge 1 network port.exists Gauge 1 port ID
floating_ip Gauge 1 ip ID Duration of floating ip floating_ip Gauge 1 ip ID Duration of floating ip
======================== ========== ======= ======== ======================================================= ======================== ========== ======= ======== =======================================================

View File

@ -161,27 +161,27 @@ class TestNotifications(unittest.TestCase):
def test_network_create(self): def test_network_create(self):
v = notifications.Network() v = notifications.Network()
counters = v.process_notification(NOTIFICATION_NETWORK_CREATE) counters = v.process_notification(NOTIFICATION_NETWORK_CREATE)
self.assertEqual(len(counters), 2) self.assertEqual(len(list(counters)), 2)
def test_subnet_create(self): def test_subnet_create(self):
v = notifications.Subnet() v = notifications.Subnet()
counters = v.process_notification(NOTIFICATION_SUBNET_CREATE) counters = v.process_notification(NOTIFICATION_SUBNET_CREATE)
self.assertEqual(len(counters), 2) self.assertEqual(len(list(counters)), 2)
def test_port_create(self): def test_port_create(self):
v = notifications.Port() v = notifications.Port()
counters = v.process_notification(NOTIFICATION_PORT_CREATE) counters = v.process_notification(NOTIFICATION_PORT_CREATE)
self.assertEqual(len(counters), 2) self.assertEqual(len(list(counters)), 2)
def test_port_update(self): def test_port_update(self):
v = notifications.Port() v = notifications.Port()
counters = v.process_notification(NOTIFICATION_PORT_UPDATE) counters = v.process_notification(NOTIFICATION_PORT_UPDATE)
self.assertEqual(len(counters), 2) self.assertEqual(len(list(counters)), 2)
def test_network_exists(self): def test_network_exists(self):
v = notifications.Network() v = notifications.Network()
counters = v.process_notification(NOTIFICATION_NETWORK_EXISTS) counters = v.process_notification(NOTIFICATION_NETWORK_EXISTS)
self.assertEqual(len(counters), 2) self.assertEqual(len(list(counters)), 1)
class TestEventTypes(unittest.TestCase): class TestEventTypes(unittest.TestCase):