mirror of
https://blitiri.com.ar/repos/chasquid
synced 2026-02-06 22:25:54 +00:00
expvarom: Remove empty newlines and comments to conform to stricter parsing
The openmetrics format doesn't support empty newlines or miscellaneous comments, and the Prometheus parser has become more strict over time, which is now causing scraping errors. This patch fixes those issues by adjusting to the stricter openmetrics format. Thanks to Jakub Ječmínek for reporting this issue!
This commit is contained in:
@@ -98,9 +98,8 @@ func MetricsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
writeVar(w, &v)
|
||||
}
|
||||
|
||||
fmt.Fprintf(w, "# Generated by expvarom\n")
|
||||
fmt.Fprintf(w, "# EXPERIMENTAL - Format is not fully standard yet\n")
|
||||
fmt.Fprintf(w, "# Ignored variables: %q\n", ignored)
|
||||
fmt.Fprintf(w, "# HELP generated_by expvarom\n")
|
||||
fmt.Fprintf(w, "# HELP ignored_variables %q\n", ignored)
|
||||
fmt.Fprintf(w, "# EOF\n") // Mandated by the standard.
|
||||
}
|
||||
|
||||
@@ -110,12 +109,12 @@ func writeVar(w io.Writer, v *exportedVar) {
|
||||
}
|
||||
|
||||
if v.I != nil {
|
||||
fmt.Fprintf(w, "%s %d\n\n", v.Name, v.I.Value())
|
||||
fmt.Fprintf(w, "%s %d\n", v.Name, v.I.Value())
|
||||
return
|
||||
}
|
||||
|
||||
if v.F != nil {
|
||||
fmt.Fprintf(w, "%s %g\n\n", v.Name, v.F.Value())
|
||||
fmt.Fprintf(w, "%s %g\n", v.Name, v.F.Value())
|
||||
return
|
||||
}
|
||||
|
||||
@@ -139,9 +138,6 @@ func writeVar(w io.Writer, v *exportedVar) {
|
||||
v.Name, v.LabelName, labelValue, vs)
|
||||
count++
|
||||
})
|
||||
if count > 0 {
|
||||
fmt.Fprintf(w, "\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user