From f1171198de1a5f06e83e6d4b8e785f8e49fc80d9 Mon Sep 17 00:00:00 2001 From: benniekiss <63211101+benniekiss@users.noreply.github.com> Date: Sat, 14 Sep 2024 04:34:32 -0400 Subject: [PATCH] [management] Add command flag to set metrics port for signal and relay service, and update management port (#2599) * add flags to customize metrics port for relay and signal * change management default metrics port to match other services --- management/cmd/root.go | 2 +- relay/cmd/root.go | 8 +++----- signal/cmd/run.go | 6 ++---- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/management/cmd/root.go b/management/cmd/root.go index 9b6a96b82..86155a956 100644 --- a/management/cmd/root.go +++ b/management/cmd/root.go @@ -54,7 +54,7 @@ func Execute() error { func init() { stopCh = make(chan int) mgmtCmd.Flags().IntVar(&mgmtPort, "port", 80, "server port to listen on (defaults to 443 if TLS is enabled, 80 otherwise") - mgmtCmd.Flags().IntVar(&mgmtMetricsPort, "metrics-port", 8081, "metrics endpoint http port. Metrics are accessible under host:metrics-port/metrics") + mgmtCmd.Flags().IntVar(&mgmtMetricsPort, "metrics-port", 9090, "metrics endpoint http port. Metrics are accessible under host:metrics-port/metrics") mgmtCmd.Flags().StringVar(&mgmtDataDir, "datadir", defaultMgmtDataDir, "server data directory location") mgmtCmd.Flags().StringVar(&mgmtConfig, "config", defaultMgmtConfig, "Netbird config file location. Config params specified via command line (e.g. datadir) have a precedence over configuration from this file") mgmtCmd.Flags().StringVar(&mgmtLetsencryptDomain, "letsencrypt-domain", "", "a domain to issue Let's Encrypt certificate for. Enables TLS using Let's Encrypt. Will fetch and renew certificate, and run the server with TLS") diff --git a/relay/cmd/root.go b/relay/cmd/root.go index dcc1465d0..d603ff73b 100644 --- a/relay/cmd/root.go +++ b/relay/cmd/root.go @@ -23,15 +23,12 @@ import ( "github.com/netbirdio/netbird/util" ) -const ( - metricsPort = 9090 -) - type Config struct { ListenAddress string // in HA every peer connect to a common domain, the instance domain has been distributed during the p2p connection // it is a domain:port or ip:port ExposedAddress string + MetricsPort int LetsencryptEmail string LetsencryptDataDir string LetsencryptDomains []string @@ -80,6 +77,7 @@ func init() { cobraConfig = &Config{} rootCmd.PersistentFlags().StringVarP(&cobraConfig.ListenAddress, "listen-address", "l", ":443", "listen address") rootCmd.PersistentFlags().StringVarP(&cobraConfig.ExposedAddress, "exposed-address", "e", "", "instance domain address (or ip) and port, it will be distributes between peers") + rootCmd.PersistentFlags().IntVar(&cobraConfig.MetricsPort, "metrics-port", 9090, "metrics endpoint http port. Metrics are accessible under host:metrics-port/metrics") rootCmd.PersistentFlags().StringVarP(&cobraConfig.LetsencryptDataDir, "letsencrypt-data-dir", "d", "", "a directory to store Let's Encrypt data. Required if Let's Encrypt is enabled.") rootCmd.PersistentFlags().StringSliceVarP(&cobraConfig.LetsencryptDomains, "letsencrypt-domains", "a", nil, "list of domains to issue Let's Encrypt certificate for. Enables TLS using Let's Encrypt. Will fetch and renew certificate, and run the server with TLS") rootCmd.PersistentFlags().StringVar(&cobraConfig.LetsencryptEmail, "letsencrypt-email", "", "email address to use for Let's Encrypt certificate registration") @@ -116,7 +114,7 @@ func execute(cmd *cobra.Command, args []string) error { return fmt.Errorf("failed to initialize log: %s", err) } - metricsServer, err := metrics.NewServer(metricsPort, "") + metricsServer, err := metrics.NewServer(cobraConfig.MetricsPort, "") if err != nil { log.Debugf("setup metrics: %v", err) return fmt.Errorf("setup metrics: %v", err) diff --git a/signal/cmd/run.go b/signal/cmd/run.go index 61f7a32a7..0bdc62ead 100644 --- a/signal/cmd/run.go +++ b/signal/cmd/run.go @@ -29,12 +29,9 @@ import ( "google.golang.org/grpc/keepalive" ) -const ( - metricsPort = 9090 -) - var ( signalPort int + metricsPort int signalLetsencryptDomain string signalSSLDir string defaultSignalSSLDir string @@ -288,6 +285,7 @@ func loadTLSConfig(certFile string, certKey string) (*tls.Config, error) { func init() { runCmd.PersistentFlags().IntVar(&signalPort, "port", 80, "Server port to listen on (defaults to 443 if TLS is enabled, 80 otherwise") + runCmd.Flags().IntVar(&metricsPort, "metrics-port", 9090, "metrics endpoint http port. Metrics are accessible under host:metrics-port/metrics") runCmd.Flags().StringVar(&signalSSLDir, "ssl-dir", defaultSignalSSLDir, "server ssl directory location. *Required only for Let's Encrypt certificates.") runCmd.Flags().StringVar(&signalLetsencryptDomain, "letsencrypt-domain", "", "a domain to issue Let's Encrypt certificate for. Enables TLS using Let's Encrypt. Will fetch and renew certificate, and run the server with TLS") runCmd.Flags().StringVar(&signalCertFile, "cert-file", "", "Location of your SSL certificate. Can be used when you have an existing certificate and don't want a new certificate be generated automatically. If letsencrypt-domain is specified this property has no effect")