Fix cleanup of csv parser options, use per file parser (#4712)

This commit is contained in:
Daniel Nelson
2018-09-18 09:23:45 -07:00
committed by GitHub
parent 1d76343422
commit b5299f4cc4
7 changed files with 160 additions and 53 deletions

View File

@@ -26,6 +26,11 @@ type Parser struct {
TimestampColumn string
TimestampFormat string
DefaultTags map[string]string
TimeFunc func() time.Time
}
func (p *Parser) SetTimeFunc(fn metric.TimeFunc) {
p.TimeFunc = fn
}
func (p *Parser) compile(r *bytes.Reader) (*csv.Reader, error) {
@@ -167,7 +172,7 @@ outer:
measurementName = fmt.Sprintf("%v", recordFields[p.MeasurementColumn])
}
metricTime := time.Now()
metricTime := p.TimeFunc()
if p.TimestampColumn != "" {
if recordFields[p.TimestampColumn] == nil {
return nil, fmt.Errorf("timestamp column: %v could not be found", p.TimestampColumn)