Skip to content

Commit

Permalink
Allow specifying different http readiness host (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Bączek authored Sep 26, 2022
1 parent 7da40d2 commit 4c6b98b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 26 deletions.
11 changes: 10 additions & 1 deletion cmd/flags/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Target struct {
GrpcPort int
ReadinessProtocol string
ReadinessHTTPPath string
ReadinessHTTPHost string
ReadinessGrpcMethod string
ReadinessPort int
Insecure bool
Expand All @@ -46,6 +47,7 @@ func (t *Target) initFlags() {
flag.IntVar(&t.GrpcPort, "target-grpc-port", 50051, "Grpc port for warm up requests")
flag.StringVar(&t.ReadinessProtocol, "target-readiness-protocol", "http", "Protocol to be used for readiness check. One of [http, grpc]")
flag.StringVar(&t.ReadinessHTTPPath, "target-readiness-http-path", "/ready", "The path used for HTTP target readiness probe")
flag.StringVar(&t.ReadinessHTTPHost, "target-readiness-http-host", toStringOrDefaultIfNull(&t.HTTPHost, "http://localhost"), "The HTTP host used for target readiness probe")
flag.StringVar(&t.ReadinessGrpcMethod, "target-readiness-grpc-method", "grpc.health.v1.Health/Check", "The service method used for gRPC target readiness probe")
flag.IntVar(&t.ReadinessPort, "target-readiness-port", toIntOrDefaultIfNull(&t.HTTPPort, 8080), "The port used for target readiness probe")
flag.BoolVar(&t.Insecure, "target-insecure", false, "Whether to skip TLS validation")
Expand All @@ -58,6 +60,13 @@ func toIntOrDefaultIfNull(value *int, defaultValue int) int {
return *value
}

func toStringOrDefaultIfNull(value *string, defaultValue string) string {
if value == nil {
return defaultValue
}
return *value
}

func (t *Target) getWarmupTargetOptions() warmup.TargetOptions {

return warmup.TargetOptions{
Expand All @@ -69,7 +78,7 @@ func (t *Target) getWarmupTargetOptions() warmup.TargetOptions {
}

func (t *Target) getReadinessHTTPClient() http.Client {
return http.NewClient(fmt.Sprintf("%s:%d", t.HTTPHost, t.ReadinessPort), t.Insecure)
return http.NewClient(fmt.Sprintf("%s:%d", t.ReadinessHTTPHost, t.ReadinessPort), t.Insecure)
}

func (t *Target) getReadinessGrpcClient() grpc.Client {
Expand Down
Loading

0 comments on commit 4c6b98b

Please sign in to comment.