mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-23 05:20:19 +00:00
43f753760b
nlreturn linter requires a new line before return and branch statements except when the return is alone inside a statement group (such as an if statement) to increase code clarity. This commit addresses such issues. Updates: #1586 Signed-off-by: Rakshith R <rar@redhat.com>
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package util
|
|
|
|
import (
|
|
"net"
|
|
"net/http"
|
|
"net/http/pprof"
|
|
"net/url"
|
|
runtime_pprof "runtime/pprof"
|
|
"strconv"
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
)
|
|
|
|
// ValidateURL validates the url.
|
|
func ValidateURL(c *Config) error {
|
|
_, err := url.Parse(c.MetricsPath)
|
|
|
|
return err
|
|
}
|
|
|
|
// StartMetricsServer starts http server.
|
|
func StartMetricsServer(c *Config) {
|
|
addr := net.JoinHostPort(c.MetricsIP, strconv.Itoa(c.MetricsPort))
|
|
http.Handle(c.MetricsPath, promhttp.Handler())
|
|
err := http.ListenAndServe(addr, nil)
|
|
if err != nil {
|
|
FatalLogMsg("failed to listen on address %v: %s", addr, err)
|
|
}
|
|
}
|
|
|
|
func addPath(name string, handler http.Handler) {
|
|
http.Handle(name, handler)
|
|
DebugLogMsg("DEBUG: registered profiling handler on /debug/pprof/%s\n", name)
|
|
}
|
|
|
|
// EnableProfiling enables golang profiling.
|
|
func EnableProfiling() {
|
|
for _, profile := range runtime_pprof.Profiles() {
|
|
name := profile.Name()
|
|
handler := pprof.Handler(name)
|
|
addPath(name, handler)
|
|
}
|
|
|
|
// static profiles as listed in net/http/pprof/pprof.go:init()
|
|
addPath("cmdline", http.HandlerFunc(pprof.Cmdline))
|
|
addPath("profile", http.HandlerFunc(pprof.Profile))
|
|
addPath("symbol", http.HandlerFunc(pprof.Symbol))
|
|
addPath("trace", http.HandlerFunc(pprof.Trace))
|
|
}
|