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
4 changes: 2 additions & 2 deletions components/core/config/schemas.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Delimiters
delimiters: \t\r\n!"#$%&'\(\)\*,:;<>?@\[\]\^_`\{\|\}~
delimiters: \t\r\n!"#$%&'()*,:;<>?@[]^_`{}|~

// Timestamps (using the `timestamp` keyword)
// E.g. 2015-01-31 15:50:45,392
Expand All @@ -16,4 +16,4 @@ float:\-{0,1}[0-9]+\.[0-9]+
// Dictionary variables
hex:[a-fA-F]+
hasNumber:.*\d.*
equals:.*=(?<var>.*[a-zA-Z0-9].*)
equals:[a-zA-Z0-9]+=(?<var>.*[a-zA-Z0-9].*)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm understanding correctly, doesn't this stop this rule from working with most unicode?

Would be fine with this as a temporary workaround as long as we create an issue to track fixing this case.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, although afaik log-surgeon doesn't work properly with unicode in general.

I made y-scope/log-surgeon#207 (I forgot to add it to the PR description sorry). I'm not sure if we also want to add an issue to clp to track the log surgeon issue (lmk if you'd like that).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as it's tracked somewhere that's fine with me.

9 changes: 5 additions & 4 deletions components/core/src/clp_s/log_converter/LogConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ namespace {
* minus sign for timezone offsets.
*/
constexpr std::string_view cTimestampSchema{
R"(timestamp:(\d{2,4}[ /\-]{0,1}[ 0-9]{2}[ /\-][ 0-9]{2})|([ 0-9]{2}[ /\-])"
R"(header:(?<timestamp>((\d{2,4}[ /\-]{0,1}[ 0-9]{2}[ /\-][ 0-9]{2})|([ 0-9]{2}[ /\-])"
R"(((Jan(uary){0,1})|(Feb(ruary){0,1})|(Mar(ch){0,1})|(Apr(il){0,1})|(May)|(Jun(e){0,1})|)"
R"((Jul(y){0,1})|(Aug(ust){0,1})|(Sep(tember){0,1})|(Oct(ober){0,1})|(Nov(ember){0,1})|)"
R"((Dec(ember){0,1}))[ /\-]\d{2,4})[ T:][ 0-9]{2}:[ 0-9]{2}:[ 0-9]{2})"
R"(([,\.:]\d{1,9}){0,1}([ ]{0,1}(UTC){0,1}[\+\-]\d{2}(:{0,1}\d{2}){0,1}Z{0,1}){0,1})"
R"((Dec(ember){0,1}))[ /\-]\d{2,4}))[ T:][ 0-9]{2}:[ 0-9]{2}:[ 0-9]{2})"
R"(([,\.:]\d{1,9}){0,1}([ ]{0,1}(UTC){0,1}[\+\-]\d{2}(:{0,1}\d{2}){0,1}Z{0,1}){0,1}))"
Comment on lines 28 to +33

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Verify timestamp capture boundaries after the regex regrouping.

The added header: prefix and closing-group changes can shift what the timestamp named capture returns; please confirm it still includes full date+time (plus optional fractional/timezone) in LogConverter, ideally with a focused sample-log test.

🤖 Prompt for AI Agents
In `@components/core/src/clp_s/log_converter/LogConverter.cpp` around lines 28 -
33, The regex change to cTimestampSchema (used by LogConverter) likely altered
capture group boundaries so the named capture "timestamp" may no longer include
the entire date+time and optional fractional/timezone; verify and fix by
creating a focused unit/integration test that feeds representative sample log
lines (with variants: numeric months, month names, fractional seconds,
UTC/offset/Z) into LogConverter and asserts the extracted "timestamp" equals the
full expected substring, then adjust grouping/parentheses in cTimestampSchema so
the named capture timestamp encompasses the complete date+time plus optional
fractional and timezone parts (ensure no stray outer groups cut off trailing
parts). Ensure tests reference LogConverter and cTimestampSchema so future edits
detect regressions.

};
constexpr std::string_view cDelimiters{R"(delimiters: \t\r\n\[\(:)"};

constexpr std::string_view cDelimiters{R"(delimiters: \t\r\n[(:)"};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, let's check the current state of the file
cat -n components/core/src/clp_s/log_converter/LogConverter.cpp | sed -n '30,40p'

Repository: y-scope/clp

Length of output: 695


🏁 Script executed:

# Check if schemas.txt exists and what it contains regarding delimiters
find . -name "schemas.txt" -type f

Repository: y-scope/clp

Length of output: 91


🏁 Script executed:

# Look for any reference to cDelimiters in the codebase
rg "cDelimiters" --type cpp --type hpp -A 2 -B 2

Repository: y-scope/clp

Length of output: 82


🌐 Web query:

C++ raw string literal terminator )" how to include ) and " in raw string content

