20
20
21
21
#include " boost/regex.hpp"
22
22
23
- #include " PipelineEventGroup.h"
24
- #include " TagConstants.h"
25
23
#include " app_config/AppConfig.h"
26
24
#include " collection_pipeline/plugin/instance/ProcessorInstance.h"
27
25
#include " common/ParamExtractor.h"
28
26
#include " constants/Constants.h"
27
+ #include " constants/TagConstants.h"
29
28
#include " logger/Logger.h"
30
29
#include " models/LogEvent.h"
30
+ #include " models/PipelineEventGroup.h"
31
31
#include " monitor/metric_constants/MetricConstants.h"
32
+ #include " runner/ProcessorRunner.h"
32
33
33
34
namespace logtail {
34
35
@@ -67,6 +68,18 @@ bool ProcessorSplitMultilineLogStringNative::Init(const Json::Value& config) {
67
68
mContext ->GetRegion ());
68
69
}
69
70
71
+ for (int i = 0 ; i < AppConfig::GetInstance ()->GetProcessThreadCount (); ++i) {
72
+ if (!mMultiline .mStartPattern .empty ()) {
73
+ mStartPatternReg .emplace_back (mMultiline .mStartPattern );
74
+ }
75
+ if (!mMultiline .mContinuePattern .empty ()) {
76
+ mContinuePatternReg .emplace_back (mMultiline .mContinuePattern );
77
+ }
78
+ if (!mMultiline .mEndPattern .empty ()) {
79
+ mEndPatternReg .emplace_back (mMultiline .mEndPattern );
80
+ }
81
+ }
82
+
70
83
mMatchedEventsTotal = GetMetricsRecordRef ().CreateCounter (METRIC_PLUGIN_MATCHED_EVENTS_TOTAL);
71
84
mMatchedLinesTotal = GetMetricsRecordRef ().CreateCounter (METRIC_PLUGIN_MATCHED_LINES_TOTAL);
72
85
mUnmatchedLinesTotal = GetMetricsRecordRef ().CreateCounter (METRIC_PLUGIN_UNMATCHED_LINES_TOTAL);
@@ -150,8 +163,7 @@ void ProcessorSplitMultilineLogStringNative::ProcessEvent(PipelineEventGroup& lo
150
163
std::string exception ;
151
164
const char * multiStartIndex = nullptr ;
152
165
bool isPartialLog = false ;
153
- if (mMultiline .GetStartPatternReg () == nullptr && mMultiline .GetContinuePatternReg () == nullptr
154
- && mMultiline .GetEndPatternReg () != nullptr ) {
166
+ if (!HasStartPattern () && !HasContinuePattern () && HasEndPattern ()) {
155
167
// if only end pattern is given, then it will stick to this state
156
168
isPartialLog = true ;
157
169
multiStartIndex = sourceVal.data ();
@@ -165,17 +177,16 @@ void ProcessorSplitMultilineLogStringNative::ProcessEvent(PipelineEventGroup& lo
165
177
if (!isPartialLog) {
166
178
// it is impossible to enter this state if only end pattern is given
167
179
boost::regex regex;
168
- if (mMultiline . GetStartPatternReg () != nullptr ) {
169
- regex = * mMultiline . GetStartPatternReg ();
180
+ if (HasStartPattern () ) {
181
+ regex = GetStartPatternReg ();
170
182
} else {
171
- regex = * mMultiline . GetContinuePatternReg ();
183
+ regex = GetContinuePatternReg ();
172
184
}
173
185
if (BoostRegexSearch (content.data (), content.size (), regex, exception )) {
174
186
multiStartIndex = content.data ();
175
187
isPartialLog = true ;
176
- } else if (mMultiline .GetEndPatternReg () != nullptr && mMultiline .GetStartPatternReg () == nullptr
177
- && mMultiline .GetContinuePatternReg () != nullptr
178
- && BoostRegexSearch (content.data (), content.size (), *mMultiline .GetEndPatternReg (), exception )) {
188
+ } else if (HasEndPattern () && !HasStartPattern () && HasContinuePattern ()
189
+ && BoostRegexSearch (content.data (), content.size (), GetEndPatternReg (), exception )) {
179
190
// case: continue + end
180
191
CreateNewEvent (content, isLastLog, sourceKey, sourceEvent, logGroup, newEvents);
181
192
multiStartIndex = content.data () + content.size () + 1 ;
@@ -186,17 +197,17 @@ void ProcessorSplitMultilineLogStringNative::ProcessEvent(PipelineEventGroup& lo
186
197
}
187
198
} else {
188
199
// case: start + continue or continue + end
189
- if (mMultiline . GetContinuePatternReg () != nullptr
190
- && BoostRegexSearch (content.data (), content.size (), * mMultiline . GetContinuePatternReg (), exception )) {
200
+ if (HasContinuePattern ()
201
+ && BoostRegexSearch (content.data (), content.size (), GetContinuePatternReg (), exception )) {
191
202
begin += content.size () + 1 ;
192
203
continue ;
193
204
}
194
- if (mMultiline . GetEndPatternReg () != nullptr ) {
205
+ if (HasEndPattern () ) {
195
206
// case: start + end or continue + end or end
196
- if (mMultiline . GetContinuePatternReg () != nullptr ) {
207
+ if (HasContinuePattern () ) {
197
208
// current line is not matched against the continue pattern, so the end pattern will decide
198
209
// if the current log is a match or not
199
- if (BoostRegexSearch (content.data (), content.size (), * mMultiline . GetEndPatternReg (), exception )) {
210
+ if (BoostRegexSearch (content.data (), content.size (), GetEndPatternReg (), exception )) {
200
211
CreateNewEvent (StringView (multiStartIndex, content.data () + content.size () - multiStartIndex),
201
212
isLastLog,
202
213
sourceKey,
@@ -218,14 +229,14 @@ void ProcessorSplitMultilineLogStringNative::ProcessEvent(PipelineEventGroup& lo
218
229
isPartialLog = false ;
219
230
} else {
220
231
// case: start + end or end
221
- if (BoostRegexSearch (content.data (), content.size (), * mMultiline . GetEndPatternReg (), exception )) {
232
+ if (BoostRegexSearch (content.data (), content.size (), GetEndPatternReg (), exception )) {
222
233
CreateNewEvent (StringView (multiStartIndex, content.data () + content.size () - multiStartIndex),
223
234
isLastLog,
224
235
sourceKey,
225
236
sourceEvent,
226
237
logGroup,
227
238
newEvents);
228
- if (mMultiline . GetStartPatternReg () != nullptr ) {
239
+ if (HasStartPattern () ) {
229
240
isPartialLog = false ;
230
241
} else {
231
242
multiStartIndex = content.data () + content.size () + 1 ;
@@ -237,9 +248,9 @@ void ProcessorSplitMultilineLogStringNative::ProcessEvent(PipelineEventGroup& lo
237
248
// so wait for the next line
238
249
}
239
250
} else {
240
- if (mMultiline . GetContinuePatternReg () == nullptr ) {
251
+ if (! HasContinuePattern () ) {
241
252
// case: start
242
- if (BoostRegexSearch (content.data (), content.size (), * mMultiline . GetStartPatternReg (), exception )) {
253
+ if (BoostRegexSearch (content.data (), content.size (), GetStartPatternReg (), exception )) {
243
254
CreateNewEvent (StringView (multiStartIndex, content.data () - 1 - multiStartIndex),
244
255
isLastLog,
245
256
sourceKey,
@@ -259,8 +270,7 @@ void ProcessorSplitMultilineLogStringNative::ProcessEvent(PipelineEventGroup& lo
259
270
logGroup,
260
271
newEvents);
261
272
ADD_COUNTER (mMatchedEventsTotal , 1 );
262
- if (!BoostRegexSearch (
263
- content.data (), content.size (), *mMultiline .GetStartPatternReg (), exception )) {
273
+ if (!BoostRegexSearch (content.data (), content.size (), GetStartPatternReg (), exception )) {
264
274
// when no end pattern is given, the only chance to enter unmatched state is when both
265
275
// start and continue pattern are given, and the current line is not matched against the
266
276
// start pattern
@@ -278,7 +288,7 @@ void ProcessorSplitMultilineLogStringNative::ProcessEvent(PipelineEventGroup& lo
278
288
// when in unmatched state, the unmatched log is handled one by one, so there is no need for additional handle
279
289
// here
280
290
if (isPartialLog && multiStartIndex - sourceVal.data () < static_cast <int64_t >(sourceVal.size ())) {
281
- if (mMultiline . GetEndPatternReg () == nullptr ) {
291
+ if (! HasEndPattern () ) {
282
292
CreateNewEvent (StringView (multiStartIndex, sourceVal.data () + sourceVal.size () - multiStartIndex),
283
293
true ,
284
294
sourceKey,
@@ -383,4 +393,16 @@ StringView ProcessorSplitMultilineLogStringNative::GetNextLine(StringView log, s
383
393
return StringView (log .data () + begin, log .size () - begin);
384
394
}
385
395
396
+ const boost::regex& ProcessorSplitMultilineLogStringNative::GetStartPatternReg () const {
397
+ return mStartPatternReg [ProcessorRunner::GetThreadNo ()];
398
+ }
399
+
400
+ const boost::regex& ProcessorSplitMultilineLogStringNative::GetContinuePatternReg () const {
401
+ return mContinuePatternReg [ProcessorRunner::GetThreadNo ()];
402
+ }
403
+
404
+ const boost::regex& ProcessorSplitMultilineLogStringNative::GetEndPatternReg () const {
405
+ return mEndPatternReg [ProcessorRunner::GetThreadNo ()];
406
+ }
407
+
386
408
} // namespace logtail
0 commit comments