Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Enable configuration of hostnames for hotrod services #6782

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/hotrod/cmd/customer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var customerCmd = &cobra.Command{
zapLogger := logger.With(zap.String("service", "customer"))
logger := log.NewFactory(zapLogger)
server := customer.NewServer(
net.JoinHostPort("0.0.0.0", strconv.Itoa(customerPort)),
net.JoinHostPort(customerHostname, strconv.Itoa(customerPort)),
otelExporter,
metricsFactory,
logger,
Expand Down
2 changes: 1 addition & 1 deletion examples/hotrod/cmd/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var driverCmd = &cobra.Command{
zapLogger := logger.With(zap.String("service", "driver"))
logger := log.NewFactory(zapLogger)
server := driver.NewServer(
net.JoinHostPort("0.0.0.0", strconv.Itoa(driverPort)),
net.JoinHostPort(driverHostname, strconv.Itoa(driverPort)),
otelExporter,
metricsFactory,
logger,
Expand Down
11 changes: 11 additions & 0 deletions examples/hotrod/cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ var (
fixDBConnDisableMutex bool
fixRouteWorkerPoolSize int

customerHostname string
driverHostname string
frontendHostname string
routeHostname string

customerPort int
driverPort int
frontendPort int
Expand All @@ -34,6 +39,12 @@ func addFlags(cmd *cobra.Command) {
cmd.PersistentFlags().BoolVarP(&fixDBConnDisableMutex, "fix-disable-db-conn-mutex", "M", false, "Disables the mutex guarding db connection")
cmd.PersistentFlags().IntVarP(&fixRouteWorkerPoolSize, "fix-route-worker-pool-size", "W", 3, "Default worker pool size")

// Add flags to choose hostnames for services
cmd.PersistentFlags().StringVar(&customerHostname, "customer-service-hostname", "0.0.0.0", "Hostname for customer service")
cmd.PersistentFlags().StringVar(&driverHostname, "driver-service-hostname", "0.0.0.0", "Hostname for driver service")
cmd.PersistentFlags().StringVar(&frontendHostname, "frontend-service-hostname", "0.0.0.0", "Hostname for frontend service")
cmd.PersistentFlags().StringVar(&routeHostname, "route-service-hostname", "0.0.0.0", "Hostname for routing service")

// Add flags to choose ports for services
cmd.PersistentFlags().IntVarP(&customerPort, "customer-service-port", "c", 8081, "Port for customer service")
cmd.PersistentFlags().IntVarP(&driverPort, "driver-service-port", "d", 8082, "Port for driver service")
Expand Down
8 changes: 4 additions & 4 deletions examples/hotrod/cmd/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ var frontendCmd = &cobra.Command{
Short: "Starts Frontend service",
Long: `Starts Frontend service.`,
RunE: func(_ *cobra.Command, _ /* args */ []string) error {
options.FrontendHostPort = net.JoinHostPort("0.0.0.0", strconv.Itoa(frontendPort))
options.DriverHostPort = net.JoinHostPort("0.0.0.0", strconv.Itoa(driverPort))
options.CustomerHostPort = net.JoinHostPort("0.0.0.0", strconv.Itoa(customerPort))
options.RouteHostPort = net.JoinHostPort("0.0.0.0", strconv.Itoa(routePort))
options.FrontendHostPort = net.JoinHostPort(frontendHostname, strconv.Itoa(frontendPort))
options.DriverHostPort = net.JoinHostPort(driverHostname, strconv.Itoa(driverPort))
options.CustomerHostPort = net.JoinHostPort(customerHostname, strconv.Itoa(customerPort))
options.RouteHostPort = net.JoinHostPort(routeHostname, strconv.Itoa(routePort))
options.Basepath = basepath
options.JaegerUI = jaegerUI

Expand Down
16 changes: 16 additions & 0 deletions examples/hotrod/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ func onInitialize() {
config.RouteWorkerPoolSize = fixRouteWorkerPoolSize
}

if customerHostname != "0.0.0.0" {
logger.Info("changing customer service hostname", zap.String("old", "0.0.0.0"), zap.String("new", customerHostname))
}

if driverHostname != "0.0.0.0" {
logger.Info("changing driver service hostname", zap.String("old", "0.0.0.0"), zap.String("new", driverHostname))
}

if frontendHostname != "0.0.0.0" {
logger.Info("changing frontend service hostname", zap.String("old", "0.0.0.0"), zap.String("new", frontendHostname))
}

if routeHostname != "0.0.0.0" {
logger.Info("changing route service hostname", zap.String("old", "0.0.0.0"), zap.String("new", routeHostname))
}

if customerPort != 8081 {
logger.Info("changing customer service port", zap.Int("old", 8081), zap.Int("new", customerPort))
}
Expand Down
2 changes: 1 addition & 1 deletion examples/hotrod/cmd/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var routeCmd = &cobra.Command{
zapLogger := logger.With(zap.String("service", "route"))
logger := log.NewFactory(zapLogger)
server := route.NewServer(
net.JoinHostPort("0.0.0.0", strconv.Itoa(routePort)),
net.JoinHostPort(routeHostname, strconv.Itoa(routePort)),
tracing.InitOTEL("route", otelExporter, metricsFactory, logger),
logger,
)
Expand Down
Loading