Skip to content

Commit 5901049

Browse files
gibber9809junhaoliaoLinZhihao-723
authored
feat(clp-s::log_converter): Add max-log-event-size argument; Make default max log event size 512 MiB to match clp-s (fixes #2176). (#2193)
Co-authored-by: Junhao Liao <junhao.liao@yscope.com> Co-authored-by: Lin Zhihao <59785146+LinZhihao-723@users.noreply.github.com>
1 parent 9ae078e commit 5901049

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

components/core/src/clp_s/log_converter/CommandLineArguments.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ auto CommandLineArguments::parse_arguments(int argc, char const** argv)
137137
"Type of authentication required for network requests (s3 | none). Authentication"
138138
" with s3 requires the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment"
139139
" variables, and optionally the AWS_SESSION_TOKEN environment variable."
140+
)(
141+
"max-log-event-size",
142+
po::value<size_t>(&m_max_log_event_size)
143+
->value_name("LOG_EVENT_SIZE")
144+
->default_value(m_max_log_event_size),
145+
"Maximum allowed size (B) for a single log event before conversion fails."
140146
);
141147
// clang-format on
142148

@@ -188,6 +194,10 @@ auto CommandLineArguments::parse_arguments(int argc, char const** argv)
188194
}
189195

190196
validate_network_auth(auth, m_network_auth);
197+
198+
if (m_max_log_event_size <= 0) {
199+
throw std::invalid_argument("Max event size must be greater than zero.");
200+
}
191201
} catch (std::exception& e) {
192202
SPDLOG_ERROR("{}", e.what());
193203
print_basic_usage();

components/core/src/clp_s/log_converter/CommandLineArguments.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef CLP_S_COMMANDLINEARGUMENTS_HPP
22
#define CLP_S_COMMANDLINEARGUMENTS_HPP
33

4+
#include <cstddef>
45
#include <cstdint>
56
#include <string>
67
#include <string_view>
@@ -34,6 +35,8 @@ class CommandLineArguments {
3435

3536
[[nodiscard]] auto get_output_dir() const -> std::string const& { return m_output_dir; }
3637

38+
[[nodiscard]] auto get_max_log_event_size() const -> size_t { return m_max_log_event_size; }
39+
3740
private:
3841
// Methods
3942
void print_basic_usage() const;
@@ -43,6 +46,7 @@ class CommandLineArguments {
4346
std::vector<Path> m_input_paths;
4447
NetworkAuthOption m_network_auth{};
4548
std::string m_output_dir{"./"};
49+
size_t m_max_log_event_size{512ULL * 1024ULL * 1024ULL}; // 512 MiB
4650
};
4751
} // namespace clp_s::log_converter
4852

components/core/src/clp_s/log_converter/LogConverter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ auto LogConverter::grow_buffer_if_full() -> ystdlib::error_handling::Result<void
136136
}
137137

138138
size_t const new_size{2 * m_buffer.size()};
139-
if (new_size > cMaxBufferSize) {
139+
if (new_size > m_max_buffer_size) {
140140
return std::errc::result_out_of_range;
141141
}
142142
ystdlib::containers::Array<char> new_buffer(new_size);

components/core/src/clp_s/log_converter/LogConverter.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ namespace clp_s::log_converter {
1717
class LogConverter {
1818
public:
1919
// Constructors
20-
LogConverter() : m_buffer(cDefaultBufferSize) {}
20+
explicit LogConverter(size_t max_buffer_size)
21+
: m_buffer(max_buffer_size < cDefaultBufferSize ? max_buffer_size : cDefaultBufferSize),
22+
m_max_buffer_size{max_buffer_size} {}
2123

2224
// Methods
2325
/**
@@ -38,7 +40,6 @@ class LogConverter {
3840
private:
3941
// Constants
4042
static constexpr size_t cDefaultBufferSize{64ULL * 1024ULL}; // 64 KiB
41-
static constexpr size_t cMaxBufferSize{64ULL * 1024ULL * 1024ULL}; // 64 MiB
4243

4344
// Methods
4445
/**
@@ -68,6 +69,7 @@ class LogConverter {
6869
ystdlib::containers::Array<char> m_buffer;
6970
size_t m_num_bytes_buffered{};
7071
size_t m_parser_offset{};
72+
size_t m_max_buffer_size{cDefaultBufferSize};
7173
};
7274
} // namespace clp_s::log_converter
7375
#endif // CLP_S_LOG_CONVERTER_LOGCONVERTER_HPP

components/core/src/clp_s/log_converter/log_converter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace {
2626
[[nodiscard]] auto convert_files(CommandLineArguments const& command_line_arguments) -> bool;
2727

2828
auto convert_files(CommandLineArguments const& command_line_arguments) -> bool {
29-
LogConverter log_converter;
29+
LogConverter log_converter{command_line_arguments.get_max_log_event_size()};
3030

3131
std::error_code ec{};
3232
if (false == std::filesystem::create_directory(command_line_arguments.get_output_dir(), ec)

0 commit comments

Comments
 (0)