From 34b1f6cf21693b61945022021c354d0e4408a74d Mon Sep 17 00:00:00 2001 From: Alberto Bertogli Date: Sat, 16 Jan 2021 13:08:46 +0000 Subject: [PATCH] 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. --- internal/expvarom/expvarom.go | 6 ++++++ internal/expvarom/expvarom_test.go | 1 + 2 files changed, 7 insertions(+) diff --git a/internal/expvarom/expvarom.go b/internal/expvarom/expvarom.go index 1d02fd7..d9d00a4 100644 --- a/internal/expvarom/expvarom.go +++ b/internal/expvarom/expvarom.go @@ -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) { diff --git a/internal/expvarom/expvarom_test.go b/internal/expvarom/expvarom_test.go index 4ce3c1e..511ce97 100644 --- a/internal/expvarom/expvarom_test.go +++ b/internal/expvarom/expvarom_test.go @@ -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) {