mirror of https://github.com/dapr/cli.git
Add flags for app health checks (#1083)
* Add flags for app health checks Fixes #1082 Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com> * Added tests Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com> * 💄 Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com> * Update pkg/standalone/run_test.go Co-authored-by: Shubham Sharma <shubhash@microsoft.com> Signed-off-by: Alessandro (Ale) Segala <43508+ItalyPaleAle@users.noreply.github.com> * Update pkg/standalone/run_test.go Co-authored-by: Shubham Sharma <shubhash@microsoft.com> Signed-off-by: Alessandro (Ale) Segala <43508+ItalyPaleAle@users.noreply.github.com> * fix go version to 1.19.2 Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com> Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com> Signed-off-by: Alessandro (Ale) Segala <43508+ItalyPaleAle@users.noreply.github.com> Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com> Co-authored-by: Shubham Sharma <shubhash@microsoft.com> Co-authored-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>
This commit is contained in:
parent
8bdd4893d3
commit
657310541a
|
@ -29,7 +29,7 @@ jobs:
|
|||
name: Build ${{ matrix.target_os }}_${{ matrix.target_arch }} binaries
|
||||
runs-on: ${{ matrix.os }}
|
||||
env:
|
||||
GOVER: 1.19
|
||||
GOVER: 1.19.2
|
||||
GOLANG_CI_LINT_VER: v1.49.0
|
||||
GOOS: ${{ matrix.target_os }}
|
||||
GOARCH: ${{ matrix.target_arch }}
|
||||
|
|
|
@ -50,7 +50,7 @@ jobs:
|
|||
name: E2E tests for K8s (KinD)
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
GOVER: 1.19
|
||||
GOVER: 1.19.2
|
||||
DAPR_RUNTIME_VERSION: 1.9.0-rc.3
|
||||
DAPR_DASHBOARD_VERSION: 0.10.0
|
||||
DAPR_TGZ: dapr-1.9.0-rc.3.tgz
|
||||
|
|
|
@ -35,7 +35,7 @@ jobs:
|
|||
name: Run Self-Hosted E2E tests in ${{ matrix.target_os }}_${{ matrix.target_arch }}_${{ matrix.dapr_install_mode }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
env:
|
||||
GOVER: 1.19
|
||||
GOVER: 1.19.2
|
||||
GOOS: ${{ matrix.target_os }}
|
||||
GOARCH: ${{ matrix.target_arch }}
|
||||
GOPROXY: https://proxy.golang.org
|
||||
|
|
|
@ -50,7 +50,7 @@ jobs:
|
|||
name: Upgrade path tests (KinD)
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
GOVER: 1.19
|
||||
GOVER: 1.19.2
|
||||
strategy:
|
||||
fail-fast: false # Keep running if one leg fails.
|
||||
matrix:
|
||||
|
|
15
cmd/run.go
15
cmd/run.go
|
@ -49,6 +49,11 @@ var (
|
|||
maxRequestBodySize int
|
||||
readBufferSize int
|
||||
unixDomainSocket string
|
||||
appHealthEnabled bool
|
||||
appHealthPath string
|
||||
appHealthInterval int
|
||||
appHealthTimeout int
|
||||
appHealthThreshold int
|
||||
enableAPILogging bool
|
||||
)
|
||||
|
||||
|
@ -119,6 +124,11 @@ dapr run --app-id myapp --app-port 3000 --app-protocol grpc -- go run main.go
|
|||
MaxRequestBodySize: maxRequestBodySize,
|
||||
HTTPReadBufferSize: readBufferSize,
|
||||
UnixDomainSocket: unixDomainSocket,
|
||||
AppHealthEnabled: appHealthEnabled,
|
||||
AppHealthPath: appHealthPath,
|
||||
AppHealthInterval: appHealthInterval,
|
||||
AppHealthTimeout: appHealthTimeout,
|
||||
AppHealthThreshold: appHealthThreshold,
|
||||
EnableAPILogging: enableAPILogging,
|
||||
InternalGRPCPort: internalGRPCPort,
|
||||
})
|
||||
|
@ -371,6 +381,11 @@ func init() {
|
|||
RunCmd.Flags().IntVarP(&maxRequestBodySize, "dapr-http-max-request-size", "", -1, "Max size of request body in MB")
|
||||
RunCmd.Flags().IntVarP(&readBufferSize, "dapr-http-read-buffer-size", "", -1, "HTTP header read buffer in KB")
|
||||
RunCmd.Flags().StringVarP(&unixDomainSocket, "unix-domain-socket", "u", "", "Path to a unix domain socket dir. If specified, Dapr API servers will use Unix Domain Sockets")
|
||||
RunCmd.Flags().BoolVar(&appHealthEnabled, "enable-app-health-check", false, "Enable health checks for the application using the protocol defined with app-protocol")
|
||||
RunCmd.Flags().StringVar(&appHealthPath, "app-health-check-path", "", "Path used for health checks; HTTP only")
|
||||
RunCmd.Flags().IntVar(&appHealthInterval, "app-health-probe-interval", 0, "Interval to probe for the health of the app in seconds")
|
||||
RunCmd.Flags().IntVar(&appHealthTimeout, "app-health-probe-timeout", 0, "Timeout for app health probes in milliseconds")
|
||||
RunCmd.Flags().IntVar(&appHealthThreshold, "app-health-threshold", 0, "Number of consecutive failures for the app to be considered unhealthy")
|
||||
RunCmd.Flags().BoolVar(&enableAPILogging, "enable-api-logging", false, "Log API calls at INFO verbosity. Valid values are: true or false")
|
||||
|
||||
RootCmd.AddCommand(RunCmd)
|
||||
|
|
|
@ -54,6 +54,11 @@ type RunConfig struct {
|
|||
HTTPReadBufferSize int `arg:"dapr-http-read-buffer-size"`
|
||||
UnixDomainSocket string `arg:"unix-domain-socket"`
|
||||
InternalGRPCPort int `arg:"dapr-internal-grpc-port"`
|
||||
AppHealthEnabled bool `arg:"enable-app-health-check"`
|
||||
AppHealthPath string `arg:"app-health-check-path"`
|
||||
AppHealthInterval int `arg:"app-health-probe-interval" ifneq:"0"`
|
||||
AppHealthTimeout int `arg:"app-health-probe-timeout" ifneq:"0"`
|
||||
AppHealthThreshold int `arg:"app-health-threshold" ifneq:"0"`
|
||||
EnableAPILogging bool `arg:"enable-api-logging"`
|
||||
}
|
||||
|
||||
|
@ -235,6 +240,8 @@ func (config *RunConfig) getArgs() []string {
|
|||
}
|
||||
key = "--" + key
|
||||
|
||||
ifneq, hasIfneq := typeField.Tag.Lookup("ifneq")
|
||||
|
||||
switch valueField.(type) {
|
||||
case bool:
|
||||
if valueField == true {
|
||||
|
@ -242,7 +249,7 @@ func (config *RunConfig) getArgs() []string {
|
|||
}
|
||||
default:
|
||||
value := fmt.Sprintf("%v", reflect.ValueOf(valueField))
|
||||
if len(value) != 0 {
|
||||
if len(value) != 0 && (!hasIfneq || value != ifneq) {
|
||||
args = append(args, key, value)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ package standalone
|
|||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
|
@ -157,7 +158,7 @@ func TestRun(t *testing.T) {
|
|||
|
||||
t.Run("run happy http", func(t *testing.T) {
|
||||
output, err := Run(basicConfig)
|
||||
assert.Nil(t, err)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assertCommonArgs(t, basicConfig, output)
|
||||
assert.Equal(t, "MyCommand", output.AppCMD.Args[0])
|
||||
|
@ -171,7 +172,7 @@ func TestRun(t *testing.T) {
|
|||
basicConfig.EnableAPILogging = true
|
||||
basicConfig.ConfigFile = DefaultConfigFilePath()
|
||||
output, err := Run(basicConfig)
|
||||
assert.Nil(t, err)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assertCommonArgs(t, basicConfig, output)
|
||||
assertArgumentEqual(t, "config", DefaultConfigFilePath(), output.DaprCMD.Args)
|
||||
|
@ -184,11 +185,61 @@ func TestRun(t *testing.T) {
|
|||
basicConfig.MetricsPort = -1
|
||||
output, err := Run(basicConfig)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, output)
|
||||
|
||||
assertArgumentNotEqual(t, "http-port", "-1", output.DaprCMD.Args)
|
||||
assertArgumentNotEqual(t, "grpc-port", "-1", output.DaprCMD.Args)
|
||||
assertArgumentNotEqual(t, "metrics-port", "-1", output.DaprCMD.Args)
|
||||
})
|
||||
|
||||
t.Run("app health check flags missing if not set", func(t *testing.T) {
|
||||
output, err := Run(basicConfig)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, output)
|
||||
|
||||
argsFlattened := strings.Join(output.DaprCMD.Args, " ")
|
||||
assert.NotRegexp(t, regexp.MustCompile(`( |^)--enable-app-health-check( |$)`), argsFlattened)
|
||||
assert.NotRegexp(t, regexp.MustCompile(`( |^)--app-health-check-path( |=)`), argsFlattened)
|
||||
assert.NotRegexp(t, regexp.MustCompile(`( |^)--app-health-probe-interval( |=)`), argsFlattened)
|
||||
assert.NotRegexp(t, regexp.MustCompile(`( |^)--app-health-probe-timeout( |=)`), argsFlattened)
|
||||
assert.NotRegexp(t, regexp.MustCompile(`( |^)--app-health-threshold( |=)`), argsFlattened)
|
||||
})
|
||||
|
||||
t.Run("enable app health checks with default flags", func(t *testing.T) {
|
||||
basicConfig.AppHealthEnabled = true
|
||||
output, err := Run(basicConfig)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, output)
|
||||
|
||||
argsFlattened := strings.Join(output.DaprCMD.Args, " ")
|
||||
assert.Regexp(t, regexp.MustCompile(`( |^)--enable-app-health-check( |$)`), argsFlattened)
|
||||
|
||||
// Other flags are not included so daprd can use the default value.
|
||||
assert.NotRegexp(t, regexp.MustCompile(`( |^)--app-health-check-path( |=)`), argsFlattened)
|
||||
assert.NotRegexp(t, regexp.MustCompile(`( |^)--app-health-probe-interval( |=)`), argsFlattened)
|
||||
assert.NotRegexp(t, regexp.MustCompile(`( |^)--app-health-probe-timeout( |=)`), argsFlattened)
|
||||
assert.NotRegexp(t, regexp.MustCompile(`( |^)--app-health-threshold( |=)`), argsFlattened)
|
||||
})
|
||||
|
||||
t.Run("enable app health checks with all flags set", func(t *testing.T) {
|
||||
basicConfig.AppHealthEnabled = true
|
||||
basicConfig.AppHealthInterval = 2
|
||||
basicConfig.AppHealthTimeout = 200
|
||||
basicConfig.AppHealthThreshold = 1
|
||||
basicConfig.AppHealthPath = "/foo"
|
||||
output, err := Run(basicConfig)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, output)
|
||||
|
||||
argsFlattened := strings.Join(output.DaprCMD.Args, " ")
|
||||
assert.Regexp(t, regexp.MustCompile(`( |^)--enable-app-health-check( |$)`), argsFlattened)
|
||||
assert.Regexp(t, regexp.MustCompile(`( |^)--app-health-check-path( |=)/foo`), argsFlattened)
|
||||
assert.Regexp(t, regexp.MustCompile(`( |^)--app-health-probe-interval( |=)2`), argsFlattened)
|
||||
assert.Regexp(t, regexp.MustCompile(`( |^)--app-health-probe-timeout( |=)200`), argsFlattened)
|
||||
assert.Regexp(t, regexp.MustCompile(`( |^)--app-health-threshold( |=)1`), argsFlattened)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue