wp-core-connectors 0.5.2

Core connector registry and sink runtimes for WarpParse
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
//! TCP Syslog source implementation
//!
//! This module provides the TCP-based syslog source that can receive syslog messages
//! over TCP protocol with connection management, automatic framing, and message distribution.

use crate::sources::event_id::next_event_id;
use std::sync::Arc;

use bytes::BytesMut;
use tokio::sync::mpsc::Sender;
use wp_connector_api::{
    CtrlRx, DataSource, EventPreHook, SourceBatch, SourceEvent, SourceReason, SourceResult, Tags,
};
use wp_model_core::raw::RawData;

use super::normalize;
use crate::sources::syslog::constants::Message;
use crate::sources::tcp::framing::{self};
use crate::sources::tcp::{TcpSource, ZcpMessage};

// 分帧由公共模块提供;此处不再定义局部 framing 常量

/// TCP Syslog data source with full lifecycle management
///
/// Manages TCP connections, line framing, and message distribution
pub struct TcpSyslogSource {
    key: String,
    tags: Tags,
    strip_header: bool,
    attach_meta_tags: bool,
    fast_strip: bool,
    inner: TcpSource,
    // 复用预处理闭包,避免每条事件都构建一次
    preproc_hook: Option<EventPreHook>,
}

impl TcpSyslogSource {
    /// Create a new TCP syslog source with a pre-built TCP aggregator source
    pub async fn new(
        key: String,
        tags: Tags,
        strip_header: bool,
        attach_meta_tags: bool,
        fast_strip: bool,
        inner: TcpSource,
    ) -> SourceResult<Self> {
        // 先初始化,再构建可复用的预处理闭包
        let mut this = Self {
            key,
            tags,
            strip_header,
            attach_meta_tags,
            fast_strip,
            inner,
            preproc_hook: None,
        };
        this.preproc_hook = this.build_preproc_hook();
        Ok(this)
    }

    fn base_source_tags(&self) -> Tags {
        let mut stags = Tags::new();
        for (k, v) in self.tags.iter() {
            stags.set(k, v);
        }
        stags
    }

    // 连接管理由通用 TcpServer 承担;此处只保留事件构造与预处理逻辑。

