Skip to content

Commit e23598d

Browse files
authored
fix: Dedup pattern tokens on output (#13534)
1 parent 5fa9c4b commit e23598d

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

pkg/pattern/drain/drain.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ func New(config *Config, format string, metrics *Metrics) *Drain {
158158
default:
159159
tokenizer = newPunctuationTokenizer()
160160
}
161+
161162
d.idToCluster = createLogClusterCache(config.MaxClusters, func(int, *LogCluster) {
162163
if metrics != nil {
163164
if d.pruning {
@@ -170,7 +171,10 @@ func New(config *Config, format string, metrics *Metrics) *Drain {
170171
limiter.Evict()
171172
}
172173
})
173-
d.tokenizer = tokenizer
174+
d.tokenizer = &DedupingTokenizer{
175+
LineTokenizer: tokenizer,
176+
dedupParam: config.ParamString,
177+
}
174178
d.limiter = limiter
175179
return d
176180
}
@@ -297,14 +301,6 @@ func deduplicatePlaceholders(line string, placeholder string) string {
297301
return unsafeString(builder)
298302
}
299303

300-
func (d *Drain) PatternString(c *LogCluster) string {
301-
s := deduplicatePlaceholders(d.tokenizer.Join(c.Tokens, c.TokenState), d.config.ParamString)
302-
if s == d.config.ParamString {
303-
return ""
304-
}
305-
return s
306-
}
307-
308304
func (d *Drain) Prune() {
309305
d.pruneTree(d.rootNode)
310306
}

pkg/pattern/drain/drain_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ func TestDrain_TrainExtractsPatterns(t *testing.T) {
260260
`I0507 <_> 1 defaultevictor.go:202] "Pod fails the following checks" pod="<_>" checks="[pod is a mirror pod, pod is a static pod, pod has system critical priority, pod has higher priority than specified priority class threshold, pod has local storage and descheduler is not configured with evictLocalStoragePods]"`,
261261
`I0507 <_> 1 defaultevictor.go:202] "Pod fails the following checks" pod="<_>" checks="pod has local storage and descheduler is not configured with evictLocalStoragePods"`,
262262
`I0507 <_> 1 defaultevictor.go:202] "Pod fails the following checks" pod="<_>" checks="pod is a DaemonSet pod"`,
263-
`I0507 <_> 1 node.go:157] "Pod does not fit on any other node" pod:="<_>" node:="<_>" error:="[pod node selector does not match the node label, <_> <_><_> <_> <_><_> <_> <_>]"`,
263+
`I0507 <_> 1 node.go:157] "Pod does not fit on any other node" pod:="<_>" node:="<_>" error:="[pod node selector does not match the node label, <_> <_> <_> <_> <_> <_>]"`,
264264
`I0507 <_> 1 node.go:157] "Pod does not fit on any other node" pod:="<_>" node:="<_>" error:="[pod node selector does not match the node label, insufficient <_>, insufficient <_>]"`,
265265
`I0507 <_> 1 node.go:157] "Pod does not fit on any other node" pod:="<_>" node:="<_>" error:="[pod node selector does not match the node label, insufficient <_>]"`,
266266
`I0507 <_> 1 node.go:157] "Pod does not fit on any other node" pod:="<_>" node:="<_>" error:="[pod node selector does not match the node label, pod does not tolerate taints on the node, insufficient <_>, insufficient <_>]"`,

pkg/pattern/drain/line_tokenizer.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,12 @@ func isVariableField(key []byte) bool {
286286
bytes.EqualFold(key, []byte("time")) ||
287287
bytes.EqualFold(key, []byte("timestamp"))
288288
}
289+
290+
type DedupingTokenizer struct {
291+
LineTokenizer
292+
dedupParam string
293+
}
294+
295+
func (d DedupingTokenizer) Join(tokens []string, state interface{}) string {
296+
return deduplicatePlaceholders(d.LineTokenizer.Join(tokens, state), d.dedupParam)
297+
}

0 commit comments

Comments
 (0)