-
Notifications
You must be signed in to change notification settings - Fork 3
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
Implemented Proper log handling #86
Conversation
WalkthroughThe project underwent significant refactoring and enhancement, focusing on error handling, logging, and mode management. Modules were added and removed to streamline functionality, with a strong emphasis on improving the user experience through command-line arguments. The network functionality saw updates in packet capture and flow analysis, refining error management and logging. Overall, these changes aim to make the application more robust, user-friendly, and maintainable. Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 8
Configuration used: CodeRabbit UI
Files ignored due to path filters (3)
Cargo.toml
is excluded by:!**/*.toml
fluere-config/Cargo.toml
is excluded by:!**/*.toml
fluere-plugin/Cargo.toml
is excluded by:!**/*.toml
Files selected for processing (17)
- fluere-config/src/init.rs (2 hunks)
- fluere-plugin/src/downloader.rs (4 hunks)
- fluere-plugin/src/lib.rs (10 hunks)
- src/cli.rs (1 hunks)
- src/logger.rs (1 hunks)
- src/main.rs (1 hunks)
- src/net/capture.rs (1 hunks)
- src/net/interface.rs (2 hunks)
- src/net/live_fluereflow.rs (12 hunks)
- src/net/mod.rs (2 hunks)
- src/net/offline_fluereflows.rs (5 hunks)
- src/net/online_fluereflow.rs (13 hunks)
- src/net/packet_pcap.rs (2 hunks)
- src/net/parser/time.rs (1 hunks)
- src/types/argument.rs (1 hunks)
- src/utils/fluere_csv_exporter.rs (2 hunks)
- src/utils/log.rs (1 hunks)
Files skipped from review due to trivial changes (1)
- src/types/argument.rs
Additional comments: 51
src/utils/fluere_csv_exporter.rs (1)
- 1-12: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [8-72]
The replacement of
println!
withlog::debug
andlog::trace
is a good practice for more configurable logging. Ensure that the logging library is correctly initialized in the application to make these logging statements effective.src/net/interface.rs (1)
- 1-7: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-39]
The reorganization of imports and removal of the
list_interfaces
function are good practices for maintaining clean code. Ensure to verify the impact of removinglist_interfaces
on other parts of the application.src/net/packet_pcap.rs (1)
- 33-62: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [9-61]
The refactoring and introduction of logging statements in
pcap_capture
improve clarity and configurability. Consider revisiting the commented-out section related to slowing down the loop for Windows to ensure it's not needed. Also, ensure robust error handling for file and directory operations.src/net/capture.rs (1)
- 1-93: The refactoring of error handling and logging, along with the use of
Cow
forname
anddesc
fields inCaptureDevice
, are good practices. Ensure to add error handling for file and directory operations to avoid potential panics.fluere-config/src/init.rs (1)
- 1-35: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-52]
The introduction of conditional logging based on the "log" feature flag and changes in public entities are well-implemented. Ensure that critical information is not omitted in non-logging builds to maintain functionality.
src/main.rs (1)
- 6-130: The restructuring of the application with the addition of
cli
andlogger
modules, the removal ofplugin
, and the implementation of error handling and logging enhance the application's robustness and configurability. Ensure to verify theLogger
initialization to avoid unexpected behavior regarding file logging.src/net/offline_fluereflows.rs (7)
- 29-29: The use of
debug!
for logging the creation of a directory is appropriate and aligns with the goal of enhancing logging capabilities.- 66-66: The
trace!
log level is correctly used here to log the establishment of a flow, which is a detailed operational event.- 73-73: Repeating the use of
trace!
for logging flow establishment in different conditions maintains consistency in logging practices.- 117-120: The use of
trace!
to log flow updates with dynamic content (forward or reverse) is a good practice for detailed operational logging.- 123-123: Logging the completion of a flow with
trace!
is consistent with the detailed level of logging intended for operational events.- 129-129: Using
info!
to log the capture duration provides a higher-level overview suitable for general monitoring, aligning with the logging enhancements.- 141-141: Logging the result of the export operation with
info!
is appropriate for providing users with a summary of the operation's outcome.fluere-plugin/src/downloader.rs (5)
- 88-89: The conditional logging using the
log
crate for informational messages is a good practice, allowing for dynamic log output based on the build configuration. This aligns with the PR's objectives of enhancing logging capabilities.- 107-110: The use of
info!
for logging successful updates or skipped updates based on user confirmation is appropriate and enhances the visibility of the operation's outcome.- 118-118: Repeating the use of
info!
for logging skipped updates in a different conditional branch maintains consistency in logging practices.- 124-124: Logging the up-to-date status of a plugin with
info!
provides a clear and concise summary of the plugin's state, which is beneficial for monitoring.- 152-152: The use of
debug!
for logging a timeout event is suitable for detailed operational logging, providing insights into the behavior of the system under specific conditions.src/net/online_fluereflow.rs (12)
- 62-62: The use of
trace!
for logging directory creation is consistent with the detailed level of logging intended for operational events.- 84-84: Logging the receipt of a packet with
trace!
is a good practice for detailed operational logging, providing insights into the packet capture process.- 109-109: Repeating the use of
trace!
for logging flow establishment in different conditions maintains consistency in logging practices.- 115-115: Consistently using
trace!
for logging flow establishment across different protocol conditions aligns with the detailed operational logging strategy.- 146-149: Logging detailed information about the current input flow with
trace!
enhances the visibility into the flow processing logic, which is beneficial for debugging.- 161-164: The use of
trace!
to log flow updates with dynamic content (forward or reverse) is a good practice for detailed operational logging.- 167-167: Logging the completion of a flow with
trace!
is consistent with the detailed level of logging intended for operational events.- 192-192: Using
trace!
to log flow expiration events is appropriate for detailed operational logging, providing insights into the flow management process.- 209-209: Logging the result of the export operation with
info!
is appropriate for providing users with a summary of the operation's outcome.- 220-220: Repeating the use of
trace!
for logging flow expiration events in a different context maintains consistency in logging practices.- 232-232: Using
debug!
to log the capture duration provides a higher-level overview suitable for general monitoring, aligning with the logging enhancements.- 245-245: Logging the result of the exporting task with
info!
is appropriate for providing users with a summary of the operation's outcome, enhancing the visibility into the application's operations.src/cli.rs (1)
- 10-241: The CLI setup using the clap library is well-structured and provides a comprehensive set of commands and options for the application. This setup allows users to interact with the application effectively, specifying various parameters and modes of operation.
fluere-plugin/src/lib.rs (10)
- 41-41: The use of
debug!
for logging the start of the plugin loading process is appropriate and aligns with the goal of enhancing logging capabilities.- 61-61: Logging the Lua path with
debug!
provides valuable information for debugging plugin loading issues, enhancing the visibility into the plugin management process.- 74-74: Using
debug!
to log extra argument details for plugins is a good practice for detailed operational logging, providing insights into the plugin configuration process.- 104-104: The use of
info!
for logging successful plugin loading is appropriate and provides users with a clear indication of the plugin's availability.- 110-112: Using
warn!
anderror!
to log failures in reading plugin files provides a clear distinction between the severity of the issue and the specific error encountered, enhancing error visibility.- 173-173: Repeating the use of
info!
for logging successful plugin loading in a different context maintains consistency in logging practices.- 179-181: Consistently using
warn!
anderror!
to log failures in reading plugin files across different scenarios aligns with the detailed operational logging strategy.- 195-196: Logging the inability to download a plugin with
warn!
anderror!
provides a clear indication of the issue and its severity, which is beneficial for troubleshooting.- 278-280: Using
error!
to log the absence of theprocess_data
function in a plugin is appropriate for highlighting critical issues in plugin functionality.- 324-324: Logging the absence of a cleanup function in a plugin with
warn!
is suitable for indicating potential issues in plugin cleanup processes without treating it as a critical error.src/net/live_fluereflow.rs (10)
- 22-39: The addition of new imports (
fluere_config::Config
,fluere_plugin::PluginManager
,fluereflow::FluereRecord
,crossterm
,log
,ratatui
,tokio
) is well-organized and follows Rust's convention of grouping and ordering imports. This enhances readability and maintainability of the code. However, ensure that all newly introduced dependencies are indeed used within the file to avoid unnecessary bloat.- 47-50: The logging statements added at the start and end of the
packet_capture
function using thedebug!
macro are a good practice for tracking the execution flow of the application. This aligns with the PR's objective of enhancing logging capabilities. Ensure that the log level chosen (debug
) is appropriate for the information being logged.- 80-91: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [72-84]
The initialization of configuration and plugin management within the
online_packet_capture
function introduces external dependencies (Config
andPluginManager
). While this enhances the functionality, consider the implications on testability and maintainability. It might be beneficial to abstract these dependencies or inject them as parameters to facilitate easier testing and to decouple the function from specific implementations.Consider abstracting or injecting dependencies like
Config
andPluginManager
to improve testability and maintainability.
- 109-109: The commented-out
packet_count
variable suggests that there was an intention to track the number of packets processed. If this feature is no longer needed, it's good practice to remove such commented-out code to keep the codebase clean and maintainable.Consider removing the commented-out
packet_count
variable if it's no longer needed.
- 170-176: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [173-201]
The logging statement using
trace!
to log the reception of a packet and the establishment of a flow is a good use of the logging framework to provide detailed insights into the application's behavior. However, ensure that logging at this level of detail (trace
) is consistent with the application's logging strategy and does not introduce performance overhead in production environments.
- 258-261: The logging statement using
trace!
to indicate whether a flow was updated as "forward" or "reverse" is a clear and informative use of logging. This contributes to the application's observability by providing insights into the flow processing logic.- 264-264: The logging statement using
trace!
to indicate the completion of a flow is consistent with the PR's objective of enhancing logging capabilities. This provides valuable information for debugging and monitoring the application's behavior.- 273-276: The commented-out code related to slowing down the loop for Windows suggests an attempt to address a platform-specific issue. If this workaround is no longer necessary, consider removing the commented-out code to maintain code clarity. If it might be needed in the future, add a comment explaining the context and conditions under which it should be re-enabled.
Consider removing or clarifying the commented-out code related to slowing down the loop for Windows.
- 330-330: The logging statement at the end of the capture loop using
debug!
to log the total capture duration is a good practice. It provides valuable information for performance monitoring and debugging. Ensure that the log level chosen (debug
) is appropriate for the information being logged.- 343-343: The logging statement indicating the result of the exporting task execution is a good example of using logging to track asynchronous operations. This enhances the application's observability and aids in debugging. Ensure that the log level chosen (
debug
) is appropriate for the information being logged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (4)
- src/net/capture.rs (1 hunks)
- src/net/online_fluereflow.rs (13 hunks)
- src/net/packet_pcap.rs (2 hunks)
- src/net/parser/time.rs (1 hunks)
Files skipped from review as they are similar to previous changes (4)
- src/net/capture.rs
- src/net/online_fluereflow.rs
- src/net/packet_pcap.rs
- src/net/parser/time.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (5)
- fluere-plugin/src/lib.rs (9 hunks)
- src/net/live_fluereflow.rs (12 hunks)
- src/net/offline_fluereflows.rs (5 hunks)
- src/net/parser/ports.rs (2 hunks)
- src/net/parser/time.rs (1 hunks)
Check Runs (4)
clippy completed (4)
build completed (1)
Run rustfmt style commit completed (1)
Run rust-clippy analyzing completed (6)
Files skipped from review as they are similar to previous changes (4)
- fluere-plugin/src/lib.rs
- src/net/live_fluereflow.rs
- src/net/offline_fluereflows.rs
- src/net/parser/time.rs
Additional comments: 2
src/net/parser/ports.rs (2)
- 3-3: The addition of the
log::debug
import aligns with the PR's objective to enhance logging capabilities. This change is appropriate for the intended logging improvements.- 26-26: Using
debug!
for logging unknown protocols is a good practice, as it provides detailed information useful for debugging without cluttering the log with information that might not always be relevant. This change effectively replaces aprintln!
statement with a structured logging call, which is a significant improvement in terms of maintainability and functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (3)
- fluere-plugin/src/lib.rs (9 hunks)
- src/net/live_fluereflow.rs (12 hunks)
- src/net/parser/ports.rs (2 hunks)
Files skipped from review as they are similar to previous changes (3)
- fluere-plugin/src/lib.rs
- src/net/live_fluereflow.rs
- src/net/parser/ports.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (8)
- src/main.rs (1 hunks)
- src/net/mod.rs (2 hunks)
- src/net/offline_fluereflows.rs (6 hunks)
- src/net/online_fluereflow.rs (14 hunks)
- src/net/parser/fluereflows.rs (4 hunks)
- src/net/parser/keys.rs (2 hunks)
- src/net/parser/ports.rs (1 hunks)
- src/net/parser/tos.rs (2 hunks)
Check Runs (4)
clippy completed (4)
- src/main.rs: 32-32: warning: variants
InterfaceNotFound
,ArgumentParseError
,ModeNotSupported
, andNetworkError
are never constructed
--> src/main.rs:32:5
|
31 | enum FluereError {
| ----------- variants in this enum
32 | InterfaceNotFound,
| ^^^^^^^^^^^^^^^^^
33 | DeviceError(DeviceError),
34 | ArgumentParseError(String),
| ^^^^^^^^^^^^^^^^^^
35 | ModeNotSupported(String),
| ^^^^^^^^^^^^^^^^
36 | NetworkError(String),
| ^^^^^^^^^^^^
|
= note:FluereError
has a derived impl for the traitDebug
, but this is intentionally ignored during dead code analysis
= note:#[warn(dead_code)]
on by default
build completed (1)
Run rust-clippy analyzing completed (6)
Run rustfmt style commit completed (1)
Files skipped from review as they are similar to previous changes (4)
- src/net/mod.rs
- src/net/offline_fluereflows.rs
- src/net/online_fluereflow.rs
- src/net/parser/ports.rs
Additional comments: 13
src/net/parser/tos.rs (2)
- 1-1: The import statement for
NetError
is correctly updated to reflect the new error handling structure. This change aligns with the PR's objective to enhance error handling across the application.- 1-6: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [3-26]
The function
dscp_to_tos
has been updated to return aResult<u8, NetError>
, which is a good practice for error handling in Rust. The use ofNetError::UnknownDSCP
for unmatched DSCP values is appropriate and improves the clarity of error messages. This change enhances the maintainability and readability of the code by clearly indicating the type of error that can occur.src/main.rs (6)
- 6-7: The addition of
cli
andlogger
modules is in line with the PR's objectives to enhance logging capabilities and command-line interface functionality. This modular approach improves the maintainability and extensibility of the code.- 9-9: The removal of the
plugin
module suggests a refactoring or cleanup effort. Assuming this module is no longer needed, its removal contributes to cleaner and more maintainable code. However, ensure that any dependencies or functionalities relying on this module have been appropriately addressed.- 31-37: The
FluereError
enum is well-defined, covering a range of error scenarios that the application might encounter. This centralized error handling mechanism is a good practice, enhancing the readability and maintainability of the code.- 59-64: The
Mode
enum and its implementation are well-designed, providing a clear and concise way to handle different modes of operation. This approach enhances the code's readability and maintainability.- 89-97: The
from_verbose
function correctly maps verbosity levels toLevelFilter
values. This implementation supports dynamic log filtering based on the-v
flag, aligning with the PR's objectives. Good use of pattern matching for clarity and maintainability.- 104-130: The refactored
main
function demonstrates a clear structure for handling different modes based on command-line arguments. The use of async/await and the structured approach to initializing logging and handling modes contribute to the application's robustness and usability. Ensure that all error scenarios are adequately handled and that the application exits gracefully in case of errors.src/net/parser/keys.rs (2)
- 11-11: The modification of the import statement for
NetError
correctly reflects the new error handling structure. This change is consistent with the PR's objective to enhance error handling across the application.- 149-151: The change from
UnknownProtocol
toUnknownEtherType
in the error handling logic is appropriate and improves the clarity of error messages. This adjustment aligns with the PR's objectives to refine error handling and logging, making the code more maintainable and understandable.src/net/parser/fluereflows.rs (3)
- 3-3: The update to the import statement for
NetError
is correctly aligned with the new error handling structure, supporting the PR's objectives to enhance error handling across the application.- 133-135: The modification in error handling for unknown EtherType is appropriate and improves the clarity of error messages. This change aligns with the PR's objectives to refine error handling and logging, making the code more maintainable and understandable.
- 200-201: Simplifying error handling for parsing ports in IPv4 and IPv6 packets by directly using the
?
operator is a good practice. It makes the code more concise and readable, aligning with Rust's idiomatic error handling patterns.Also applies to: 251-251
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (6)
- src/net/mod.rs (2 hunks)
- src/net/offline_fluereflows.rs (6 hunks)
- src/net/parser/fluereflows.rs (4 hunks)
- src/net/parser/keys.rs (2 hunks)
- src/net/parser/ports.rs (1 hunks)
- src/net/parser/tos.rs (2 hunks)
Files skipped from review as they are similar to previous changes (6)
- src/net/mod.rs
- src/net/offline_fluereflows.rs
- src/net/parser/fluereflows.rs
- src/net/parser/keys.rs
- src/net/parser/ports.rs
- src/net/parser/tos.rs
Logger Known Issue
|
Type of PR
Description:
In this pull request, proper log handling is implemented.
This includes:
-v
flag.Additional context:
closes #65
Summary by CodeRabbit
New Features
Improvements
DateTime
from thechrono
crate.Refactor
plugin
.Bug Fixes