2018-06-15 17:32:35 +00:00
|
|
|
#include "InternalTextLogsQueue.h"
|
2018-06-06 20:57:07 +00:00
|
|
|
#include <DataTypes/DataTypeDateTime.h>
|
|
|
|
#include <DataTypes/DataTypeString.h>
|
|
|
|
#include <DataTypes/DataTypeEnum.h>
|
|
|
|
#include <DataTypes/DataTypesNumber.h>
|
2022-04-27 15:05:45 +00:00
|
|
|
#include <Common/logger_useful.h>
|
2018-06-06 20:57:07 +00:00
|
|
|
|
|
|
|
#include <Poco/Message.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2018-06-15 17:32:35 +00:00
|
|
|
InternalTextLogsQueue::InternalTextLogsQueue()
|
2018-06-20 15:21:42 +00:00
|
|
|
: ConcurrentBoundedQueue<MutableColumns>(std::numeric_limits<int>::max()),
|
|
|
|
max_priority(Poco::Message::Priority::PRIO_INFORMATION) {}
|
2018-06-06 20:57:07 +00:00
|
|
|
|
|
|
|
|
2018-06-15 17:32:35 +00:00
|
|
|
Block InternalTextLogsQueue::getSampleBlock()
|
2018-06-06 20:57:07 +00:00
|
|
|
{
|
|
|
|
return Block {
|
2018-06-20 15:21:42 +00:00
|
|
|
{std::make_shared<DataTypeDateTime>(), "event_time"},
|
2019-07-10 12:19:17 +00:00
|
|
|
{std::make_shared<DataTypeUInt32>(), "event_time_microseconds"},
|
|
|
|
{std::make_shared<DataTypeString>(), "host_name"},
|
|
|
|
{std::make_shared<DataTypeString>(), "query_id"},
|
2020-02-02 20:01:13 +00:00
|
|
|
{std::make_shared<DataTypeUInt64>(), "thread_id"},
|
2019-07-10 12:19:17 +00:00
|
|
|
{std::make_shared<DataTypeInt8>(), "priority"},
|
|
|
|
{std::make_shared<DataTypeString>(), "source"},
|
|
|
|
{std::make_shared<DataTypeString>(), "text"}
|
2018-06-06 20:57:07 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-06-15 17:32:35 +00:00
|
|
|
MutableColumns InternalTextLogsQueue::getSampleColumns()
|
2018-06-06 20:57:07 +00:00
|
|
|
{
|
|
|
|
static Block sample_block = getSampleBlock();
|
|
|
|
return sample_block.cloneEmptyColumns();
|
|
|
|
}
|
|
|
|
|
2018-06-18 16:30:26 +00:00
|
|
|
void InternalTextLogsQueue::pushBlock(Block && log_block)
|
|
|
|
{
|
2018-06-20 15:21:42 +00:00
|
|
|
static Block sample_block = getSampleBlock();
|
2018-06-18 16:30:26 +00:00
|
|
|
|
2018-06-20 15:21:42 +00:00
|
|
|
if (blocksHaveEqualStructure(sample_block, log_block))
|
2021-10-07 22:06:33 +00:00
|
|
|
(void)(emplace(log_block.mutateColumns()));
|
2018-06-20 15:21:42 +00:00
|
|
|
else
|
2018-06-18 16:30:26 +00:00
|
|
|
LOG_WARNING(&Poco::Logger::get("InternalTextLogsQueue"), "Log block have different structure");
|
|
|
|
}
|
|
|
|
|
2023-01-16 14:20:47 +00:00
|
|
|
std::string_view InternalTextLogsQueue::getPriorityName(int priority)
|
2018-06-06 20:57:07 +00:00
|
|
|
{
|
2023-01-16 14:20:47 +00:00
|
|
|
using namespace std::literals;
|
|
|
|
|
2018-06-06 20:57:07 +00:00
|
|
|
/// See Poco::Message::Priority
|
2023-01-16 14:20:47 +00:00
|
|
|
static constexpr std::array PRIORITIES =
|
2020-03-23 02:12:31 +00:00
|
|
|
{
|
2023-01-16 14:20:47 +00:00
|
|
|
"Unknown"sv,
|
|
|
|
"Fatal"sv,
|
|
|
|
"Critical"sv,
|
|
|
|
"Error"sv,
|
|
|
|
"Warning"sv,
|
|
|
|
"Notice"sv,
|
|
|
|
"Information"sv,
|
|
|
|
"Debug"sv,
|
|
|
|
"Trace"sv,
|
|
|
|
"Test"sv,
|
2018-06-06 20:57:07 +00:00
|
|
|
};
|
2023-01-16 14:20:47 +00:00
|
|
|
return (priority >= 1 && priority < static_cast<int>(PRIORITIES.size())) ? PRIORITIES[priority] : PRIORITIES[0];
|
2018-06-06 20:57:07 +00:00
|
|
|
}
|
|
|
|
|
2022-07-13 08:15:37 +00:00
|
|
|
bool InternalTextLogsQueue::isNeeded(int priority, const String & source) const
|
|
|
|
{
|
|
|
|
bool is_needed = priority <= max_priority;
|
|
|
|
|
|
|
|
if (is_needed && source_regexp)
|
|
|
|
is_needed = re2::RE2::PartialMatch(source, *source_regexp);
|
|
|
|
|
|
|
|
return is_needed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InternalTextLogsQueue::setSourceRegexp(const String & regexp)
|
|
|
|
{
|
|
|
|
source_regexp = std::make_unique<re2::RE2>(regexp);
|
|
|
|
}
|
|
|
|
|
2018-06-06 20:57:07 +00:00
|
|
|
}
|