mirror of
https://github.com/caddyserver/caddy.git
synced 2025-05-23 19:10:03 +08:00
metrics: scope metrics to active config, add optional per-host metrics (#6531)
* Add per host config * Pass host label when option is enabled * Test per host enabled * metrics: scope metrics per loaded config * doc and linter Signed-off-by: Mohammed Al Sahaf <msaa1990@gmail.com> * inject the custom registry into the admin handler Co-Authored-By: Dave Henderson <dhenderson@gmail.com> * remove `TODO` comment * fixes Signed-off-by: Mohammed Al Sahaf <msaa1990@gmail.com> * refactor to delay metrics admin handler provision Signed-off-by: Mohammed Al Sahaf <msaa1990@gmail.com> --------- Signed-off-by: Mohammed Al Sahaf <msaa1990@gmail.com> Co-authored-by: Hussam Almarzooq <me@hussam.io> Co-authored-by: Dave Henderson <dhenderson@gmail.com>
This commit is contained in:

committed by
GitHub

parent
16724842d9
commit
41f5dd56e1
9
caddy.go
9
caddy.go
@ -399,6 +399,7 @@ func unsyncedDecodeAndRun(cfgJSON []byte, allowPersist bool) error {
|
||||
func run(newCfg *Config, start bool) (Context, error) {
|
||||
ctx, err := provisionContext(newCfg, start)
|
||||
if err != nil {
|
||||
globalMetrics.configSuccess.Set(0)
|
||||
return ctx, err
|
||||
}
|
||||
|
||||
@ -410,6 +411,7 @@ func run(newCfg *Config, start bool) (Context, error) {
|
||||
// some of the other apps at runtime
|
||||
err = ctx.cfg.Admin.provisionAdminRouters(ctx)
|
||||
if err != nil {
|
||||
globalMetrics.configSuccess.Set(0)
|
||||
return ctx, err
|
||||
}
|
||||
|
||||
@ -435,9 +437,11 @@ func run(newCfg *Config, start bool) (Context, error) {
|
||||
return nil
|
||||
}()
|
||||
if err != nil {
|
||||
globalMetrics.configSuccess.Set(0)
|
||||
return ctx, err
|
||||
}
|
||||
|
||||
globalMetrics.configSuccess.Set(1)
|
||||
globalMetrics.configSuccessTime.SetToCurrentTime()
|
||||
// now that the user's config is running, finish setting up anything else,
|
||||
// such as remote admin endpoint, config loader, etc.
|
||||
return ctx, finishSettingUp(ctx, ctx.cfg)
|
||||
@ -471,6 +475,7 @@ func provisionContext(newCfg *Config, replaceAdminServer bool) (Context, error)
|
||||
ctx, cancel := NewContext(Context{Context: context.Background(), cfg: newCfg})
|
||||
defer func() {
|
||||
if err != nil {
|
||||
globalMetrics.configSuccess.Set(0)
|
||||
// if there were any errors during startup,
|
||||
// we should cancel the new context we created
|
||||
// since the associated config won't be used;
|
||||
@ -497,7 +502,7 @@ func provisionContext(newCfg *Config, replaceAdminServer bool) (Context, error)
|
||||
|
||||
// start the admin endpoint (and stop any prior one)
|
||||
if replaceAdminServer {
|
||||
err = replaceLocalAdminServer(newCfg)
|
||||
err = replaceLocalAdminServer(newCfg, ctx)
|
||||
if err != nil {
|
||||
return ctx, fmt.Errorf("starting caddy administration endpoint: %v", err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user