Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 23 additions & 8 deletions src/clp_ffi_js/ir/StructuredIrStreamReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <clp/ffi/ir_stream/Deserializer.hpp>
#include <clp/ir/types.hpp>
#include <clp/TraceableException.hpp>
#include <emscripten/bind.h>
#include <emscripten/val.h>
#include <json/single_include/nlohmann/json.hpp>
#include <spdlog/spdlog.h>
Expand All @@ -28,6 +29,8 @@ namespace {
constexpr std::string_view cEmptyJsonStr{"{}"};
constexpr std::string_view cReaderOptionsLogLevelKey{"logLevelKey"};
constexpr std::string_view cReaderOptionsTimestampKey{"timestampKey"};
constexpr std::string_view cMergedKvPairsAutoGeneratedKey{"auto-generated"};
constexpr std::string_view cMergedKvPairsUserGeneratedKey{"user-generated"};

/**
* @see nlohmann::basic_json::dump
Expand All @@ -42,6 +45,16 @@ auto dump_json_with_replace(nlohmann::json const& json) -> std::string {
return json.dump(-1, ' ', false, nlohmann::json::error_handler_t::replace);
}

EMSCRIPTEN_BINDINGS(ClpStructuredIrStreamReader) {
emscripten::constant(
"MERGED_KV_PAIRS_AUTO_GENERATED_KEY",
std::string{cMergedKvPairsAutoGeneratedKey}
);
emscripten::constant(
"MERGED_KV_PAIRS_USER_GENERATED_KEY",
std::string{cMergedKvPairsUserGeneratedKey}
);
}
} // namespace

auto StructuredIrStreamReader::create(
Expand Down Expand Up @@ -137,20 +150,22 @@ auto StructuredIrStreamReader::deserialize_stream() -> size_t {
auto StructuredIrStreamReader::decode_range(size_t begin_idx, size_t end_idx, bool use_filter) const
-> DecodedResultsTsType {
auto log_event_to_string = [](StructuredLogEvent const& log_event) -> std::string {
std::string json_str;
auto const json_result{log_event.serialize_to_json()};
if (false == json_result.has_value()) {
auto error_code{json_result.error()};
auto json_pair_result{log_event.serialize_to_json()};
if (json_pair_result.has_error()) {
auto const error_code{json_pair_result.error()};
SPDLOG_ERROR(
"Failed to deserialize log event to JSON: {}:{}",
error_code.category().name(),
error_code.message()
);
json_str = std::string(cEmptyJsonStr);
} else {
json_str = dump_json_with_replace(json_result.value());
return std::string{cEmptyJsonStr};
}
return json_str;

auto& [auto_generated, user_generated] = json_pair_result.value();
nlohmann::json const merged_kv_pairs
= {{std::string{cMergedKvPairsAutoGeneratedKey}, std::move(auto_generated)},
{std::string{cMergedKvPairsUserGeneratedKey}, std::move(user_generated)}};
return dump_json_with_replace(merged_kv_pairs);
};

return generic_decode_range(
Expand Down
8 changes: 7 additions & 1 deletion src/clp_ffi_js/ir/StructuredIrUnitHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ auto parse_log_level(std::string_view str) -> LogLevel {

auto StructuredIrUnitHandler::handle_log_event(StructuredLogEvent&& log_event
) -> clp::ffi::ir_stream::IRErrorCode {
auto const& id_value_pairs{log_event.get_node_id_value_pairs()};
auto const& id_value_pairs{log_event.get_user_gen_node_id_value_pairs()};
auto const timestamp = get_timestamp(id_value_pairs);
auto const log_level = get_log_level(id_value_pairs);

Expand All @@ -75,8 +75,14 @@ auto StructuredIrUnitHandler::handle_utc_offset_change(
}

auto StructuredIrUnitHandler::handle_schema_tree_node_insertion(
bool is_auto_generated,
clp::ffi::SchemaTree::NodeLocator schema_tree_node_locator
) -> clp::ffi::ir_stream::IRErrorCode {
if (is_auto_generated) {
// TODO: Currently, all auto-generated keys are ignored.
return clp::ffi::ir_stream::IRErrorCode::IRErrorCode_Success;
}

++m_current_node_id;

auto const& key_name{schema_tree_node_locator.get_key_name()};
Expand Down
2 changes: 2 additions & 0 deletions src/clp_ffi_js/ir/StructuredIrUnitHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ class StructuredIrUnitHandler {
/**
* Saves the node's ID if it corresponds to events' authoritative log level or timestamp
* kv-pair.
* @param is_auto_generated
* @param schema_tree_node_locator
* @return IRErrorCode::IRErrorCode_Success
*/
[[nodiscard]] auto handle_schema_tree_node_insertion(
bool is_auto_generated,
clp::ffi::SchemaTree::NodeLocator schema_tree_node_locator
) -> clp::ffi::ir_stream::IRErrorCode;

Expand Down
2 changes: 1 addition & 1 deletion src/submodules/clp
Submodule clp updated 312 files
Loading