@@ -8,12 +8,13 @@ import (
8
8
9
9
"github.com/buger/jsonparser"
10
10
gologfmt "github.com/go-logfmt/logfmt"
11
+ "github.com/prometheus/client_golang/prometheus"
11
12
12
13
"github.com/grafana/loki/v3/pkg/logql/log/logfmt"
13
14
)
14
15
15
16
type LineTokenizer interface {
16
- Tokenize (line string , tokens []string , state interface {}) ([]string , interface {})
17
+ Tokenize (line string , tokens []string , state interface {}, linesDropped * prometheus. CounterVec ) ([]string , interface {})
17
18
Join (tokens []string , state interface {}) string
18
19
Clone (tokens []string , state interface {}) ([]string , interface {})
19
20
}
@@ -56,8 +57,16 @@ func newPunctuationTokenizer(maxLineLength int) *punctuationTokenizer {
56
57
}
57
58
}
58
59
59
- func (p * punctuationTokenizer ) Tokenize (line string , tokens []string , state interface {}) ([]string , interface {}) {
60
+ func (p * punctuationTokenizer ) Tokenize (
61
+ line string ,
62
+ tokens []string ,
63
+ state interface {},
64
+ linesDropped * prometheus.CounterVec ,
65
+ ) ([]string , interface {}) {
60
66
if len (line ) > p .maxLineLength {
67
+ if linesDropped != nil {
68
+ linesDropped .WithLabelValues (LineTooLong ).Inc ()
69
+ }
61
70
return nil , nil
62
71
}
63
72
@@ -131,7 +140,12 @@ func (p *punctuationTokenizer) Clone(tokens []string, state interface{}) ([]stri
131
140
132
141
type splittingTokenizer struct {}
133
142
134
- func (splittingTokenizer ) Tokenize (line string , tokens []string , state interface {}) ([]string , interface {}) {
143
+ func (splittingTokenizer ) Tokenize (
144
+ line string ,
145
+ tokens []string ,
146
+ state interface {},
147
+ _ * prometheus.CounterVec ,
148
+ ) ([]string , interface {}) {
135
149
numEquals := strings .Count (line , "=" )
136
150
numColons := strings .Count (line , ":" )
137
151
numSpaces := strings .Count (line , " " )
@@ -209,8 +223,16 @@ func newLogfmtTokenizer(varReplace string, maxLineLength int) *logfmtTokenizer {
209
223
}
210
224
}
211
225
212
- func (t * logfmtTokenizer ) Tokenize (line string , tokens []string , _ interface {}) ([]string , interface {}) {
226
+ func (t * logfmtTokenizer ) Tokenize (
227
+ line string ,
228
+ tokens []string ,
229
+ _ interface {},
230
+ linesDropped * prometheus.CounterVec ,
231
+ ) ([]string , interface {}) {
213
232
if len (line ) > t .maxLineLength {
233
+ if linesDropped != nil {
234
+ linesDropped .WithLabelValues (LineTooLong ).Inc ()
235
+ }
214
236
return nil , nil
215
237
}
216
238
@@ -277,7 +299,12 @@ func newJSONTokenizer(varReplace string, maxLineLength int, fieldsToTokenize []s
277
299
}
278
300
}
279
301
280
- func (t * jsonTokenizer ) Tokenize (line string , tokens []string , state interface {}) ([]string , interface {}) {
302
+ func (t * jsonTokenizer ) Tokenize (
303
+ line string ,
304
+ tokens []string ,
305
+ state interface {},
306
+ linesDropped * prometheus.CounterVec ,
307
+ ) ([]string , interface {}) {
281
308
var found []byte
282
309
for _ , key := range t .fieldsToTokenize {
283
310
msg , ty , _ , err := jsonparser .Get (unsafeBytes (line ), key )
@@ -297,7 +324,7 @@ func (t *jsonTokenizer) Tokenize(line string, tokens []string, state interface{}
297
324
return nil , nil
298
325
}
299
326
300
- return t .punctuationTokenizer .Tokenize (foundLine , tokens , state )
327
+ return t .punctuationTokenizer .Tokenize (foundLine , tokens , state , linesDropped )
301
328
}
302
329
303
330
func (t * jsonTokenizer ) Join (tokens []string , state interface {}) string {
0 commit comments