diff options
author | Steve Baker <sbaker@redhat.com> | 2016-06-03 12:58:30 +1200 |
---|---|---|
committer | Steve Baker <sbaker@redhat.com> | 2016-06-14 13:39:38 +1200 |
commit | 32ade7a24342781dc6887aae78d83d2119f0c8cd (patch) | |
tree | e957542b90e425226982f7f204af549392a02d06 /heat/api | |
parent | 2a04ea4bb55a8c6f140134ec91bd700e8207dfd2 (diff) | |
download | heat-32ade7a24342781dc6887aae78d83d2119f0c8cd.tar.gz |
Implement event list nested-depth
The GET call to list events will support a nested_depth parameter. The
response will have an additional links url with the ref 'root_stack'
to indicate that this API supports nested_depth queries.
This has the following consequences for old/new combinations of
client/server
- new heatclient, new server - nested_depth param is set, server
returns nested events
- new heatclient, old server - nested_depth param is set, server
returns events with no root_stack, heatclient falls back to
recursive event fetch
- old heatclient, new server - nested_depth param is never set,
recursive event fetch works as before
Here are some timings for a TripleO overcloud stack with ~700 events.
Current heat and python-heatclient master:
time openstack stack event list --nested-depth 4 overcloud |wc -l
744
real 0m17.500s
This change, with heatclient 31278ff5f77b152b5ef7a4197e15c441c72ff163:
time openstack stack event list --nested-depth 4 overcloud |wc -l
608
real 0m1.725s
The difference in event count (744 vs 608) is due to the stack events
being filtered out for stacks with zero resources - these are a source
of unnecessary noise so their removal should be considered an improvement.
Closes-Bug: #1588561
Change-Id: I27e1ffb770e00a7f929c081b2a505e2007f5d584
Diffstat (limited to 'heat/api')
-rw-r--r-- | heat/api/openstack/v1/events.py | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/heat/api/openstack/v1/events.py b/heat/api/openstack/v1/events.py index d1d40a561..9cfc14f3f 100644 --- a/heat/api/openstack/v1/events.py +++ b/heat/api/openstack/v1/events.py @@ -69,9 +69,15 @@ def format_event(req, event, keys=None): else: yield (key, value) - return dict(itertools.chain.from_iterable( + ev = dict(itertools.chain.from_iterable( transform(k, v) for k, v in event.items())) + root_stack_id = event.get(rpc_api.EVENT_ROOT_STACK_ID) + if root_stack_id: + root_identifier = identifier.HeatIdentifier(**root_stack_id) + ev['links'].append(util.make_link(req, root_identifier, 'root_stack')) + return ev + class EventController(object): """WSGI controller for Events in Heat v1 API. @@ -86,14 +92,16 @@ class EventController(object): self.rpc_client = rpc_client.EngineClient() def _event_list(self, req, identity, detail=False, filters=None, - limit=None, marker=None, sort_keys=None, sort_dir=None): + limit=None, marker=None, sort_keys=None, sort_dir=None, + nested_depth=None): events = self.rpc_client.list_events(req.context, identity, filters=filters, limit=limit, marker=marker, sort_keys=sort_keys, - sort_dir=sort_dir) + sort_dir=sort_dir, + nested_depth=nested_depth) keys = None if detail else summary_keys return [format_event(req, e, keys) for e in events] @@ -106,6 +114,7 @@ class EventController(object): 'marker': util.PARAM_TYPE_SINGLE, 'sort_dir': util.PARAM_TYPE_SINGLE, 'sort_keys': util.PARAM_TYPE_MULTI, + 'nested_depth': util.PARAM_TYPE_SINGLE, } filter_whitelist = { 'resource_status': util.PARAM_TYPE_MIXED, @@ -115,14 +124,15 @@ class EventController(object): } params = util.get_allowed_params(req.params, whitelist) filter_params = util.get_allowed_params(req.params, filter_whitelist) - key = rpc_api.PARAM_LIMIT - if key in params: - try: - limit = param_utils.extract_int(key, params[key], - allow_zero=True) - except ValueError as e: - raise exc.HTTPBadRequest(six.text_type(e)) - params[key] = limit + + int_params = (rpc_api.PARAM_LIMIT, rpc_api.PARAM_NESTED_DEPTH) + try: + for key in int_params: + if key in params: + params[key] = param_utils.extract_int( + key, params[key], allow_zero=True) + except ValueError as e: + raise exc.HTTPBadRequest(six.text_type(e)) if resource_name is None: if not filter_params: |