Skip to content

Commit

Permalink
Merge "Tracked Steps which errored out in the runbook metrics"
Browse files Browse the repository at this point in the history
-- Branch commit log --
commit 60c1640c0e4d6297b0626546f6d61a031780efe5
Author:  Kwesi Graham <[email protected]>
Date:    2024-09-21T04:06:39Z

    Tracked Steps which errored out in the runbook metrics

Change-Id: Ie3a72ba15f5a2b76c1cd03f759fb5b47dc5eabd3
GitOrigin-RevId: 2ed613000c6d136edf3de1427f494f5dc6be0a81
  • Loading branch information
ebenezergraham authored and copybara-github committed Sep 23, 2024
1 parent 0aff6f5 commit 7d97161
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
10 changes: 6 additions & 4 deletions gcpdiag/runbook/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import re
import sys
import warnings
from typing import List
from typing import List, Tuple

import yaml

Expand Down Expand Up @@ -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:])
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion gcpdiag/runbook/gce/generalized_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
3 changes: 2 additions & 1 deletion gcpdiag/runbook/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,20 +236,21 @@ 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)
end = util.parse_time_input(result.end_time)
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
Expand Down

0 comments on commit 7d97161

Please sign in to comment.