mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 00:52:02 +00:00
Distinguish remote and local error info
This commit is contained in:
parent
a337691b06
commit
9dee842b60
@ -564,7 +564,7 @@ namespace ErrorCodes
|
||||
#undef M
|
||||
|
||||
constexpr ErrorCode END = 3000;
|
||||
ValuePairHolder values[END + 1]{};
|
||||
ErrorPairHolder values[END + 1]{};
|
||||
|
||||
struct ErrorCodesNames
|
||||
{
|
||||
@ -595,35 +595,23 @@ namespace ErrorCodes
|
||||
error_code = end() - 1;
|
||||
}
|
||||
|
||||
ValuePair inc_value{
|
||||
!remote, /* local */
|
||||
remote, /* remote */
|
||||
0, /* error_time_ms */
|
||||
message, /* message */
|
||||
stacktrace, /* stacktrace */
|
||||
};
|
||||
values[error_code].increment(inc_value);
|
||||
values[error_code].increment(remote, message, stacktrace);
|
||||
}
|
||||
|
||||
ValuePair & ValuePair::operator+=(const ValuePair & value)
|
||||
void ErrorPairHolder::increment(bool remote, const std::string & message, const std::string & stacktrace)
|
||||
{
|
||||
local += value.local;
|
||||
remote += value.remote;
|
||||
message = value.message;
|
||||
stacktrace = value.stacktrace;
|
||||
|
||||
const auto now = std::chrono::system_clock::now();
|
||||
error_time_ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void ValuePairHolder::increment(const ValuePair & value_)
|
||||
{
|
||||
std::lock_guard lock(mutex);
|
||||
value += value_;
|
||||
|
||||
auto & error = remote ? value.remote : value.local;
|
||||
|
||||
++error.count;
|
||||
error.message = message;
|
||||
error.stacktrace = stacktrace;
|
||||
error.error_time_ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
|
||||
}
|
||||
ValuePair ValuePairHolder::get()
|
||||
ErrorPair ErrorPairHolder::get()
|
||||
{
|
||||
std::lock_guard lock(mutex);
|
||||
return value;
|
||||
|
@ -24,31 +24,37 @@ namespace ErrorCodes
|
||||
/// Returns statically allocated string.
|
||||
std::string_view getName(ErrorCode error_code);
|
||||
|
||||
struct ValuePair
|
||||
struct Error
|
||||
{
|
||||
Value local = 0;
|
||||
Value remote = 0;
|
||||
/// Number of times Exception with this ErrorCode had been throw.
|
||||
Value count;
|
||||
/// Time of the last error.
|
||||
UInt64 error_time_ms = 0;
|
||||
/// Message for the last error.
|
||||
std::string message;
|
||||
/// Stacktrace for the last error.
|
||||
std::string stacktrace;
|
||||
|
||||
ValuePair & operator+=(const ValuePair & value);
|
||||
};
|
||||
struct ErrorPair
|
||||
{
|
||||
Error local;
|
||||
Error remote;
|
||||
};
|
||||
|
||||
/// Thread-safe
|
||||
struct ValuePairHolder
|
||||
struct ErrorPairHolder
|
||||
{
|
||||
public:
|
||||
void increment(const ValuePair & value_);
|
||||
ValuePair get();
|
||||
ErrorPair get();
|
||||
void increment(bool remote, const std::string & message, const std::string & stacktrace);
|
||||
|
||||
private:
|
||||
ValuePair value;
|
||||
ErrorPair value;
|
||||
std::mutex mutex;
|
||||
};
|
||||
|
||||
/// ErrorCode identifier -> current value of error_code.
|
||||
extern ValuePairHolder values[];
|
||||
extern ErrorPairHolder values[];
|
||||
|
||||
/// Get index just after last error_code identifier.
|
||||
ErrorCode end();
|
||||
|
@ -24,17 +24,17 @@ NamesAndTypesList StorageSystemErrors::getNamesAndTypes()
|
||||
|
||||
void StorageSystemErrors::fillData(MutableColumns & res_columns, const Context & context, const SelectQueryInfo &) const
|
||||
{
|
||||
auto add_row = [&](std::string_view name, size_t code, size_t value, UInt64 error_time_ms, const std::string & message, const std::string & stacktrace, bool remote)
|
||||
auto add_row = [&](std::string_view name, size_t code, const auto & error, bool remote)
|
||||
{
|
||||
if (value || context.getSettingsRef().system_events_show_zero_values)
|
||||
if (error.count || context.getSettingsRef().system_events_show_zero_values)
|
||||
{
|
||||
size_t col_num = 0;
|
||||
res_columns[col_num++]->insert(name);
|
||||
res_columns[col_num++]->insert(code);
|
||||
res_columns[col_num++]->insert(value);
|
||||
res_columns[col_num++]->insert(error_time_ms / 1000);
|
||||
res_columns[col_num++]->insert(message);
|
||||
res_columns[col_num++]->insert(stacktrace);
|
||||
res_columns[col_num++]->insert(error.count);
|
||||
res_columns[col_num++]->insert(error.error_time_ms / 1000);
|
||||
res_columns[col_num++]->insert(error.message);
|
||||
res_columns[col_num++]->insert(error.stacktrace);
|
||||
res_columns[col_num++]->insert(remote);
|
||||
}
|
||||
};
|
||||
@ -47,8 +47,8 @@ void StorageSystemErrors::fillData(MutableColumns & res_columns, const Context &
|
||||
if (name.empty())
|
||||
continue;
|
||||
|
||||
add_row(name, i, error.local, error.error_time_ms, error.message, error.stacktrace, false /* remote=0 */);
|
||||
add_row(name, i, error.remote, error.error_time_ms, error.message, error.stacktrace, true /* remote=1 */);
|
||||
add_row(name, i, error.local, /* remote= */ false);
|
||||
add_row(name, i, error.remote, /* remote= */ true);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user