Add option to disable timestamp adjustment in grok parser (#5488)
This commit is contained in:
@@ -86,6 +86,9 @@ type Parser struct {
|
||||
Timezone string
|
||||
loc *time.Location
|
||||
|
||||
// UniqueTimestamp when set to "disable", timestamp will not incremented if there is a duplicate.
|
||||
UniqueTimestamp string
|
||||
|
||||
// typeMap is a map of patterns -> capture name -> modifier,
|
||||
// ie, {
|
||||
// "%{TESTLOG}":
|
||||
@@ -134,6 +137,10 @@ func (p *Parser) Compile() error {
|
||||
return err
|
||||
}
|
||||
|
||||
if p.UniqueTimestamp == "" {
|
||||
p.UniqueTimestamp = "auto"
|
||||
}
|
||||
|
||||
// Give Patterns fake names so that they can be treated as named
|
||||
// "custom patterns"
|
||||
p.NamedPatterns = make([]string, 0, len(p.Patterns))
|
||||
@@ -358,6 +365,10 @@ func (p *Parser) ParseLine(line string) (telegraf.Metric, error) {
|
||||
return nil, fmt.Errorf("grok: must have one or more fields")
|
||||
}
|
||||
|
||||
if p.UniqueTimestamp != "auto" {
|
||||
return metric.New(p.Measurement, tags, fields, timestamp)
|
||||
}
|
||||
|
||||
return metric.New(p.Measurement, tags, fields, p.tsModder.tsMod(timestamp))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user