Fix precision truncation when no timestamp included (#3961)

This commit is contained in:
Daniel Nelson
2018-04-02 14:32:33 -07:00
committed by GitHub
parent 9d2f3fcbb9
commit bcaaeda49c
5 changed files with 97 additions and 11 deletions

View File

@@ -10,13 +10,15 @@ type TimeFunc func() time.Time
type Builder struct {
TimeFunc
TimePrecision time.Duration
*metric
}
func NewBuilder() *Builder {
b := &Builder{
TimeFunc: time.Now,
TimeFunc: time.Now,
TimePrecision: 1 * time.Nanosecond,
}
b.Reset()
return b
@@ -44,7 +46,7 @@ func (b *Builder) Reset() {
func (b *Builder) Metric() (telegraf.Metric, error) {
if b.tm.IsZero() {
b.tm = b.TimeFunc()
b.tm = b.TimeFunc().Truncate(b.TimePrecision)
}
return b.metric, nil