Skip to content
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: Add support for finding the log event that's closest to a target timestamp. #42

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ea23947
search timestamp works for unstructured logs
Henry8192 Nov 19, 2024
7edaa48
Merge branch 'y-scope:main' into search-timestamp
Henry8192 Dec 16, 2024
7481573
Merge branch 'main' into search-timestamp
Henry8192 Dec 18, 2024
3ee05a2
fix lint
Henry8192 Dec 19, 2024
f1a71a1
implement structured logs search by timestamp
Henry8192 Dec 22, 2024
5263385
Merge branch 'main' into search-timestamp
Henry8192 Dec 22, 2024
c423ec5
address partial changes from review
Henry8192 Dec 27, 2024
467e998
snapshot: get_timestamp seems to be undefined for std::upper_bound
Henry8192 Dec 30, 2024
c66cb80
fix lint
Henry8192 Dec 30, 2024
89338f7
pass in log_events instead of iterators to generic_get_log_event_inde…
Henry8192 Jan 2, 2025
a99ec2a
switch back to std::upper_bound because std::ranges::upper_bound is n…
Henry8192 Jan 6, 2025
9ec039f
fix lint
Henry8192 Jan 6, 2025
4f125b8
change generic_get_log_event_index_by_timestamp behavior: only return…
Henry8192 Jan 6, 2025
5221588
edit docstring for get_log_event_index_by_timestamp
Henry8192 Jan 6, 2025
abeb4f8
fix lint
Henry8192 Jan 6, 2025
6647fbd
Apply suggestions from code review
Henry8192 Jan 8, 2025
046191e
use concept to shorten function definition; minor change to generic_g…
Henry8192 Jan 8, 2025
4c7386d
Merge branch 'main' into search-timestamp
Henry8192 Jan 9, 2025
c400361
fix lint & syntax
Henry8192 Jan 9, 2025
ca4a616
rename get_log_event_index_by_timestamp to get_log_event_idx_by_times…
Henry8192 Jan 9, 2025
9443ba3
revert comments and plan to fix in the next pr
Henry8192 Jan 10, 2025
db60efd
add back the missing space
Henry8192 Jan 10, 2025
0e3e21b
revert decode_range (without creating concept)
Henry8192 Jan 10, 2025
412b96e
address changes from Marco's review
Henry8192 Jan 13, 2025
54c7df1
remove unnecessary require statement for get_log_event_idx_by_timestamp
Henry8192 Jan 13, 2025
eff1849
address the rest of the comments
Henry8192 Jan 13, 2025
00f89d4
address code review changes
Henry8192 Jan 14, 2025
122f1cf
fix lint
Henry8192 Jan 15, 2025
f4a0207
resolve the rest of the conflicts
Henry8192 Jan 29, 2025
46fa81f
revert the CMakeList Change
Henry8192 Jan 30, 2025
8c8c42e
address kirk's comments in the code review
Henry8192 Feb 1, 2025
a984d7b
revert function name to find_nearest_log_event_by_timestamp
Henry8192 Feb 3, 2025
4788157
amend find_nearest_log_event_by_timestamp's comments, warning this fu…
Henry8192 Feb 4, 2025
ba1b01a
Update src/clp_ffi_js/ir/StreamReader.hpp
Henry8192 Feb 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/clp_ffi_js/ir/StreamReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ EMSCRIPTEN_BINDINGS(ClpStreamReader) {
)
.function("filterLogEvents", &clp_ffi_js::ir::StreamReader::filter_log_events)
.function("deserializeStream", &clp_ffi_js::ir::StreamReader::deserialize_stream)
.function("decodeRange", &clp_ffi_js::ir::StreamReader::decode_range);
.function("decodeRange", &clp_ffi_js::ir::StreamReader::decode_range)
.function(
"getLogEventIndexByTimestamp",
Henry8192 marked this conversation as resolved.
Show resolved Hide resolved
&clp_ffi_js::ir::StreamReader::find_timestamp_last_occurrence
Henry8192 marked this conversation as resolved.
Show resolved Hide resolved
);
}
} // namespace

