Timestamp InfraScan CLI logs to show scan duration distribution#72
Timestamp InfraScan CLI logs to show scan duration distribution#72Natan-gal wants to merge 4 commits into
Conversation
Added a logging function to print messages with timestamps, enhancing the visibility of the scanning process. Updated the main function to utilize this logging for various stages of execution.
| from datetime import datetime | ||
|
|
||
|
|
||
| def log_with_timestamp(message: str) -> None: |
There was a problem hiding this comment.
Move this lower, so that it is next to other method definitions
| [2026-10-10 16:23:34] Starting scan... | ||
| """ | ||
| timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") | ||
| print(f"[{timestamp}] {message}", flush=True) |
There was a problem hiding this comment.
Can we use logging for this? We configure logging below
| traceback.print_exc() | ||
| sys.exit(1) | ||
|
|
||
| if __name__ == "__main__": |
There was a problem hiding this comment.
This is why this doesn't run, you removed the main check
…odule, restore main check
Updated logging configuration to use INFO level and added timestamps to log messages. Replaced print statements with logger calls for error handling and notifications.
|
I think this PR is moving in the right direction, but it does not fully resolve issue #63 yet. The goal in #63 was:
Right now only the logs emitted through
Current output still looks like: Detected framework: terraform
Scanning image: nginx:alpine
Failed to parse Docker Scout output for nginx:alpine ...without any timestamps attached. That means we still cannot reliably determine where most of the 20+ minute runtime is spent, especially around container scanning which is likely one of the slowest stages. I think to fully satisfy #63 we should:
start = time.perf_counter()
logger.info(f"Scanning image: {image}")
# scan...
logger.info(
f"Finished scanning {image} in {time.perf_counter() - start:.2f}s"
)That would make the logs much more useful for profiling bottlenecks in CI/CD runs. Also worth noting: Adding issue #63 as a reference because I think this PR partially addresses it, but doesn’t completely fulfill the original intent yet. |
Add timestamped logging and execution duration metrics to InfraScan CLI. This update improves log visibility during long-running scans by adding timestamps to log output and tracking execution time for key operations such as: * directory scanning * report generation * report saving * Slack notifications * total CLI execution The goal is to make GitHub Actions and CI logs easier to debug and help identify performance bottlenecks during large scans.
Summary
Added timestamped log messages to the InfraScan CLI to make it easier to see how long each major stage of the scan takes.
Changes
Added a
log_with_timestamp()helper that prefixes messages with the current timestamp in the format:Added timestamped logs for the following stages:
Purpose
InfraScan builds can take more than 20 minutes to complete. These timestamps make it possible to identify which parts of the process consume the most time.
Notes
External tool output (e.g. Docker Scout, Grype) is not modified, but the added timestamped logs provide clear boundaries around the major processing steps.