mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 10:06:24 +05:00
Add http pprof_path cfg option
This commit is contained in:
committed by
Dan Christian Bogos
parent
73fc386036
commit
594e8404dc
@@ -201,7 +201,7 @@ func (s *Server) RegisterProfiler() {
|
||||
registerProfiler(s.httpsMux)
|
||||
}
|
||||
|
||||
func (s *Server) ServeHTTP(addr, jsonRPCURL, wsRPCURL, promURL string, useBasicAuth bool,
|
||||
func (s *Server) ServeHTTP(addr, jsonRPCURL, wsRPCURL, promURL, pprofPath string, useBasicAuth bool,
|
||||
userList map[string]string, shdChan *utils.SyncedChan) {
|
||||
s.RLock()
|
||||
enabled := s.rpcEnabled
|
||||
@@ -237,7 +237,7 @@ func (s *Server) ServeHTTP(addr, jsonRPCURL, wsRPCURL, promURL string, useBasicA
|
||||
s.Lock()
|
||||
s.httpEnabled = true
|
||||
s.Unlock()
|
||||
utils.Logger.Info("<HTTP> enabling handler for Prometheus connections")
|
||||
utils.Logger.Info(fmt.Sprintf("<HTTP> prometheus metrics endpoint registered at %q", promURL))
|
||||
promHandler := promhttp.Handler()
|
||||
if useBasicAuth {
|
||||
s.httpMux.HandleFunc(promURL, use(promHandler.ServeHTTP, basicAuth(userList)))
|
||||
@@ -245,6 +245,28 @@ func (s *Server) ServeHTTP(addr, jsonRPCURL, wsRPCURL, promURL string, useBasicA
|
||||
s.httpMux.Handle(promURL, promHandler)
|
||||
}
|
||||
}
|
||||
if pprofPath != "" {
|
||||
s.Lock()
|
||||
s.httpEnabled = true
|
||||
s.Unlock()
|
||||
if !strings.HasSuffix(pprofPath, "/") {
|
||||
pprofPath += "/"
|
||||
}
|
||||
utils.Logger.Info(fmt.Sprintf("<HTTP> profiling endpoints registered at %q", pprofPath))
|
||||
if useBasicAuth {
|
||||
s.httpMux.HandleFunc(pprofPath, use(pprof.Index, basicAuth(userList)))
|
||||
s.httpMux.HandleFunc(pprofPath+"cmdline", use(pprof.Cmdline, basicAuth(userList)))
|
||||
s.httpMux.HandleFunc(pprofPath+"profile", use(pprof.Profile, basicAuth(userList)))
|
||||
s.httpMux.HandleFunc(pprofPath+"symbol", use(pprof.Symbol, basicAuth(userList)))
|
||||
s.httpMux.HandleFunc(pprofPath+"trace", use(pprof.Trace, basicAuth(userList)))
|
||||
} else {
|
||||
s.httpMux.HandleFunc(pprofPath, pprof.Index)
|
||||
s.httpMux.HandleFunc(pprofPath+"cmdline", pprof.Cmdline)
|
||||
s.httpMux.HandleFunc(pprofPath+"profile", pprof.Profile)
|
||||
s.httpMux.HandleFunc(pprofPath+"symbol", pprof.Symbol)
|
||||
s.httpMux.HandleFunc(pprofPath+"trace", pprof.Trace)
|
||||
}
|
||||
}
|
||||
if !s.httpEnabled {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -211,6 +211,7 @@ func testServeHHTPPass(t *testing.T) {
|
||||
cfg.HTTPCfg().HTTPJsonRPCURL,
|
||||
cfg.HTTPCfg().HTTPWSURL,
|
||||
cfg.HTTPCfg().PrometheusURL,
|
||||
cfg.HTTPCfg().PprofPath,
|
||||
cfg.HTTPCfg().HTTPUseBasicAuth,
|
||||
cfg.HTTPCfg().HTTPAuthUsers,
|
||||
shdChan)
|
||||
@@ -233,6 +234,7 @@ func testServeHHTPPassUseBasicAuth(t *testing.T) {
|
||||
cfg.HTTPCfg().HTTPJsonRPCURL,
|
||||
cfg.HTTPCfg().HTTPWSURL,
|
||||
cfg.HTTPCfg().PrometheusURL,
|
||||
cfg.HTTPCfg().PprofPath,
|
||||
!cfg.HTTPCfg().HTTPUseBasicAuth,
|
||||
cfg.HTTPCfg().HTTPAuthUsers,
|
||||
shdChan)
|
||||
@@ -255,6 +257,7 @@ func testServeHHTPEnableHttp(t *testing.T) {
|
||||
utils.EmptyString,
|
||||
utils.EmptyString,
|
||||
utils.EmptyString,
|
||||
utils.EmptyString,
|
||||
!cfg.HTTPCfg().HTTPUseBasicAuth,
|
||||
cfg.HTTPCfg().HTTPAuthUsers,
|
||||
shdChan)
|
||||
@@ -277,6 +280,7 @@ func testServeHHTPFail(t *testing.T) {
|
||||
cfg.HTTPCfg().HTTPJsonRPCURL,
|
||||
cfg.HTTPCfg().HTTPWSURL,
|
||||
cfg.HTTPCfg().PrometheusURL,
|
||||
cfg.HTTPCfg().PprofPath,
|
||||
cfg.HTTPCfg().HTTPUseBasicAuth,
|
||||
cfg.HTTPCfg().HTTPAuthUsers,
|
||||
shdChan)
|
||||
@@ -302,6 +306,7 @@ func testServeHHTPFailEnableRpc(t *testing.T) {
|
||||
cfg.HTTPCfg().HTTPJsonRPCURL,
|
||||
cfg.HTTPCfg().HTTPWSURL,
|
||||
cfg.HTTPCfg().PrometheusURL,
|
||||
cfg.HTTPCfg().PprofPath,
|
||||
cfg.HTTPCfg().HTTPUseBasicAuth,
|
||||
cfg.HTTPCfg().HTTPAuthUsers,
|
||||
shdChan)
|
||||
|
||||
Reference in New Issue
Block a user