Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add checks runtime #27

Merged
merged 2 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Unreleased

* Add `checks_runtime` into summary (\#27)

# 0.1.7

* Add `include_login` option (\#23).
Expand Down
7 changes: 5 additions & 2 deletions src/fractal_healthcheck/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import click
import logging
import sys
import time
from typing import Optional

from fractal_healthcheck import LOGGER_NAME
Expand Down Expand Up @@ -64,11 +65,13 @@ def main(
if send_mail:
email_config = load_email_config(config_file)

# Run checks
# Run checks and get the checks' execution time
t_start = time.time()
checks_suite.run()
checks_runtime = round(time.time() - t_start, 2)

# Prepare report
report = prepare_report(checks_suite)
report = prepare_report(checks_suite, checks_runtime=checks_runtime)

# Write report to file
if output_file is not None:
Expand Down
5 changes: 4 additions & 1 deletion src/fractal_healthcheck/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ def update(self):
return self


def prepare_report(check_suite: CheckSuite) -> str:
def prepare_report(check_suite: CheckSuite, checks_runtime: float) -> str:
"""
Format the results in a CheckSuite instance to a string.
It takes as argument also the time needed to run the checks.

Also reports the number of triggering and not succeeding checks.
Apart from this, for the moment being this does not expect any schema in 'results_dict',
Expand All @@ -87,6 +88,7 @@ def prepare_report(check_suite: CheckSuite) -> str:
Formatting is minimal. Since a newline at the end of a check output is not ensured,
one is always added before a check. Then we strip duplicate newlines.
Indent is added, for readability.

"""

# Filtering triggering, failing, count them and print a list
Expand All @@ -100,6 +102,7 @@ def prepare_report(check_suite: CheckSuite) -> str:
f"Total number of checks: {len(check_suite.checks)}\n"
f"Number of checks setting off triggers: {len(triggering)}\n"
f"Number of checks that did not complete: {len(failing)}\n"
f"Checks Runtime: {checks_runtime} seconds\n"
"\n"
)

Expand Down