2020-06-10 21:16:58 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Interpreters/SystemLog.h>
|
|
|
|
#include <Common/ProfileEvents.h>
|
|
|
|
#include <Common/CurrentMetrics.h>
|
2022-01-10 19:01:41 +00:00
|
|
|
#include <Core/NamesAndTypes.h>
|
|
|
|
#include <Core/NamesAndAliases.h>
|
2020-06-10 21:16:58 +00:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <atomic>
|
|
|
|
#include <ctime>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-06-28 11:42:21 +00:00
|
|
|
using AsynchronousMetricValue = double;
|
|
|
|
using AsynchronousMetricValues = std::unordered_map<std::string, AsynchronousMetricValue>;
|
2020-06-10 21:16:58 +00:00
|
|
|
|
|
|
|
/** AsynchronousMetricLog is a log of metric values measured at regular time interval.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct AsynchronousMetricLogElement
|
|
|
|
{
|
|
|
|
UInt16 event_date;
|
|
|
|
time_t event_time;
|
|
|
|
std::string metric_name;
|
|
|
|
double value;
|
|
|
|
|
|
|
|
static std::string name() { return "AsynchronousMetricLog"; }
|
2021-06-28 11:42:21 +00:00
|
|
|
static NamesAndTypesList getNamesAndTypes();
|
|
|
|
static NamesAndAliases getNamesAndAliases() { return {}; }
|
2020-06-10 21:16:58 +00:00
|
|
|
void appendToBlock(MutableColumns & columns) const;
|
2022-04-17 21:49:39 +00:00
|
|
|
|
|
|
|
/// Returns the list of columns as in CREATE TABLE statement or nullptr.
|
|
|
|
/// If it's not nullptr, this list of columns will be used to create the table.
|
|
|
|
/// Otherwise the list will be constructed from LogElement::getNamesAndTypes and LogElement::getNamesAndAliases.
|
|
|
|
static const char * getCustomColumnList()
|
|
|
|
{
|
Avoid recreation of system.asynchronous_metric_log (due to difference in codec)
From the log:
2022.04.29 12:33:40.397528 [ 486 ] {} <Debug> SystemLog (system.asynchronous_metric_log): Existing table system.asynchronous_metric_log for system log has obsolete or different structure. Renaming it to asynchronous_metric_log_352.
Old: CREATE TABLE system.asynchronous_metric_log (`event_date` Date CODEC(Delta(2), ZSTD(1)), `event_time` DateTime CODEC(Delta(4), ZSTD(1)), `metric` LowCardinality(String) CODEC(ZSTD(1)), `value` Float64 CODEC(Gorilla, ZSTD(3))) ENGINE = MergeTree PARTITION BY toYYYYMM(event_date) ORDER BY (metric, event_date, event_time) SETTINGS index_granularity = 8192
New: CREATE TABLE system.asynchronous_metric_log (`event_date` Date CODEC(Delta(2), ZSTD), `event_time` DateTime CODEC(Delta(4), ZSTD), `metric` LowCardinality(String) CODEC(ZSTD), `value` Float64 CODEC(Gorilla, ZSTD(3))) ENGINE = MergeTree PARTITION BY toYYYYMM(event_date) ORDER BY (metric, event_date, event_time) SETTINGS index_granularity = 8192
As you can see the difference in default ZSTD level.
P.S. I decided not to fix the printer, since this may introduce changes
in metadata, that may lead to changes in metadata between ZooKeeper and
clickhouse server.
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
2022-04-30 09:17:22 +00:00
|
|
|
return "event_date Date CODEC(Delta(2), ZSTD(1)), "
|
|
|
|
"event_time DateTime CODEC(Delta(4), ZSTD(1)), "
|
|
|
|
"metric LowCardinality(String) CODEC(ZSTD(1)), "
|
2022-04-17 21:49:39 +00:00
|
|
|
"value Float64 CODEC(Gorilla, ZSTD(3))";
|
|
|
|
}
|
2020-06-10 21:16:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class AsynchronousMetricLog : public SystemLog<AsynchronousMetricLogElement>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
using SystemLog<AsynchronousMetricLogElement>::SystemLog;
|
|
|
|
|
|
|
|
void addValues(const AsynchronousMetricValues &);
|
2022-04-17 19:56:36 +00:00
|
|
|
|
2022-04-17 21:59:05 +00:00
|
|
|
/// This table is usually queried for fixed metric name.
|
|
|
|
static const char * getDefaultOrderBy() { return "(metric, event_date, event_time)"; }
|
2020-06-10 21:16:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|