From 6563ca242f63f3505a960f4683179f1ecadbc5f2 Mon Sep 17 00:00:00 2001 From: Lionel Jouin Date: Wed, 14 Sep 2022 15:38:35 +0200 Subject: [PATCH] Add Profiling option - Profilier disabled by default - Exposed on port 9995 by default except in fe where 9996 is used (to avoid port conflict with load-balancer) - Exposed via http (no TLS) - Remove logrus from NSP and IPAM (no usage of NSM in these containers) --- cmd/frontend/internal/env/config.go | 3 ++ cmd/frontend/main.go | 13 +++++ cmd/ipam/config.go | 3 ++ cmd/ipam/main.go | 16 +++++-- cmd/load-balancer/config.go | 3 ++ cmd/load-balancer/main.go | 13 +++++ cmd/nsp/config.go | 3 ++ cmd/nsp/main.go | 16 +++++-- cmd/proxy/internal/config/config.go | 3 ++ cmd/proxy/main.go | 13 +++++ cmd/tapa/config.go | 3 ++ cmd/tapa/main.go | 13 +++++ deployments/helm/templates/ipam.yaml | 2 + deployments/helm/templates/load-balancer.yaml | 4 ++ deployments/helm/templates/nsp.yaml | 2 + deployments/helm/templates/proxy.yaml | 2 + deployments/helm/values.yaml | 2 + docs/front-end.md | 2 + docs/ipam.md | 2 + docs/load-balancer.md | 2 + docs/nsp.md | 2 + docs/proxy.md | 2 + docs/tapa.md | 2 + docs/trouble-shooting/README.md | 47 +++++++++++++++++++ pkg/profiling/profiling.go | 37 +++++++++++++++ readme.md | 2 +- 26 files changed, 205 insertions(+), 7 deletions(-) create mode 100644 pkg/profiling/profiling.go diff --git a/cmd/frontend/internal/env/config.go b/cmd/frontend/internal/env/config.go index b1d77b40..f3e0bdad 100644 --- a/cmd/frontend/internal/env/config.go +++ b/cmd/frontend/internal/env/config.go @@ -39,4 +39,7 @@ type Config struct { AttractorName string `default:"default" desc:"Name of the Attractor the frontend is associated with" split_words:"true"` LogLevel string `default:"DEBUG" desc:"Log level" split_words:"true"` NSPEntryTimeout time.Duration `default:"30s" desc:"Timeout of the entries" envconfig:"nsp_entry_timeout"` + + ProfilingEnabled bool `default:"false" desc:"enable profiling" split_words:"true"` + ProfilingPort int `default:"9996" desc:"port of the profiling http server" split_words:"true"` } diff --git a/cmd/frontend/main.go b/cmd/frontend/main.go index 9fab2a30..23cc2e26 100644 --- a/cmd/frontend/main.go +++ b/cmd/frontend/main.go @@ -21,6 +21,7 @@ import ( "flag" "fmt" "io" + "net/http" "os" "os/signal" "syscall" @@ -37,6 +38,7 @@ import ( "github.com/nordix/meridio/cmd/frontend/internal/frontend" "github.com/nordix/meridio/pkg/health" "github.com/nordix/meridio/pkg/health/connection" + "github.com/nordix/meridio/pkg/profiling" "github.com/nordix/meridio/pkg/retry" "github.com/nordix/meridio/pkg/security/credentials" ) @@ -97,6 +99,17 @@ func main() { ) defer cancel() + if config.ProfilingEnabled { + go func() { + mux := http.NewServeMux() + profiling.AddProfilerHandlers(mux) + err := http.ListenAndServe(fmt.Sprintf(":%d", config.ProfilingPort), mux) + if err != nil { + logrus.Errorf("err starting profiling: %v", err) + } + }() + } + // create and start health server ctx = health.CreateChecker(ctx) if err := health.RegisterReadinesSubservices(ctx, health.FEReadinessServices...); err != nil { diff --git a/cmd/ipam/config.go b/cmd/ipam/config.go index 4885e4da..d89f08d3 100644 --- a/cmd/ipam/config.go +++ b/cmd/ipam/config.go @@ -30,4 +30,7 @@ type Config struct { NodePrefixLengthIPv6 int `default:"64" desc:"node prefix length which will be allocated" envconfig:"node_prefix_length_ipv6"` IPFamily string `default:"dualstack" desc:"ip family" envconfig:"ip_family"` LogLevel string `default:"DEBUG" desc:"Log level" split_words:"true"` + + ProfilingEnabled bool `default:"false" desc:"enable profiling" split_words:"true"` + ProfilingPort int `default:"9995" desc:"port of the profiling http server" split_words:"true"` } diff --git a/cmd/ipam/main.go b/cmd/ipam/main.go index ead73afd..3a557940 100644 --- a/cmd/ipam/main.go +++ b/cmd/ipam/main.go @@ -21,6 +21,7 @@ import ( "flag" "fmt" "net" + "net/http" "os" "os/signal" "strings" @@ -36,8 +37,8 @@ import ( "github.com/nordix/meridio/pkg/ipam" "github.com/nordix/meridio/pkg/ipam/types" "github.com/nordix/meridio/pkg/log" + "github.com/nordix/meridio/pkg/profiling" "github.com/nordix/meridio/pkg/security/credentials" - "github.com/sirupsen/logrus" "google.golang.org/grpc" grpcHealth "google.golang.org/grpc/health" "google.golang.org/grpc/health/grpc_health_v1" @@ -83,10 +84,19 @@ func main() { ) defer cancel() + if config.ProfilingEnabled { + go func() { + mux := http.NewServeMux() + profiling.AddProfilerHandlers(mux) + err := http.ListenAndServe(fmt.Sprintf(":%d", config.ProfilingPort), mux) + if err != nil { + logger.Error(err, "err starting profiling") + } + }() + } + if config.LogLevel == "TRACE" { nsmlog.EnableTracing(true) - // Work-around for hard-coded logrus dependency in NSM - logrus.SetLevel(logrus.TraceLevel) } logger.Info("NSM trace", "enabled", nsmlog.IsTracingEnabled()) ctx = nsmlog.WithLog(ctx, log.NSMLogger(logger)) // allow NSM logs diff --git a/cmd/load-balancer/config.go b/cmd/load-balancer/config.go index 31a0dfd5..832f15d3 100644 --- a/cmd/load-balancer/config.go +++ b/cmd/load-balancer/config.go @@ -39,6 +39,9 @@ type Config struct { LogLevel string `default:"DEBUG" desc:"Log level" split_words:"true"` Nfqueue string `default:"0:3" desc:"netfilter queue(s) to be used by nfqlb" split_words:"true"` NfqueueFanout bool `default:"false" desc:"enable fanout nfqueue option" split_words:"true"` + + ProfilingEnabled bool `default:"false" desc:"enable profiling" split_words:"true"` + ProfilingPort int `default:"9995" desc:"port of the profiling http server" split_words:"true"` } // IsValid checks if the configuration is valid diff --git a/cmd/load-balancer/main.go b/cmd/load-balancer/main.go index df3c2f27..50afa1ea 100644 --- a/cmd/load-balancer/main.go +++ b/cmd/load-balancer/main.go @@ -22,6 +22,7 @@ import ( "flag" "fmt" "io" + "net/http" "os" "os/signal" "sync" @@ -53,6 +54,7 @@ import ( "github.com/nordix/meridio/pkg/networking" "github.com/nordix/meridio/pkg/nsm" "github.com/nordix/meridio/pkg/nsm/interfacemonitor" + "github.com/nordix/meridio/pkg/profiling" "github.com/nordix/meridio/pkg/retry" "github.com/nordix/meridio/pkg/security/credentials" "github.com/sirupsen/logrus" @@ -108,6 +110,17 @@ func main() { log.Fatal(logger, "invalid config", "error", err) } + if config.ProfilingEnabled { + go func() { + mux := http.NewServeMux() + profiling.AddProfilerHandlers(mux) + err := http.ListenAndServe(fmt.Sprintf(":%d", config.ProfilingPort), mux) + if err != nil { + logger.Error(err, "err starting profiling") + } + }() + } + if config.LogLevel == "TRACE" { nsmlog.EnableTracing(true) // Work-around for hard-coded logrus dependency in NSM diff --git a/cmd/nsp/config.go b/cmd/nsp/config.go index 806c122a..080c59d3 100644 --- a/cmd/nsp/config.go +++ b/cmd/nsp/config.go @@ -26,4 +26,7 @@ type Config struct { Datasource string `default:"/run/nsp/data/registry.db" desc:"Path and file name of the sqlite database" split_words:"true"` LogLevel string `default:"DEBUG" desc:"Log level" split_words:"true"` EntryTimeout time.Duration `default:"60s" desc:"Timeout of the entries" split_words:"true"` + + ProfilingEnabled bool `default:"false" desc:"enable profiling" split_words:"true"` + ProfilingPort int `default:"9995" desc:"port of the profiling http server" split_words:"true"` } diff --git a/cmd/nsp/main.go b/cmd/nsp/main.go index 167d8854..29a47f5f 100644 --- a/cmd/nsp/main.go +++ b/cmd/nsp/main.go @@ -21,6 +21,7 @@ import ( "flag" "fmt" "net" + "net/http" "os" "os/signal" "syscall" @@ -34,12 +35,12 @@ import ( "github.com/nordix/meridio/pkg/health" "github.com/nordix/meridio/pkg/log" "github.com/nordix/meridio/pkg/nsp" + "github.com/nordix/meridio/pkg/profiling" nsmlog "github.com/networkservicemesh/sdk/pkg/tools/log" keepAliveRegistry "github.com/nordix/meridio/pkg/nsp/registry/keepalive" sqliteRegistry "github.com/nordix/meridio/pkg/nsp/registry/sqlite" "github.com/nordix/meridio/pkg/security/credentials" - "github.com/sirupsen/logrus" "google.golang.org/grpc" grpcHealth "google.golang.org/grpc/health" "google.golang.org/grpc/health/grpc_health_v1" @@ -85,10 +86,19 @@ func main() { ) defer cancel() + if config.ProfilingEnabled { + go func() { + mux := http.NewServeMux() + profiling.AddProfilerHandlers(mux) + err := http.ListenAndServe(fmt.Sprintf(":%d", config.ProfilingPort), mux) + if err != nil { + logger.Error(err, "err starting profiling") + } + }() + } + if config.LogLevel == "TRACE" { nsmlog.EnableTracing(true) - // Work-around for hard-coded logrus dependency in NSM - logrus.SetLevel(logrus.TraceLevel) } logger.Info("NSM trace", "enabled", nsmlog.IsTracingEnabled()) ctx = nsmlog.WithLog(ctx, log.NSMLogger(logger)) // allow NSM logs diff --git a/cmd/proxy/internal/config/config.go b/cmd/proxy/internal/config/config.go index 3037d7ae..5acd05c0 100644 --- a/cmd/proxy/internal/config/config.go +++ b/cmd/proxy/internal/config/config.go @@ -42,6 +42,9 @@ type Config struct { IPFamily string `default:"dualstack" desc:"ip family" envconfig:"ip_family"` LogLevel string `default:"DEBUG" desc:"Log level" split_words:"true"` MTU int `default:"1500" desc:"Conduit MTU considered by local NSCs and NSE composing the network mesh" split_words:"true"` + + ProfilingEnabled bool `default:"false" desc:"enable profiling" split_words:"true"` + ProfilingPort int `default:"9995" desc:"port of the profiling http server" split_words:"true"` } // IsValid checks if the configuration is valid diff --git a/cmd/proxy/main.go b/cmd/proxy/main.go index 2bbcb2e3..84644e15 100644 --- a/cmd/proxy/main.go +++ b/cmd/proxy/main.go @@ -21,6 +21,7 @@ import ( "flag" "fmt" "io" + "net/http" "os" "os/signal" "syscall" @@ -40,6 +41,7 @@ import ( "github.com/nordix/meridio/pkg/nsm" "github.com/nordix/meridio/pkg/nsm/interfacemonitor" "github.com/nordix/meridio/pkg/nsp" + "github.com/nordix/meridio/pkg/profiling" "github.com/nordix/meridio/pkg/retry" "github.com/go-logr/logr" @@ -89,6 +91,17 @@ func main() { logr.NewContext(context.Background(), logger)) defer cancel() + if config.ProfilingEnabled { + go func() { + mux := http.NewServeMux() + profiling.AddProfilerHandlers(mux) + err := http.ListenAndServe(fmt.Sprintf(":%d", config.ProfilingPort), mux) + if err != nil { + logger.Error(err, "err starting profiling") + } + }() + } + // allow NSM logs if config.LogLevel == "TRACE" { nsmlog.EnableTracing(true) diff --git a/cmd/tapa/config.go b/cmd/tapa/config.go index d571988e..e68d035c 100644 --- a/cmd/tapa/config.go +++ b/cmd/tapa/config.go @@ -35,6 +35,9 @@ type Config struct { MaxTokenLifetime time.Duration `default:"24h" desc:"maximum lifetime of tokens" split_words:"true"` LogLevel string `default:"DEBUG" desc:"Log level" split_words:"true"` NSPEntryTimeout time.Duration `default:"30s" desc:"Timeout of the entries" envconfig:"nsp_entry_timeout"` + + ProfilingEnabled bool `default:"false" desc:"enable profiling" split_words:"true"` + ProfilingPort int `default:"9995" desc:"port of the profiling http server" split_words:"true"` } // IsValid checks if the configuration is valid diff --git a/cmd/tapa/main.go b/cmd/tapa/main.go index 8eef0273..675f41d7 100644 --- a/cmd/tapa/main.go +++ b/cmd/tapa/main.go @@ -21,6 +21,7 @@ import ( "flag" "fmt" "net" + "net/http" "os" "os/signal" "syscall" @@ -47,6 +48,7 @@ import ( "github.com/nordix/meridio/pkg/log" "github.com/nordix/meridio/pkg/nsm" "github.com/nordix/meridio/pkg/nsm/interfacename" + "github.com/nordix/meridio/pkg/profiling" "github.com/sirupsen/logrus" "google.golang.org/grpc" grpcHealth "google.golang.org/grpc/health" @@ -93,6 +95,17 @@ func main() { defer cancel() logger.Info("Config read", "config", config) + if config.ProfilingEnabled { + go func() { + mux := http.NewServeMux() + profiling.AddProfilerHandlers(mux) + err := http.ListenAndServe(fmt.Sprintf(":%d", config.ProfilingPort), mux) + if err != nil { + logger.Error(err, "err starting profiling") + } + }() + } + if config.LogLevel == "TRACE" { nsmlog.EnableTracing(true) // enable tracing in NSM logrus.SetLevel(logrus.TraceLevel) diff --git a/deployments/helm/templates/ipam.yaml b/deployments/helm/templates/ipam.yaml index fa5c6478..f9a2c0ab 100644 --- a/deployments/helm/templates/ipam.yaml +++ b/deployments/helm/templates/ipam.yaml @@ -56,6 +56,8 @@ spec: value: "{{ .Values.subnetPool.nodePrefixLength.ipv6 }}" - name: IPAM_IP_FAMILY value: "{{ .Values.ipFamily }}" + - name: NSM_PROFILING_ENABLED + value: "{{ .Values.profilingEnabled }}" securityContext: runAsNonRoot: true readOnlyRootFilesystem: true diff --git a/deployments/helm/templates/load-balancer.yaml b/deployments/helm/templates/load-balancer.yaml index 5168c842..d72aa83c 100644 --- a/deployments/helm/templates/load-balancer.yaml +++ b/deployments/helm/templates/load-balancer.yaml @@ -68,6 +68,8 @@ spec: value: {{ .Values.maxTokenLifetime }} - name: NSM_LOG_LEVEL value: "DEBUG" + - name: NSM_PROFILING_ENABLED + value: "{{ .Values.profilingEnabled }}" volumeMounts: - name: spire-agent-socket mountPath: /run/spire/sockets @@ -163,6 +165,8 @@ spec: value: {{ .Values.trench.name }} - name: NFE_ATTRACTOR_NAME value: "attractor-a" + - name: NFE_PROFILING_ENABLED + value: "{{ .Values.profilingEnabled }}" volumeMounts: - name: spire-agent-socket mountPath: /run/spire/sockets diff --git a/deployments/helm/templates/nsp.yaml b/deployments/helm/templates/nsp.yaml index 64762070..7995a65f 100644 --- a/deployments/helm/templates/nsp.yaml +++ b/deployments/helm/templates/nsp.yaml @@ -41,6 +41,8 @@ spec: value: {{ template "meridio.configuration" . }} - name: NSP_DATASOURCE value: /run/nsp/data/registry.db + - name: NSM_PROFILING_ENABLED + value: "{{ .Values.profilingEnabled }}" securityContext: runAsNonRoot: true readOnlyRootFilesystem: true diff --git a/deployments/helm/templates/proxy.yaml b/deployments/helm/templates/proxy.yaml index a2cddc9d..3171c21c 100644 --- a/deployments/helm/templates/proxy.yaml +++ b/deployments/helm/templates/proxy.yaml @@ -73,6 +73,8 @@ spec: value: "DEBUG" - name: NSM_MTU value: "1500" + - name: NSM_PROFILING_ENABLED + value: "{{ .Values.profilingEnabled }}" volumeMounts: - name: spire-agent-socket mountPath: /run/spire/sockets diff --git a/deployments/helm/values.yaml b/deployments/helm/values.yaml index e0bb552c..6a7e40ec 100644 --- a/deployments/helm/values.yaml +++ b/deployments/helm/values.yaml @@ -8,6 +8,8 @@ pullPolicy: IfNotPresent maxTokenLifetime: 10m fsGroup: 3000 +profilingEnabled: false + nsm: namespace: nsm registryService: nsm-registry-svc diff --git a/docs/front-end.md b/docs/front-end.md index d2410d58..ffe3e9fc 100644 --- a/docs/front-end.md +++ b/docs/front-end.md @@ -53,6 +53,8 @@ NFE_NSP_SERVICE | string | IP (or domain) and port of the NSP Service | nsp-serv NFE_TRENCH_NAME | string | Name of the Trench the frontend is associated with | default NFE_ATTRACTOR_NAME | string | Name of the Attractor the frontend is associated with | default NFE_LOG_LEVEL | string | Log level | DEBUG +NFE_PROFILING_ENABLED | bool | Enable profiling | false +NFE_NFQUEUE_FANOUT | int | port of the profiling http server | 9996 ## Command Line diff --git a/docs/ipam.md b/docs/ipam.md index 781203ee..8e775a43 100644 --- a/docs/ipam.md +++ b/docs/ipam.md @@ -49,6 +49,8 @@ IPAM_CONDUIT_PREFIX_LENGTH_IPV6 | int | Conduit prefix length which will be allo IPAM_NODE_PREFIX_LENGTH_IPV6 | int | node prefix length which will be allocated | 64 IPAM_IP_FAMILY | string | IP family (ipv4, ipv6, dualstack) | dualstack IPAM_LOG_LEVEL | string | Log level (TRACE, DEBUG, INFO, WARNING, ERROR, FATAL, PANIC) | DEBUG +NSM_PROFILING_ENABLED | bool | Enable profiling | false +NSM_NFQUEUE_FANOUT | int | port of the profiling http server | 9995 ## Command Line diff --git a/docs/load-balancer.md b/docs/load-balancer.md index bc954f62..e8967007 100644 --- a/docs/load-balancer.md +++ b/docs/load-balancer.md @@ -29,6 +29,8 @@ NSM_TRENCH_NAME | string | Trench the pod is running on | default NSM_LOG_LEVEL | string | Log level | DEBUG NSM_NFQUEUE | string | netfilter queue(s) to be used by nfqlb | 0:3 NSM_NFQUEUE_FANOUT | bool | enable fanout nfqueue option | false +NSM_PROFILING_ENABLED | bool | Enable profiling | false +NSM_NFQUEUE_FANOUT | int | port of the profiling http server | 9995 ## Command Line diff --git a/docs/nsp.md b/docs/nsp.md index c8968ba0..318bcd0c 100644 --- a/docs/nsp.md +++ b/docs/nsp.md @@ -40,6 +40,8 @@ NSM_PORT | string | Trench the pod is running on | 7778 NSM_CONFIG_MAP_NAME | string | Name of the ConfigMap containing the configuration | meridio-configuration NSM_DATASOURCE | string | Path and file name of the sqlite database | /run/nsp/data/registry.db NSM_LOG_LEVEL | string | Log level | DEBUG +NSM_PROFILING_ENABLED | bool | Enable profiling | false +NSM_NFQUEUE_FANOUT | int | port of the profiling http server | 9995 ## Command Line diff --git a/docs/proxy.md b/docs/proxy.md index 927edd48..74b6b8b2 100644 --- a/docs/proxy.md +++ b/docs/proxy.md @@ -39,6 +39,8 @@ NSM_NSP_SERVICE_NAME | string | IP (or domain) of the NSP Service | nsp-service NSM_NSP_SERVICE_PORT | int | port of the NSP Service | 7778 NSM_IP_FAMILY | string | ip family | dualstack NSM_LOG_LEVEL | string | Log level | DEBUG +NSM_PROFILING_ENABLED | bool | Enable profiling | false +NSM_NFQUEUE_FANOUT | int | port of the profiling http server | 9995 ## Command Line diff --git a/docs/tapa.md b/docs/tapa.md index 5353586f..c1f5d36c 100644 --- a/docs/tapa.md +++ b/docs/tapa.md @@ -57,6 +57,8 @@ MERIDIO_TIMEOUT | time.Duration | timeout of NSM request/close, NSP register/unr MERIDIO_DIAL_TIMEOUT | time.Duration | timeout to dial NSMgr | 5s MERIDIO_MAX_TOKEN_LIFETIME | time.Duration | maximum lifetime of tokens | 24h MERIDIO_LOG_LEVEL | string | Log level | DEBUG +MERIDIO_PROFILING_ENABLED | bool | Enable profiling | false +MERIDIO_NFQUEUE_FANOUT | int | port of the profiling http server | 9995 ## Command Line diff --git a/docs/trouble-shooting/README.md b/docs/trouble-shooting/README.md index 31275328..f519efa4 100644 --- a/docs/trouble-shooting/README.md +++ b/docs/trouble-shooting/README.md @@ -521,3 +521,50 @@ nsc: flags=4163 mtu 9000 default via fd00::ac10:201 dev nsc metric 1024 onlink pref medium # kubectl exec -n red meridio-app-74f796dd77-9xbmh -c tapa -- ping -c1 -W1 fd00::ac10:201 ``` + +## Debugger + +// TDOD + +## Profiler + +Pprof can be enabled on every component to collect the profiling data. By default, the data are exposed on port 9995 (Except for FE container which uses 9996 to avoid port collision with the load-balancer container) and can be read over a file or over http. + +To reach the exposed data, multiple ways are possible: +- Port forwarding: e.g. `kubectl port-forward load-balancer-trench-a-7f5dcd6765-d2285 -n red 9995:9995` +- Ephemeral container (Doesn't require the profiling to be expose externally) +- From another pod (Doesn't require the profiling to be expose externally if the pod can access to pod network namespace (privileges + hostnetwork)) +- A service + +List of profiling data with their description: +| Profile | Description | +| - | - | +| allocs | A sampling of all past memory allocations | +| block | Stack traces that led to blocking on synchronization primitives | +| cmdline | The command line invocation of the current program | +| goroutine | Stack traces of all current goroutines | +| heap | A sampling of memory allocations of live objects. You can specify the gc GET parameter to run GC before taking the heap sample. | +| mutex | Stack traces of holders of contended mutexes | +| profile | CPU profile. You can specify the duration in the seconds GET parameter. After you get the profile file, use the go tool pprof command to investigate the profile. | +| threadcreate | Stack traces that led to the creation of new OS threads | +| trace | A trace of execution of the current program. You can specify the duration in the seconds GET parameter. After you get the trace file, use the go tool trace command to investigate the trace. | + +Install pprof and graphviz (prerequisites for visualization/analysis): +``` +make pprof +sudo apt install graphviz +``` + +Example of commands to read goroutine profile: +``` +# Download profile +curl http://localhost:9995/debug/pprof/goroutine --output goroutine.tar.gz +# CLI profile visualization +go tool pprof -top goroutine.tar.gz +# Web graph profile visualization +go tool pprof -web goroutine.tar.gz +# Web profile visualization +go tool pprof -http :9090 http://localhost:9995/debug/pprof/goroutine +# CLI profile visualization +go tool pprof -top http://localhost:9995/debug/pprof/goroutine +``` \ No newline at end of file diff --git a/pkg/profiling/profiling.go b/pkg/profiling/profiling.go new file mode 100644 index 00000000..b4062e46 --- /dev/null +++ b/pkg/profiling/profiling.go @@ -0,0 +1,37 @@ +/* +Copyright (c) 2022 Nordix Foundation + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package profiling + +import ( + "net/http" + "net/http/pprof" +) + +// AddProfilerHandlers adds the profiling Handle Func in a ServeMux. +// This must be called before any usage of http.DefaultServeMux. +func AddProfilerHandlers(mux *http.ServeMux) { + // pprof has an init() which adds the handle functions + // in the default mux. + // https://mmcloughlin.com/posts/your-pprof-is-showing + http.DefaultServeMux = http.NewServeMux() + + mux.HandleFunc("/debug/pprof/", pprof.Index) + mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) + mux.HandleFunc("/debug/pprof/profile", pprof.Profile) + mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol) + mux.HandleFunc("/debug/pprof/trace", pprof.Trace) +} diff --git a/readme.md b/readme.md index 4f2067a6..f9d2f7a3 100644 --- a/readme.md +++ b/readme.md @@ -3,7 +3,7 @@ [![GitHub release](https://img.shields.io/github/release/nordix/meridio)](https://GitHub.com/nordix/meridio/releases/) -[![Build Status](https://jenkins.nordix.org/job/nordix-nsm-meridio-ctraffic-verify-build-master/badge/icon)](https://jenkins.nordix.org/job/nordix-nsm-meridio-ctraffic-verify-build-master/) +[![Build Status](https://jenkins.nordix.org/view/all/job/meridio-periodic/badge/icon)](https://jenkins.nordix.org/view/all/job/meridio-periodic/) [![Go Reference](https://img.shields.io/badge/godoc-reference-blue)](https://pkg.go.dev/github.com/nordix/meridio) [![go.mod version](https://img.shields.io/github/go-mod/go-version/nordix/meridio)](https://github.com/nordix/meridio) [![Go Report Card](https://goreportcard.com/badge/github.com/nordix/meridio)](https://goreportcard.com/report/github.com/nordix/meridio)