From 7d971611a0bf4e33bf4f8fc2f73ab53b2be0ab15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kwesi=20Akyen=20Graham=E2=80=8E?= Date: Mon, 23 Sep 2024 17:38:37 +0000 Subject: [PATCH] Merge "Tracked Steps which errored out in the runbook metrics" -- Branch commit log -- commit 60c1640c0e4d6297b0626546f6d61a031780efe5 Author: Kwesi Graham Date: 2024-09-21T04:06:39Z Tracked Steps which errored out in the runbook metrics Change-Id: Ie3a72ba15f5a2b76c1cd03f759fb5b47dc5eabd3 GitOrigin-RevId: 2ed613000c6d136edf3de1427f494f5dc6be0a81 --- gcpdiag/runbook/command.py | 10 ++++++---- gcpdiag/runbook/gce/generalized_steps.py | 2 +- gcpdiag/runbook/report.py | 3 ++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/gcpdiag/runbook/command.py b/gcpdiag/runbook/command.py index 256226476..d04299598 100644 --- a/gcpdiag/runbook/command.py +++ b/gcpdiag/runbook/command.py @@ -21,7 +21,7 @@ import re import sys import warnings -from typing import List +from typing import List, Tuple import yaml @@ -312,7 +312,7 @@ def _initialize_output(): return output -def run_and_get_report(argv=None, credentials: str = None) -> dict: +def run_and_get_report(argv=None, credentials: str = None) -> Tuple[int, dict]: # Initialize argument parser parser = _init_runbook_args_parser() args = parser.parse_args(argv[1:]) @@ -389,8 +389,10 @@ def run_and_get_report(argv=None, credentials: str = None) -> dict: output.display_footer(dt_engine.interface.rm) # Clean up the kubeconfig file generated for gcpdiag kubectl.clean_up() - return report + # return success if we get to this point and the report.. + return (0, report) def run(argv) -> None: - run_and_get_report(argv) + code, _ = run_and_get_report(argv) + sys.exit(code) diff --git a/gcpdiag/runbook/gce/generalized_steps.py b/gcpdiag/runbook/gce/generalized_steps.py index bb5effec2..aa9402218 100644 --- a/gcpdiag/runbook/gce/generalized_steps.py +++ b/gcpdiag/runbook/gce/generalized_steps.py @@ -124,7 +124,7 @@ class HighVmDiskUtilization(runbook.Step): project_id: str zone: str instance_name: str - serial_console_file: str + serial_console_file: str = '' def execute(self): """Verifying VM's Boot disk space utilization is within optimal levels.""" diff --git a/gcpdiag/runbook/report.py b/gcpdiag/runbook/report.py index a99c23257..9444adfab 100644 --- a/gcpdiag/runbook/report.py +++ b/gcpdiag/runbook/report.py @@ -236,6 +236,7 @@ def get_totals_by_status(self) -> Dict[str, int]: def generate_report_metrics(self, report: Report) -> Dict[str, dict]: reports_metrics: Dict[str, Any] = {} all_step_metrics = [] + reports_metrics['execution_mode'] = report.execution_mode for result in report.results.values(): step_metrics: Dict[str, dict] = collections.defaultdict(dict) start = util.parse_time_input(result.start_time) @@ -243,13 +244,13 @@ def generate_report_metrics(self, report: Report) -> Dict[str, dict]: duration = (end - start).total_seconds() * 1000 step_metrics[result.step.id]['execution_duration'] = duration step_metrics[result.step.id]['totals_by_status'] = result.totals_by_status + step_metrics[result.step.id]['error'] = bool(result.step_error) all_step_metrics.append(step_metrics) if report.runbook_name: start = util.parse_time_input(report.run_start_time) end = util.parse_time_input(report.run_end_time) duration = (end - start).total_seconds() * 1000 reports_metrics['runbook_name'] = report.runbook_name - reports_metrics['execution_mode'] = report.execution_mode reports_metrics['run_duration'] = duration reports_metrics['totals_by_status'] = report.get_totals_by_status() reports_metrics['steps'] = all_step_metrics