@@ -40,9 +40,22 @@ func TestFilestreamMetrics(t *testing.T) {
40
40
"close.on_state_change.inactive" : "2s" ,
41
41
"prospector.scanner.fingerprint.enabled" : false ,
42
42
"file_identity.native" : map [string ]any {},
43
+ "message_max_bytes" : 20 ,
44
+ "parsers" : []map [string ]interface {}{
45
+ {
46
+ "multiline" : map [string ]interface {}{
47
+ "type" : "pattern" ,
48
+ "pattern" : "^multiline" ,
49
+ "negate" : true ,
50
+ "match" : "after" ,
51
+ "max_lines" : 1 ,
52
+ "timeout" : "1s" ,
53
+ },
54
+ },
55
+ },
43
56
})
44
57
45
- testlines := []byte ("first line\n second line\n third line\n " )
58
+ testlines := []byte ("first line\n second line\n third line\n this is a very long line exceeding message_max_bytes \n multiline first line \n multiline second line \ n " )
46
59
env .mustWriteToFile (testlogName , testlines )
47
60
48
61
ctx , cancelInput := context .WithCancel (context .Background ())
@@ -53,37 +66,132 @@ func TestFilestreamMetrics(t *testing.T) {
53
66
env .waitUntilHarvesterIsDone ()
54
67
55
68
checkMetrics (t , "fake-ID" , expectedMetrics {
56
- FilesOpened : 1 ,
57
- FilesClosed : 1 ,
58
- FilesActive : 0 ,
59
- MessagesRead : 3 ,
60
- BytesProcessed : 34 ,
61
- EventsProcessed : 3 ,
62
- ProcessingErrors : 0 ,
69
+ FilesOpened : 1 ,
70
+ FilesClosed : 1 ,
71
+ FilesActive : 0 ,
72
+ MessagesRead : 3 ,
73
+ MessagesTruncated : 2 ,
74
+ BytesProcessed : 130 ,
75
+ EventsProcessed : 3 ,
76
+ ProcessingErrors : 0 ,
77
+ })
78
+
79
+ cancelInput ()
80
+ env .waitUntilInputStops ()
81
+ }
82
+
83
+ func TestFilestreamMessageMaxBytesTruncatedMetric (t * testing.T ) {
84
+ env := newInputTestingEnvironment (t )
85
+
86
+ testlogName := "test.log"
87
+ inp := env .mustCreateInput (map [string ]interface {}{
88
+ "id" : "fake-ID" ,
89
+ "paths" : []string {env .abspath (testlogName )},
90
+ "prospector.scanner.check_interval" : "24h" ,
91
+ "close.on_state_change.check_interval" : "100ms" ,
92
+ "close.on_state_change.inactive" : "2s" ,
93
+ "prospector.scanner.fingerprint.enabled" : false ,
94
+ "file_identity.native" : map [string ]any {},
95
+ "message_max_bytes" : 20 ,
96
+ })
97
+
98
+ testlines := []byte ("first line\n second line\n third line\n this is a long line exceeding message_max_bytes\n " )
99
+ env .mustWriteToFile (testlogName , testlines )
100
+
101
+ ctx , cancelInput := context .WithCancel (context .Background ())
102
+ env .startInput (ctx , inp )
103
+
104
+ env .waitUntilEventCount (4 )
105
+ env .requireOffsetInRegistry (testlogName , "fake-ID" , len (testlines ))
106
+ env .waitUntilHarvesterIsDone ()
107
+
108
+ checkMetrics (t , "fake-ID" , expectedMetrics {
109
+ FilesOpened : 1 ,
110
+ FilesClosed : 1 ,
111
+ FilesActive : 0 ,
112
+ MessagesRead : 4 ,
113
+ MessagesTruncated : 1 ,
114
+ BytesProcessed : 82 ,
115
+ EventsProcessed : 4 ,
116
+ ProcessingErrors : 0 ,
117
+ })
118
+
119
+ cancelInput ()
120
+ env .waitUntilInputStops ()
121
+ }
122
+
123
+ func TestFilestreamMultilineMaxLinesTruncatedMetric (t * testing.T ) {
124
+ env := newInputTestingEnvironment (t )
125
+
126
+ testlogName := "test.log"
127
+ inp := env .mustCreateInput (map [string ]interface {}{
128
+ "id" : "fake-ID" ,
129
+ "paths" : []string {env .abspath (testlogName )},
130
+ "prospector.scanner.check_interval" : "24h" ,
131
+ "close.on_state_change.check_interval" : "100ms" ,
132
+ "close.on_state_change.inactive" : "2s" ,
133
+ "prospector.scanner.fingerprint.enabled" : false ,
134
+ "file_identity.native" : map [string ]any {},
135
+ "parsers" : []map [string ]interface {}{
136
+ {
137
+ "multiline" : map [string ]interface {}{
138
+ "type" : "pattern" ,
139
+ "pattern" : "^multiline" ,
140
+ "negate" : true ,
141
+ "match" : "after" ,
142
+ "max_lines" : 1 ,
143
+ "timeout" : "1s" ,
144
+ },
145
+ },
146
+ },
147
+ })
148
+
149
+ testlines := []byte ("first line\n second line\n multiline first line\n multiline second line\n " )
150
+ env .mustWriteToFile (testlogName , testlines )
151
+
152
+ ctx , cancelInput := context .WithCancel (context .Background ())
153
+ env .startInput (ctx , inp )
154
+
155
+ env .waitUntilEventCount (3 )
156
+ env .requireOffsetInRegistry (testlogName , "fake-ID" , len (testlines ))
157
+ env .waitUntilHarvesterIsDone ()
158
+
159
+ checkMetrics (t , "fake-ID" , expectedMetrics {
160
+ FilesOpened : 1 ,
161
+ FilesClosed : 1 ,
162
+ FilesActive : 0 ,
163
+ MessagesRead : 3 ,
164
+ MessagesTruncated : 1 ,
165
+ BytesProcessed : 66 ,
166
+ EventsProcessed : 3 ,
167
+ ProcessingErrors : 0 ,
63
168
})
64
169
65
170
cancelInput ()
66
171
env .waitUntilInputStops ()
67
172
}
68
173
69
174
type expectedMetrics struct {
70
- FilesOpened uint64
71
- FilesClosed uint64
72
- FilesActive uint64
73
- MessagesRead uint64
74
- BytesProcessed uint64
75
- EventsProcessed uint64
76
- ProcessingErrors uint64
175
+ FilesOpened uint64
176
+ FilesClosed uint64
177
+ FilesActive uint64
178
+ MessagesRead uint64
179
+ MessagesTruncated uint64
180
+ BytesProcessed uint64
181
+ EventsProcessed uint64
182
+ ProcessingErrors uint64
77
183
}
78
184
79
185
func checkMetrics (t * testing.T , id string , expected expectedMetrics ) {
80
- reg := monitoring .GetNamespace ("dataset" ).GetRegistry ().Get (id ).(* monitoring.Registry )
186
+ reg , ok := monitoring .GetNamespace ("dataset" ).GetRegistry ().Get (id ).(* monitoring.Registry )
187
+ require .True (t , ok , "registry not found" )
81
188
82
189
require .Equal (t , id , reg .Get ("id" ).(* monitoring.String ).Get (), "id" )
83
190
require .Equal (t , "filestream" , reg .Get ("input" ).(* monitoring.String ).Get (), "input" )
84
191
require .Equal (t , expected .FilesOpened , reg .Get ("files_opened_total" ).(* monitoring.Uint ).Get (), "files_opened_total" )
85
192
require .Equal (t , expected .FilesClosed , reg .Get ("files_closed_total" ).(* monitoring.Uint ).Get (), "files_closed_total" )
86
193
require .Equal (t , expected .MessagesRead , reg .Get ("messages_read_total" ).(* monitoring.Uint ).Get (), "messages_read_total" )
194
+ require .Equal (t , expected .MessagesTruncated , reg .Get ("messages_truncated_total" ).(* monitoring.Uint ).Get (), "messages_truncated_total" )
87
195
require .Equal (t , expected .BytesProcessed , reg .Get ("bytes_processed_total" ).(* monitoring.Uint ).Get (), "bytes_processed_total" )
88
196
require .Equal (t , expected .EventsProcessed , reg .Get ("events_processed_total" ).(* monitoring.Uint ).Get (), "events_processed_total" )
89
197
require .Equal (t , expected .ProcessingErrors , reg .Get ("processing_errors_total" ).(* monitoring.Uint ).Get (), "processing_errors_total" )
0 commit comments