Expand Down
5 changes: 5 additions & 0 deletions src/clp_ffi_js/ir/StreamReader.hpp
Henry8192 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <concepts>
#include <cstddef>
#include <cstdint>
#include <ir/types.hpp>
Henry8192 marked this conversation as resolved.
Show resolved Hide resolved
#include <memory>
#include <optional>
#include <string>
Expand Down Expand Up @@ -124,6 +125,10 @@ class StreamReader {
[[nodiscard]] virtual auto decode_range(size_t begin_idx, size_t end_idx, bool use_filter) const
-> DecodedResultsTsType = 0;

[[nodiscard]] virtual auto find_timestamp_last_occurrence(
Henry8192 marked this conversation as resolved.
Show resolved Hide resolved
clp::ir::epoch_time_ms_t input_timestamp
Henry8192 marked this conversation as resolved.
Show resolved Hide resolved
) -> std::ptrdiff_t = 0;
Henry8192 marked this conversation as resolved.
Show resolved Hide resolved

protected:
explicit StreamReader() = default;

Expand Down
24 changes: 24 additions & 0 deletions src/clp_ffi_js/ir/StructuredIrStreamReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,30 @@ auto StructuredIrStreamReader::decode_range(size_t begin_idx, size_t end_idx, bo
);
}

auto StructuredIrStreamReader::find_timestamp_last_occurrence(
clp::ir::epoch_time_ms_t input_timestamp
) -> std::ptrdiff_t {
// Use std::lower_bound with a custom comparator
Henry8192 marked this conversation as resolved.
Show resolved Hide resolved
auto it = std::lower_bound(
m_deserialized_log_events->begin(),
m_deserialized_log_events->end(),
input_timestamp,
[](const LogEventWithFilterData<StructuredLogEvent>& event, clp::ir::epoch_time_ms_t timestamp) {
return event.get_timestamp() <= timestamp;
}
);

// Adjust the iterator to find the last valid index
if (it == m_deserialized_log_events->end() || it->get_timestamp() > input_timestamp) {
if (it == m_deserialized_log_events->begin()) {
Henry8192 marked this conversation as resolved.
Show resolved Hide resolved
return -1; // No element satisfies the condition
}
--it;
Henry8192 marked this conversation as resolved.
Show resolved Hide resolved
}

return std::distance(m_deserialized_log_events->begin(), it);
}

StructuredIrStreamReader::StructuredIrStreamReader(
StreamReaderDataContext<StructuredIrDeserializer>&& stream_reader_data_context,
std::shared_ptr<StructuredLogEvents> deserialized_log_events
Expand Down
3 changes: 3 additions & 0 deletions src/clp_ffi_js/ir/StructuredIrStreamReader.hpp
Henry8192 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ class StructuredIrStreamReader : public StreamReader {
[[nodiscard]] auto decode_range(size_t begin_idx, size_t end_idx, bool use_filter) const
-> DecodedResultsTsType override;

[[nodiscard]] auto find_timestamp_last_occurrence(clp::ir::epoch_time_ms_t input_timestamp
) -> std::ptrdiff_t override;

private:
// Constructor
explicit StructuredIrStreamReader(
Expand Down
23 changes: 23 additions & 0 deletions src/clp_ffi_js/ir/UnstructuredIrStreamReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,29 @@ auto UnstructuredIrStreamReader::decode_range(size_t begin_idx, size_t end_idx,
);
}

auto UnstructuredIrStreamReader::find_timestamp_last_occurrence(
Henry8192 marked this conversation as resolved.
Show resolved Hide resolved
clp::ir::epoch_time_ms_t input_timestamp
) -> std::ptrdiff_t {
// Use std::lower_bound with a custom comparator
auto it = std::lower_bound(
m_encoded_log_events.begin(),
m_encoded_log_events.end(),
input_timestamp,
[](LogEventWithFilterData<UnstructuredLogEvent> const& event,
clp::ir::epoch_time_ms_t timestamp) { return event.get_timestamp() <= timestamp; }
);

// Adjust the iterator to find the last valid index
if (it == m_encoded_log_events.end() || it->get_timestamp() > input_timestamp) {
if (it == m_encoded_log_events.begin()) {
return -1; // No element satisfies the condition
}
--it;
}

return std::distance(m_encoded_log_events.begin(), it);
}

UnstructuredIrStreamReader::UnstructuredIrStreamReader(
StreamReaderDataContext<UnstructuredIrDeserializer>&& stream_reader_data_context
)
Expand Down
3 changes: 3 additions & 0 deletions src/clp_ffi_js/ir/UnstructuredIrStreamReader.hpp
Henry8192 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ class UnstructuredIrStreamReader : public StreamReader {
[[nodiscard]] auto decode_range(size_t begin_idx, size_t end_idx, bool use_filter) const
-> DecodedResultsTsType override;

[[nodiscard]] auto find_timestamp_last_occurrence(clp::ir::epoch_time_ms_t input_timestamp
) -> std::ptrdiff_t override;

private:
// Constructor
explicit UnstructuredIrStreamReader(
Expand Down
Loading