mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
Merge pull request #26282 from FArthur-cmd/adding-system-warnings-26039
Show warnings
This commit is contained in:
commit
c9a917a163
@ -26,6 +26,7 @@
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include <Poco/String.h>
|
||||
#include <Poco/Util/Application.h>
|
||||
#include <Columns/ColumnString.h>
|
||||
#include <common/find_symbols.h>
|
||||
#include <common/LineReader.h>
|
||||
#include <Common/ClickHouseRevision.h>
|
||||
@ -487,6 +488,52 @@ private:
|
||||
}
|
||||
#endif
|
||||
|
||||
/// Make query to get all server warnings
|
||||
std::vector<String> loadWarningMessages()
|
||||
{
|
||||
std::vector<String> messages;
|
||||
connection->sendQuery(connection_parameters.timeouts, "SELECT message FROM system.warnings", "" /* query_id */, QueryProcessingStage::Complete);
|
||||
while (true)
|
||||
{
|
||||
Packet packet = connection->receivePacket();
|
||||
switch (packet.type)
|
||||
{
|
||||
case Protocol::Server::Data:
|
||||
if (packet.block)
|
||||
{
|
||||
const ColumnString & column = typeid_cast<const ColumnString &>(*packet.block.getByPosition(0).column);
|
||||
|
||||
size_t rows = packet.block.rows();
|
||||
for (size_t i = 0; i < rows; ++i)
|
||||
messages.emplace_back(column.getDataAt(i).toString());
|
||||
}
|
||||
continue;
|
||||
|
||||
case Protocol::Server::Progress:
|
||||
continue;
|
||||
case Protocol::Server::ProfileInfo:
|
||||
continue;
|
||||
case Protocol::Server::Totals:
|
||||
continue;
|
||||
case Protocol::Server::Extremes:
|
||||
continue;
|
||||
case Protocol::Server::Log:
|
||||
continue;
|
||||
|
||||
case Protocol::Server::Exception:
|
||||
packet.exception->rethrow();
|
||||
return messages;
|
||||
|
||||
case Protocol::Server::EndOfStream:
|
||||
return messages;
|
||||
|
||||
default:
|
||||
throw Exception(ErrorCodes::UNKNOWN_PACKET_FROM_SERVER, "Unknown packet {} from server {}",
|
||||
packet.type, connection->getDescription());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int mainImpl()
|
||||
{
|
||||
UseSSL use_ssl;
|
||||
@ -565,6 +612,26 @@ private:
|
||||
suggest->load(connection_parameters, config().getInt("suggestion_limit"));
|
||||
}
|
||||
|
||||
/// Load Warnings at the beginning of connection
|
||||
if (!config().has("no-warnings"))
|
||||
{
|
||||
try
|
||||
{
|
||||
std::vector<String> messages = loadWarningMessages();
|
||||
if (!messages.empty())
|
||||
{
|
||||
std::cout << "Warnings:" << std::endl;
|
||||
for (const auto & message : messages)
|
||||
std::cout << " * " << message << std::endl;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
/// Ignore exception
|
||||
}
|
||||
}
|
||||
|
||||
/// Load command history if present.
|
||||
if (config().has("history_file"))
|
||||
history_file = config().getString("history_file");
|
||||
@ -2529,6 +2596,7 @@ public:
|
||||
("opentelemetry-traceparent", po::value<std::string>(), "OpenTelemetry traceparent header as described by W3C Trace Context recommendation")
|
||||
("opentelemetry-tracestate", po::value<std::string>(), "OpenTelemetry tracestate header as described by W3C Trace Context recommendation")
|
||||
("history_file", po::value<std::string>(), "path to history file")
|
||||
("no-warnings", "disable warnings when client connects to server")
|
||||
;
|
||||
|
||||
Settings cmd_settings;
|
||||
@ -2689,6 +2757,8 @@ public:
|
||||
config().setBool("highlight", options["highlight"].as<bool>());
|
||||
if (options.count("history_file"))
|
||||
config().setString("history_file", options["history_file"].as<std::string>());
|
||||
if (options.count("no-warnings"))
|
||||
config().setBool("no-warnings", true);
|
||||
|
||||
if ((query_fuzzer_runs = options["query-fuzzer-runs"].as<int>()))
|
||||
{
|
||||
|
@ -4,7 +4,7 @@ log_user 1
|
||||
set timeout 5
|
||||
match_max 100000
|
||||
|
||||
spawn bash -c "$env(CLICKHOUSE_CLIENT_BINARY) $env(CLICKHOUSE_CLIENT_OPT)"
|
||||
spawn bash -c "$env(CLICKHOUSE_CLIENT_BINARY) --no-warnings $env(CLICKHOUSE_CLIENT_OPT)"
|
||||
expect ":) "
|
||||
send -- "\4"
|
||||
expect eof
|
||||
|
50
tests/queries/0_stateless/01945_show_debug_warning.expect
Executable file
50
tests/queries/0_stateless/01945_show_debug_warning.expect
Executable file
@ -0,0 +1,50 @@
|
||||
#!/usr/bin/expect -f
|
||||
|
||||
# This is a test for system.warnings. Testing in interactive mode is necessary,
|
||||
# as we want to see certain warnings from client
|
||||
|
||||
log_user 0
|
||||
set timeout 60
|
||||
match_max 100000
|
||||
|
||||
# A default timeout action is to do nothing, change it to fail
|
||||
expect_after {
|
||||
timeout {
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
set basedir [file dirname $argv0]
|
||||
set Debug_type 0
|
||||
|
||||
spawn bash -c "source $basedir/../shell_config.sh ; \$CLICKHOUSE_CLIENT_BINARY \$CLICKHOUSE_CLIENT_OPT --disable_suggestion"
|
||||
expect ":) "
|
||||
|
||||
# Check debug type
|
||||
send -- "SELECT value FROM system.build_options WHERE name='BUILD_TYPE'\r"
|
||||
expect {
|
||||
"Debug" {
|
||||
set Debug_type 1
|
||||
expect ":) "
|
||||
}
|
||||
"RelWithDebInfo"
|
||||
}
|
||||
|
||||
send -- "q\r"
|
||||
expect eof
|
||||
|
||||
if { $Debug_type > 0} {
|
||||
|
||||
spawn bash -c "source $basedir/../shell_config.sh ; \$CLICKHOUSE_CLIENT_BINARY \$CLICKHOUSE_CLIENT_OPT --disable_suggestion"
|
||||
expect "Warnings:"
|
||||
expect " * Server was built in debug mode. It will work slowly."
|
||||
expect ":) "
|
||||
|
||||
# Check debug message in system.warnings
|
||||
send -- "SELECT message FROM system.warnings WHERE message='Server was built in debug mode. It will work slowly.'\r"
|
||||
expect "Server was built in debug mode. It will work slowly."
|
||||
expect ":) "
|
||||
|
||||
send -- "q\r"
|
||||
expect eof
|
||||
}
|
@ -36,5 +36,5 @@ expect {
|
||||
}
|
||||
|
||||
# Finish test
|
||||
send -- "\4"
|
||||
send -- "q\r"
|
||||
expect eof
|
||||
|
Loading…
Reference in New Issue
Block a user