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
9 changes: 4 additions & 5 deletions components/core/src/clp/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,13 @@ load_lexer_from_file(std::string const& schema_file_path, log_surgeon::lexers::B
for (std::unique_ptr<log_surgeon::ParserAST> const& parser_ast : schema_ast->m_schema_vars) {
auto* rule = dynamic_cast<log_surgeon::SchemaVarAST*>(parser_ast.get());

// Currently, we only support at most a single capture group in each variable. If a capture
// group is present its match will be treated as the variable rather than the full match.
auto const num_captures = rule->m_regex_ptr->get_subtree_positive_captures().size();
if (1 < num_captures) {
// Capture groups are temporarily disabled, until NFA intersection supports for search.
auto const num_captures{rule->m_regex_ptr->get_subtree_positive_captures().size()};
if (0 < num_captures) {
throw std::runtime_error(
schema_file_path + ":" + std::to_string(rule->m_line_num + 1)
+ ": error: the schema rule '" + rule->m_name
+ "' has a regex pattern containing > 1 capture groups (found "
+ "' has a regex pattern containing capture groups (found "
+ std::to_string(num_captures) + ").\n"
);
}
Expand Down
10 changes: 10 additions & 0 deletions components/core/src/clp/clp/run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ int run(int argc, char const* argv[]) {
if (!command_line_args.get_use_heuristic()) {
std::string const& schema_file_path = command_line_args.get_schema_file_path();
reader_parser = std::make_unique<log_surgeon::ReaderParser>(schema_file_path);
// Capture groups are temporarily disabled, until NFA intersection support for search.
auto const& lexer{reader_parser->get_log_parser().m_lexer};
for (auto const& [rule_id, rule_name] : lexer.m_id_symbol) {
if (lexer.get_captures_from_rule_id(rule_id).has_value()) {
throw std::runtime_error(
schema_file_path + ": error: the schema rule '" + rule_name
+ "' has a regex pattern containing capture groups.\n"
);
}
}
}

boost::filesystem::path path_prefix_to_remove(
Expand Down
55 changes: 16 additions & 39 deletions components/core/tests/test-ParserWithUserSchema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,15 @@ TEST_CASE("Test lexer", "[Search]") {
}
}

TEST_CASE("Test schema with single capture group", "[load_lexer]") {
TEST_CASE("Error on schema rule with a single capture group", "[load_lexer]") {
auto const schema_file_path{get_test_schema_files_dir() / "single_capture_group.txt"};
ByteLexer lexer;
load_lexer_from_file(schema_file_path, lexer);

auto const rule_id{lexer.m_symbol_id.at("capture")};
auto captures{lexer.get_captures_from_rule_id(rule_id)};
REQUIRE(captures.has_value());
REQUIRE(1 == captures->size());
REQUIRE("group" == captures->at(0)->get_name());
REQUIRE_THROWS_WITH(
load_lexer_from_file(schema_file_path, lexer),
schema_file_path.string()
+ ":3: error: the schema rule 'capture' has a regex pattern containing capture "
"groups (found 1).\n"
);
}

TEST_CASE("Error on schema rule with multiple capture groups", "[load_lexer]") {
Expand All @@ -209,43 +208,21 @@ TEST_CASE("Error on schema rule with multiple capture groups", "[load_lexer]") {
REQUIRE_THROWS_WITH(
load_lexer_from_file(schema_file_path, lexer),
schema_file_path.string()
+ ":3: error: the schema rule 'multicapture' has a regex pattern containing > "
"1 capture groups (found 2).\n"
+ ":3: error: the schema rule 'multicapture' has a regex pattern containing "
"capture groups (found 2).\n"
);
}

TEST_CASE("Verify dictionary contents", "[Compression]") {
TEST_CASE("Verify CLP compression fails with capture groups", "[Compression]") {
auto const log_file_path{get_test_log_dir() / "log_with_capture.txt"};
auto const schema_file_path{get_test_schema_files_dir() / "single_capture_group.txt"};
TestOutputCleaner const cleaner{{std::string{cTestArchiveDirectory}}};
std::filesystem::create_directory(cTestArchiveDirectory);

REQUIRE(0 == run_clp_compress(schema_file_path, cTestArchiveDirectory, log_file_path));

std::vector<std::filesystem::path> archive_paths;
for (auto const& entry : std::filesystem::directory_iterator{cTestArchiveDirectory}) {
auto const& path{entry.path()};
if (false == path.string().ends_with(clp::streaming_archive::cMetadataDBFileName)) {
archive_paths.emplace_back(path);
}
}
REQUIRE(1 == archive_paths.size());

clp::streaming_archive::reader::Archive archive_reader;
archive_reader.open(archive_paths.at(0));
archive_reader.refresh_dictionaries();

auto const& logtype_dict{archive_reader.get_logtype_dictionary()};
REQUIRE(1 == logtype_dict.get_entries().size());
REQUIRE(fmt::format(
"2016-05-08 07:34:05.251 MyDog{} APet{} test.txt\n",
clp::enum_to_underlying_type(clp::ir::VariablePlaceholder::Dictionary),
clp::enum_to_underlying_type(clp::ir::VariablePlaceholder::Dictionary)
)
== logtype_dict.get_value(0));

auto const& var_dict{archive_reader.get_var_dictionary()};
REQUIRE(2 == var_dict.get_entries().size());
REQUIRE("123" == var_dict.get_value(0));
REQUIRE("4123" == var_dict.get_value(1));
REQUIRE_THROWS_WITH(
run_clp_compress(schema_file_path, cTestArchiveDirectory, log_file_path),
schema_file_path.string()
+ ": error: the schema rule 'capture' has a regex pattern containing capture "
"groups.\n"
);
}
Loading