feat(metrics): publish the collector and a transformer to serve it
The transformer is exported instead of a route: the path, the auth and whether the endpoint exists are the application's decisions, and a plugin that mounted /metrics itself would be taking them. No onShutdown — a bus subscription is an entry in a set and keeps nothing alive, which is what rule 7 asks about. Closes green-tea#68. Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
3 files changed
+119
No files matched your search
@@ -0,0 +1,22 @@
|
||||
import type { TransformerFn } from '@green-tea/core';
|
||||
|
||||
/**
|
||||
* Serves a rendered scrape as the Prometheus text exposition format.
|
||||
*
|
||||
* A `TransformerFn` rather than a route: the path, the auth and whether the endpoint exists at all
|
||||
* are the application's decisions, and a plugin that mounted `/metrics` itself would be taking them.
|
||||
* The version is part of the content type — Prometheus reads it, and omitting it makes a scrape fall
|
||||
* back to a guess.
|
||||
*
|
||||
* @example
|
||||
* @Get('/metrics')
|
||||
* @Transformer(prometheus)
|
||||
* scrape(@needs('metrics') collector: Metrics) {
|
||||
* return collector.render();
|
||||
* }
|
||||
*/
|
||||
export const prometheus: TransformerFn = (value) => ({
|
||||
status: 200,
|
||||
headers: { 'content-type': 'text/plain; version=0.0.4; charset=utf-8' },
|
||||
body: String(value),
|
||||
});
|
||||
Reference in new issue
Block a user