From 6aa0fde85b8247f7f1eec82527306aeed1b2de64 Mon Sep 17 00:00:00 2001 From: simonebruzzechesse <60114646+simonebruzzechesse@users.noreply.github.com> Date: Sun, 12 Mar 2023 10:53:22 +0100 Subject: [PATCH] Small fixes on Network Dashboard cloud function code (#1218) * small fix on discovery compute quota file decresed severity of log in discover cai from INFO to DEBUG * remove else statement in condition * add flag for debug logging --------- Co-authored-by: Ludo --- blueprints/cloud-operations/network-dashboard/src/main.py | 6 ++++-- .../network-dashboard/src/plugins/discover-cai.py | 2 +- .../network-dashboard/src/plugins/discover-compute-quota.py | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/blueprints/cloud-operations/network-dashboard/src/main.py b/blueprints/cloud-operations/network-dashboard/src/main.py index bd57f18e..ec5e5c6e 100755 --- a/blueprints/cloud-operations/network-dashboard/src/main.py +++ b/blueprints/cloud-operations/network-dashboard/src/main.py @@ -266,11 +266,13 @@ def main_cf_pubsub(event, context): help='Load JSON resources from file, skips init and discovery.') @click.option('--debug-plugin', help='Run only core and specified timeseries plugin.') +@click.option('--debug', is_flag=True, default=False, + help='Turn on debug logging.') def main(discovery_root, monitoring_project, project=None, folder=None, custom_quota_file=None, dump_file=None, load_file=None, - debug_plugin=None): + debug_plugin=None, debug=False): 'CLI entry point.' - logging.basicConfig(level=logging.INFO) + logging.basicConfig(level=logging.INFO if not debug else logging.DEBUG) if discovery_root.partition('/')[0] not in ('folders', 'organizations'): raise SystemExit('Invalid discovery root.') descriptors = [] diff --git a/blueprints/cloud-operations/network-dashboard/src/plugins/discover-cai.py b/blueprints/cloud-operations/network-dashboard/src/plugins/discover-cai.py index 1ac62d06..16d2c5b8 100644 --- a/blueprints/cloud-operations/network-dashboard/src/plugins/discover-cai.py +++ b/blueprints/cloud-operations/network-dashboard/src/plugins/discover-cai.py @@ -98,7 +98,7 @@ def _handle_resource(resources, asset_type, data): # derive parent type and id and skip if parent is not within scope parent_data = _get_parent(data['parent'], resources) if not parent_data: - LOGGER.info(f'{resource["self_link"]} outside perimeter') + LOGGER.debug(f'{resource["self_link"]} outside perimeter') LOGGER.debug([ resources['organization'], resources['folders'], resources['projects:number'] diff --git a/blueprints/cloud-operations/network-dashboard/src/plugins/discover-compute-quota.py b/blueprints/cloud-operations/network-dashboard/src/plugins/discover-compute-quota.py index 9c9e8f94..9801803a 100644 --- a/blueprints/cloud-operations/network-dashboard/src/plugins/discover-compute-quota.py +++ b/blueprints/cloud-operations/network-dashboard/src/plugins/discover-compute-quota.py @@ -45,6 +45,7 @@ def _handle_discovery(resources, response): self_link = part.get('selfLink') if not self_link: logging.warn('invalid quota response') + continue self_link = self_link.split('/') if kind == 'compute#project': project_id = self_link[-1]