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:
parent
4a82b98ca7
commit
f3e7d2a611
@ -70,8 +70,8 @@ class NetworkNotificationBase(plugin.NotificationBase):
|
||||
def process_notification(self, message):
|
||||
LOG.info('network notification %r', message)
|
||||
message['payload'] = message['payload'][self.resource_name]
|
||||
return [
|
||||
counter.Counter(source='?',
|
||||
metadata = self.notification_to_metadata(message)
|
||||
yield counter.Counter(source='?',
|
||||
name=self.resource_name,
|
||||
type=counter.TYPE_GAUGE,
|
||||
volume=1,
|
||||
@ -79,21 +79,21 @@ class NetworkNotificationBase(plugin.NotificationBase):
|
||||
project_id=message['payload']['tenant_id'],
|
||||
resource_id=message['payload']['id'],
|
||||
timestamp=message['timestamp'],
|
||||
resource_metadata=self.notification_to_metadata(
|
||||
message),
|
||||
),
|
||||
counter.Counter(source='?',
|
||||
name=message['event_type'].rpartition('.')[0],
|
||||
resource_metadata=metadata,
|
||||
)
|
||||
|
||||
network_counter_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,
|
||||
volume=1,
|
||||
user_id=message['_context_user_id'],
|
||||
project_id=message['payload']['tenant_id'],
|
||||
resource_id='network',
|
||||
resource_id=message['payload']['id'],
|
||||
timestamp=message['timestamp'],
|
||||
resource_metadata=self.notification_to_metadata(
|
||||
message),
|
||||
),
|
||||
]
|
||||
resource_metadata=metadata,
|
||||
)
|
||||
|
||||
|
||||
class Network(NetworkNotificationBase):
|
||||
|
@ -62,17 +62,17 @@ Network (Quantum)
|
||||
Name Type Volume Resource Note
|
||||
======================== ========== ======= ======== =======================================================
|
||||
network Gauge 1 netw ID Duration of network
|
||||
network.create Gauge 1 network
|
||||
network.update Gauge 1 network
|
||||
network.exists Gauge 1 network
|
||||
network.create Gauge 1 netw ID
|
||||
network.update Gauge 1 netw ID
|
||||
network.exists Gauge 1 netw ID
|
||||
subnet Gauge 1 subnt ID Duration of subnet
|
||||
subnet.create Gauge 1 network
|
||||
subnet.update Gauge 1 network
|
||||
subnet.exists Gauge 1 network
|
||||
subnet.create Gauge 1 subnt ID
|
||||
subnet.update Gauge 1 subnt ID
|
||||
subnet.exists Gauge 1 subnt ID
|
||||
port Gauge 1 port ID Duration of port
|
||||
port.create Gauge 1 network
|
||||
port.update Gauge 1 network
|
||||
port.exists Gauge 1 network
|
||||
port.create Gauge 1 port ID
|
||||
port.update Gauge 1 port ID
|
||||
port.exists Gauge 1 port ID
|
||||
floating_ip Gauge 1 ip ID Duration of floating ip
|
||||
======================== ========== ======= ======== =======================================================
|
||||
|
||||
|
@ -161,27 +161,27 @@ class TestNotifications(unittest.TestCase):
|
||||
def test_network_create(self):
|
||||
v = notifications.Network()
|
||||
counters = v.process_notification(NOTIFICATION_NETWORK_CREATE)
|
||||
self.assertEqual(len(counters), 2)
|
||||
self.assertEqual(len(list(counters)), 2)
|
||||
|
||||
def test_subnet_create(self):
|
||||
v = notifications.Subnet()
|
||||
counters = v.process_notification(NOTIFICATION_SUBNET_CREATE)
|
||||
self.assertEqual(len(counters), 2)
|
||||
self.assertEqual(len(list(counters)), 2)
|
||||
|
||||
def test_port_create(self):
|
||||
v = notifications.Port()
|
||||
counters = v.process_notification(NOTIFICATION_PORT_CREATE)
|
||||
self.assertEqual(len(counters), 2)
|
||||
self.assertEqual(len(list(counters)), 2)
|
||||
|
||||
def test_port_update(self):
|
||||
v = notifications.Port()
|
||||
counters = v.process_notification(NOTIFICATION_PORT_UPDATE)
|
||||
self.assertEqual(len(counters), 2)
|
||||
self.assertEqual(len(list(counters)), 2)
|
||||
|
||||
def test_network_exists(self):
|
||||
v = notifications.Network()
|
||||
counters = v.process_notification(NOTIFICATION_NETWORK_EXISTS)
|
||||
self.assertEqual(len(counters), 2)
|
||||
self.assertEqual(len(list(counters)), 1)
|
||||
|
||||
|
||||
class TestEventTypes(unittest.TestCase):
|
||||
|
Loading…
Reference in New Issue
Block a user