Support outputting docstrings

This commit is contained in:
Christopher Baines 2020-11-29 08:49:46 +00:00
parent 8980f39baf
commit 826704723a

View file

@ -367,30 +367,42 @@ so that it can receive and store the metric values."
(hash-for-each
(lambda (name metric)
(hash-for-each
(lambda (label-values value)
(simple-format
port
"~A~A~A ~A\n"
(or (and=> (metrics-registry-namespace registry)
(lambda (namespace)
(string-append namespace "_")))
"")
name
(if (null? label-values)
""
(string-append
"{"
(string-join (map
(match-lambda
((label . value)
(simple-format
#f
"~A=\"~A\""
label value)))
label-values)
",")
"}"))
value))
(metric-values metric)))
(let ((full-name
(string-append
(or (and=> (metrics-registry-namespace registry)
(lambda (namespace)
(string-append namespace "_")))
"")
name)))
(and=> (metric-docstring metric)
(lambda (docstring)
(simple-format
port
"# HELP ~A ~A\n"
full-name
docstring)))
(hash-for-each
(lambda (label-values value)
(simple-format
port
"~A~A ~A\n"
full-name
(if (null? label-values)
""
(string-append
"{"
(string-join (map
(match-lambda
((label . value)
(simple-format
#f
"~A=\"~A\""
label value)))
label-values)
",")
"}"))
value))
(metric-values metric))))
(metrics-registry-metrics-hash registry)))