Skip to content

Refactor logging levels and improve event parsing error handling#350

Merged
harp-intel merged 1 commit into
mainfrom
sysbenchmetrics
May 25, 2025
Merged

Refactor logging levels and improve event parsing error handling#350
harp-intel merged 1 commit into
mainfrom
sysbenchmetrics

Conversation

@harp-intel
Copy link
Copy Markdown
Contributor

@harp-intel harp-intel commented May 24, 2025

This pull request focuses on improving logging, refining error handling, and enhancing validation logic in the metrics collection codebase. The most significant changes include switching certain log levels from Warn to Debug, restructuring error handling in event parsing, and adding more detailed flag validation checks.

Logging Improvements:

  • Changed log levels from Warn to Debug for cases where there are no collectable events in a group or uncollectable events on the target in cmd/metrics/event_defs.go. [1] [2]
  • Added debug logs for unsupported or uncounted events in cmd/metrics/event_frame.go. These logs provide more granular insights into event parsing.

Error Handling Enhancements:

  • Updated the parseEvents function in cmd/metrics/event_frame.go to return errors immediately when encountering unrecognized event formats, ensuring better error propagation.
  • Improved the parseEventJSON function in cmd/metrics/event_frame.go to handle parsing failures more gracefully by logging errors and assigning NaN to invalid event values.

Validation Logic Refinements:

  • Enhanced flag validation in cmd/metrics/metrics.go to allow a refresh value of 0 (indicating no refresh) and added checks to ensure refresh and perf print interval values align correctly with other flags. [1] [2]
  • Updated the help text for the refresh flag to clarify its behavior when set to 0.

Signed-off-by: Harper, Jason M <jason.m.harper@intel.com>
@harp-intel harp-intel requested a review from Copilot May 24, 2025 03:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors flag validation logic, improves error handling in event parsing, and adjusts log levels for uncollectable events.

  • Expanded help text and tightened validation for refresh and perfPrintInterval flags
  • Reworked parseEvents/parseEventJSON to collect and warn about unsupported or uncounted events
  • Downgraded log severity for empty or uncollectable event groups in definitions

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
cmd/metrics/metrics.go Updated flag help text and added boundary checks on timing flags
cmd/metrics/event_frame.go Changed parseEvents signature, aggregated unsupported/not counted events, and refined JSON parsing
cmd/metrics/event_defs.go Switched two Warn logs to Debug for uncollectable event groups
Comments suppressed due to low confidence (3)

cmd/metrics/metrics.go:473

  • [nitpick] The variable name relevant is ambiguous; consider renaming it to something more descriptive like shouldValidateRefreshInterval to clarify its purpose.
relevant := flagRefresh > 0 && flagScope != scopeSystem && len(flagPidList) == 0 && len(flagCidList) == 0

cmd/metrics/event_defs.go:80

  • Consider retaining Warn severity for this log to ensure the user is alerted when an entire event group contains no collectable events.
slog.Debug("No collectable events in group", slog.String("ending", line))

cmd/metrics/event_defs.go:93

  • Similar to the previous log, consider using Warn here so that missing event definitions are not overlooked in normal runs.
slog.Debug("Events not collectable on target", slog.String("events", uncollectable.String()))

@harp-intel harp-intel merged commit 2c20a60 into main May 25, 2025
4 checks passed
@harp-intel harp-intel deleted the sysbenchmetrics branch May 27, 2025 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants