forked from vieter-v/vieter
feat(server): ability to disable metrics
This commit is contained in:
parent
c0f58ddc77
commit
4ca2521937
6 changed files with 25 additions and 9 deletions
|
|
@ -3,14 +3,17 @@ module server
|
|||
import metrics
|
||||
import web
|
||||
|
||||
['/api/v1/metrics'; get]
|
||||
// v1_metrics serves a Prometheus-compatible metrics endpoint.
|
||||
['/api/v1/metrics'; get; markused]
|
||||
fn (mut app App) v1_metrics() web.Result {
|
||||
if !app.conf.collect_metrics {
|
||||
return app.status(.not_found)
|
||||
}
|
||||
|
||||
mut exporter := metrics.new_prometheus_exporter([0.01, 0.05, 0.1, 0.5, 1, 100])
|
||||
exporter.load(app.collector)
|
||||
|
||||
|
||||
// TODO stream to connection instead
|
||||
body := exporter.export_to_string() or {
|
||||
return app.status(.internal_server_error)
|
||||
}
|
||||
body := exporter.export_to_string() or { return app.status(.internal_server_error) }
|
||||
return app.body(.ok, 'text/plain', body)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ pub:
|
|||
base_image string = 'archlinux:base-devel'
|
||||
max_log_age int [empty_default]
|
||||
log_removal_schedule string = '0 0'
|
||||
collect_metrics bool [empty_default]
|
||||
}
|
||||
|
||||
// cmd returns the cli submodule that handles starting the server
|
||||
|
|
|
|||
|
|
@ -101,14 +101,20 @@ pub fn server(conf Config) ! {
|
|||
util.exit_with_message(1, 'Failed to initialize database: $err.msg()')
|
||||
}
|
||||
|
||||
collector := if conf.collect_metrics {
|
||||
&metrics.MetricsCollector(metrics.new_default_collector())
|
||||
} else {
|
||||
&metrics.MetricsCollector(metrics.new_null_collector())
|
||||
}
|
||||
|
||||
mut app := &App{
|
||||
logger: logger
|
||||
api_key: conf.api_key
|
||||
conf: conf
|
||||
repo: repo
|
||||
db: db
|
||||
collector: collector
|
||||
job_queue: build.new_job_queue(global_ce, conf.base_image)
|
||||
collector: metrics.new_default_collector()
|
||||
}
|
||||
app.init_job_queue() or {
|
||||
util.exit_with_message(1, 'Failed to inialize job queue: $err.msg()')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue