Skip to content

Commit

Permalink
Add flags so user can choose service ports
Browse files Browse the repository at this point in the history
Signed-off-by: Corey Boornazian <coreyb220@gmail.com>

Update config file to reflect changes to flags
Signed-off-by Corey Boornazian <coreyb220@gmail.com>

Change wording and clean up structs in cmd files
Signed-off-by: Corey Boornazian <coreyb220@gmail.com>

Add cmd flags for hotrod service ports
Signed-off-by: Corey Boornazian <coreyb220@gmail.com>
  • Loading branch information
cboornaz17 committed Jul 24, 2018
1 parent fe43631 commit 8cef0fe
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 12 deletions.
5 changes: 2 additions & 3 deletions examples/hotrod/cmd/customer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -48,13 +49,11 @@ var customerCmd = &cobra.Command{
var (
customerOptions struct {
serverInterface string
serverPort int
}
)

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")
}
5 changes: 2 additions & 3 deletions examples/hotrod/cmd/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -48,13 +49,11 @@ var driverCmd = &cobra.Command{
var (
driverOptions struct {
serverInterface string
serverPort int
}
)

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")
}
5 changes: 2 additions & 3 deletions examples/hotrod/cmd/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
)
Expand All @@ -46,13 +47,11 @@ var frontendCmd = &cobra.Command{
var (
frontendOptions struct {
serverInterface string
serverPort int
}
)

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")
}
32 changes: 32 additions & 0 deletions examples/hotrod/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions examples/hotrod/cmd/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
)
Expand All @@ -46,13 +47,11 @@ var routeCmd = &cobra.Command{
var (
routeOptions struct {
serverInterface string
serverPort int
}
)

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")
}
14 changes: 14 additions & 0 deletions examples/hotrod/services/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

0 comments on commit 8cef0fe

Please sign in to comment.