1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2026-01-02 17:07:02 +00:00

expvarom: Add EOF marker, and minor documentation updates

This patch adds the EOF marker as required by the new specification, and
also adds some links to it in the comments, as reference.
This commit is contained in:
Alberto Bertogli
2021-01-16 13:08:46 +00:00
parent 887a1cef68
commit 34b1f6cf21
2 changed files with 7 additions and 0 deletions

View File

@@ -13,6 +13,7 @@
//
// The exporter uses the text-based format, as documented in:
// https://prometheus.io/docs/instrumenting/exposition_formats/#text-based-format
// https://github.com/OpenObservability/OpenMetrics/blob/master/specification/OpenMetrics.md
//
// Note the adoption of that format as OpenMetrics' one isn't finalized yet,
// and it is possible that it will change in the future.
@@ -54,6 +55,10 @@ var (
func MetricsHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain; version=0.0.4")
// Update to this once it's standard and Prometheus and other ingesters
// can handle this.
//w.Header().Set("Content-Type", "application/openmetrics-text; version=1.0.0; charset=utf-8")
vars := []exportedVar{}
ignored := []string{}
expvar.Do(func(kv expvar.KeyValue) {
@@ -99,6 +104,7 @@ func MetricsHandler(w http.ResponseWriter, r *http.Request) {
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, "# EOF\n") // Mandated by the standard.
}
func writeVar(w io.Writer, v *exportedVar) {

View File

@@ -73,6 +73,7 @@ testMXI{key="key3"} 7
# Generated by expvarom
# EXPERIMENTAL - Format is not fully standard yet
# Ignored variables: ["cmdline" "memstats" "testS"]
# EOF
`
func TestHandler(t *testing.T) {