diff --git a/.golangci.yml b/.golangci.yml index d60b30d..4cd40d7 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -37,7 +37,7 @@ linters-settings: threshold: 150 funlen: Lines: 300 - Statements: 125 + Statements: 130 goconst: min-len: 2 min-occurrences: 2 diff --git a/README.md b/README.md index 4ba5994..0ec69a6 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,8 @@ docker build . * `NSM_PREFIX_SERVER_URL` - URL to VL3 IPAM server(s) (default: "vl3-ipam:5006") * `NSM_DNS_TEMPLATES` - Represents domain naming templates in go-template format. It is using for generating the domain name for each nse/nsc in the vl3 network (default: "{{ index .Labels "podName" }}.{{ .NetworkService }}.") * `NSM_LOG_LEVEL` - Log level (default: "INFO") +* `NSM_PPROF_ENABLED` - is pprof enabled (default: "false") +* `NSM_PPROF_LISTEN_ON` - pprof URL to ListenAndServe (default: "localhost:6060") # Testing diff --git a/internal/imports/imports_linux.go b/internal/imports/imports_linux.go new file mode 100644 index 0000000..3d7b7a3 --- /dev/null +++ b/internal/imports/imports_linux.go @@ -0,0 +1,72 @@ +// Code generated by github.com/edwarnicke/imports-gen DO NOT EDIT. +package imports + +import ( + _ "context" + _ "crypto/tls" + _ "github.com/antonfisher/nested-logrus-formatter" + _ "github.com/edwarnicke/genericsync" + _ "github.com/edwarnicke/grpcfd" + _ "github.com/kelseyhightower/envconfig" + _ "github.com/networkservicemesh/api/pkg/api/ipam" + _ "github.com/networkservicemesh/api/pkg/api/networkservice" + _ "github.com/networkservicemesh/api/pkg/api/networkservice/payload" + _ "github.com/networkservicemesh/api/pkg/api/registry" + _ "github.com/networkservicemesh/sdk-vpp/pkg/networkservice/connectioncontext/ipcontext/ipaddress" + _ "github.com/networkservicemesh/sdk-vpp/pkg/networkservice/connectioncontext/ipcontext/routes" + _ "github.com/networkservicemesh/sdk-vpp/pkg/networkservice/connectioncontext/ipcontext/unnumbered" + _ "github.com/networkservicemesh/sdk-vpp/pkg/networkservice/connectioncontext/mtu" + _ "github.com/networkservicemesh/sdk-vpp/pkg/networkservice/loopback" + _ "github.com/networkservicemesh/sdk-vpp/pkg/networkservice/mechanisms/memif" + _ "github.com/networkservicemesh/sdk-vpp/pkg/networkservice/tag" + _ "github.com/networkservicemesh/sdk-vpp/pkg/networkservice/up" + _ "github.com/networkservicemesh/sdk-vpp/pkg/networkservice/vrf" + _ "github.com/networkservicemesh/sdk/pkg/ipam/strictvl3ipam" + _ "github.com/networkservicemesh/sdk/pkg/networkservice/chains/client" + _ "github.com/networkservicemesh/sdk/pkg/networkservice/chains/endpoint" + _ "github.com/networkservicemesh/sdk/pkg/networkservice/common/authorize" + _ "github.com/networkservicemesh/sdk/pkg/networkservice/common/clientinfo" + _ "github.com/networkservicemesh/sdk/pkg/networkservice/common/heal" + _ "github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms" + _ "github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms/kernel" + _ "github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms/recvfd" + _ "github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms/sendfd" + _ "github.com/networkservicemesh/sdk/pkg/networkservice/common/null" + _ "github.com/networkservicemesh/sdk/pkg/networkservice/common/onidle" + _ "github.com/networkservicemesh/sdk/pkg/networkservice/common/retry" + _ "github.com/networkservicemesh/sdk/pkg/networkservice/common/upstreamrefresh" + _ "github.com/networkservicemesh/sdk/pkg/networkservice/connectioncontext/dnscontext/vl3dns" + _ "github.com/networkservicemesh/sdk/pkg/networkservice/connectioncontext/ipcontext/vl3" + _ "github.com/networkservicemesh/sdk/pkg/networkservice/connectioncontext/mtu/vl3mtu" + _ "github.com/networkservicemesh/sdk/pkg/networkservice/core/chain" + _ "github.com/networkservicemesh/sdk/pkg/networkservice/core/next" + _ "github.com/networkservicemesh/sdk/pkg/registry/chains/client" + _ "github.com/networkservicemesh/sdk/pkg/registry/common/authorize" + _ "github.com/networkservicemesh/sdk/pkg/registry/common/clientinfo" + _ "github.com/networkservicemesh/sdk/pkg/registry/common/sendfd" + _ "github.com/networkservicemesh/sdk/pkg/tools/debug" + _ "github.com/networkservicemesh/sdk/pkg/tools/grpcutils" + _ "github.com/networkservicemesh/sdk/pkg/tools/log" + _ "github.com/networkservicemesh/sdk/pkg/tools/log/logruslogger" + _ "github.com/networkservicemesh/sdk/pkg/tools/opentelemetry" + _ "github.com/networkservicemesh/sdk/pkg/tools/pprofutils" + _ "github.com/networkservicemesh/sdk/pkg/tools/spiffejwt" + _ "github.com/networkservicemesh/sdk/pkg/tools/token" + _ "github.com/networkservicemesh/sdk/pkg/tools/tracing" + _ "github.com/networkservicemesh/vpphelper" + _ "github.com/pkg/errors" + _ "github.com/sirupsen/logrus" + _ "github.com/spiffe/go-spiffe/v2/spiffetls/tlsconfig" + _ "github.com/spiffe/go-spiffe/v2/svid/x509svid" + _ "github.com/spiffe/go-spiffe/v2/workloadapi" + _ "google.golang.org/grpc" + _ "google.golang.org/grpc/credentials" + _ "google.golang.org/protobuf/proto" + _ "net" + _ "net/url" + _ "os" + _ "os/signal" + _ "path/filepath" + _ "syscall" + _ "time" +) diff --git a/main.go b/main.go index 403120d..c3ddbb9 100644 --- a/main.go +++ b/main.go @@ -94,6 +94,7 @@ import ( "github.com/networkservicemesh/sdk/pkg/tools/grpcutils" "github.com/networkservicemesh/sdk/pkg/tools/log" "github.com/networkservicemesh/sdk/pkg/tools/log/logruslogger" + "github.com/networkservicemesh/sdk/pkg/tools/pprofutils" "github.com/networkservicemesh/sdk/pkg/tools/spiffejwt" ) @@ -117,6 +118,8 @@ type Config struct { PrefixServerURL []url.URL `default:"vl3-ipam:5006" desc:"URL to VL3 IPAM server(s)" split_words:"true"` DNSTemplates []string `default:"{{ index .Labels \"podName\" }}.{{ .NetworkService }}." desc:"Represents domain naming templates in go-template format. It is using for generating the domain name for each nse/nsc in the vl3 network" split_words:"true"` LogLevel string `default:"INFO" desc:"Log level" split_words:"true"` + PprofEnabled bool `default:"false" desc:"is pprof enabled" split_words:"true"` + PprofListenOn string `default:"localhost:6060" desc:"pprof URL to ListenAndServe" split_words:"true"` dnsServerAddr net.IP dnsServerAddrCh chan net.IP dnsConfigs genericsync.Map[string, []*networkservice.DNSConfig] @@ -243,6 +246,13 @@ func main() { }() } + // ******************************************************************************** + // Configure pprof + // ******************************************************************************** + if config.PprofEnabled { + go pprofutils.ListenAndServe(ctx, config.PprofListenOn) + } + log.FromContext(ctx).Infof("Config: %#v", config) // ********************************************************************************