metrics: Prometheus text exposition for /metrics
/metrics was Prometheus-ish name/value text with a custom banner and text/plain Content-Type, so strict scrapers could fail. Emit Prometheus text 0.0.4 (# HELP, # TYPE, counter|gauge) with stable metric names, and set Content-Type to text/plain; version=0.0.4; charset=utf-8.
This commit is contained in:
@@ -61,6 +61,9 @@ func TestNegativeCache404(t *testing.T) {
|
||||
if !bytes.Contains(mrec.Body.Bytes(), []byte("negative_cache_hits")) {
|
||||
t.Errorf("/metrics missing negative_cache_hits:\n%s", mrec.Body.String())
|
||||
}
|
||||
if ct := mrec.Header().Get("Content-Type"); ct != "text/plain; version=0.0.4; charset=utf-8" {
|
||||
t.Errorf("/metrics Content-Type=%q, want Prometheus text 0.0.4", ct)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNegativeCache410(t *testing.T) {
|
||||
@@ -207,4 +210,13 @@ func TestWriteTextNegativeCacheHits(t *testing.T) {
|
||||
if !bytes.Contains(out, []byte("negative_cache_hits 0\n")) {
|
||||
t.Errorf("/metrics missing negative_cache_hits 0:\n%s", out)
|
||||
}
|
||||
if ct := resp.Header.Get("Content-Type"); ct != "text/plain; version=0.0.4; charset=utf-8" {
|
||||
t.Errorf("/metrics Content-Type=%q, want Prometheus text 0.0.4", ct)
|
||||
}
|
||||
if !bytes.Contains(out, []byte("# HELP negative_cache_hits ")) {
|
||||
t.Errorf("/metrics missing # HELP negative_cache_hits:\n%s", out)
|
||||
}
|
||||
if !bytes.Contains(out, []byte("# TYPE negative_cache_hits counter")) {
|
||||
t.Errorf("/metrics missing # TYPE negative_cache_hits counter:\n%s", out)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user