Skip to content

Commit 00098de

Browse files
committed
Merge branch 'master' of https://github.com/fstab/grok_exporter into kafka-tailer-integration
2 parents 3ed0af1 + 6d86abe commit 00098de

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

exporter/grok.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ func verifyFieldName(metricName string, template template.Template, regex *onigu
6666
return fmt.Errorf("%v: field name %v is ambigous, as this field is defined in the grok pattern but is also a global field provided by grok_exporter for the %v", metricName, grokFieldName, description)
6767
}
6868
} else {
69-
if !regex.HasCaptureGroup(grokFieldName) {
69+
numGroups := regex.NumberOfCaptureGroups(grokFieldName)
70+
if numGroups == 0 {
7071
return fmt.Errorf("%v: grok field %v not found in match pattern", metricName, grokFieldName)
72+
} else if numGroups > 1 {
73+
return fmt.Errorf("%v: grok field %v found %d times in match pattern: this is ambiguous, the pattern should define each grok field exactly once", metricName, grokFieldName, numGroups)
7174
}
7275
}
7376
}

oniguruma/oniguruma.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,15 @@ func (regex *Regex) Free() {
8383
}
8484

8585
func (regex *Regex) HasCaptureGroup(name string) bool {
86-
_, err := regex.getCaptureGroupNums(name)
87-
return err == nil
86+
return regex.NumberOfCaptureGroups(name) > 0
87+
}
88+
89+
func (regex *Regex) NumberOfCaptureGroups(name string) int {
90+
groups, err := regex.getCaptureGroupNums(name)
91+
if err != nil {
92+
return 0
93+
}
94+
return len(groups)
8895
}
8996

9097
func (r *Regex) getCaptureGroupNums(name string) ([]C.int, error) {

0 commit comments

Comments
 (0)