forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ClickHouse#65381 from pamarcos/system-error-log
Add system.error_log
- Loading branch information
Showing
41 changed files
with
514 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
slug: /en/operations/system-tables/error_log | ||
--- | ||
# error_log | ||
|
||
Contains history of error values from table `system.errors`, periodically flushed to disk. | ||
|
||
Columns: | ||
- `hostname` ([LowCardinality(String)](../../sql-reference/data-types/string.md)) — Hostname of the server executing the query. | ||
- `event_date` ([Date](../../sql-reference/data-types/date.md)) — Event date. | ||
- `event_time` ([DateTime](../../sql-reference/data-types/datetime.md)) — Event time. | ||
- `code` ([Int32](../../sql-reference/data-types/int-uint.md)) — Code number of the error. | ||
- `error` ([LowCardinality(String)](../../sql-reference/data-types/string.md)) - Name of the error. | ||
- `value` ([UInt64](../../sql-reference/data-types/int-uint.md)) — The number of times this error happened. | ||
- `remote` ([UInt8](../../sql-reference/data-types/int-uint.md)) — Remote exception (i.e. received during one of the distributed queries). | ||
|
||
**Example** | ||
|
||
``` sql | ||
SELECT * FROM system.error_log LIMIT 1 FORMAT Vertical; | ||
``` | ||
|
||
``` text | ||
Row 1: | ||
────── | ||
hostname: clickhouse.eu-central1.internal | ||
event_date: 2024-06-18 | ||
event_time: 2024-06-18 07:32:39 | ||
code: 999 | ||
error: KEEPER_EXCEPTION | ||
value: 2 | ||
remote: 0 | ||
``` | ||
|
||
**See also** | ||
|
||
- [error_log setting](../../operations/server-configuration-parameters/settings.md#error_log) — Enabling and disabling the setting. | ||
- [system.errors](../../operations/system-tables/errors.md) — Contains error codes with the number of times they have been triggered. | ||
- [Monitoring](../../operations/monitoring.md) — Base concepts of ClickHouse monitoring. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
#include <DataTypes/DataTypeDate.h> | ||
#include <DataTypes/DataTypeDateTime.h> | ||
#include <DataTypes/DataTypeDateTime64.h> | ||
#include <DataTypes/DataTypeLowCardinality.h> | ||
#include <DataTypes/DataTypeString.h> | ||
#include <DataTypes/DataTypesNumber.h> | ||
#include <Interpreters/ErrorLog.h> | ||
#include <base/getFQDNOrHostName.h> | ||
#include <Common/DateLUTImpl.h> | ||
#include <Common/ThreadPool.h> | ||
#include <Common/ErrorCodes.h> | ||
#include <Parsers/ExpressionElementParsers.h> | ||
#include <Parsers/parseQuery.h> | ||
|
||
#include <vector> | ||
|
||
namespace DB | ||
{ | ||
|
||
ColumnsDescription ErrorLogElement::getColumnsDescription() | ||
{ | ||
ParserCodec codec_parser; | ||
return ColumnsDescription { | ||
{ | ||
"hostname", | ||
std::make_shared<DataTypeLowCardinality>(std::make_shared<DataTypeString>()), | ||
parseQuery(codec_parser, "(ZSTD(1))", 0, DBMS_DEFAULT_MAX_PARSER_DEPTH, DBMS_DEFAULT_MAX_PARSER_BACKTRACKS), | ||
"Hostname of the server executing the query." | ||
}, | ||
{ | ||
"event_date", | ||
std::make_shared<DataTypeDate>(), | ||
parseQuery(codec_parser, "(Delta(2), ZSTD(1))", 0, DBMS_DEFAULT_MAX_PARSER_DEPTH, DBMS_DEFAULT_MAX_PARSER_BACKTRACKS), | ||
"Event date." | ||
}, | ||
{ | ||
"event_time", | ||
std::make_shared<DataTypeDateTime>(), | ||
parseQuery(codec_parser, "(Delta(4), ZSTD(1))", 0, DBMS_DEFAULT_MAX_PARSER_DEPTH, DBMS_DEFAULT_MAX_PARSER_BACKTRACKS), | ||
"Event time." | ||
}, | ||
{ | ||
"code", | ||
std::make_shared<DataTypeInt32>(), | ||
parseQuery(codec_parser, "(ZSTD(1))", 0, DBMS_DEFAULT_MAX_PARSER_DEPTH, DBMS_DEFAULT_MAX_PARSER_BACKTRACKS), | ||
"Error code." | ||
}, | ||
{ | ||
"error", | ||
std::make_shared<DataTypeLowCardinality>(std::make_shared<DataTypeString>()), | ||
parseQuery(codec_parser, "(ZSTD(1))", 0, DBMS_DEFAULT_MAX_PARSER_DEPTH, DBMS_DEFAULT_MAX_PARSER_BACKTRACKS), | ||
"Error name." | ||
}, | ||
{ | ||
"value", | ||
std::make_shared<DataTypeUInt64>(), | ||
parseQuery(codec_parser, "(ZSTD(3))", 0, DBMS_DEFAULT_MAX_PARSER_DEPTH, DBMS_DEFAULT_MAX_PARSER_BACKTRACKS), | ||
"Number of errors happened in time interval." | ||
}, | ||
{ | ||
"remote", | ||
std::make_shared<DataTypeUInt8>(), | ||
parseQuery(codec_parser, "(ZSTD(1))", 0, DBMS_DEFAULT_MAX_PARSER_DEPTH, DBMS_DEFAULT_MAX_PARSER_BACKTRACKS), | ||
"Remote exception (i.e. received during one of the distributed queries)." | ||
} | ||
}; | ||
} | ||
|
||
void ErrorLogElement::appendToBlock(MutableColumns & columns) const | ||
{ | ||
size_t column_idx = 0; | ||
|
||
columns[column_idx++]->insert(getFQDNOrHostName()); | ||
columns[column_idx++]->insert(DateLUT::instance().toDayNum(event_time).toUnderType()); | ||
columns[column_idx++]->insert(event_time); | ||
columns[column_idx++]->insert(code); | ||
columns[column_idx++]->insert(ErrorCodes::getName(code)); | ||
columns[column_idx++]->insert(value); | ||
columns[column_idx++]->insert(remote); | ||
} | ||
|
||
struct ValuePair | ||
{ | ||
UInt64 local = 0; | ||
UInt64 remote = 0; | ||
}; | ||
|
||
void ErrorLog::stepFunction(TimePoint current_time) | ||
{ | ||
/// Static lazy initialization to avoid polluting the header with implementation details | ||
static std::vector<ValuePair> previous_values(ErrorCodes::end()); | ||
|
||
auto event_time = std::chrono::system_clock::to_time_t(current_time); | ||
|
||
for (ErrorCodes::ErrorCode code = 0, end = ErrorCodes::end(); code < end; ++code) | ||
{ | ||
const auto & error = ErrorCodes::values[code].get(); | ||
if (error.local.count != previous_values.at(code).local) | ||
{ | ||
ErrorLogElement local_elem { | ||
.event_time=event_time, | ||
.code=code, | ||
.value=error.local.count - previous_values.at(code).local, | ||
.remote=false | ||
}; | ||
this->add(std::move(local_elem)); | ||
previous_values[code].local = error.local.count; | ||
} | ||
if (error.remote.count != previous_values.at(code).remote) | ||
{ | ||
ErrorLogElement remote_elem { | ||
.event_time=event_time, | ||
.code=code, | ||
.value=error.remote.count - previous_values.at(code).remote, | ||
.remote=true | ||
}; | ||
this->add(std::move(remote_elem)); | ||
previous_values[code].remote = error.remote.count; | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#pragma once | ||
|
||
#include <Interpreters/SystemLog.h> | ||
#include <Interpreters/PeriodicLog.h> | ||
#include <Common/ErrorCodes.h> | ||
#include <Core/NamesAndTypes.h> | ||
#include <Core/NamesAndAliases.h> | ||
#include <Storages/ColumnsDescription.h> | ||
|
||
|
||
namespace DB | ||
{ | ||
|
||
/** ErrorLog is a log of error values measured at regular time interval. | ||
*/ | ||
|
||
struct ErrorLogElement | ||
{ | ||
time_t event_time{}; | ||
ErrorCodes::ErrorCode code{}; | ||
ErrorCodes::Value value{}; | ||
bool remote{}; | ||
|
||
static std::string name() { return "ErrorLog"; } | ||
static ColumnsDescription getColumnsDescription(); | ||
static NamesAndAliases getNamesAndAliases() { return {}; } | ||
void appendToBlock(MutableColumns & columns) const; | ||
}; | ||
|
||
|
||
class ErrorLog : public PeriodicLog<ErrorLogElement> | ||
{ | ||
using PeriodicLog<ErrorLogElement>::PeriodicLog; | ||
|
||
protected: | ||
void stepFunction(TimePoint current_time) override; | ||
}; | ||
|
||
} |
Oops, something went wrong.