2017-04-01 09:19:00 +00:00
|
|
|
#include <Storages/System/StorageSystemGraphite.h>
|
2019-03-04 17:40:49 +00:00
|
|
|
#include <Storages/StorageMergeTree.h>
|
|
|
|
#include <Storages/StorageReplicatedMergeTree.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
|
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>()},
|
|
|
|
{"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
|
|
|
|
*/
|
|
|
|
StorageSystemGraphite::Configs StorageSystemGraphite::getConfigs(const Context & context) const
|
2017-03-04 14:14:41 +00:00
|
|
|
{
|
2019-03-04 17:40:49 +00:00
|
|
|
const Databases databases = context.getDatabases();
|
|
|
|
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
|
|
|
{
|
2019-03-04 17:40:49 +00:00
|
|
|
for (auto iterator = db.second->getIterator(context); iterator->isValid(); iterator->next())
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2019-03-04 17:40:49 +00:00
|
|
|
auto & table = iterator->table();
|
|
|
|
const MergeTreeData * table_data = nullptr;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-03-04 17:40:49 +00:00
|
|
|
if (const StorageMergeTree * merge_tree = dynamic_cast<StorageMergeTree *>(table.get()))
|
|
|
|
{
|
|
|
|
table_data = & merge_tree->getData();
|
|
|
|
}
|
|
|
|
else if (const StorageReplicatedMergeTree * replicated_merge_tree = dynamic_cast<StorageReplicatedMergeTree *>(table.get()))
|
|
|
|
{
|
|
|
|
table_data = & replicated_merge_tree->getData();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
const String config_name = table_data->merging_params.graphite_params.config_name;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-03-04 17:40:49 +00:00
|
|
|
if (graphite_configs.find(config_name) == graphite_configs.end())
|
|
|
|
{
|
|
|
|
Config new_config = {
|
|
|
|
& table_data->merging_params.graphite_params,
|
|
|
|
{ table_data->getDatabaseName() },
|
|
|
|
{ table_data->getTableName() },
|
|
|
|
};
|
|
|
|
graphite_configs.insert(std::make_pair(config_name, new_config));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
graphite_configs[config_name].databases.emplace_back(table_data->getDatabaseName());
|
|
|
|
graphite_configs[config_name].tables.emplace_back(table_data->getTableName());
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2019-03-04 17:40:49 +00:00
|
|
|
void StorageSystemGraphite::fillData(MutableColumns & res_columns, const Context & context, const SelectQueryInfo &) const
|
2017-03-04 14:14:41 +00:00
|
|
|
{
|
2019-03-04 17:40:49 +00:00
|
|
|
Configs graphite_configs = StorageSystemGraphite::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;
|
|
|
|
for (const auto & pattern : config.second.graphite_params->patterns)
|
|
|
|
{
|
|
|
|
bool is_default = pattern.regexp == nullptr;
|
|
|
|
String regexp = "";
|
|
|
|
String function = "";
|
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++;
|
|
|
|
regexp = pattern.regexp->getRE2()->pattern();
|
|
|
|
}
|
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);
|
|
|
|
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);
|
|
|
|
res_columns[i++]->insert(regexp);
|
|
|
|
res_columns[i++]->insert(function);
|
|
|
|
res_columns[i++]->insert(NULL);
|
|
|
|
res_columns[i++]->insert(NULL);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|