fix(inputs.influxdb_listener): error on invalid precision (#11866)

This commit is contained in:
Joshua Powers 2022-10-03 07:23:06 -06:00 committed by GitHub
parent 53175321e0
commit 173d32a201
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -371,7 +371,14 @@ func (h *InfluxDBListener) handleWriteUpstreamParser(res http.ResponseWriter, re
precisionStr := req.URL.Query().Get("precision") precisionStr := req.URL.Query().Get("precision")
if precisionStr != "" { if precisionStr != "" {
precision := getPrecisionMultiplier(precisionStr) precision := getPrecisionMultiplier(precisionStr)
parser.SetTimePrecision(precision) err := parser.SetTimePrecision(precision)
if err != nil {
h.Log.Debugf("error in upstream parser: %v", err)
if err := badRequest(res, err.Error()); err != nil {
h.Log.Debugf("error in bad-request: %v", err)
}
return
}
} }
if req.ContentLength >= 0 { if req.ContentLength >= 0 {

View File

@ -226,7 +226,7 @@ func (sp *StreamParser) SetTimeFunc(f TimeFunc) {
sp.defaultTime = f sp.defaultTime = f
} }
func (sp *StreamParser) SetTimePrecision(u time.Duration) { func (sp *StreamParser) SetTimePrecision(u time.Duration) error {
switch u { switch u {
case time.Nanosecond: case time.Nanosecond:
sp.precision = lineprotocol.Nanosecond sp.precision = lineprotocol.Nanosecond
@ -236,7 +236,13 @@ func (sp *StreamParser) SetTimePrecision(u time.Duration) {
sp.precision = lineprotocol.Millisecond sp.precision = lineprotocol.Millisecond
case time.Second: case time.Second:
sp.precision = lineprotocol.Second sp.precision = lineprotocol.Second
case time.Minute:
return fmt.Errorf("time precision 'm' is not supported")
case time.Hour:
return fmt.Errorf("time precision 'h' is not supported")
} }
return nil
} }
// Next parses the next item from the stream. You can repeat calls to this // Next parses the next item from the stream. You can repeat calls to this