@@ -7,13 +7,13 @@ import (
77 "encoding/json"
88 "errors"
99 "fmt"
10- "github.com/dunglas/frankenphp/internal/fastabs"
11- "github.com/prometheus/client_golang/prometheus"
1210 "net/http"
1311 "path/filepath"
1412 "strconv"
1513 "strings"
1614
15+ "github.com/dunglas/frankenphp/internal/fastabs"
16+
1717 "github.com/caddyserver/caddy/v2"
1818 "github.com/caddyserver/caddy/v2/caddyconfig"
1919 "github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
@@ -40,8 +40,6 @@ func init() {
4040 httpcaddyfile .RegisterDirectiveOrder ("php_server" , "before" , "file_server" )
4141}
4242
43- var metrics = frankenphp .NewPrometheusMetrics (prometheus .DefaultRegisterer )
44-
4543type workerConfig struct {
4644 // FileName sets the path to the worker script.
4745 FileName string `json:"file_name,omitempty"`
@@ -58,6 +56,8 @@ type FrankenPHPApp struct {
5856 NumThreads int `json:"num_threads,omitempty"`
5957 // Workers configures the worker scripts to start.
6058 Workers []workerConfig `json:"workers,omitempty"`
59+
60+ metrics frankenphp.Metrics
6161}
6262
6363// CaddyModule returns the Caddy module information.
@@ -68,11 +68,18 @@ func (f FrankenPHPApp) CaddyModule() caddy.ModuleInfo {
6868 }
6969}
7070
71+ // Provision sets up the module.
72+ func (f * FrankenPHPApp ) Provision (ctx caddy.Context ) error {
73+ f .metrics = frankenphp .NewPrometheusMetrics (ctx .GetMetricsRegistry ())
74+
75+ return nil
76+ }
77+
7178func (f * FrankenPHPApp ) Start () error {
7279 repl := caddy .NewReplacer ()
7380 logger := caddy .Log ()
7481
75- opts := []frankenphp.Option {frankenphp .WithNumThreads (f .NumThreads ), frankenphp .WithLogger (logger ), frankenphp .WithMetrics (metrics )}
82+ opts := []frankenphp.Option {frankenphp .WithNumThreads (f .NumThreads ), frankenphp .WithLogger (logger ), frankenphp .WithMetrics (f . metrics )}
7683 for _ , w := range f .Workers {
7784 opts = append (opts , frankenphp .WithWorkers (repl .ReplaceKnown (w .FileName , "" ), w .Num , w .Env , w .Watch ))
7885 }
@@ -671,6 +678,7 @@ func parsePhpServer(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error)
671678// Interface guards
672679var (
673680 _ caddy.App = (* FrankenPHPApp )(nil )
681+ _ caddy.Provisioner = (* FrankenPHPApp )(nil )
674682 _ caddy.Provisioner = (* FrankenPHPModule )(nil )
675683 _ caddyhttp.MiddlewareHandler = (* FrankenPHPModule )(nil )
676684 _ caddyfile.Unmarshaler = (* FrankenPHPModule )(nil )
0 commit comments