From 15c4078032d5a5a40ef3b5436261dc21a568c56b Mon Sep 17 00:00:00 2001 From: aimuz Date: Mon, 5 Dec 2022 03:49:54 +0800 Subject: [PATCH] Enable profiler-address to be configured (#9311) Signed-off-by: aimuz Signed-off-by: aimuz --- cmd/dataplane/main.go | 3 +-- cmd/nginx/main.go | 2 +- internal/nginx/main.go | 3 +++ pkg/flags/flags.go | 5 ++++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cmd/dataplane/main.go b/cmd/dataplane/main.go index 8ea59a412..0ab978429 100644 --- a/cmd/dataplane/main.go +++ b/cmd/dataplane/main.go @@ -82,8 +82,7 @@ func main() { mc.Start(conf.ValidationWebhook) if conf.EnableProfiling { - // TODO: Turn Profiler address configurable via flags - go metrics.RegisterProfiler("127.0.0.1", nginx.ProfilerPort) + go metrics.RegisterProfiler(nginx.ProfilerAddress, nginx.ProfilerPort) } ngx := controller.NewNGINXController(conf, mc) diff --git a/cmd/nginx/main.go b/cmd/nginx/main.go index c585ed95e..9f0973ec9 100644 --- a/cmd/nginx/main.go +++ b/cmd/nginx/main.go @@ -143,7 +143,7 @@ func main() { mc.Start(conf.ValidationWebhook) if conf.EnableProfiling { - go metrics.RegisterProfiler("127.0.0.1", nginx.ProfilerPort) + go metrics.RegisterProfiler(nginx.ProfilerAddress, nginx.ProfilerPort) } ngx := controller.NewNGINXController(conf, mc) diff --git a/internal/nginx/main.go b/internal/nginx/main.go index 88d2ee877..ae319fe1f 100644 --- a/internal/nginx/main.go +++ b/internal/nginx/main.go @@ -36,6 +36,9 @@ import ( // ProfilerPort port used by the ingress controller to expose the Go Profiler when it is enabled. var ProfilerPort = 10245 +// ProfilerAddress IP address used by the ingress controller to expose the Go Profiler when it is enabled. +var ProfilerAddress = "127.0.0.1" + // TemplatePath path of the NGINX template var TemplatePath = "/etc/nginx/template/nginx.tmpl" diff --git a/pkg/flags/flags.go b/pkg/flags/flags.go index f7c1771e8..877000a7d 100644 --- a/pkg/flags/flags.go +++ b/pkg/flags/flags.go @@ -19,6 +19,7 @@ package flags import ( "flag" "fmt" + "net" "os" "time" @@ -201,7 +202,8 @@ Takes the form ":port". If not provided, no admission controller is starte internalLoggerAddress = flags.String("internal-logger-address", "127.0.0.1:11514", "Address to be used when binding internal syslogger") - profilerPort = flags.Int("profiler-port", 10245, "Port to use for expose the ingress controller Go profiler when it is enabled.") + profilerPort = flags.Int("profiler-port", 10245, "Port to use for expose the ingress controller Go profiler when it is enabled.") + profilerAddress = flags.IP("profiler-address", net.ParseIP("127.0.0.1"), "IP address used by the ingress controller to expose the Go Profiler when it is enabled.") statusUpdateInterval = flags.Int("status-update-interval", status.UpdateInterval, "Time interval in seconds in which the status should check if an update is required. Default is 60 seconds") @@ -275,6 +277,7 @@ https://blog.maxmind.com/2019/12/18/significant-changes-to-accessing-and-using-g nginx.StatusPort = *statusPort nginx.StreamPort = *streamPort nginx.ProfilerPort = *profilerPort + nginx.ProfilerAddress = profilerAddress.String() if *enableSSLPassthrough && !ing_net.IsPortAvailable(*sslProxyPort) { return false, nil, fmt.Errorf("port %v is already in use. Please check the flag --ssl-passthrough-proxy-port", *sslProxyPort)