From fc276abadd8ba15842e05f1e5b49f21a47389bc9 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sat, 14 Jan 2023 15:01:07 +0100 Subject: [PATCH 1/2] Fix log level "Test" for send_logs_level in client Signed-off-by: Azat Khuzhin --- src/Interpreters/InternalTextLogsQueue.cpp | 11 +++++++--- .../02532_send_logs_level_test.reference | 3 +++ .../0_stateless/02532_send_logs_level_test.sh | 22 +++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 tests/queries/0_stateless/02532_send_logs_level_test.reference create mode 100755 tests/queries/0_stateless/02532_send_logs_level_test.sh diff --git a/src/Interpreters/InternalTextLogsQueue.cpp b/src/Interpreters/InternalTextLogsQueue.cpp index 8e689069cec6..88d33cea0c61 100644 --- a/src/Interpreters/InternalTextLogsQueue.cpp +++ b/src/Interpreters/InternalTextLogsQueue.cpp @@ -46,10 +46,13 @@ void InternalTextLogsQueue::pushBlock(Block && log_block) LOG_WARNING(&Poco::Logger::get("InternalTextLogsQueue"), "Log block have different structure"); } +// ARRAY_SIZE for C++ using constexpr +template +constexpr size_t array_size(T (&)[N]) { return N; } + const char * InternalTextLogsQueue::getPriorityName(int priority) { /// See Poco::Message::Priority - static constexpr const char * const PRIORITIES[] = { "Unknown", @@ -60,10 +63,12 @@ const char * InternalTextLogsQueue::getPriorityName(int priority) "Notice", "Information", "Debug", - "Trace" + "Trace", + "Test", }; + static_assert(array_size(PRIORITIES) > 0); - return (priority >= 1 && priority <= 8) ? PRIORITIES[priority] : PRIORITIES[0]; + return (priority >= 1 && priority < static_cast(array_size(PRIORITIES))) ? PRIORITIES[priority] : PRIORITIES[0]; } bool InternalTextLogsQueue::isNeeded(int priority, const String & source) const diff --git a/tests/queries/0_stateless/02532_send_logs_level_test.reference b/tests/queries/0_stateless/02532_send_logs_level_test.reference new file mode 100644 index 000000000000..e3378ac8c3d1 --- /dev/null +++ b/tests/queries/0_stateless/02532_send_logs_level_test.reference @@ -0,0 +1,3 @@ + MergeTreeBaseSelectProcessor: PREWHERE actions: + MergeTreeRangeReader: First reader returned: num_rows: 1, columns: 1, total_rows_per_granule: 1, no filter, column[0]: Int32(size = 1), requested columns: key + MergeTreeRangeReader: read() returned num_rows: 1, columns: 1, total_rows_per_granule: 1, no filter, column[0]: Int32(size = 1), sample block key diff --git a/tests/queries/0_stateless/02532_send_logs_level_test.sh b/tests/queries/0_stateless/02532_send_logs_level_test.sh new file mode 100755 index 000000000000..7dd9a152385d --- /dev/null +++ b/tests/queries/0_stateless/02532_send_logs_level_test.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +# Tags: no-s3-storage, no-debug +# - no-s3-storage - S3 has additional logging +# - no-debug - debug builds also has additional logging + +CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +# shellcheck source=../shell_config.sh +. "$CURDIR"/../shell_config.sh + +$CLICKHOUSE_CLIENT -nm -q " + drop table if exists data; + create table data (key Int) engine=MergeTree order by tuple(); + insert into data values (1); +" + +# NOTE: boost multitoken (--allow_repeated_settings) could prefer "first" +# instead of "last" value, hence you cannot simply append another +# --send_logs_level here. +CLICKHOUSE_CLIENT_CLEAN=$(echo ${CLICKHOUSE_CLIENT} | sed 's/'"--send_logs_level=${CLICKHOUSE_CLIENT_SERVER_LOGS_LEVEL}"'/--send_logs_level=test/g') +$CLICKHOUSE_CLIENT_CLEAN -q "select * from data" |& grep -o -e '.*' -e '.*' + +$CLICKHOUSE_CLIENT -q "drop table data" From 1f9a65b87500102a226642e89ec19e363e969559 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Mon, 16 Jan 2023 15:20:47 +0100 Subject: [PATCH 2/2] Modernize InternalTextLogsQueue::getPriorityName() Signed-off-by: Azat Khuzhin --- src/Interpreters/InternalTextLogsQueue.cpp | 34 ++++++++++------------ src/Interpreters/InternalTextLogsQueue.h | 2 +- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/Interpreters/InternalTextLogsQueue.cpp b/src/Interpreters/InternalTextLogsQueue.cpp index 88d33cea0c61..3be58a11beba 100644 --- a/src/Interpreters/InternalTextLogsQueue.cpp +++ b/src/Interpreters/InternalTextLogsQueue.cpp @@ -46,29 +46,25 @@ void InternalTextLogsQueue::pushBlock(Block && log_block) LOG_WARNING(&Poco::Logger::get("InternalTextLogsQueue"), "Log block have different structure"); } -// ARRAY_SIZE for C++ using constexpr -template -constexpr size_t array_size(T (&)[N]) { return N; } - -const char * InternalTextLogsQueue::getPriorityName(int priority) +std::string_view InternalTextLogsQueue::getPriorityName(int priority) { + using namespace std::literals; + /// See Poco::Message::Priority - static constexpr const char * const PRIORITIES[] = + static constexpr std::array PRIORITIES = { - "Unknown", - "Fatal", - "Critical", - "Error", - "Warning", - "Notice", - "Information", - "Debug", - "Trace", - "Test", + "Unknown"sv, + "Fatal"sv, + "Critical"sv, + "Error"sv, + "Warning"sv, + "Notice"sv, + "Information"sv, + "Debug"sv, + "Trace"sv, + "Test"sv, }; - static_assert(array_size(PRIORITIES) > 0); - - return (priority >= 1 && priority < static_cast(array_size(PRIORITIES))) ? PRIORITIES[priority] : PRIORITIES[0]; + return (priority >= 1 && priority < static_cast(PRIORITIES.size())) ? PRIORITIES[priority] : PRIORITIES[0]; } bool InternalTextLogsQueue::isNeeded(int priority, const String & source) const diff --git a/src/Interpreters/InternalTextLogsQueue.h b/src/Interpreters/InternalTextLogsQueue.h index 9c3c9f9e7073..bbe41ca33fe3 100644 --- a/src/Interpreters/InternalTextLogsQueue.h +++ b/src/Interpreters/InternalTextLogsQueue.h @@ -24,7 +24,7 @@ class InternalTextLogsQueue : public ConcurrentBoundedQueue void pushBlock(Block && log_block); /// Converts priority from Poco::Message::Priority to a string - static const char * getPriorityName(int priority); + static std::string_view getPriorityName(int priority); void setSourceRegexp(const String & regexp); private: