2017-04-01 09:19:00 +00:00
|
|
|
#include <Storages/System/StorageSystemGraphite.h>
|
2019-05-03 02:00:57 +00:00
|
|
|
#include <Storages/MergeTree/MergeTreeData.h>
|
2017-08-24 14:51:13 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2017-02-14 14:24:30 +00:00
|
|
|
|
2018-06-05 19:46:49 +00:00
|
|
|
|
2017-02-14 14:24:30 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2019-03-04 17:40:49 +00:00
|
|
|
NamesAndTypesList StorageSystemGraphite::getNamesAndTypes()
|
2017-03-04 14:14:41 +00:00
|
|
|
{
|
2019-03-04 17:40:49 +00:00
|
|
|
return {
|
|
|
|
{"config_name", std::make_shared<DataTypeString>()},
|
2022-01-10 11:34:16 +00:00
|
|
|
{"rule_type", std::make_shared<DataTypeString>()},
|
2019-03-04 17:40:49 +00:00
|
|
|
{"regexp", std::make_shared<DataTypeString>()},
|
|
|
|
{"function", std::make_shared<DataTypeString>()},
|
|
|
|
{"age", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"precision", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"priority", std::make_shared<DataTypeUInt16>()},
|
|
|
|
{"is_default", std::make_shared<DataTypeUInt8>()},
|
|
|
|
{"Tables.database", std::make_shared<DataTypeArray>(std::make_shared<DataTypeString>())},
|
|
|
|
{"Tables.table", std::make_shared<DataTypeArray>(std::make_shared<DataTypeString>())},
|
2017-04-01 07:20:54 +00:00
|
|
|
};
|
2019-03-04 17:40:49 +00:00
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-03-04 14:14:41 +00:00
|
|
|
|
2019-03-04 17:40:49 +00:00
|
|
|
/*
|
|
|
|
* Looking for (Replicated)*GraphiteMergeTree and get all configuration parameters for them
|
|
|
|
*/
|
2021-04-10 23:33:54 +00:00
|
|
|
static StorageSystemGraphite::Configs getConfigs(ContextPtr context)
|
2017-03-04 14:14:41 +00:00
|
|
|
{
|
2020-02-10 13:10:17 +00:00
|
|
|
const Databases databases = DatabaseCatalog::instance().getDatabases();
|
2020-03-18 00:57:00 +00:00
|
|
|
StorageSystemGraphite::Configs graphite_configs;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-03-04 17:40:49 +00:00
|
|
|
for (const auto & db : databases)
|
2017-09-08 23:25:42 +00:00
|
|
|
{
|
2020-10-15 15:57:17 +00:00
|
|
|
/// Check if database can contain MergeTree tables
|
|
|
|
if (!db.second->canContainMergeTreeTables())
|
2019-10-01 12:44:17 +00:00
|
|
|
continue;
|
|
|
|
|
2020-05-28 20:10:45 +00:00
|
|
|
for (auto iterator = db.second->getTablesIterator(context); iterator->isValid(); iterator->next())
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2020-04-22 07:03:43 +00:00
|
|
|
const auto & table = iterator->table();
|
2020-06-02 02:06:16 +00:00
|
|
|
if (!table)
|
|
|
|
continue;
|
2019-05-03 02:00:57 +00:00
|
|
|
|
|
|
|
const MergeTreeData * table_data = dynamic_cast<const MergeTreeData *>(table.get());
|
|
|
|
if (!table_data)
|
2019-03-04 17:40:49 +00:00
|
|
|
continue;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-03-04 17:40:49 +00:00
|
|
|
if (table_data->merging_params.mode == MergeTreeData::MergingParams::Graphite)
|
|
|
|
{
|
2019-03-07 16:55:53 +00:00
|
|
|
const String & config_name = table_data->merging_params.graphite_params.config_name;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-12-10 20:47:05 +00:00
|
|
|
auto table_id = table_data->getStorageID();
|
2019-03-07 16:55:53 +00:00
|
|
|
if (!graphite_configs.count(config_name))
|
2019-03-04 17:40:49 +00:00
|
|
|
{
|
2020-03-18 00:57:00 +00:00
|
|
|
StorageSystemGraphite::Config new_config =
|
2019-03-07 16:55:53 +00:00
|
|
|
{
|
2019-03-07 20:17:06 +00:00
|
|
|
table_data->merging_params.graphite_params,
|
2019-12-10 20:47:05 +00:00
|
|
|
{ table_id.database_name },
|
2019-12-12 12:30:31 +00:00
|
|
|
{ table_id.table_name },
|
2019-03-07 16:55:53 +00:00
|
|
|
};
|
|
|
|
graphite_configs.emplace(config_name, new_config);
|
2019-03-04 17:40:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-10 20:47:05 +00:00
|
|
|
graphite_configs[config_name].databases.emplace_back(table_id.database_name);
|
2019-12-12 12:30:31 +00:00
|
|
|
graphite_configs[config_name].tables.emplace_back(table_id.table_name);
|
2019-03-04 17:40:49 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 17:40:49 +00:00
|
|
|
return graphite_configs;
|
2017-03-04 14:14:41 +00:00
|
|
|
}
|
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
void StorageSystemGraphite::fillData(MutableColumns & res_columns, ContextPtr context, const SelectQueryInfo &) const
|
2017-03-04 14:14:41 +00:00
|
|
|
{
|
2020-05-28 20:10:45 +00:00
|
|
|
Configs graphite_configs = getConfigs(context);
|
2017-03-04 14:14:41 +00:00
|
|
|
|
2019-03-04 17:40:49 +00:00
|
|
|
for (const auto & config : graphite_configs)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2019-03-04 17:40:49 +00:00
|
|
|
UInt16 priority = 0;
|
2019-03-07 20:17:06 +00:00
|
|
|
for (const auto & pattern : config.second.graphite_params.patterns)
|
2019-03-04 17:40:49 +00:00
|
|
|
{
|
|
|
|
bool is_default = pattern.regexp == nullptr;
|
2019-03-07 16:55:53 +00:00
|
|
|
String regexp;
|
|
|
|
String function;
|
2022-01-10 11:34:16 +00:00
|
|
|
const String & rule_type = ruleTypeStr(pattern.rule_type);
|
2017-02-14 14:24:30 +00:00
|
|
|
|
2019-03-04 17:40:49 +00:00
|
|
|
if (is_default)
|
|
|
|
{
|
|
|
|
priority = std::numeric_limits<UInt16>::max();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
priority++;
|
2019-03-07 20:17:06 +00:00
|
|
|
regexp = pattern.regexp_str;
|
2019-03-04 17:40:49 +00:00
|
|
|
}
|
2017-02-14 14:24:30 +00:00
|
|
|
|
2019-03-04 17:40:49 +00:00
|
|
|
if (pattern.function)
|
|
|
|
{
|
|
|
|
function = pattern.function->getName();
|
|
|
|
}
|
2017-08-24 14:51:13 +00:00
|
|
|
|
2019-02-17 20:56:27 +00:00
|
|
|
if (!pattern.retentions.empty())
|
|
|
|
{
|
2019-03-04 17:40:49 +00:00
|
|
|
for (const auto & retention : pattern.retentions)
|
2019-02-17 20:56:27 +00:00
|
|
|
{
|
2019-03-04 17:40:49 +00:00
|
|
|
size_t i = 0;
|
|
|
|
res_columns[i++]->insert(config.first);
|
2022-01-10 11:34:16 +00:00
|
|
|
res_columns[i++]->insert(rule_type);
|
2019-03-04 17:40:49 +00:00
|
|
|
res_columns[i++]->insert(regexp);
|
|
|
|
res_columns[i++]->insert(function);
|
|
|
|
res_columns[i++]->insert(retention.age);
|
|
|
|
res_columns[i++]->insert(retention.precision);
|
|
|
|
res_columns[i++]->insert(priority);
|
|
|
|
res_columns[i++]->insert(is_default);
|
|
|
|
res_columns[i++]->insert(config.second.databases);
|
|
|
|
res_columns[i++]->insert(config.second.tables);
|
2019-02-17 20:56:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2019-03-04 17:40:49 +00:00
|
|
|
size_t i = 0;
|
|
|
|
res_columns[i++]->insert(config.first);
|
2022-01-10 11:34:16 +00:00
|
|
|
res_columns[i++]->insert(rule_type);
|
2019-03-04 17:40:49 +00:00
|
|
|
res_columns[i++]->insert(regexp);
|
|
|
|
res_columns[i++]->insert(function);
|
2019-03-14 20:55:34 +00:00
|
|
|
res_columns[i++]->insertDefault();
|
|
|
|
res_columns[i++]->insertDefault();
|
2019-03-04 17:40:49 +00:00
|
|
|
res_columns[i++]->insert(priority);
|
|
|
|
res_columns[i++]->insert(is_default);
|
|
|
|
res_columns[i++]->insert(config.second.databases);
|
|
|
|
res_columns[i++]->insert(config.second.tables);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-14 14:24:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|