in core/unittest/processor/ProcessorMergeMultilineLogNativeUnittest.cpp [1328:1840]
void ProcessEventsWithPartLogUnittest::TestProcess() {
// make config
Json::Value config;
config["MergeType"] = "flag";
// make ProcessorMergeMultilineLogNative
ProcessorMergeMultilineLogNative processorMergeMultilineLogNative;
processorMergeMultilineLogNative.SetContext(mContext);
processorMergeMultilineLogNative.SetMetricsRecordRef(ProcessorMergeMultilineLogNative::sName, "1");
APSARA_TEST_TRUE(processorMergeMultilineLogNative.Init(config));
// event 不支持
{
// 第一个event就不支持 不支持PPFFF
{
auto sourceBuffer = std::make_shared<SourceBuffer>();
PipelineEventGroup eventGroup(sourceBuffer);
eventGroup.AddMetricEvent();
std::string inJson = R"({
"events": [
{
"contents" :
{
"P": "",
"content": "Ex"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
},
{
"contents" :
{
"P": "",
"content": "ce"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
},
{
"contents" :
{
"content": "ption"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
},
{
"contents" :
{
"content": "Exception"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
},
{
"contents" :
{
"content": "Exception"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
}
],
"metadata": {
"has.part.log": "P"
}
})";
eventGroup.FromJsonString(inJson);
// run test function
processorMergeMultilineLogNative.Process(eventGroup);
// judge result
std::stringstream expectJson;
expectJson << R"({
"events": [
{
"name": "",
"timestamp": 0,
"type": 2,
"value": {
"type": "unknown"
}
},
{
"contents" :
{
"P": "",
"content": "Ex"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
},
{
"contents" :
{
"P": "",
"content": "ce"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
},
{
"contents" :
{
"content": "ption"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
},
{
"contents" :
{
"content": "Exception"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
},
{
"contents" :
{
"content": "Exception"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
}
]
})";
std::string outJson = eventGroup.ToJsonString();
APSARA_TEST_STREQ(CompactJson(expectJson.str()).c_str(), CompactJson(outJson).c_str());
}
// P匹配过程中不支持 P不支持PFFF
{
auto sourceBuffer = std::make_shared<SourceBuffer>();
PipelineEventGroup eventGroup(sourceBuffer);
std::string inJson = R"({
"events": [
{
"contents" :
{
"P": "",
"content": "Ex"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
}
],
"metadata": {
"has.part.log": "P"
}
})";
eventGroup.FromJsonString(inJson);
eventGroup.AddMetricEvent();
inJson = R"({
"events": [
{
"contents" :
{
"P": "",
"content": "ce"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
},
{
"contents" :
{
"content": "ption"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
},
{
"contents" :
{
"content": "Exception"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
},
{
"contents" :
{
"content": "Exception"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
}
],
"metadata": {
"has.part.log": "P"
}
})";
eventGroup.FromJsonString(inJson);
// run test function
processorMergeMultilineLogNative.Process(eventGroup);
// judge result
std::stringstream expectJson;
expectJson << R"({
"events": [
{
"contents" :
{
"content": "Ex"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
},
{
"name": "",
"timestamp": 0,
"type": 2,
"value": {
"type": "unknown"
}
},
{
"contents" :
{
"P": "",
"content": "ce"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
},
{
"contents" :
{
"content": "ption"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
},
{
"contents" :
{
"content": "Exception"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
},
{
"contents" :
{
"content": "Exception"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
}
]
})";
std::string outJson = eventGroup.ToJsonString();
APSARA_TEST_STREQ(CompactJson(expectJson.str()).c_str(), CompactJson(outJson).c_str());
}
// PF匹配过程中不支持 PP不支持FFF
{
auto sourceBuffer = std::make_shared<SourceBuffer>();
PipelineEventGroup eventGroup(sourceBuffer);
std::string inJson = R"({
"events": [
{
"contents" :
{
"P": "",
"content": "Ex"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
},
{
"contents" :
{
"P": "",
"content": "ce"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
}
],
"metadata": {
"has.part.log": "P"
}
})";
eventGroup.FromJsonString(inJson);
eventGroup.AddMetricEvent();
inJson = R"({
"events": [
{
"contents" :
{
"content": "ption"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
},
{
"contents" :
{
"content": "Exception"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
},
{
"contents" :
{
"content": "Exception"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
}
]
})";
eventGroup.FromJsonString(inJson);
// run test function
processorMergeMultilineLogNative.Process(eventGroup);
// judge result
std::stringstream expectJson;
expectJson << R"({
"events": [
{
"contents" :
{
"content": "Ex"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
},
{
"contents" :
{
"P": "",
"content": "ce"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
},
{
"name": "",
"timestamp": 0,
"type": 2,
"value": {
"type": "unknown"
}
},
{
"contents" :
{
"content": "ption"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
},
{
"contents" :
{
"content": "Exception"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
},
{
"contents" :
{
"content": "Exception"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
}
]
})";
std::string outJson = eventGroup.ToJsonString();
APSARA_TEST_STREQ(CompactJson(expectJson.str()).c_str(), CompactJson(outJson).c_str());
}
// FF中不支持 PPFF不支持F
{
auto sourceBuffer = std::make_shared<SourceBuffer>();
PipelineEventGroup eventGroup(sourceBuffer);
std::string inJson = R"({
"events": [
{
"contents" :
{
"P": "",
"content": "Ex"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
},
{
"contents" :
{
"P": "",
"content": "ce"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
},
{
"contents" :
{
"content": "ption"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
},
{
"contents" :
{
"content": "Exception"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
},
],
"metadata": {
"has.part.log": "P"
}
})";
eventGroup.FromJsonString(inJson);
eventGroup.AddMetricEvent();
inJson = R"({
"events": [
{
"contents" :
{
"content": "Exception"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
}
]
})";
eventGroup.FromJsonString(inJson);
// run test function
processorMergeMultilineLogNative.Process(eventGroup);
// judge result
std::stringstream expectJson;
expectJson << R"({
"events": [
{
"contents" :
{
"content": "Exception"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
},
{
"contents" :
{
"content": "Exception"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
},
{
"name": "",
"timestamp": 0,
"type": 2,
"value": {
"type": "unknown"
}
},
{
"contents" :
{
"content": "Exception"
},
"timestamp" : 12345678901,
"timestampNanosecond" : 0,
"type" : 1
}
]
})";
std::string outJson = eventGroup.ToJsonString();
APSARA_TEST_STREQ(CompactJson(expectJson.str()).c_str(), CompactJson(outJson).c_str());
}
}
}