💡 Result:

In a C++ raw string literal, the only thing you must avoid inside the content is the exact closing sequence:

)delimiter"

where delimiter is whatever you chose after R" (it can be empty, up to 16 chars, and can’t contain spaces, (, ), or \). (en.cppreference.com)

So how do you include )" (and " and )) in the content?

Use a non-empty delimiter so the terminator is no longer )".

Example: include )" in the string by choosing delimiter END:

auto s = R"END(Here is )" inside the content.)END";

This works because the literal only ends at )END" (not at )"). (en.cppreference.com)

If your content might contain )END" too

Pick a delimiter that does not appear after a ) in your content, e.g.:

auto s = R"___MYDELIM___( ... any text including )" ... )___MYDELIM___";

(Or, if unavoidable, split/concatenate into multiple string literals.) (en.cppreference.com)

Citations:


🏁 Script executed:

# Let's check the schemas.txt file to see what delimiters are expected
cat components/core/config/schemas.txt | grep -i "delimiters" -A 2 -B 2

Repository: y-scope/clp

Length of output: 160


🏁 Script executed:

# Also let's search for any other references or usage of cDelimiters
rg "cDelimiters" -A 3 -B 3

Repository: y-scope/clp

Length of output: 1452


Use a custom delimiter for the raw string to preserve ) and " characters

The raw string with default terminator R"(...)" has )" as its closing sequence. Since the current content ends with (:) followed by ", the ) and " are interpreted as the closing sequence and string literal terminator, not as part of the delimiter list. Both characters are required in the expected delimiter set (from components/core/config/schemas.txt).

🛠️ Suggested fix
-constexpr std::string_view cDelimiters{R"(delimiters: \t\r\n[(:)"};
+constexpr std::string_view cDelimiters{R"delim(delimiters: \t\r\n[(:)")delim"};
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
constexpr std::string_view cDelimiters{R"(delimiters: \t\r\n[(:)"};
constexpr std::string_view cDelimiters{R"delim(delimiters: \t\r\n[(:)")delim"};
🤖 Prompt for AI Agents
In `@components/core/src/clp_s/log_converter/LogConverter.cpp` at line 35, The raw
string literal for cDelimiters in LogConverter.cpp ends prematurely because the
default raw-string terminator R"(...)" clashes with the intended delimiter
characters ')' and '"' — change cDelimiters to use a custom raw-string delimiter
(e.g., R"DELIM(... )DELIM") so the characters ')' and '"' inside the content are
preserved; update the declaration of constexpr std::string_view cDelimiters to
use that custom delimiter delimiter name to ensure the full delimiter list from
components/core/config/schemas.txt is included unchanged.

} // namespace

auto LogConverter::convert_file(
Expand Down
11 changes: 11 additions & 0 deletions components/core/tests/test-ParserWithUserSchema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ auto run_clp_compress(
std::filesystem::path const& output_path,
std::filesystem::path const& input_path
) -> int;
[[nodiscard]] auto get_config_schema_files_dir() -> std::filesystem::path;
[[nodiscard]] auto get_tests_dir() -> std::filesystem::path;
[[nodiscard]] auto get_test_schema_files_dir() -> std::filesystem::path;
[[nodiscard]] auto get_test_queries_dir() -> std::filesystem::path;
Expand All @@ -50,6 +51,11 @@ auto get_tests_dir() -> std::filesystem::path {
return std::filesystem::canonical(current_file_path.parent_path());
}

auto get_config_schema_files_dir() -> std::filesystem::path {
std::filesystem::path const current_file_path{__FILE__};
return std::filesystem::canonical(current_file_path.parent_path().parent_path()) / "config";
}

auto get_test_schema_files_dir() -> std::filesystem::path {
return get_tests_dir() / "test_schema_files";
}
Expand Down Expand Up @@ -147,6 +153,11 @@ TEST_CASE("Test creating log parser with delimiters", "[LALR1Parser][LogParser]"
generate_log_parser(schema_file_path.string());
}

TEST_CASE("Test creating log parser from config schema", "[LALR1Parser][LogParser]") {
auto const schema_file_path = get_config_schema_files_dir() / "schemas.txt";
REQUIRE_NOTHROW(generate_log_parser(schema_file_path.string()));
}

TEST_CASE("Test creating log parser without delimiters", "[LALR1Parser][LogParser]") {
auto const schema_file_path = get_test_schema_files_dir() / "schema_without_delimiters.txt";
REQUIRE_THROWS_WITH(
Expand Down
Loading