mirror of
https://blitiri.com.ar/repos/chasquid
synced 2026-02-02 21:45:55 +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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,24 +36,16 @@ var (
|
||||
)
|
||||
|
||||
const expected string = `_ame_5 5
|
||||
|
||||
i3name 3
|
||||
|
||||
nAme_4Z 4
|
||||
|
||||
name_1z 1
|
||||
|
||||
# HELP name_2 name with $
|
||||
name_2 2
|
||||
|
||||
# HELP testF float test var
|
||||
testF 3.43434
|
||||
|
||||
# HELP testI1 int test var
|
||||
testI1 1
|
||||
|
||||
testI2 2
|
||||
|
||||
# HELP testMF float map test var
|
||||
testMF{label="key2.0"} 6.6
|
||||
testMF{label="key2.1"} 6.61
|
||||
@@ -63,17 +55,12 @@ testMF{label="key2.4- "} 6.64
|
||||
testMF{label="key2.5-a\nb"} 6.65
|
||||
testMF{label="key2.6-a\"b"} 6.66
|
||||
testMF{label="key2.7-\\u00f1aca-A\\t\\xff\\xfe\\xfdB"} 6.67
|
||||
|
||||
# HELP testMI int map test var
|
||||
testMI{label="key1"} 5
|
||||
|
||||
testMXF{key="key4"} 8e-08
|
||||
|
||||
testMXI{key="key3"} 7
|
||||
|
||||
# Generated by expvarom
|
||||
# EXPERIMENTAL - Format is not fully standard yet
|
||||
# Ignored variables: ["cmdline" "memstats" "testS"]
|
||||
# HELP generated_by expvarom
|
||||
# HELP ignored_variables ["cmdline" "memstats" "testS"]
|
||||
# EOF
|
||||
`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user