From 8cef0fe43bf917b51482bd5352e89ee75defd319 Mon Sep 17 00:00:00 2001 From: Corey Boornazian Date: Mon, 23 Jul 2018 16:43:06 -0400 Subject: [PATCH] Add flags so user can choose service ports Signed-off-by: Corey Boornazian Update config file to reflect changes to flags Signed-off-by Corey Boornazian Change wording and clean up structs in cmd files Signed-off-by: Corey Boornazian Add cmd flags for hotrod service ports Signed-off-by: Corey Boornazian --- examples/hotrod/cmd/customer.go | 5 ++-- examples/hotrod/cmd/driver.go | 5 ++-- examples/hotrod/cmd/frontend.go | 5 ++-- examples/hotrod/cmd/root.go | 32 +++++++++++++++++++++++ examples/hotrod/cmd/route.go | 5 ++-- examples/hotrod/services/config/config.go | 14 ++++++++++ 6 files changed, 54 insertions(+), 12 deletions(-) diff --git a/examples/hotrod/cmd/customer.go b/examples/hotrod/cmd/customer.go index e31743af4a1..767c006c1a0 100644 --- a/examples/hotrod/cmd/customer.go +++ b/examples/hotrod/cmd/customer.go @@ -24,6 +24,7 @@ import ( "github.com/jaegertracing/jaeger/examples/hotrod/pkg/log" "github.com/jaegertracing/jaeger/examples/hotrod/pkg/tracing" "github.com/jaegertracing/jaeger/examples/hotrod/services/customer" + "github.com/jaegertracing/jaeger/examples/hotrod/services/config" ) // customerCmd represents the customer command @@ -35,7 +36,7 @@ var customerCmd = &cobra.Command{ zapLogger := logger.With(zap.String("service", "customer")) logger := log.NewFactory(zapLogger) server := customer.NewServer( - net.JoinHostPort(customerOptions.serverInterface, strconv.Itoa(customerOptions.serverPort)), + net.JoinHostPort(customerOptions.serverInterface, strconv.Itoa(config.CustomerPort)), tracing.Init("customer", metricsFactory.Namespace("customer", nil), logger, jAgentHostPort), metricsFactory, logger, @@ -48,7 +49,6 @@ var customerCmd = &cobra.Command{ var ( customerOptions struct { serverInterface string - serverPort int } ) @@ -56,5 +56,4 @@ func init() { RootCmd.AddCommand(customerCmd) customerCmd.Flags().StringVarP(&customerOptions.serverInterface, "bind", "", "0.0.0.0", "interface to which the Customer server will bind") - customerCmd.Flags().IntVarP(&customerOptions.serverPort, "port", "p", 8081, "port on which the Customer server will listen") } diff --git a/examples/hotrod/cmd/driver.go b/examples/hotrod/cmd/driver.go index c795aecfc11..d690ca03252 100644 --- a/examples/hotrod/cmd/driver.go +++ b/examples/hotrod/cmd/driver.go @@ -24,6 +24,7 @@ import ( "github.com/jaegertracing/jaeger/examples/hotrod/pkg/log" "github.com/jaegertracing/jaeger/examples/hotrod/pkg/tracing" "github.com/jaegertracing/jaeger/examples/hotrod/services/driver" + "github.com/jaegertracing/jaeger/examples/hotrod/services/config" ) // driverCmd represents the driver command @@ -35,7 +36,7 @@ var driverCmd = &cobra.Command{ zapLogger := logger.With(zap.String("service", "driver")) logger := log.NewFactory(zapLogger) server := driver.NewServer( - net.JoinHostPort(driverOptions.serverInterface, strconv.Itoa(driverOptions.serverPort)), + net.JoinHostPort(driverOptions.serverInterface, strconv.Itoa(config.DriverPort)), tracing.Init("driver", metricsFactory.Namespace("driver", nil), logger, jAgentHostPort), metricsFactory, logger, @@ -48,7 +49,6 @@ var driverCmd = &cobra.Command{ var ( driverOptions struct { serverInterface string - serverPort int } ) @@ -56,5 +56,4 @@ func init() { RootCmd.AddCommand(driverCmd) driverCmd.Flags().StringVarP(&driverOptions.serverInterface, "bind", "", "0.0.0.0", "interface to which the driver server will bind") - driverCmd.Flags().IntVarP(&driverOptions.serverPort, "port", "p", 8082, "port on which the driver server will listen") } diff --git a/examples/hotrod/cmd/frontend.go b/examples/hotrod/cmd/frontend.go index d5001f99fb2..635b5a298fb 100644 --- a/examples/hotrod/cmd/frontend.go +++ b/examples/hotrod/cmd/frontend.go @@ -24,6 +24,7 @@ import ( "github.com/jaegertracing/jaeger/examples/hotrod/pkg/log" "github.com/jaegertracing/jaeger/examples/hotrod/pkg/tracing" "github.com/jaegertracing/jaeger/examples/hotrod/services/frontend" + "github.com/jaegertracing/jaeger/examples/hotrod/services/config" ) // frontendCmd represents the frontend command @@ -35,7 +36,7 @@ var frontendCmd = &cobra.Command{ zapLogger := logger.With(zap.String("service", "frontend")) logger := log.NewFactory(zapLogger) server := frontend.NewServer( - net.JoinHostPort(frontendOptions.serverInterface, strconv.Itoa(frontendOptions.serverPort)), + net.JoinHostPort(frontendOptions.serverInterface, strconv.Itoa(config.FrontendPort)), tracing.Init("frontend", metricsFactory.Namespace("frontend", nil), logger, jAgentHostPort), logger, ) @@ -46,7 +47,6 @@ var frontendCmd = &cobra.Command{ var ( frontendOptions struct { serverInterface string - serverPort int } ) @@ -54,5 +54,4 @@ func init() { RootCmd.AddCommand(frontendCmd) frontendCmd.Flags().StringVarP(&frontendOptions.serverInterface, "bind", "", "0.0.0.0", "interface to which the frontend server will bind") - frontendCmd.Flags().IntVarP(&frontendOptions.serverPort, "port", "p", 8080, "port on which the frontend server will listen") } diff --git a/examples/hotrod/cmd/root.go b/examples/hotrod/cmd/root.go index 5b1730bcedd..220534fa2cb 100644 --- a/examples/hotrod/cmd/root.go +++ b/examples/hotrod/cmd/root.go @@ -38,6 +38,11 @@ var ( fixDBConnDelay time.Duration fixDBConnDisableMutex bool fixRouteWorkerPoolSize int + + customerPort int + driverPort int + frontendPort int + routePort int ) // RootCmd represents the base command when called without any subcommands @@ -62,6 +67,13 @@ func init() { RootCmd.PersistentFlags().DurationVarP(&fixDBConnDelay, "fix-db-query-delay", "D", 300*time.Millisecond, "Average lagency of MySQL DB query") RootCmd.PersistentFlags().BoolVarP(&fixDBConnDisableMutex, "fix-disable-db-conn-mutex", "M", false, "Disables the mutex guarding db connection") RootCmd.PersistentFlags().IntVarP(&fixRouteWorkerPoolSize, "fix-route-worker-pool-size", "W", 3, "Default worker pool size") + + // Add flags to choose ports for services + RootCmd.PersistentFlags().IntVarP(&customerPort, "customer-service-port", "c", 8081, "Port for customer service") + RootCmd.PersistentFlags().IntVarP(&driverPort, "driver-service-port", "d", 8082, "Port for driver service") + RootCmd.PersistentFlags().IntVarP(&frontendPort, "frontend-service-port", "f", 8080, "Port for frontend service") + RootCmd.PersistentFlags().IntVarP(&routePort, "route-service-port", "r", 8083, "Port for routing service") + rand.Seed(int64(time.Now().Nanosecond())) logger, _ = zap.NewDevelopment(zap.AddStacktrace(zapcore.FatalLevel)) cobra.OnInitialize(onInitialize) @@ -90,6 +102,26 @@ func onInitialize() { logger.Info("fix: overriding route worker pool size", zap.Int("old", config.RouteWorkerPoolSize), zap.Int("new", fixRouteWorkerPoolSize)) config.RouteWorkerPoolSize = fixRouteWorkerPoolSize } + + if config.CustomerPort != customerPort { + logger.Info("changing customer service port", zap.Int("old", config.CustomerPort), zap.Int("new", customerPort)) + config.CustomerPort = customerPort + } + + if config.DriverPort != driverPort { + logger.Info("changing driver service port", zap.Int("old", config.DriverPort), zap.Int("new", driverPort)) + config.DriverPort = driverPort + } + + if config.FrontendPort != frontendPort { + logger.Info("changing frontend service port", zap.Int("old", config.FrontendPort), zap.Int("new", frontendPort)) + config.FrontendPort = frontendPort + } + + if config.RoutePort != routePort { + logger.Info("changing route service port", zap.Int("old", config.RoutePort), zap.Int("new", routePort)) + config.RoutePort = routePort + } } func logError(logger *zap.Logger, err error) error { diff --git a/examples/hotrod/cmd/route.go b/examples/hotrod/cmd/route.go index 04c79201bcf..f119c76ed9f 100644 --- a/examples/hotrod/cmd/route.go +++ b/examples/hotrod/cmd/route.go @@ -24,6 +24,7 @@ import ( "github.com/jaegertracing/jaeger/examples/hotrod/pkg/log" "github.com/jaegertracing/jaeger/examples/hotrod/pkg/tracing" "github.com/jaegertracing/jaeger/examples/hotrod/services/route" + "github.com/jaegertracing/jaeger/examples/hotrod/services/config" ) // routeCmd represents the route command @@ -35,7 +36,7 @@ var routeCmd = &cobra.Command{ zapLogger := logger.With(zap.String("service", "route")) logger := log.NewFactory(zapLogger) server := route.NewServer( - net.JoinHostPort(routeOptions.serverInterface, strconv.Itoa(routeOptions.serverPort)), + net.JoinHostPort(routeOptions.serverInterface, strconv.Itoa(config.RoutePort)), tracing.Init("route", metricsFactory.Namespace("route", nil), logger, jAgentHostPort), logger, ) @@ -46,7 +47,6 @@ var routeCmd = &cobra.Command{ var ( routeOptions struct { serverInterface string - serverPort int } ) @@ -54,5 +54,4 @@ func init() { RootCmd.AddCommand(routeCmd) routeCmd.Flags().StringVarP(&routeOptions.serverInterface, "bind", "", "0.0.0.0", "interface to which the Route server will bind") - routeCmd.Flags().IntVarP(&routeOptions.serverPort, "port", "p", 8083, "port on which the Route server will listen") } diff --git a/examples/hotrod/services/config/config.go b/examples/hotrod/services/config/config.go index ff0a8eaf8c2..ead8c5504ae 100644 --- a/examples/hotrod/services/config/config.go +++ b/examples/hotrod/services/config/config.go @@ -59,4 +59,18 @@ var ( // RouteCalcDelayStdDev is standard deviation RouteCalcDelayStdDev = RouteCalcDelay / 4 + + // Port settings, can be overwritten from command line + + // Customer Service Port + CustomerPort = 8081 + + // Driver Service Port + DriverPort = 8082 + + // Frontend Service Port + FrontendPort = 8080 + + // Routing Service Port + RoutePort = 8083 )