Add http pprof_path cfg option

Remove redundant http_pprof cgr-engine flag since runtime profiling is now
configurable within the http cfg section and is enabled by default
This commit is contained in:
ionutboangiu
2024-10-31 13:46:09 +02:00
committed by Dan Christian Bogos
parent c7dbcaea03
commit ce856c7815
12 changed files with 136 additions and 115 deletions

View File

@@ -232,6 +232,7 @@ const CGRATES_CFG_JSON = `
"ws_url": "/ws", // WebSockets relative URL ("" to disable)
"freeswitch_cdrs_url": "/freeswitch_json", // Freeswitch CDRS relative URL ("" to disable)
"http_cdrs": "/cdr_http", // CDRS relative URL ("" to disable)
"pprof_path": "/debug/pprof/", // endpoint for serving runtime profiling data for pprof visualization
"use_basic_auth": false, // use basic authentication
"auth_users": {}, // basic authentication usernames and base64-encoded passwords (eg: { "username1": "cGFzc3dvcmQ=", "username2": "cGFzc3dvcmQy "})
"client_opts":{

View File

@@ -1785,15 +1785,16 @@ func TestDfSureTaxJsonCfg(t *testing.T) {
func TestDfHttpJsonCfg(t *testing.T) {
eCfg := &HTTPJsonCfg{
Json_rpc_url: utils.StringPointer("/jsonrpc"),
Registrars_url: utils.StringPointer("/registrar"),
Prometheus_url: utils.StringPointer("/prometheus"),
Ws_url: utils.StringPointer("/ws"),
Freeswitch_cdrs_url: utils.StringPointer("/freeswitch_json"),
Http_Cdrs: utils.StringPointer("/cdr_http"),
Use_basic_auth: utils.BoolPointer(false),
Auth_users: utils.MapStringStringPointer(map[string]string{}),
Client_opts: &HTTPClientOptsJson{
JSONRPCURL: utils.StringPointer("/jsonrpc"),
RegistrarsURL: utils.StringPointer("/registrar"),
PrometheusURL: utils.StringPointer("/prometheus"),
WSURL: utils.StringPointer("/ws"),
FreeswitchCDRsURL: utils.StringPointer("/freeswitch_json"),
HTTPCDRs: utils.StringPointer("/cdr_http"),
PprofPath: utils.StringPointer("/debug/pprof/"),
UseBasicAuth: utils.BoolPointer(false),
AuthUsers: utils.MapStringStringPointer(map[string]string{}),
ClientOpts: &HTTPClientOptsJson{
SkipTLSVerification: utils.BoolPointer(false),
TLSHandshakeTimeout: utils.StringPointer("10s"),
DisableKeepAlives: utils.BoolPointer(false),

File diff suppressed because one or more lines are too long

View File

@@ -35,6 +35,7 @@ type HTTPCfg struct {
WSURL string // WebSocket relative URL ("" to disable)
FreeswitchCDRsURL string // Freeswitch CDRS relative URL ("" to disable)
CDRsURL string // CDRS relative URL ("" to disable)
PprofPath string // runtime profiling url path ("" to disable)
UseBasicAuth bool // Use basic auth for HTTP API
AuthUsers map[string]string // Basic auth user:password map (base64 passwords)
ClientOpts *http.Transport
@@ -128,35 +129,38 @@ func (httpcfg *HTTPCfg) loadFromJSONCfg(jsnHTTPCfg *HTTPJsonCfg) (err error) {
if jsnHTTPCfg == nil {
return
}
if jsnHTTPCfg.Json_rpc_url != nil {
httpcfg.JsonRPCURL = *jsnHTTPCfg.Json_rpc_url
if jsnHTTPCfg.JSONRPCURL != nil {
httpcfg.JsonRPCURL = *jsnHTTPCfg.JSONRPCURL
}
if jsnHTTPCfg.Registrars_url != nil {
httpcfg.RegistrarSURL = *jsnHTTPCfg.Registrars_url
if jsnHTTPCfg.RegistrarsURL != nil {
httpcfg.RegistrarSURL = *jsnHTTPCfg.RegistrarsURL
}
if jsnHTTPCfg.Prometheus_url != nil {
httpcfg.PrometheusURL = *jsnHTTPCfg.Prometheus_url
if jsnHTTPCfg.PrometheusURL != nil {
httpcfg.PrometheusURL = *jsnHTTPCfg.PrometheusURL
}
if jsnHTTPCfg.Ws_url != nil {
httpcfg.WSURL = *jsnHTTPCfg.Ws_url
if jsnHTTPCfg.WSURL != nil {
httpcfg.WSURL = *jsnHTTPCfg.WSURL
}
if jsnHTTPCfg.Freeswitch_cdrs_url != nil {
httpcfg.FreeswitchCDRsURL = *jsnHTTPCfg.Freeswitch_cdrs_url
if jsnHTTPCfg.FreeswitchCDRsURL != nil {
httpcfg.FreeswitchCDRsURL = *jsnHTTPCfg.FreeswitchCDRsURL
}
if jsnHTTPCfg.Http_Cdrs != nil {
httpcfg.CDRsURL = *jsnHTTPCfg.Http_Cdrs
if jsnHTTPCfg.HTTPCDRs != nil {
httpcfg.CDRsURL = *jsnHTTPCfg.HTTPCDRs
}
if jsnHTTPCfg.Use_basic_auth != nil {
httpcfg.UseBasicAuth = *jsnHTTPCfg.Use_basic_auth
if jsnHTTPCfg.PprofPath != nil {
httpcfg.PprofPath = *jsnHTTPCfg.PprofPath
}
if jsnHTTPCfg.Auth_users != nil {
httpcfg.AuthUsers = *jsnHTTPCfg.Auth_users
if jsnHTTPCfg.UseBasicAuth != nil {
httpcfg.UseBasicAuth = *jsnHTTPCfg.UseBasicAuth
}
if jsnHTTPCfg.Client_opts != nil {
if err = newDialer(httpcfg.dialer, jsnHTTPCfg.Client_opts); err != nil {
if jsnHTTPCfg.AuthUsers != nil {
httpcfg.AuthUsers = *jsnHTTPCfg.AuthUsers
}
if jsnHTTPCfg.ClientOpts != nil {
if err = newDialer(httpcfg.dialer, jsnHTTPCfg.ClientOpts); err != nil {
return
}
err = loadTransportFromJSONCfg(httpcfg.ClientOpts, httpcfg.dialer, jsnHTTPCfg.Client_opts)
err = loadTransportFromJSONCfg(httpcfg.ClientOpts, httpcfg.dialer, jsnHTTPCfg.ClientOpts)
}
return
}
@@ -189,6 +193,7 @@ func (httpcfg HTTPCfg) AsMapInterface(string) any {
utils.HTTPWSURLCfg: httpcfg.WSURL,
utils.HTTPFreeswitchCDRsURLCfg: httpcfg.FreeswitchCDRsURL,
utils.HTTPCDRsURLCfg: httpcfg.CDRsURL,
utils.PprofPathCfg: httpcfg.PprofPath,
utils.HTTPUseBasicAuthCfg: httpcfg.UseBasicAuth,
utils.HTTPAuthUsersCfg: httpcfg.AuthUsers,
utils.HTTPClientOptsCfg: clientOpts,
@@ -213,6 +218,7 @@ func (httpcfg HTTPCfg) Clone() (cln *HTTPCfg) {
WSURL: httpcfg.WSURL,
FreeswitchCDRsURL: httpcfg.FreeswitchCDRsURL,
CDRsURL: httpcfg.CDRsURL,
PprofPath: httpcfg.PprofPath,
UseBasicAuth: httpcfg.UseBasicAuth,
AuthUsers: make(map[string]string),
ClientOpts: httpcfg.ClientOpts.Clone(),
@@ -243,15 +249,16 @@ type HTTPClientOptsJson struct {
// HTTP config section
type HTTPJsonCfg struct {
Json_rpc_url *string
Registrars_url *string
Prometheus_url *string
Ws_url *string
Freeswitch_cdrs_url *string
Http_Cdrs *string
Use_basic_auth *bool
Auth_users *map[string]string
Client_opts *HTTPClientOptsJson
JSONRPCURL *string `json:"json_rpc_url"`
RegistrarsURL *string `json:"registrars_url"`
PrometheusURL *string `json:"prometheus_url"`
WSURL *string `json:"ws_url"`
FreeswitchCDRsURL *string `json:"freeswitch_cdrs_url"`
HTTPCDRs *string `json:"http_cdrs"`
PprofPath *string `json:"pprof_path"`
UseBasicAuth *bool `json:"use_basic_auth"`
AuthUsers *map[string]string `json:"auth_users"`
ClientOpts *HTTPClientOptsJson `json:"client_opts"`
}
func diffHTTPClientOptsJsonCfgDialer(d *HTTPClientOptsJson, v1, v2 *net.Dialer) *HTTPClientOptsJson {
@@ -317,30 +324,33 @@ func diffHTTPJsonCfg(d *HTTPJsonCfg, v1, v2 *HTTPCfg) *HTTPJsonCfg {
}
if v1.JsonRPCURL != v2.JsonRPCURL {
d.Json_rpc_url = utils.StringPointer(v2.JsonRPCURL)
d.JSONRPCURL = utils.StringPointer(v2.JsonRPCURL)
}
if v1.RegistrarSURL != v2.RegistrarSURL {
d.Registrars_url = utils.StringPointer(v2.RegistrarSURL)
d.RegistrarsURL = utils.StringPointer(v2.RegistrarSURL)
}
if v1.PrometheusURL != v2.PrometheusURL {
d.Prometheus_url = utils.StringPointer(v2.PrometheusURL)
d.PrometheusURL = utils.StringPointer(v2.PrometheusURL)
}
if v1.WSURL != v2.WSURL {
d.Ws_url = utils.StringPointer(v2.WSURL)
d.WSURL = utils.StringPointer(v2.WSURL)
}
if v1.FreeswitchCDRsURL != v2.FreeswitchCDRsURL {
d.Freeswitch_cdrs_url = utils.StringPointer(v2.FreeswitchCDRsURL)
d.FreeswitchCDRsURL = utils.StringPointer(v2.FreeswitchCDRsURL)
}
if v1.CDRsURL != v2.CDRsURL {
d.Http_Cdrs = utils.StringPointer(v2.CDRsURL)
d.HTTPCDRs = utils.StringPointer(v2.CDRsURL)
}
if v1.PprofPath != v2.PprofPath {
d.PprofPath = utils.StringPointer(v2.PprofPath)
}
if v1.UseBasicAuth != v2.UseBasicAuth {
d.Use_basic_auth = utils.BoolPointer(v2.UseBasicAuth)
d.UseBasicAuth = utils.BoolPointer(v2.UseBasicAuth)
}
if !utils.MapStringStringEqual(v1.AuthUsers, v2.AuthUsers) {
d.Auth_users = &v2.AuthUsers
d.AuthUsers = &v2.AuthUsers
}
d.Client_opts = diffHTTPClientOptsJsonCfg(d.Client_opts, v1.ClientOpts, v2.ClientOpts)
d.Client_opts = diffHTTPClientOptsJsonCfgDialer(d.Client_opts, v1.dialer, v2.dialer)
d.ClientOpts = diffHTTPClientOptsJsonCfg(d.ClientOpts, v1.ClientOpts, v2.ClientOpts)
d.ClientOpts = diffHTTPClientOptsJsonCfgDialer(d.ClientOpts, v1.dialer, v2.dialer)
return d
}

View File

@@ -30,14 +30,14 @@ import (
func TestHTTPCfgloadFromJsonCfg(t *testing.T) {
cfgJSONStr := &HTTPJsonCfg{
Json_rpc_url: utils.StringPointer("/jsonrpc"),
Ws_url: utils.StringPointer("/ws"),
Prometheus_url: utils.StringPointer("/metrics"),
Registrars_url: utils.StringPointer("/randomUrl"),
Freeswitch_cdrs_url: utils.StringPointer("/freeswitch_json"),
Http_Cdrs: utils.StringPointer("/cdr_http"),
Use_basic_auth: utils.BoolPointer(false),
Auth_users: utils.MapStringStringPointer(map[string]string{}),
JSONRPCURL: utils.StringPointer("/jsonrpc"),
WSURL: utils.StringPointer("/ws"),
PrometheusURL: utils.StringPointer("/metrics"),
RegistrarsURL: utils.StringPointer("/randomUrl"),
FreeswitchCDRsURL: utils.StringPointer("/freeswitch_json"),
HTTPCDRs: utils.StringPointer("/cdr_http"),
UseBasicAuth: utils.BoolPointer(false),
AuthUsers: utils.MapStringStringPointer(map[string]string{}),
}
expected := &HTTPCfg{
JsonRPCURL: "/jsonrpc",
@@ -46,6 +46,7 @@ func TestHTTPCfgloadFromJsonCfg(t *testing.T) {
RegistrarSURL: "/randomUrl",
FreeswitchCDRsURL: "/freeswitch_json",
CDRsURL: "/cdr_http",
PprofPath: "/debug/pprof/",
UseBasicAuth: false,
AuthUsers: map[string]string{},
ClientOpts: &http.Transport{
@@ -99,6 +100,7 @@ func TestHTTPCfgAsMapInterface(t *testing.T) {
utils.HTTPWSURLCfg: "/ws",
utils.HTTPFreeswitchCDRsURLCfg: "/freeswitch_json",
utils.HTTPCDRsURLCfg: "/cdr_http",
utils.PprofPathCfg: "/debug/pprof/",
utils.HTTPUseBasicAuthCfg: false,
utils.HTTPAuthUsersCfg: map[string]string{},
utils.HTTPClientOptsCfg: map[string]any{
@@ -141,6 +143,7 @@ func TestHTTPCfgAsMapInterface1(t *testing.T) {
utils.HTTPWSURLCfg: "",
utils.HTTPFreeswitchCDRsURLCfg: "/freeswitch_json",
utils.HTTPCDRsURLCfg: "/cdr_http",
utils.PprofPathCfg: "/debug/pprof/",
utils.HTTPUseBasicAuthCfg: true,
utils.HTTPAuthUsersCfg: map[string]string{
"user1": "authenticated",
@@ -253,19 +256,19 @@ func TestDiffHTTPJsonCfg(t *testing.T) {
}
expected := &HTTPJsonCfg{
Json_rpc_url: utils.StringPointer("JsonRpcUrl2"),
Registrars_url: utils.StringPointer("RegistrarSUrl2"),
Ws_url: utils.StringPointer("WsUrl2"),
Freeswitch_cdrs_url: utils.StringPointer("FsCdrsUrl2"),
Http_Cdrs: utils.StringPointer("CdrsUrl2"),
Use_basic_auth: utils.BoolPointer(false),
Auth_users: &map[string]string{
JSONRPCURL: utils.StringPointer("JsonRpcUrl2"),
RegistrarsURL: utils.StringPointer("RegistrarSUrl2"),
WSURL: utils.StringPointer("WsUrl2"),
FreeswitchCDRsURL: utils.StringPointer("FsCdrsUrl2"),
HTTPCDRs: utils.StringPointer("CdrsUrl2"),
UseBasicAuth: utils.BoolPointer(false),
AuthUsers: &map[string]string{
"User2": "passUser2",
},
Client_opts: &HTTPClientOptsJson{
ClientOpts: &HTTPClientOptsJson{
MaxIdleConns: utils.IntPointer(100),
},
Prometheus_url: utils.StringPointer("PrometheusURL2"),
PrometheusURL: utils.StringPointer("PrometheusURL2"),
}
rcv := diffHTTPJsonCfg(d, v1, v2)
@@ -275,7 +278,7 @@ func TestDiffHTTPJsonCfg(t *testing.T) {
v1 = v2
expected = &HTTPJsonCfg{
Client_opts: &HTTPClientOptsJson{},
ClientOpts: &HTTPClientOptsJson{},
}
rcv = diffHTTPJsonCfg(d, v1, v2)
if !reflect.DeepEqual(rcv, expected) {
@@ -481,7 +484,7 @@ func TestLoadTransportFromJSONCfgExpectContinueTimeout(t *testing.T) {
func TestHTTPCfgloadFromJsonCfgClientOptsErr(t *testing.T) {
cfgJSONStr := &HTTPJsonCfg{
Client_opts: &HTTPClientOptsJson{
ClientOpts: &HTTPClientOptsJson{
DialTimeout: utils.StringPointer("invalid value"),
},
}

View File

@@ -26,6 +26,7 @@ import (
"net"
"net/http"
"net/http/pprof"
"strings"
"sync"
"github.com/cgrates/birpc"
@@ -114,28 +115,6 @@ func (s *Server) BiRPCUnregisterName(name string) {
s.birpcSrv.UnregisterName(name)
}
func registerProfiler(addr string, mux *http.ServeMux) {
mux.HandleFunc(addr, pprof.Index)
mux.HandleFunc(addr+"cmdline", pprof.Cmdline)
mux.HandleFunc(addr+"profile", pprof.Profile)
mux.HandleFunc(addr+"symbol", pprof.Symbol)
mux.HandleFunc(addr+"trace", pprof.Trace)
mux.Handle(addr+"goroutine", pprof.Handler("goroutine"))
mux.Handle(addr+"heap", pprof.Handler("heap"))
mux.Handle(addr+"threadcreate", pprof.Handler("threadcreate"))
mux.Handle(addr+"block", pprof.Handler("block"))
mux.Handle(addr+"allocs", pprof.Handler("allocs"))
mux.Handle(addr+"mutex", pprof.Handler("mutex"))
}
func (s *Server) RegisterProfiler(addr string) {
if addr[len(addr)-1] != '/' {
addr = addr + "/"
}
registerProfiler(addr, s.httpMux)
registerProfiler(addr, s.httpsMux)
}
func (s *Server) handleRequest(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
rmtIP, _ := utils.GetRemoteIP(r)
@@ -173,10 +152,11 @@ func (s *Server) ServeGOB(ctx *context.Context, shtdwnEngine context.CancelFunc,
})
}
func (s *Server) ServeHTTP(shtdwnEngine context.CancelFunc, addr, jsonRPCURL, wsRPCURL, promURL string,
func (s *Server) ServeHTTP(shtdwnEngine context.CancelFunc,
addr, jsonRPCURL, wsRPCURL, promURL, pprofPath string,
useBasicAuth bool, userList map[string]string) {
s.Lock()
s.httpEnabled = s.httpEnabled || jsonRPCURL != "" || wsRPCURL != ""
s.httpEnabled = s.httpEnabled || jsonRPCURL != "" || wsRPCURL != "" || pprofPath != ""
enabled := s.httpEnabled
s.Unlock()
if !enabled {
@@ -208,6 +188,25 @@ func (s *Server) ServeHTTP(shtdwnEngine context.CancelFunc, addr, jsonRPCURL, ws
s.httpMux.Handle(promURL, wsHandler)
}
}
if pprofPath != "" {
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 useBasicAuth {
utils.Logger.Info("<HTTP> enabling basic auth")
}
@@ -287,10 +286,10 @@ func (s *Server) ServeJSONTLS(ctx *context.Context, shtdwnEngine context.CancelF
func (s *Server) ServeHTTPS(shtdwnEngine context.CancelFunc,
addr, serverCrt, serverKey, caCert string, serverPolicy int,
serverName string, jsonRPCURL string, wsRPCURL string,
serverName, jsonRPCURL, wsRPCURL, pprofPath string,
useBasicAuth bool, userList map[string]string) {
s.Lock()
s.httpEnabled = s.httpEnabled || jsonRPCURL != "" || wsRPCURL != ""
s.httpEnabled = s.httpEnabled || jsonRPCURL != "" || wsRPCURL != "" || pprofPath != ""
enabled := s.httpEnabled
s.Unlock()
if !enabled {
@@ -313,6 +312,25 @@ func (s *Server) ServeHTTPS(shtdwnEngine context.CancelFunc,
s.httpsMux.Handle(wsRPCURL, wsHandler)
}
}
if pprofPath != "" {
if !strings.HasSuffix(pprofPath, "/") {
pprofPath += "/"
}
utils.Logger.Info(fmt.Sprintf("<HTTPS> profiling endpoints registered at %q", pprofPath))
if useBasicAuth {
s.httpsMux.HandleFunc(pprofPath, use(pprof.Index, basicAuth(userList)))
s.httpsMux.HandleFunc(pprofPath+"cmdline", use(pprof.Cmdline, basicAuth(userList)))
s.httpsMux.HandleFunc(pprofPath+"profile", use(pprof.Profile, basicAuth(userList)))
s.httpsMux.HandleFunc(pprofPath+"symbol", use(pprof.Symbol, basicAuth(userList)))
s.httpsMux.HandleFunc(pprofPath+"trace", use(pprof.Trace, basicAuth(userList)))
} else {
s.httpsMux.HandleFunc(pprofPath, pprof.Index)
s.httpsMux.HandleFunc(pprofPath+"cmdline", pprof.Cmdline)
s.httpsMux.HandleFunc(pprofPath+"profile", pprof.Profile)
s.httpsMux.HandleFunc(pprofPath+"symbol", pprof.Symbol)
s.httpsMux.HandleFunc(pprofPath+"trace", pprof.Trace)
}
}
if useBasicAuth {
utils.Logger.Info("<HTTPS> enabling basic auth")
}
@@ -369,6 +387,7 @@ func (s *Server) StartServer(ctx *context.Context, shtdwnEngine context.CancelFu
cfg.HTTPCfg().JsonRPCURL,
cfg.HTTPCfg().WSURL,
cfg.HTTPCfg().PrometheusURL,
cfg.HTTPCfg().PprofPath,
cfg.HTTPCfg().UseBasicAuth,
cfg.HTTPCfg().AuthUsers,
)
@@ -413,6 +432,7 @@ func (s *Server) StartServer(ctx *context.Context, shtdwnEngine context.CancelFu
cfg.TLSCfg().ServerName,
cfg.HTTPCfg().JsonRPCURL,
cfg.HTTPCfg().WSURL,
cfg.HTTPCfg().PprofPath,
cfg.HTTPCfg().UseBasicAuth,
cfg.HTTPCfg().AuthUsers,
)

View File

@@ -151,6 +151,7 @@ func testServeHHTPFail(t *testing.T) {
cfgDflt.HTTPCfg().JsonRPCURL,
cfgDflt.HTTPCfg().WSURL,
cfgDflt.HTTPCfg().PrometheusURL,
cfgDflt.HTTPCfg().PprofPath,
cfgDflt.HTTPCfg().UseBasicAuth,
cfgDflt.HTTPCfg().AuthUsers,
)

View File

@@ -94,14 +94,3 @@ func TestRegisterHTTPFunc(t *testing.T) {
}
rcv.StopBiRPC()
}
func TestRegisterProfiler(t *testing.T) {
cfgDflt := config.NewDefaultCGRConfig()
cfgDflt.CoreSCfg().CapsStatsInterval = 1
caps := engine.NewCaps(0, utils.MetaBusy)
rcv := NewServer(caps)
rcv.RegisterProfiler("/test_prefix")
rcv.StopBiRPC()
}

View File

@@ -149,7 +149,7 @@ func testConfigSReload(t *testing.T) {
t.Errorf("\nExpected %+v ,\n received: %+v", cfgStr, rpl4)
}
cfgStr = `{"http":{"auth_users":{},"client_opts":{"dialFallbackDelay":"300ms","dialKeepAlive":"30s","dialTimeout":"30s","disableCompression":false,"disableKeepAlives":false,"expectContinueTimeout":"0s","forceAttemptHttp2":true,"idleConnTimeout":"1m30s","maxConnsPerHost":0,"maxIdleConns":100,"maxIdleConnsPerHost":2,"responseHeaderTimeout":"0s","skipTLSVerification":false,"tlsHandshakeTimeout":"10s"},"freeswitch_cdrs_url":"/freeswitch_json","http_cdrs":"/cdr_http","json_rpc_url":"/jsonrpc","prometheus_url":"/prometheus","registrars_url":"/registrar","use_basic_auth":false,"ws_url":"/ws"}}`
cfgStr = `{"http":{"auth_users":{},"client_opts":{"dialFallbackDelay":"300ms","dialKeepAlive":"30s","dialTimeout":"30s","disableCompression":false,"disableKeepAlives":false,"expectContinueTimeout":"0s","forceAttemptHttp2":true,"idleConnTimeout":"1m30s","maxConnsPerHost":0,"maxIdleConns":100,"maxIdleConnsPerHost":2,"responseHeaderTimeout":"0s","skipTLSVerification":false,"tlsHandshakeTimeout":"10s"},"freeswitch_cdrs_url":"/freeswitch_json","http_cdrs":"/cdr_http","json_rpc_url":"/jsonrpc","pprof_path":"/debug/pprof/","prometheus_url":"/prometheus","registrars_url":"/registrar","use_basic_auth":false,"ws_url":"/ws"}}`
var rpl5 string
if err := testRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{

View File

@@ -130,16 +130,13 @@ func (cgr *CGREngine) AddService(service servmanager.Service, connName, apiPrefi
cgr.cM.AddInternalConn(connName, apiPrefix, iConnCh)
}
func (cgr *CGREngine) InitServices(httpPrfPath string, cpuPrfFl *os.File) {
func (cgr *CGREngine) InitServices(cpuPrfFl *os.File) {
if len(cgr.cfg.HTTPCfg().RegistrarSURL) != 0 {
cgr.server.RegisterHTTPFunc(cgr.cfg.HTTPCfg().RegistrarSURL, registrarc.Registrar)
}
if cgr.cfg.ConfigSCfg().Enabled {
cgr.server.RegisterHTTPFunc(cgr.cfg.ConfigSCfg().URL, config.HandlerConfigS)
}
if httpPrfPath != utils.EmptyString {
cgr.server.RegisterProfiler(httpPrfPath)
}
// init the channel here because we need to pass them to connManager
cgr.iServeManagerCh = make(chan birpc.ClientConnector, 1)
@@ -385,7 +382,7 @@ func (cgr *CGREngine) Init(ctx *context.Context, shtDw context.CancelFunc, flags
}
efs.SetFailedPostCacheTTL(cgr.cfg.EFsCfg().FailedPostsTTL) // init failedPosts to posts loggers/exporters in case of failing
utils.Logger.Info(fmt.Sprintf("<CoreS> starting version <%s><%s>", vers, runtime.Version()))
cgr.InitServices(*flags.HttpPrfPath, cpuPrfF)
cgr.InitServices(cpuPrfF)
return nil
}

View File

@@ -48,7 +48,6 @@ func NewCGREngineFlags() *CGREngineFlags {
CfgPath: fs.String(utils.CfgPathCgr, utils.ConfigPath, "Configuration directory path."),
Version: fs.Bool(utils.VersionCgr, false, "Prints the application version."),
PidFile: fs.String(utils.PidCgr, utils.EmptyString, "Write pid file"),
HttpPrfPath: fs.String(utils.HttpPrfPthCgr, utils.EmptyString, "http address used for program profiling"),
CpuPrfDir: fs.String(utils.CpuProfDirCgr, utils.EmptyString, "Directory for CPU profiles"),
MemPrfDir: fs.String(utils.MemProfDirCgr, utils.EmptyString, "Directory for memory profiles"),
MemPrfInterval: fs.Duration(utils.MemProfIntervalCgr, 15*time.Second, "Interval between memory profile saves"),
@@ -70,7 +69,6 @@ type CGREngineFlags struct {
CfgPath *string
Version *bool
PidFile *string
HttpPrfPath *string
CpuPrfDir *string
MemPrfDir *string
MemPrfInterval *time.Duration

View File

@@ -1965,6 +1965,7 @@ const (
HTTPWSURLCfg = "ws_url"
HTTPFreeswitchCDRsURLCfg = "freeswitch_cdrs_url"
HTTPCDRsURLCfg = "http_cdrs"
PprofPathCfg = "pprof_path"
HTTPUseBasicAuthCfg = "use_basic_auth"
HTTPAuthUsersCfg = "auth_users"
HTTPClientOptsCfg = "client_opts"
@@ -2713,7 +2714,6 @@ const (
PrintCfgCgr = "print_config"
CheckCfgCgr = "check_config"
PidCgr = "pid"
HttpPrfPthCgr = "httprof_path"
CpuProfDirCgr = "cpuprof_dir"
MemProfDirCgr = "memprof_dir"
MemProfIntervalCgr = "memprof_interval"