@@ 63,15 63,17 @@ var (
type Server struct {
Schema graphql.ExecutableSchema
- addr string
- conf ini.File
- db *sql.DB
- redis goRedis.UniversalClient
- root chi.Router
- router chi.Router
- service string
- queues []*work.Queue
- email *email.Queue
+ addr string
+ metricsAddr string
+ pprofAddr string
+ conf ini.File
+ db *sql.DB
+ redis goRedis.UniversalClient
+ root chi.Router
+ router chi.Router
+ service string
+ queues []*work.Queue
+ email *email.Queue
MaxComplexity int
}
@@ 81,8 83,10 @@ type Server struct {
// up the server and initializing the [crypto] subsystem.
func New(service, defaultAddr string, conf ini.File, args []string) *Server {
addr := defaultAddr
+ metricsAddr := ":0"
+ pprofAddr := "localhost:0"
- opts, _, err := getopt.Getopts(args, "b:d")
+ opts, _, err := getopt.Getopts(args, "b:dm:p:")
if err != nil {
panic(err)
}
@@ 93,6 97,10 @@ func New(service, defaultAddr string, conf ini.File, args []string) *Server {
addr = opt.Value
case 'd':
debug = true
+ case 'm':
+ metricsAddr = opt.Value
+ case 'p':
+ pprofAddr = opt.Value
}
}
@@ 100,11 108,13 @@ func New(service, defaultAddr string, conf ini.File, args []string) *Server {
root := chi.NewRouter()
server := &Server{
- addr: addr,
- conf: conf,
- root: root,
- router: root.Group(func(_ chi.Router) {}),
- service: service,
+ addr: addr,
+ metricsAddr: metricsAddr,
+ pprofAddr: pprofAddr,
+ conf: conf,
+ root: root,
+ router: root.Group(func(_ chi.Router) {}),
+ service: service,
}
return server
}
@@ 363,18 373,18 @@ func (server *Server) Run() {
mux := &http.ServeMux{}
mux.Handle("/metrics", promhttp.Handler())
pserver := &http.Server{Handler: mux}
- plisten, err := net.Listen("tcp", ":0")
+ plisten, err := net.Listen("tcp", server.metricsAddr)
if err != nil {
panic(err)
}
- log.Printf("Prometheus listening on :%d", plisten.Addr().(*net.TCPAddr).Port)
+ log.Printf("Prometheus listening on %s", plisten.Addr().String())
go pserver.Serve(plisten)
- pplisten, err := net.Listen("tcp", "localhost:0")
+ pplisten, err := net.Listen("tcp", server.pprofAddr)
if err != nil {
panic(err)
}
- log.Printf("pprof listening on :%d", pplisten.Addr().(*net.TCPAddr).Port)
+ log.Printf("pprof listening on %s", pplisten.Addr().String())
go http.Serve(pplisten, nil)
sig := make(chan os.Signal, 1)