Browse Source

Add logic for event_update handling and set transfer event as event_update

This patch implements logic for updating resources in gnocchi when an
event_update happens. Additionally, it adds volume.transfer events to
the event_definitions.yaml and attributes for said event in
gnocchi_resources.yaml

Change-Id: I15bc4e1589f92fc856876a563122c1a1e07d4c4a
(cherry picked from commit aa6b4e8642)
changes/97/750797/1
pleimer 1 month ago
parent
commit
dafbcde009
4 changed files with 77 additions and 1 deletions
  1. +1
    -1
      ceilometer/pipeline/data/event_definitions.yaml
  2. +2
    -0
      ceilometer/publisher/data/gnocchi_resources.yaml
  3. +30
    -0
      ceilometer/publisher/gnocchi.py
  4. +44
    -0
      ceilometer/tests/unit/publisher/test_gnocchi.py

+ 1
- 1
ceilometer/pipeline/data/event_definitions.yaml View File

@@ -90,7 +90,7 @@
fields: payload.glance_metadata[?key=image_id].value
instance_id:
fields: payload.volume_attachment[0].server_id
- event_type: ['volume.exists', 'volume.retype', 'volume.create.*', 'volume.delete.*', 'volume.resize.*', 'volume.attach.*', 'volume.detach.*', 'volume.update.*']
- event_type: ['volume.transfer.*', 'volume.exists', 'volume.retype', 'volume.create.*', 'volume.delete.*', 'volume.resize.*', 'volume.attach.*', 'volume.detach.*', 'volume.update.*']
traits:
<<: *cinder_traits
resource_id:


+ 2
- 0
ceilometer/publisher/data/gnocchi_resources.yaml View File

@@ -250,8 +250,10 @@ resources:
event_delete:
- volume.delete.end
- snapshot.delete.end
event_update: volume.transfer.accept.end
event_attributes:
id: resource_id
project_id: project_id

- resource_type: volume_provider
metrics:


+ 30
- 0
ceilometer/publisher/gnocchi.py View File

@@ -495,6 +495,23 @@ class GnocchiPublisher(publisher.ConfigPublisherBase):
self._delete_event(rd, event)
if operation == EVENT_CREATE:
self._create_event(rd, event)
if operation == EVENT_UPDATE:
self._update_event(rd, event)

def _update_event(self, rd, event):
resource = rd.event_attributes(event)
associated_resources = rd.cfg.get('event_associated_resources', {})

if associated_resources:
to_update = itertools.chain([resource], *[
self._search_resource(resource_type, query % resource['id'])
for resource_type, query in associated_resources.items()
])
else:
to_update = [resource]

for resource in to_update:
self._set_update_attributes(resource)

def _delete_event(self, rd, event):
ended_at = timeutils.utcnow().isoformat()
@@ -537,6 +554,19 @@ class GnocchiPublisher(publisher.ConfigPublisherBase):
exc_info=True)
return []

def _set_update_attributes(self, resource):
try:
resource_id = resource.pop('id')
resource_type = resource.pop('type')

self._if_not_cached(resource_type, resource_id, resource)
except gnocchi_exc.ResourceNotFound:
LOG.debug("Update event received on unexisting resource (%s), "
"ignore it.", resource['id'])
except Exception:
LOG.error("Fail to update the resource %s", resource,
exc_info=True)

def _set_ended_at(self, resource, ended_at):
try:
self._gnocchi.resource.update(resource['type'], resource['id'],


+ 44
- 0
ceilometer/tests/unit/publisher/test_gnocchi.py View File

@@ -153,6 +153,28 @@ FLOATINGIP_DELETE_END = models.Event(
message_id=u'a15b94ee-cb8e-4c71-9abe-14aa80055fb4'
)

VOLUME_TRANSFER_ACCEPT_END = models.Event(
event_type='volume.transfer.accept.end',
traits=[models.Trait(u'tenant_id', 1, '945e7d09220e4308abe4b3b734bf5fce>'),
models.Trait(u'project_id', 1, '85bc015f7a2342348593077a927c4aaa'),
models.Trait(u'user_id', 1, '945e7d09220e4308abe4b3b734bf5fce'),
models.Trait(u'service', 1, 'volume.controller-0'),
models.Trait(
u'request_id', 1, 'req-71dd1ae4-81ca-431a-b9fd-ac833eba889f'),
models.Trait(
u'resource_id', 1, '156b8d3f-ad99-429b-b84c-3f263fb2a801'),
models.Trait(
u'display_name', 1, 'test-vol'),
models.Trait(
u'type', 1, 'req-71dd1ae4-81ca-431a-b9fd-ac833eba889f'),
models.Trait(u'host', 1, 'hostgroup@tripleo_iscsi#tripleo_iscsi'),
models.Trait(u'created_at', 4, '2020-08-28 12:51:52'),
models.Trait(u'size', 2, 1)],
raw={},
generated='2020-08-28T12:52:22.930413',
message_id=u'9fc4ceee-d980-4098-a685-2ad660838ac1'
)


class PublisherTest(base.BaseTestCase):

@@ -582,6 +604,28 @@ class PublisherWorkflowTest(base.BaseTestCase,
for call in expected_calls:
self.assertIn(call, fakeclient.mock_calls)

@mock.patch('gnocchiclient.v1.client.Client')
def test_update_event_workflow(self, fakeclient_cls):
url = netutils.urlsplit("gnocchi://")
self.publisher = gnocchi.GnocchiPublisher(self.conf.conf, url)

fakeclient = fakeclient_cls.return_value

now = timeutils.utcnow()
self.useFixture(utils_fixture.TimeFixture(now))

expected_calls = [
mock.call.resource.update(
'volume',
'156b8d3f-ad99-429b-b84c-3f263fb2a801',
{'project_id': '85bc015f7a2342348593077a927c4aaa'}),
]

self.publisher.publish_events([VOLUME_TRANSFER_ACCEPT_END])
self.assertEqual(1, len(fakeclient.mock_calls))
for call in expected_calls:
self.assertIn(call, fakeclient.mock_calls)

@mock.patch('ceilometer.publisher.gnocchi.LOG')
@mock.patch('gnocchiclient.v1.client.Client')
def test_workflow(self, fakeclient_cls, logger):


Loading…
Cancel
Save