From 4c6b98b91ac5ba908f5f719934eae9215cdbb572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20B=C4=85czek?= Date: Mon, 26 Sep 2022 16:06:58 +0200 Subject: [PATCH] Allow specifying different http readiness host (#255) --- cmd/flags/target.go | 11 +++++++- docs/about/getting-started.md | 51 ++++++++++++++++++----------------- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/cmd/flags/target.go b/cmd/flags/target.go index 1d08c77..e01f415 100644 --- a/cmd/flags/target.go +++ b/cmd/flags/target.go @@ -30,6 +30,7 @@ type Target struct { GrpcPort int ReadinessProtocol string ReadinessHTTPPath string + ReadinessHTTPHost string ReadinessGrpcMethod string ReadinessPort int Insecure bool @@ -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") @@ -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{ @@ -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 { diff --git a/docs/about/getting-started.md b/docs/about/getting-started.md index a89f638..28e8dec 100644 --- a/docs/about/getting-started.md +++ b/docs/about/getting-started.md @@ -11,31 +11,32 @@ The application receives a number of command-line flags including the requests t ## Flags -| Flag | Type | Default value | Description | -|:----------------------------------|:--------|:----------------------------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| -concurrency | int | 2 | Number of concurrent requests for warm up | -| -exit-after-warmup | bool | false | If mittens should exit after completion of warm up | -| -http-headers | strings | N/A | Http headers to be sent with warm up requests. To send multiple headers define this flag for each header | -| -grpc-requests | strings | N/A | gRPC requests to be sent. Request is in '\\\[:message\]' format. E.g. health/ping:{"key": "value"}. To send multiple requests, simply repeat this flag for each request. Use the notation `:file/xyz.json` if you want to use an external file for the request body. | -| -http-requests | string | N/A | Http request to be sent. Request is in `:[:body]` format. E.g. `post:/ping:{"key": "value"}`. To send multiple requests, simply repeat this flag for each request. Use the notation `:file/xyz.json` if you want to use an external file for the request body. | -| -fail-readiness | bool | false | If set to true readiness will fail if the target did not became ready in time | -| -file-probe-enabled | bool | true | If set to true writes files that can be used as readiness/liveness probes. a file with the name `alive` is created when Mittens starts and a file named `ready` is created when the warmup completes | -| -file-probe-liveness-path | string | alive | File to be used for liveness probe | -| -file-probe-readiness-path | string | ready | File to be used for readiness probe | -| -request-delay-milliseconds | int | 500 | Delay in milliseconds between requests | -| -target-grpc-host | string | localhost | gRPC host to warm up | -| -target-grpc-port | int | 50051 | gRPC port for warm up requests | -| -target-http-host | string | http://localhost | Http host to warm up | -| -target-http-port | int | 8080 | Http port for warm up requests | -| -target-insecure | bool | false | Whether to skip TLS validation | -| -target-readiness-grpc-method | string | grpc.health.v1.Health/Check | The service method used for gRPC target readiness probe | -| -target-readiness-http-path | string | /ready | The path used for target readiness probe | -| -target-readiness-port | int | same as -target-http-port | The port used for target readiness probe | -| -target-readiness-protocol | string | http | Protocol to be used for readiness check. One of [`http`, `grpc`] | -| -max-duration-seconds | int | 60 | Global maximum duration. This includes both the time spent warming up the target service and also the time waiting for the target to become ready | -| -max-readiness-wait-seconds | int | 30 | Maximum time to wait for the target to become ready | -| -max-warmup-seconds | int | 30 | Maximum time spent sending warmup requests to the target service. Please note that `max-duration-seconds` may cap this duration | -| -concurrency-target-seconds | int | 0 | Time taken to reach expected concurrency. This is useful to ramp up traffic. | +| Flag | Type | Default value | Description | +|:---------------------------------|:--------|:----------------------------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| -concurrency | int | 2 | Number of concurrent requests for warm up | +| -exit-after-warmup | bool | false | If mittens should exit after completion of warm up | +| -http-headers | strings | N/A | Http headers to be sent with warm up requests. To send multiple headers define this flag for each header | +| -grpc-requests | strings | N/A | gRPC requests to be sent. Request is in '\\\[:message\]' format. E.g. health/ping:{"key": "value"}. To send multiple requests, simply repeat this flag for each request. Use the notation `:file/xyz.json` if you want to use an external file for the request body. | +| -http-requests | string | N/A | Http request to be sent. Request is in `:[:body]` format. E.g. `post:/ping:{"key": "value"}`. To send multiple requests, simply repeat this flag for each request. Use the notation `:file/xyz.json` if you want to use an external file for the request body. | +| -fail-readiness | bool | false | If set to true readiness will fail if the target did not became ready in time | +| -file-probe-enabled | bool | true | If set to true writes files that can be used as readiness/liveness probes. a file with the name `alive` is created when Mittens starts and a file named `ready` is created when the warmup completes | +| -file-probe-liveness-path | string | alive | File to be used for liveness probe | +| -file-probe-readiness-path | string | ready | File to be used for readiness probe | +| -request-delay-milliseconds | int | 500 | Delay in milliseconds between requests | +| -target-grpc-host | string | localhost | gRPC host to warm up | +| -target-grpc-port | int | 50051 | gRPC port for warm up requests | +| -target-http-host | string | http://localhost | Http host to warm up | +| -target-http-port | int | 8080 | Http port for warm up requests | +| -target-insecure | bool | false | Whether to skip TLS validation | +| -target-readiness-grpc-method | string | grpc.health.v1.Health/Check | The service method used for gRPC target readiness probe | +| -target-readiness-http-path | string | /ready | The path used for target readiness probe | +| -target-readiness-http-host | string | same as -target-http-host | The host used for target readiness probe | +| -target-readiness-port | int | same as -target-http-port | The port used for target readiness probe | +| -target-readiness-protocol | string | http | Protocol to be used for readiness check. One of [`http`, `grpc`] | +| -max-duration-seconds | int | 60 | Global maximum duration. This includes both the time spent warming up the target service and also the time waiting for the target to become ready | +| -max-readiness-wait-seconds | int | 30 | Maximum time to wait for the target to become ready | +| -max-warmup-seconds | int | 30 | Maximum time spent sending warmup requests to the target service. Please note that `max-duration-seconds` may cap this duration | +| -concurrency-target-seconds | int | 0 | Time taken to reach expected concurrency. This is useful to ramp up traffic. | ### Warmup request A warmup request can be an HTTP one (over REST) or a gRPC one.