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>
|
2018-06-18 16:30:26 +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))
|
|
|
|
emplace(log_block.mutateColumns());
|
|
|
|
else
|
2018-06-18 16:30:26 +00:00
|
|
|
LOG_WARNING(&Poco::Logger::get("InternalTextLogsQueue"), "Log block have different structure");
|
|
|
|
}
|
|
|
|
|
2018-06-15 17:32:35 +00:00
|
|
|
const char * InternalTextLogsQueue::getPriorityName(int priority)
|
2018-06-06 20:57:07 +00:00
|
|
|
{
|
|
|
|
/// See Poco::Message::Priority
|
|
|
|
|
2020-03-23 02:12:31 +00:00
|
|
|
static constexpr const char * const PRIORITIES[] =
|
|
|
|
{
|
2018-06-06 20:57:07 +00:00
|
|
|
"Unknown",
|
2018-06-20 15:21:42 +00:00
|
|
|
"Fatal",
|
|
|
|
"Critical",
|
|
|
|
"Error",
|
|
|
|
"Warning",
|
|
|
|
"Notice",
|
|
|
|
"Information",
|
|
|
|
"Debug",
|
|
|
|
"Trace"
|
2018-06-06 20:57:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return (priority >= 1 && priority <= 8) ? PRIORITIES[priority] : PRIORITIES[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|