11use serde:: Deserialize ;
2- use std:: time:: Duration ;
32
43/// Where to start reading from when a file is first discovered
54#[ derive( Debug , Clone , Copy , PartialEq , Eq , Default , Deserialize ) ]
@@ -11,126 +10,3 @@ pub enum StartAt {
1110 #[ default]
1211 End ,
1312}
14-
15- /// Configuration for the file input operator
16- #[ derive( Debug , Clone , Deserialize ) ]
17- pub struct FileInputConfig {
18- /// Unique identifier for this operator
19- #[ serde( default = "default_id" ) ]
20- pub id : String ,
21-
22- /// Glob patterns for files to include
23- pub include : Vec < String > ,
24-
25- /// Glob patterns for files to exclude
26- #[ serde( default ) ]
27- pub exclude : Vec < String > ,
28-
29- /// How often to poll for file changes (in milliseconds)
30- #[ serde( default = "default_poll_interval_ms" ) ]
31- pub poll_interval_ms : u64 ,
32-
33- /// Where to start reading new files from
34- #[ serde( default ) ]
35- pub start_at : StartAt ,
36-
37- /// Maximum size of a single log entry (in bytes)
38- #[ serde( default = "default_max_log_size" ) ]
39- pub max_log_size : usize ,
40-
41- /// Maximum number of files to read concurrently
42- #[ serde( default = "default_max_concurrent_files" ) ]
43- pub max_concurrent_files : usize ,
44-
45- /// Whether to include the file name as a label
46- #[ serde( default = "default_true" ) ]
47- pub include_file_name : bool ,
48-
49- /// Whether to include the file path as a label
50- #[ serde( default ) ]
51- pub include_file_path : bool ,
52- }
53-
54- fn default_id ( ) -> String {
55- "file_input" . to_string ( )
56- }
57-
58- fn default_poll_interval_ms ( ) -> u64 {
59- 200
60- }
61-
62- fn default_max_log_size ( ) -> usize {
63- 1024 * 1024 // 1MB
64- }
65-
66- fn default_max_concurrent_files ( ) -> usize {
67- 512
68- }
69-
70- fn default_true ( ) -> bool {
71- true
72- }
73-
74- impl Default for FileInputConfig {
75- fn default ( ) -> Self {
76- Self {
77- id : default_id ( ) ,
78- include : vec ! [ ] ,
79- exclude : vec ! [ ] ,
80- poll_interval_ms : default_poll_interval_ms ( ) ,
81- start_at : StartAt :: default ( ) ,
82- max_log_size : default_max_log_size ( ) ,
83- max_concurrent_files : default_max_concurrent_files ( ) ,
84- include_file_name : true ,
85- include_file_path : false ,
86- }
87- }
88- }
89-
90- impl FileInputConfig {
91- /// Get the poll interval as a Duration
92- pub fn poll_interval ( & self ) -> Duration {
93- Duration :: from_millis ( self . poll_interval_ms )
94- }
95-
96- /// Validate the configuration
97- pub fn validate ( & self ) -> Result < ( ) , String > {
98- if self . include . is_empty ( ) {
99- return Err ( "include patterns cannot be empty" . to_string ( ) ) ;
100- }
101-
102- if self . max_log_size == 0 {
103- return Err ( "max_log_size must be positive" . to_string ( ) ) ;
104- }
105-
106- if self . max_concurrent_files < 2 {
107- return Err ( "max_concurrent_files must be at least 2" . to_string ( ) ) ;
108- }
109-
110- Ok ( ( ) )
111- }
112- }
113-
114- #[ cfg( test) ]
115- mod tests {
116- use super :: * ;
117-
118- #[ test]
119- fn test_config_defaults ( ) {
120- let config = FileInputConfig :: default ( ) ;
121- assert_eq ! ( config. poll_interval_ms, 200 ) ;
122- assert_eq ! ( config. max_log_size, 1024 * 1024 ) ;
123- assert_eq ! ( config. start_at, StartAt :: End ) ;
124- }
125-
126- #[ test]
127- fn test_config_validation ( ) {
128- let mut config = FileInputConfig :: default ( ) ;
129- config. include = vec ! [ "/var/log/*.log" . to_string( ) ] ;
130-
131- assert ! ( config. validate( ) . is_ok( ) ) ;
132-
133- config. include = vec ! [ ] ;
134- assert ! ( config. validate( ) . is_err( ) ) ;
135- }
136- }
0 commit comments