-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat: Support search logs by timestamp for structured and unstructured logs. #42
base: main
Are you sure you want to change the base?
Conversation
# Conflicts: # src/clp_ffi_js/ir/StreamReader.cpp # src/clp_ffi_js/ir/StreamReader.hpp
WalkthroughThe pull request introduces a new method Changes
Sequence DiagramsequenceDiagram
participant Client
participant StreamReader
participant LogEvents
Client->>StreamReader: get_log_event_idx_by_timestamp(timestamp)
StreamReader->>LogEvents: generic_get_log_event_idx_by_timestamp(log_events, timestamp)
LogEvents-->>StreamReader: return log event index
StreamReader-->>Client: return index or null
Finishing Touches
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 using PR comments)
Other keywords and placeholders
CodeRabbit Configuration 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.
For future commits, you may follow https://github.com/y-scope/clp-ffi-js?tab=readme-ov-file#linting to run the linter
This PR is blocking y-scope/yscope-log-viewer#152 |
…x_by_timestamp, use std::ranges::upper_bound instead of std::upper_bound
…s null when log events are empty, and return index with "best effort"
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.
Actionable comments posted: 4
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
src/clp_ffi_js/ir/StreamReader.cpp
(2 hunks)src/clp_ffi_js/ir/StreamReader.hpp
(6 hunks)src/clp_ffi_js/ir/StructuredIrStreamReader.cpp
(2 hunks)src/clp_ffi_js/ir/StructuredIrStreamReader.hpp
(2 hunks)src/clp_ffi_js/ir/UnstructuredIrStreamReader.cpp
(1 hunks)src/clp_ffi_js/ir/UnstructuredIrStreamReader.hpp
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
src/clp_ffi_js/ir/UnstructuredIrStreamReader.hpp (1)
Pattern **/*.{cpp,hpp,java,js,jsx,ts,tsx}
: - Prefer false == <expression>
rather than !<expression>
.
src/clp_ffi_js/ir/StructuredIrStreamReader.cpp (1)
Pattern **/*.{cpp,hpp,java,js,jsx,ts,tsx}
: - Prefer false == <expression>
rather than !<expression>
.
src/clp_ffi_js/ir/StructuredIrStreamReader.hpp (1)
Pattern **/*.{cpp,hpp,java,js,jsx,ts,tsx}
: - Prefer false == <expression>
rather than !<expression>
.
src/clp_ffi_js/ir/UnstructuredIrStreamReader.cpp (1)
Pattern **/*.{cpp,hpp,java,js,jsx,ts,tsx}
: - Prefer false == <expression>
rather than !<expression>
.
src/clp_ffi_js/ir/StreamReader.cpp (1)
Pattern **/*.{cpp,hpp,java,js,jsx,ts,tsx}
: - Prefer false == <expression>
rather than !<expression>
.
src/clp_ffi_js/ir/StreamReader.hpp (1)
Pattern **/*.{cpp,hpp,java,js,jsx,ts,tsx}
: - Prefer false == <expression>
rather than !<expression>
.
🪛 GitHub Actions: lint
src/clp_ffi_js/ir/StreamReader.hpp
[error] 65-66: Code formatting violation: Static create method declaration is not properly formatted
[error] 126-126: Code formatting violation: DecodedResultsTsType return type declaration is not properly formatted
[error] 138-139: Code formatting violation: get_log_event_index_by_timestamp method declaration is not properly formatted
[error] 201-203: Code formatting violation: requires clause and its parameters are not properly formatted
[error] 301-303: Code formatting violation: requires clause and its parameters are not properly formatted
🔇 Additional comments (10)
src/clp_ffi_js/ir/UnstructuredIrStreamReader.hpp (1)
74-75
: LGTM! Method declaration is well-defined.The method signature is consistent with the base class and follows proper C++ practices with the [[nodiscard]] attribute.
src/clp_ffi_js/ir/StructuredIrStreamReader.hpp (2)
11-11
: LGTM! Include directive is appropriately placed.The addition of
<clp/ir/types.hpp>
provides the necessary type definitions.
78-79
: LGTM! Method declaration is consistent.The method signature matches the base class and follows the same pattern as UnstructuredIrStreamReader.
src/clp_ffi_js/ir/StructuredIrStreamReader.cpp (2)
14-14
: LGTM! Include directive is appropriately placed.The addition of
<clp/ir/types.hpp>
provides the necessary type definitions.
151-158
: LGTM! Implementation is clean and efficient.The implementation properly delegates to the generic function, promoting code reuse between different reader types.
src/clp_ffi_js/ir/UnstructuredIrStreamReader.cpp (1)
161-168
: LGTM! Implementation is consistent with StructuredIrStreamReader.The implementation properly uses the generic function, ensuring consistent behaviour across different reader types.
src/clp_ffi_js/ir/StreamReader.cpp (1)
132-132
: LGTM! Type registration and function binding are properly implemented.The new type registration and function binding follow the established patterns in the codebase.
Also applies to: 149-153
src/clp_ffi_js/ir/StreamReader.hpp (3)
14-14
: LGTM! Include and type declaration are properly placed.The additions follow the established patterns in the codebase.
Also applies to: 33-33
128-137
: LGTM! Documentation is clear and comprehensive.The documentation clearly explains the method's purpose, parameters, and return values.
313-331
: LGTM! Implementation is efficient and handles edge cases properly.The implementation:
- Correctly handles empty log events
- Uses std::upper_bound for efficient binary search
- Properly handles the case when all timestamps are larger than the target
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/clp_ffi_js/ir/StreamReader.hpp (1)
312-312
: Use Yoda condition for null check.According to the coding guidelines, prefer
false == <expression>
over!<expression>
.Apply this diff:
- if (log_events.empty()) { + if (true == log_events.empty()) {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/clp_ffi_js/ir/StreamReader.hpp
(5 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/clp_ffi_js/ir/StreamReader.hpp (1)
Pattern **/*.{cpp,hpp,java,js,jsx,ts,tsx}
: - Prefer false == <expression>
rather than !<expression>
.
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: lint (ubuntu-latest)
- GitHub Check: lint (macos-latest)
🔇 Additional comments (5)
src/clp_ffi_js/ir/StreamReader.hpp (5)
33-33
: LGTM! Type declaration follows established pattern.The declaration of
LogEventIdxTsType
aligns with other type declarations in the file and properly integrates with Emscripten's type system.
128-137
: LGTM! Well-documented method declaration.The documentation thoroughly explains all possible return scenarios and the method signature follows C++ best practices with appropriate use of [[nodiscard]].
138-139
: Fix method declaration formatting.The method declaration needs to be reformatted according to the linting rules.
Apply this diff:
- [[nodiscard]] virtual auto get_log_event_index_by_timestamp(clp::ir::epoch_time_ms_t timestamp - ) -> LogEventIdxTsType = 0; + [[nodiscard]] virtual auto get_log_event_index_by_timestamp( + clp::ir::epoch_time_ms_t timestamp + ) -> LogEventIdxTsType = 0;
312-314
: LGTM! Efficient implementation with proper edge case handling.The implementation efficiently uses binary search via std::upper_bound and properly handles all edge cases:
- Empty log events return null
- No exact match returns the last smaller index
- All larger timestamps return the first index
Also applies to: 315-322, 323-329
300-307
: Fix requires clause formatting.The requires clause needs to be reformatted according to the linting rules.
Apply this diff:
-requires requires( - LogEventWithFilterData<LogEvent> const& event, - clp::ir::epoch_time_ms_t timestamp - ) { + requires requires(LogEventWithFilterData<LogEvent> const& event, + clp::ir::epoch_time_ms_t timestamp) {
Co-authored-by: Junhao Liao <[email protected]>
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.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/clp_ffi_js/ir/StreamReader.hpp (1)
196-203
: Move requires clause to a concept.The requires clause is duplicated. Consider moving it to a concept for better maintainability and reusability.
Create a new concept before the class definition:
template <typename T> concept HasTimestamp = requires(T const& event, clp::ir::epoch_time_ms_t timestamp) { { event.get_timestamp() } -> std::convertible_to<clp::ir::epoch_time_ms_t>; };Then simplify the template declarations:
template <typename LogEvent> requires HasTimestamp<LogEventWithFilterData<LogEvent>>Also applies to: 296-303
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/clp_ffi_js/ir/StreamReader.hpp
(5 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/clp_ffi_js/ir/StreamReader.hpp (1)
Pattern **/*.{cpp,hpp,java,js,jsx,ts,tsx}
: - Prefer false == <expression>
rather than !<expression>
.
🪛 GitHub Actions: lint
src/clp_ffi_js/ir/StreamReader.hpp
[error] 133-133: Code formatting violation: incorrect formatting around timestamp parameter documentation
[error] 326-326: Code formatting violation: incorrect formatting in variable declaration and initialization
🔇 Additional comments (3)
src/clp_ffi_js/ir/StreamReader.hpp (3)
33-33
: LGTM! Type declaration is well-placed and consistent.The new type
LogEventIdxTsType
follows the established naming convention and is appropriately grouped with other output types.
137-138
: LGTM! Method signature is well-defined.The virtual method declaration follows the class's pattern and correctly specifies its pure virtual nature.
133-133
:⚠️ Potential issueFix documentation formatting.
The parameter documentation needs proper formatting according to the linting rules.
Apply this diff to fix the formatting:
- * @param timestamp The timestamp to search for, in milliseconds since the Unix epoch. + * @param timestamp + * The timestamp to search for, in milliseconds since the Unix epoch.Likely invalid or redundant comment.
🧰 Tools
🪛 GitHub Actions: lint
[error] 133-133: Code formatting violation: incorrect formatting around timestamp parameter documentation
…et_log_event_index_by_timestamp
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/clp_ffi_js/ir/StreamReader.hpp (2)
145-156
: Consider adding a usage example in the documentation.The documentation is comprehensive but would benefit from a concrete example demonstrating the return values for different scenarios (exact match, approximate match, no match).
* @return null if no log event exists in the stream. + * + * @example + * For a stream with events at timestamps [100, 200, 300]: + * get_log_event_index_by_timestamp(150) returns 0 (index of timestamp 100) + * get_log_event_index_by_timestamp(200) returns 1 (exact match) + * get_log_event_index_by_timestamp(400) returns 2 (index of timestamp 300) */
297-323
: Add defensive checks for index calculations.While the implementation is efficient using binary search, consider adding safety checks:
auto const upper_index{std::distance(log_events.begin(), upper)}; + // Check for potential overflow + if (upper_index == 0) { + return LogEventIdxTsType{emscripten::val::null()}; + } auto const index{upper_index - 1}; + // Validate index is within bounds + if (index >= log_events.size()) { + return LogEventIdxTsType{emscripten::val::null()}; + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/clp_ffi_js/ir/StreamReader.hpp
(7 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/clp_ffi_js/ir/StreamReader.hpp (1)
Pattern **/*.{cpp,hpp,java,js,jsx,ts,tsx}
: - Prefer false == <expression>
rather than !<expression>
.
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: lint (ubuntu-latest)
- GitHub Check: lint (macos-latest)
🔇 Additional comments (3)
src/clp_ffi_js/ir/StreamReader.hpp (3)
14-14
: LGTM! The new include and type declaration are well-placed.The addition of
<clp/ir/types.hpp>
andLogEventIdxTsType
declaration aligns with the PR's objective of supporting timestamp-based search functionality.Also applies to: 33-33
49-64
: Well-structured concept definitions!The introduction of
GetLogEventIdxInterface
andDecodeRangeInterface
concepts improves code clarity and maintainability. The concepts effectively encapsulate the requirements for timestamp operations and string conversion respectively.
310-312
: Verify timestamp comparison edge cases.The current comparison assumes timestamps are always valid. Consider verifying how the code handles:
- Negative timestamps
- Maximum timestamp values
- Timestamp overflow scenarios
✅ Verification successful
Timestamp comparison implementation is verified safe
The current implementation correctly handles all edge cases:
- Uses consistent type system across the codebase
- Preserves ordering for all possible values including zero, negative, and maximum values
- Handles missing timestamps gracefully by defaulting to zero
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for timestamp validation or handling in the codebase rg -l "epoch_time_ms_t" | xargs rg -B2 -A2 "(numeric_limits|MAX|MIN|overflow|underflow)" # Check if there are any existing test cases for timestamp edge cases fd -e cpp -e hpp test_.*timestamp | xargs rg -A 5 "TEST.*timestamp"Length of output: 160
Script:
#!/bin/bash # Find timestamp type definition and usage ast-grep --pattern 'using epoch_time_ms_t = $_' # Find timestamp comparisons ast-grep --pattern 'get_timestamp()' # Look for test files that might contain timestamp tests fd -e cpp -e hpp test_ | xargs rg -B2 -A2 "epoch_time_ms_t"Length of output: 6520
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/clp_ffi_js/ir/StreamReader.hpp (1)
202-213
: Consider enhancing the documentation.The documentation could be more comprehensive. Consider adding details about:
- The algorithm used (binary search)
- Edge cases handling
- Performance characteristics
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
src/clp_ffi_js/ir/StreamReader.cpp
(2 hunks)src/clp_ffi_js/ir/StreamReader.hpp
(7 hunks)src/clp_ffi_js/ir/StructuredIrStreamReader.cpp
(2 hunks)src/clp_ffi_js/ir/StructuredIrStreamReader.hpp
(2 hunks)src/clp_ffi_js/ir/UnstructuredIrStreamReader.cpp
(1 hunks)src/clp_ffi_js/ir/UnstructuredIrStreamReader.hpp
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
- src/clp_ffi_js/ir/StructuredIrStreamReader.hpp
- src/clp_ffi_js/ir/StreamReader.cpp
- src/clp_ffi_js/ir/UnstructuredIrStreamReader.hpp
- src/clp_ffi_js/ir/UnstructuredIrStreamReader.cpp
- src/clp_ffi_js/ir/StructuredIrStreamReader.cpp
🧰 Additional context used
📓 Path-based instructions (1)
src/clp_ffi_js/ir/StreamReader.hpp (1)
Pattern **/*.{cpp,hpp,java,js,jsx,ts,tsx}
: - Prefer false == <expression>
rather than !<expression>
.
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: lint (ubuntu-latest)
- GitHub Check: lint (macos-latest)
🔇 Additional comments (6)
src/clp_ffi_js/ir/StreamReader.hpp (6)
14-14
: LGTM! Include statement added as suggested.The addition of
clp/ir/types.hpp
is appropriate for using theclp::ir::epoch_time_ms_t
type.
33-33
: LGTM! Type declaration follows established pattern.The declaration of
LogEventIdxTsType
aligns with the existing TypeScript type declarations in the file.
49-57
: LGTM! Well-defined concept for timestamp retrieval.The concept properly constrains the LogEvent type to ensure it provides a timestamp that's convertible to
clp::ir::epoch_time_ms_t
.
59-64
: LGTM! Good refactoring to use a concept.Moving the requirements to a named concept improves code organization and reusability.
145-156
: LGTM! Well-documented method declaration.The method declaration is properly marked as
[[nodiscard]]
and includes comprehensive documentation of parameters and return values.
297-323
: LGTM! Efficient implementation with proper edge case handling.The implementation uses
std::upper_bound
for efficient binary search and correctly handles all edge cases as documented.
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.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/clp_ffi_js/ir/StreamReader.hpp (2)
49-64
: Consider extracting the timestamp comparison lambda into the concept.The concepts are well-defined, but the timestamp comparison lambda in
generic_get_log_event_idx_by_timestamp
could be moved into theGetLogEventIdxInterface
concept for better reusability and consistency.template <typename LogEvent> concept GetLogEventIdxInterface = requires( LogEventWithFilterData<LogEvent> const& event, clp::ir::epoch_time_ms_t timestamp ) { { event.get_timestamp() } -> std::convertible_to<clp::ir::epoch_time_ms_t>; + { + timestamp < event.get_timestamp() + } -> std::convertible_to<bool>; };
298-324
: Consider using std::prev for better readability.The implementation is efficient and handles all edge cases correctly. However, the index calculation could be more concise using
std::prev
.- auto const upper_index{std::distance(log_events.begin(), upper)}; - auto const index{upper_index - 1}; - - return LogEventIdxTsType{emscripten::val(index)}; + return LogEventIdxTsType{emscripten::val( + std::distance(log_events.begin(), std::prev(upper)) + )};
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/clp_ffi_js/ir/StreamReader.hpp
(8 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/clp_ffi_js/ir/StreamReader.hpp (1)
Pattern **/*.{cpp,hpp,java,js,jsx,ts,tsx}
: - Prefer false == <expression>
rather than !<expression>
.
🪛 GitHub Actions: lint
src/clp_ffi_js/ir/StreamReader.hpp
[error] 192-192: Code formatting violation detected. The code should be clang-formatted.
🔇 Additional comments (2)
src/clp_ffi_js/ir/StreamReader.hpp (2)
14-14
: LGTM! The include and type declaration are well-placed.The addition of
<clp/ir/types.hpp>
and the declaration ofLogEventIdxTsType
properly support the new timestamp-based search functionality.Also applies to: 33-33
145-156
: LGTM! The method declaration and documentation are comprehensive.The virtual method is well-defined with clear documentation covering all edge cases and return values.
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/clp_ffi_js/ir/StreamReader.hpp (2)
49-64
: LGTM with a suggestion for improvement!The concepts are well-defined and improve code organization. The GetLogEventIdxInterface concept correctly ensures timestamp compatibility, and the DecodeRangeInterface concept effectively replaces the previous requires clause.
Consider moving these concepts to a separate header file for better reusability across the codebase, as suggested in the past review comments. This would align with the example in clp/components/core/src/clp/ffi/ir_stream/IrUnitHandlerInterface.hpp.
203-214
: Improve method documentation.The documentation is incomplete and contains a misplaced comment about returning the first log event index.
Consider updating the documentation to match the virtual method's documentation style, or simply reference the virtual method's documentation to avoid duplication, as suggested in past review comments.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/clp_ffi_js/ir/StreamReader.hpp
(7 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/clp_ffi_js/ir/StreamReader.hpp (1)
Pattern **/*.{cpp,hpp,java,js,jsx,ts,tsx}
: - Prefer false == <expression>
rather than !<expression>
.
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: lint (ubuntu-latest)
- GitHub Check: lint (macos-latest)
🔇 Additional comments (5)
src/clp_ffi_js/ir/StreamReader.hpp (5)
14-14
: LGTM!The include statement for clp/ir/types.hpp is correctly added as suggested in the past review comments.
33-33
: LGTM!The declaration of LogEventIdxTsType follows the established pattern for TypeScript type declarations.
145-156
: LGTM!The virtual method declaration is well-documented with clear return value cases and proper [[nodiscard]] attribute.
298-324
: LGTM!The implementation is efficient and handles edge cases properly. The code follows the formatting and naming conventions suggested in past review comments.
177-177
: LGTM!The requires clauses consistently use the new DecodeRangeInterface concept, improving code maintainability.
Also applies to: 218-218
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/clp_ffi_js/ir/StreamReader.hpp (1)
200-211
: Improve method documentation.The documentation is missing important details:
- Add
@param log_events
description- Clarify the return value documentation
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/clp_ffi_js/ir/StreamReader.hpp
(6 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/clp_ffi_js/ir/StreamReader.hpp (1)
Pattern **/*.{cpp,hpp,java,js,jsx,ts,tsx}
: - Prefer false == <expression>
rather than !<expression>
.
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: lint (ubuntu-latest)
- GitHub Check: lint (macos-latest)
🔇 Additional comments (5)
src/clp_ffi_js/ir/StreamReader.hpp (5)
14-14
: LGTM! The include statement for clp/ir/types.hpp is correctly added.
33-33
: LGTM! The LogEventIdxTsType declaration is correctly added and follows the established pattern.
49-57
: Consider storing the concept requirements as a constant.The concept definition is well-structured and type-safe. However, as suggested in past review comments, consider storing these requirements in an
std::concept
constant to avoid repetition.
138-149
: LGTM! The virtual method declaration is well-documented and properly designed.
299-325
: LGTM! The implementation is efficient and handles all edge cases correctly.The binary search approach using
std::upper_bound
is an excellent choice for performance, and the logic for finding the closest index is well-implemented.
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.
lgtm. Please wait for @davemarco 's approval before merging.
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.
From a high level, I noticed we aren't really considering the existing filter. Please feel free to disagree, but I think the function should only consider the filtered events more similiar to decode_range
behaviour with use_filter
set. This way it can be more efficient on smaller filtered logs. Secondly, also feel free to disagree. The function should probably return the ActiveLogEventIdx (see here and here) not the log event index. The log event idx isn't terrible, but now we have will need to convert it back to the active log event idx once it is returned to find the correct page. It is probably slightly more efficient to just get the activeLogEventIdx straight from the function. Anyways let me know your thoughts.
@@ -44,6 +46,16 @@ using LogEvents = std::vector<LogEventWithFilterData<LogEvent>>; | |||
*/ | |||
using FilteredLogEventsMap = std::optional<std::vector<size_t>>; | |||
|
|||
template <typename LogEvent> |
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.
What is the difference between doing this with a concept and just having template <typename LogEvent>
like the other generic functions?
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.
Oh, this was suggested by zhihao, and one of the pros is simplify the require statement in function declaration.
We will populate this concept keyword in the next pr, since junhao wants only the necessary things to be changed
Right, if we implement the first point, we will need the second point. Since this is only a performance optimization, it might be fine to leave that into a future PR when we have spare resources. @Henry8192 if you think this is something quick (less than a morning) to implement, go for it |
@junhaoliao Okay, Perhaps it can wait. With the binary search it probably decently fast anyways. I will review again now then with the PR as is. |
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/clp_ffi_js/ir/StreamReader.hpp (2)
49-57
: Add documentation for the GetLogEventIdxInterface concept.The concept is well-defined, but it would benefit from documentation explaining its purpose and requirements.
Add a documentation block before the concept:
+/** + * Concept defining the requirements for log event types that can be searched by timestamp. + * Types satisfying this concept must provide a get_timestamp method that returns a value + * convertible to epoch_time_ms_t. + */ template <typename LogEvent> concept GetLogEventIdxInterface = requires(
299-325
: Consider optimizing and documenting the binary search implementation.While the implementation is correct, consider these improvements:
- Add a comment explaining the binary search strategy
- Use
std::prev
for cleaner iterator manipulationApply this diff to improve the implementation:
template <GetLogEventIdxInterface LogEvent> auto StreamReader::generic_get_log_event_idx_by_timestamp( LogEvents<LogEvent> const& log_events, clp::ir::epoch_time_ms_t timestamp ) -> LogEventIdxTsType { if (log_events.empty()) { return LogEventIdxTsType{emscripten::val::null()}; } + // Use binary search to find the first element greater than the target timestamp auto upper{std::upper_bound( log_events.begin(), log_events.end(), timestamp, [](clp::ir::epoch_time_ms_t ts, LogEventWithFilterData<LogEvent> const& log_event) { return ts < log_event.get_timestamp(); } )}; if (upper == log_events.begin()) { return LogEventIdxTsType{emscripten::val(0)}; } - auto const upper_index{std::distance(log_events.begin(), upper)}; - auto const index{upper_index - 1}; + // Return the index of the previous element (last element <= timestamp) + auto const index{std::distance(log_events.begin(), std::prev(upper))}; return LogEventIdxTsType{emscripten::val(index)}; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/clp_ffi_js/ir/StreamReader.cpp
(2 hunks)src/clp_ffi_js/ir/StreamReader.hpp
(6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/clp_ffi_js/ir/StreamReader.cpp
🧰 Additional context used
📓 Path-based instructions (1)
src/clp_ffi_js/ir/StreamReader.hpp (1)
Pattern **/*.{cpp,hpp,java,js,jsx,ts,tsx}
: - Prefer false == <expression>
rather than !<expression>
.
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: lint (ubuntu-latest)
- GitHub Check: lint (macos-latest)
🔇 Additional comments (2)
src/clp_ffi_js/ir/StreamReader.hpp (2)
14-14
: LGTM! Type declarations and includes are well-organized.The new include and type declaration follow the existing patterns in the codebase.
Also applies to: 33-33
138-149
: LGTM! Well-documented virtual method declaration.The method signature and documentation are clear and comprehensive.
Description
Adds
getLogEventIndexByTimestamp
API inclp_ffi_js/ir/StreamReader.cpp
for ClpStreamReader. It returnsnull
only if there are no log events. Otherwise, it would search logs in "best effort", which means it returns the last index smaller than the timestamp if no exact timestamp match, unless all log event timestamps are larger than the target. In that case, return the first log event index.In
clp_ffi_js/ir/StreamReader.hpp
, implementsgeneric_get_log_event_index_by_timestamp()
, the core logic (basically just binary search) for finding log events by timestamp.This function is called both by
StructuredIrStreamReader
andUnstructuredIrStreamReader
'sget_log_event_index_by_timestamp
.Validation performed
Use the following javascript for testing structured and unstructured logs:
Summary by CodeRabbit
New Features
Technical Improvements