Refactor logging levels and improve event parsing error handling#350
Merged
Conversation
Signed-off-by: Harper, Jason M <jason.m.harper@intel.com>
Contributor
There was a problem hiding this comment.
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
refreshandperfPrintIntervalflags - Reworked
parseEvents/parseEventJSONto 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
relevantis ambiguous; consider renaming it to something more descriptive likeshouldValidateRefreshIntervalto clarify its purpose.
relevant := flagRefresh > 0 && flagScope != scopeSystem && len(flagPidList) == 0 && len(flagCidList) == 0
cmd/metrics/event_defs.go:80
- Consider retaining
Warnseverity 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
Warnhere so that missing event definitions are not overlooked in normal runs.
slog.Debug("Events not collectable on target", slog.String("events", uncollectable.String()))
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
WarntoDebug, restructuring error handling in event parsing, and adding more detailed flag validation checks.Logging Improvements:
WarntoDebugfor cases where there are no collectable events in a group or uncollectable events on the target incmd/metrics/event_defs.go. [1] [2]cmd/metrics/event_frame.go. These logs provide more granular insights into event parsing.Error Handling Enhancements:
parseEventsfunction incmd/metrics/event_frame.goto return errors immediately when encountering unrecognized event formats, ensuring better error propagation.parseEventJSONfunction incmd/metrics/event_frame.goto handle parsing failures more gracefully by logging errors and assigningNaNto invalid event values.Validation Logic Refinements:
cmd/metrics/metrics.goto allow arefreshvalue of 0 (indicating no refresh) and added checks to ensurerefreshandperf print intervalvalues align correctly with other flags. [1] [2]refreshflag to clarify its behavior when set to 0.