    /// Build preprocessing hook for syslog normalize and strip/tag injection
    fn build_preproc_hook(&self) -> Option<EventPreHook> {
        let strip = self.strip_header;
        let attach = self.attach_meta_tags;
        let fast = self.fast_strip;
        if strip || attach {
            Some(std::sync::Arc::new(move |f: &mut SourceEvent| {
                let s_opt = match &f.payload {
                    RawData::String(s) => Some(s.as_str()),
                    RawData::Bytes(b) => std::str::from_utf8(b).ok(),
                    RawData::ArcBytes(b) => std::str::from_utf8(b).ok(),
                };
                if let Some(s) = s_opt {
                    // 快速裁剪路径:仅 strip、不打标签时,优先使用轻量规则避免完整解析
                    if fast && strip && !attach {
                        // 0) RFC5424 快路径:在 '>' 后,VERSION + 空格 + 5 个 token + structured-data(- 或 [...])后是消息体
                        if let Some(gt) = s.find('>') {
                            let bytes = s.as_bytes();
                            let mut j = gt + 1;
                            // VERSION: 至少 1 位数字
                            let n = bytes.len();
                            let mut k = j;
                            while k < n && bytes[k].is_ascii_digit() {
                                k += 1;
                            }
                            if k > j && k < n && bytes[k] == b' ' {
                                j = k + 1; // 跳过 version 和一个空格
                                // 跳过 5 个以空格分隔的 token
                                let mut tok = 0;
                                while j < n && tok < 5 {
                                    // 跳过非空格
                                    while j < n && bytes[j] != b' ' {
                                        j += 1;
                                    }
                                    if j >= n {
                                        break;
                                    }
                                    // 跳过一个空格
                                    j += 1;
                                    tok += 1;
                                }
                                if tok == 5 && j <= n {
                                    // 结构化数据:'-' 或 '[' ... ']'
                                    if j < n && bytes[j] == b'-' {
                                        let mut start = j + 1;
                                        if start < n && bytes[start] == b' ' {
                                            start += 1;
                                        }
                                        // 直接裁剪 [start..n]
                                        match &mut f.payload {
                                            RawData::Bytes(b) => {
                                                if start <= b.len() {
                                                    *b = b.slice(start..n);
                                                }
                                            }
                                            RawData::String(st) => {
                                                if start <= st.len() {
                                                    *st = st[start..].to_string();
                                                }
                                            }
                                            RawData::ArcBytes(arc_b) => {
                                                // Convert ArcBytes to Bytes for modification
                                                if start <= arc_b.len() {
                                                    let new_bytes = bytes::Bytes::copy_from_slice(
                                                        &arc_b[start..],
                                                    );
                                                    f.payload = RawData::Bytes(new_bytes);
                                                }
                                            }
                                        }
                                        return;
                                    }
                                    if j < n && bytes[j] == b'[' {
                                        // 找到配对的 ']'
                                        if let Some(close_rel) = s[j + 1..].find(']') {
                                            let mut start = j + 1 + close_rel + 1; // 右括号后一位
                                            if start < n && bytes[start] == b' ' {
                                                start += 1;
                                            }
                                            match &mut f.payload {
                                                RawData::Bytes(b) => {
                                                    if start <= b.len() {
                                                        *b = b.slice(start..n);
                                                    }
                                                }
                                                RawData::String(st) => {
                                                    if start <= st.len() {
                                                        *st = st[start..].to_string();
                                                    }
                                                }
                                                RawData::ArcBytes(arc_b) => {
                                                    // Convert ArcBytes to Bytes for modification
                                                    if start <= arc_b.len() {
                                                        let new_bytes =
                                                            bytes::Bytes::copy_from_slice(
                                                                &arc_b[start..],
                                                            );
                                                        f.payload = RawData::Bytes(new_bytes);
                                                    }
                                                }
                                            }
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                        // 1) RFC3164 常见模式:在第一个 ": " 之后即为消息体(确保位于 PRI '>' 之后)
                        if let Some(col) = s.find(": ")
                            && let Some(gt) = s.find('>')
                            && col > gt
                        {
                            let start = col + 2;
                            match &mut f.payload {
                                RawData::Bytes(b) => {
                                    let len = b.len();
                                    if start <= len {
                                        *b = b.slice(start..len);
                                    }
                                }
                                RawData::String(st) => {
                                    if start <= st.len() {
                                        *st = st[start..].to_string();
                                    }
                                }
                                RawData::ArcBytes(arc_b) => {
                                    // Convert ArcBytes to Bytes for modification
                                    let len = arc_b.len();
                                    if start <= len {
                                        let new_bytes =
                                            bytes::Bytes::copy_from_slice(&arc_b[start..]);
                                        f.payload = RawData::Bytes(new_bytes);
                                    }
                                }
                            }
                            return;
                        }
                        // 2) 兼容历史生成样本的快剪:遇到 " wpgen: " 直接裁剪其后
                        if let Some(pos) = s.find(" wpgen: ") {
                            let start = pos + 8;
                            match &mut f.payload {
                                RawData::Bytes(b) => {
                                    let len = b.len();
                                    if start <= len {
                                        *b = b.slice(start..len);
                                    }
                                }
                                RawData::String(st) => {
                                    if start <= st.len() {
                                        *st = st[start..].to_string();
                                    }
                                }
                                RawData::ArcBytes(arc_b) => {
                                    // Convert ArcBytes to Bytes for modification
                                    let len = arc_b.len();
                                    if start <= len {
                                        let new_bytes =
                                            bytes::Bytes::copy_from_slice(&arc_b[start..]);
                                        f.payload = RawData::Bytes(new_bytes);
                                    }
                                }
                            }
                            return;
                        }
                    }
                    if fast && strip && !attach {
                        trace_data!(
                            "syslog fast strip fallback (key={}, preview='{}')",
                            f.src_key,
                            Self::syslog_preview(s)
                        );
                    }
                    let ns = normalize::normalize_slice(s);
                    if attach {
                        let tags = Arc::make_mut(&mut f.tags);
                        if let Some(pri) = ns.meta.pri {
                            tags.set("syslog.pri", pri.to_string());
                        }
                        if let Some(ref fac) = ns.meta.facility {
                            tags.set("syslog.facility", fac.clone());
                        }
                        if let Some(ref sev) = ns.meta.severity {
                            tags.set("syslog.severity", sev.clone());
                        }
                    }
                    if strip {
                        if ns.msg_start >= ns.msg_end {
                            trace_data!(
                                "syslog strip produced empty span (key={}, preview='{}')",
                                f.src_key,
                                Self::syslog_preview(s)
                            );
                        }
                        match &mut f.payload {
                            RawData::Bytes(b) => {
                                let start = ns.msg_start.min(b.len());
                                let end = ns.msg_end.min(b.len());
                                if start <= end {
                                    *b = b.slice(start..end);
                                }
                            }
                            RawData::String(st) => {
                                let start = ns.msg_start.min(st.len());
                                let end = ns.msg_end.min(st.len());
                                *st = st[start..end].to_string();
                            }
                            RawData::ArcBytes(arc_b) => {
                                // Convert ArcBytes to Bytes for modification
                                let start = ns.msg_start.min(arc_b.len());
                                let end = ns.msg_end.min(arc_b.len());
                                if start <= end {
                                    let new_bytes =
                                        bytes::Bytes::copy_from_slice(&arc_b[start..end]);
                                    f.payload = RawData::Bytes(new_bytes);
                                }
                            }
                        }
                    }
                }
            }) as EventPreHook)
        } else {
            None
        }
    }

    fn syslog_preview(data: &str) -> String {
        const LIMIT: usize = 120;
        if data.chars().count() <= LIMIT {
            data.to_string()
        } else {
            let mut out = String::with_capacity(LIMIT + 3);
            for (idx, ch) in data.char_indices() {
                if idx >= LIMIT {
                    break;
                }
                out.push(ch);
            }
            out.push_str("...");
            out
        }
    }

    fn decorate_batch(&self, mut batch: SourceBatch) -> SourceBatch {
        for event in batch.iter_mut() {
            // 仅在需要附加元标签时注入 access_ip,避免每条事件克隆 Tags
            if self.attach_meta_tags
                && let Some(ip) = event.ups_ip
            {
                Arc::make_mut(&mut event.tags).set("access_ip", ip.to_string());
            }
            // 复用预处理闭包,降低分配
            if self.strip_header || self.attach_meta_tags {
                event.preproc = self.preproc_hook.clone();
            }
        }
        batch
    }

    /// 基于零拷贝消息构造 SourceEvent,附加 access_ip/ups_ip 元信息
    pub fn build_zero_copy_frame(&self, msg: ZcpMessage) -> SourceEvent {
        let client_ip = msg.client_ip();
        let payload = RawData::ArcBytes(msg.into_payload_arc());
        let stags = self.base_source_tags();
        //stags.set("access_ip".to_string(), access_ip.clone());

        let mut event = SourceEvent::new(next_event_id(), &self.key, payload, Arc::new(stags));
        event.ups_ip = Some(client_ip);
        if self.strip_header || self.attach_meta_tags {
            event.preproc = self.preproc_hook.clone();
        }
        event
    }

    /// RFC6587 分帧辅助:供单元测试/诊断复现 framing 行为
    pub async fn process_buffer(
        buffer: &mut BytesMut,
        data: &[u8],
        client_ip: &str,
        sender: &Sender<Message>,
    ) -> SourceResult<()> {
        if !data.is_empty() {
            buffer.extend_from_slice(data);
        }

        let client_ip = Arc::<str>::from(client_ip);
        while let Some(pending) = framing::drain_auto_all(buffer, &client_ip, sender).await? {
            sender.send(pending).await.map_err(|e| {
                SourceReason::disconnect(format!("syslog framing channel closed: {}", e))
            })?;
        }
        Ok(())
    }
}

#[async_trait::async_trait]
impl DataSource for TcpSyslogSource {
    async fn receive(&mut self) -> SourceResult<SourceBatch> {
        let batch = self.inner.receive().await?;
        Ok(self.decorate_batch(batch))
    }

    fn try_receive(&mut self) -> Option<SourceBatch> {
        self.inner
            .try_receive()
            .map(|batch| self.decorate_batch(batch))
    }

    fn can_try_receive(&mut self) -> bool {
        self.inner.can_try_receive()
    }

    fn identifier(&self) -> String {
        self.key.clone()
    }

    async fn start(&mut self, ctrl_rx: CtrlRx) -> SourceResult<()> {
        self.inner.start(ctrl_rx).await
    }

    async fn close(&mut self) -> SourceResult<()> {
        self.inner.close().await
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::protocol::syslog::{EmitMessage, SyslogEncoder};

    #[tokio::test]
    async fn test_syslog_zero_copy_frame_builder() {
        // Build a minimal inner tcp aggregator
        let pool = std::sync::Arc::new(std::sync::Mutex::new(std::collections::HashSet::new()));
        let (_tx, rx) = tokio::sync::mpsc::channel(8);
        let inner = TcpSource::new(
            "test_syslog_zero_copy".to_string(),
            Tags::default(),
            "127.0.0.1:0".to_string(),
            65536,
            crate::sources::tcp::FramingMode::Line,
            pool,
            rx,
        )
        .unwrap();
        let tcp_syslog = TcpSyslogSource::new(
            "test_syslog_zero_copy".to_string(),
            Tags::default(),
            false, // strip_header
            false, // attach_meta_tags
            false, // fast_strip
            inner,
        )
        .await
        .unwrap();

        // 创建测试消息
        let zcp_msg = ZcpMessage::new(
            b"192.168.1.200",
            b"<34>Oct 22 10:52:12 myhost test message".to_vec(),
        );

        // 使用零拷贝帧构建器
        let event = tcp_syslog.build_zero_copy_frame(zcp_msg);

        // 验证事件属性
        assert_eq!(event.src_key.as_str(), "test_syslog_zero_copy");
        assert!(event.ups_ip.is_some());

        match event.payload {
            RawData::Bytes(data) => {
                let message_str = String::from_utf8_lossy(&data);
                assert!(message_str.contains("test message"));
            }
            RawData::ArcBytes(data) => {
                let message_str = String::from_utf8_lossy(&data);
                assert!(message_str.contains("test message"));
            }
            RawData::String(s) => {
                assert!(s.contains("test message"));
            }
        }
    }

    #[tokio::test]
    async fn test_syslog_zero_copy_frame_with_meta() {
        let pool = std::sync::Arc::new(std::sync::Mutex::new(std::collections::HashSet::new()));
        let (_tx, rx) = tokio::sync::mpsc::channel(8);
        let inner = TcpSource::new(
            "test_syslog_meta".to_string(),
            Tags::default(),
            "127.0.0.1:0".to_string(),
            65536,
            crate::sources::tcp::FramingMode::Line,
            pool,
            rx,
        )
        .unwrap();
        let tcp_syslog = TcpSyslogSource::new(
            "test_syslog_meta".to_string(),
            Tags::default(),
            false, // strip_header
            true,  // attach_meta_tags
            false, // fast_strip
            inner,
        )
        .await
        .unwrap();

        // 创建带有syslog优先级的消息
        let zcp_msg = ZcpMessage::new(
            b"10.0.0.1",
            b"<13>Oct 22 10:52:12 myhost test message with priority".to_vec(),
        );

        let event = tcp_syslog.build_zero_copy_frame(zcp_msg);

        // 验证事件属性
        assert_eq!(event.src_key.as_str(), "test_syslog_meta");

        match event.payload {
            RawData::Bytes(data) => {
                let message_str = String::from_utf8_lossy(&data);
                assert!(message_str.contains("test message with priority"));
            }
            RawData::ArcBytes(data) => {
                let message_str = String::from_utf8_lossy(&data);
                assert!(message_str.contains("test message with priority"));
            }
            RawData::String(s) => {
                assert!(s.contains("test message with priority"));
            }
        }
    }

    #[tokio::test]
    async fn test_syslog_zero_copy_frame_invalid_ip() {
        let pool = std::sync::Arc::new(std::sync::Mutex::new(std::collections::HashSet::new()));
        let (_tx, rx) = tokio::sync::mpsc::channel(8);
        let inner = TcpSource::new(
            "test_syslog_invalid_ip".to_string(),
            Tags::default(),
            "127.0.0.1:0".to_string(),
            65536,
            crate::sources::tcp::FramingMode::Line,
            pool,
            rx,
        )
        .unwrap();
        let tcp_syslog = TcpSyslogSource::new(
            "test_syslog_invalid_ip".to_string(),
            Tags::default(),
            false,
            false,
            false,
            inner,
        )
        .await
        .unwrap();

        // 创建包含无效UTF-8的IP
        let invalid_client_ip = &[0xFF, 0xFE, 0xFD];
        let zcp_msg = ZcpMessage::new(
            invalid_client_ip,
            b"<14>Oct 22 10:52:12 myhost test".to_vec(),
        );

        let event = tcp_syslog.build_zero_copy_frame(zcp_msg);

        // 验证无效IP被正确处理
        assert_eq!(event.src_key.as_str(), "test_syslog_invalid_ip");
    }

    #[tokio::test]
    async fn preproc_strips_header() {
        let pool = std::sync::Arc::new(std::sync::Mutex::new(std::collections::HashSet::new()));
        let (_tx, rx) = tokio::sync::mpsc::channel(8);
        let inner = TcpSource::new(
            "test-strip".to_string(),
            Tags::default(),
            "127.0.0.1:0".to_string(),
            4096,
            crate::sources::tcp::FramingMode::Line,
            pool,
            rx,
        )
        .unwrap();
        let source = TcpSyslogSource::new(
            "test-strip".to_string(),
            Tags::default(),
            true,
            true,
            false,
            inner,
        )
        .await
        .unwrap();

        let mut pre_event = SourceEvent::new(
            next_event_id(),
            "syslog",
            RawData::String("<13>Oct 11 22:14:15 host app: body".into()),
            Arc::new(Tags::new()),
        );
        let hook = source.build_preproc_hook().unwrap();
        hook(&mut pre_event);
        assert_eq!(pre_event.payload.to_string(), "body");
        assert_eq!(pre_event.tags.get("syslog.pri"), Some("13"));
    }

    #[tokio::test]
    async fn fast_strip_rfc3164_quick_path() {
        let pool = std::sync::Arc::new(std::sync::Mutex::new(std::collections::HashSet::new()));
        let (_tx, rx) = tokio::sync::mpsc::channel(8);
        let inner = TcpSource::new(
            "test-fast3164".to_string(),
            Tags::default(),
            "127.0.0.1:0".to_string(),
            4096,
            crate::sources::tcp::FramingMode::Line,
            pool,
            rx,
        )
        .unwrap();
        // strip_header=true, attach_meta_tags=false, fast_strip=true → 触发快路径
        let source = TcpSyslogSource::new(
            "test-fast3164".to_string(),
            Tags::default(),
            true,
            false,
            true,
            inner,
        )
        .await
        .unwrap();

        let mut pre_event = SourceEvent::new(
            next_event_id(),
            "syslog",
            RawData::String("<34>Oct 11 22:14:15 mymachine app: hello world".into()),
            Arc::new(Tags::new()),
        );
        let hook = source.build_preproc_hook().unwrap();
        hook(&mut pre_event);
        assert_eq!(pre_event.payload.to_string(), "hello world");
    }

    #[tokio::test]
    async fn syslog_sink_source_roundtrip_strips_header() {
        let pool = std::sync::Arc::new(std::sync::Mutex::new(std::collections::HashSet::new()));
        let (_tx, rx) = tokio::sync::mpsc::channel(8);
        let inner = TcpSource::new(
            "roundtrip".to_string(),
            Tags::default(),
            "127.0.0.1:0".to_string(),
            4096,
            crate::sources::tcp::FramingMode::Line,
            pool,
            rx,
        )
        .unwrap();
        let source = TcpSyslogSource::new(
            "roundtrip".to_string(),
            Tags::default(),
            true,
            true,
            true,
            inner,
        )
        .await
        .unwrap();

        let body = "monitor payload";
        let mut emit = EmitMessage::new(body);
        emit.priority = 13;
        emit.hostname = Some("unit-host");
        emit.app_name = Some("wpgen");
        emit.append_newline = true;
        let encoder = SyslogEncoder::new();
        let encoded = encoder.encode_rfc3164(&emit);

        let mut pre_event = SourceEvent::new(
            next_event_id(),
            "syslog",
            RawData::String(String::from_utf8(encoded.to_vec()).unwrap()),
            Arc::new(Tags::new()),
        );
        let hook = source.build_preproc_hook().unwrap();
        hook(&mut pre_event);

        let stripped = match &pre_event.payload {
            RawData::String(s) => s.clone(),
            RawData::Bytes(b) => String::from_utf8_lossy(b).to_string(),
            RawData::ArcBytes(b) => String::from_utf8_lossy(b).to_string(),
        };
        assert!(
            stripped.contains(body),
            "payload missing body: {}",
            stripped
        );
        assert!(stripped.ends_with('\n'));
        assert_eq!(pre_event.tags.get("syslog.pri"), Some("13"));
    }

    #[tokio::test]
    async fn fast_strip_rfc5424_quick_path() {
        let pool = std::sync::Arc::new(std::sync::Mutex::new(std::collections::HashSet::new()));
        let (_tx, rx) = tokio::sync::mpsc::channel(8);
        let inner = TcpSource::new(
            "test-fast5424".to_string(),
            Tags::default(),
            "127.0.0.1:0".to_string(),
            4096,
            crate::sources::tcp::FramingMode::Line,
            pool,
            rx,
        )
        .unwrap();
        let source = TcpSyslogSource::new(
            "test-fast5424".to_string(),
            Tags::default(),
            true,  // strip
            false, // !attach
            true,  // fast_strip
            inner,
        )
        .await
        .unwrap();

        let mut pre_event = SourceEvent::new(
            next_event_id(),
            "syslog",
            RawData::String("<14>1 2024-10-05T12:34:56Z host app 123 - - hello world".into()),
            Arc::new(Tags::new()),
        );
        let hook = source.build_preproc_hook().unwrap();
        hook(&mut pre_event);
        assert_eq!(pre_event.payload.to_string(), "hello world");
    }
}