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