fix(parsers.prometheus): Do not touch input data for protocol-buffers (#14606)
This commit is contained in:
parent
98cd14987a
commit
57021be82c
|
|
@ -26,19 +26,20 @@ func (p *Parser) SetDefaultTags(tags map[string]string) {
|
|||
}
|
||||
|
||||
func (p *Parser) Parse(data []byte) ([]telegraf.Metric, error) {
|
||||
// Make sure we have a finishing newline but no trailing one
|
||||
data = bytes.TrimPrefix(data, []byte("\n"))
|
||||
if !bytes.HasSuffix(data, []byte("\n")) {
|
||||
data = append(data, []byte("\n")...)
|
||||
}
|
||||
buf := bytes.NewBuffer(data)
|
||||
|
||||
// Determine the metric transport-type derived from the response header and
|
||||
// create a matching decoder.
|
||||
format := expfmt.ResponseFormat(p.Header)
|
||||
if format == expfmt.FmtUnknown {
|
||||
switch format {
|
||||
case expfmt.FmtProtoText:
|
||||
// Make sure we have a finishing newline but no trailing one
|
||||
data = bytes.TrimPrefix(data, []byte("\n"))
|
||||
if !bytes.HasSuffix(data, []byte("\n")) {
|
||||
data = append(data, []byte("\n")...)
|
||||
}
|
||||
case expfmt.FmtUnknown:
|
||||
p.Log.Warnf("Unknown format %q... Trying to continue...", p.Header.Get("Content-Type"))
|
||||
}
|
||||
buf := bytes.NewBuffer(data)
|
||||
decoder := expfmt.NewDecoder(buf, format)
|
||||
|
||||
// Decode the input data into prometheus metrics
|
||||
|
|
|
|||
Loading…
Reference in New Issue