diff --git a/agent/xds/config.go b/agent/xds/config.go index 20f07ae63c..756ca51f44 100644 --- a/agent/xds/config.go +++ b/agent/xds/config.go @@ -193,7 +193,18 @@ func (p PassiveHealthCheck) AsOutlierDetection() *envoycluster.OutlierDetection func ParseUpstreamConfigNoDefaults(m map[string]interface{}) (UpstreamConfig, error) { var cfg UpstreamConfig - err := mapstructure.WeakDecode(m, &cfg) + config := &mapstructure.DecoderConfig{ + DecodeHook: mapstructure.StringToTimeDurationHookFunc(), + Result: &cfg, + WeaklyTypedInput: true, + } + + decoder, err := mapstructure.NewDecoder(config) + if err != nil { + return cfg, err + } + + err = decoder.Decode(m) return cfg, err } diff --git a/agent/xds/config_test.go b/agent/xds/config_test.go index dea869f3db..23629089e8 100644 --- a/agent/xds/config_test.go +++ b/agent/xds/config_test.go @@ -249,7 +249,7 @@ func TestParseUpstreamConfig(t *testing.T) { name: "passive health check map", input: map[string]interface{}{ "passive_health_check": map[string]interface{}{ - "interval": 22 * time.Second, + "interval": "22s", "max_failures": 7, }, }, diff --git a/test/integration/connect/envoy/case-centralconf/s1.hcl b/test/integration/connect/envoy/case-centralconf/s1.hcl index 7f48b1c515..0d8957c000 100644 --- a/test/integration/connect/envoy/case-centralconf/s1.hcl +++ b/test/integration/connect/envoy/case-centralconf/s1.hcl @@ -13,4 +13,4 @@ services { } } } -} \ No newline at end of file +} diff --git a/test/integration/connect/envoy/case-upstream-connection-limits/s1.hcl b/test/integration/connect/envoy/case-upstream-config/s1.hcl similarity index 78% rename from test/integration/connect/envoy/case-upstream-connection-limits/s1.hcl rename to test/integration/connect/envoy/case-upstream-config/s1.hcl index 3bdf91c058..b3d4db73b8 100644 --- a/test/integration/connect/envoy/case-upstream-connection-limits/s1.hcl +++ b/test/integration/connect/envoy/case-upstream-config/s1.hcl @@ -14,6 +14,10 @@ services { max_pending_requests = 4 max_concurrent_requests = 5 } + passive_health_check { + interval = "22s" + max_failures = 4 + } } } ] diff --git a/test/integration/connect/envoy/case-upstream-connection-limits/s2.hcl b/test/integration/connect/envoy/case-upstream-config/s2.hcl similarity index 100% rename from test/integration/connect/envoy/case-upstream-connection-limits/s2.hcl rename to test/integration/connect/envoy/case-upstream-config/s2.hcl diff --git a/test/integration/connect/envoy/case-upstream-connection-limits/setup.sh b/test/integration/connect/envoy/case-upstream-config/setup.sh similarity index 100% rename from test/integration/connect/envoy/case-upstream-connection-limits/setup.sh rename to test/integration/connect/envoy/case-upstream-config/setup.sh diff --git a/test/integration/connect/envoy/case-upstream-connection-limits/verify.bats b/test/integration/connect/envoy/case-upstream-config/verify.bats similarity index 72% rename from test/integration/connect/envoy/case-upstream-connection-limits/verify.bats rename to test/integration/connect/envoy/case-upstream-config/verify.bats index 116f78cc17..a6c025ac89 100644 --- a/test/integration/connect/envoy/case-upstream-connection-limits/verify.bats +++ b/test/integration/connect/envoy/case-upstream-config/verify.bats @@ -27,7 +27,7 @@ load helpers } @test "s1 proxy should have been configured with max_connections on the cluster" { - CLUSTER_THRESHOLD=$(get_envoy_cluster_threshold localhost:19000 s2.default.primary) + CLUSTER_THRESHOLD=$(get_envoy_cluster_config localhost:19000 s2.default.primary | jq '.circuit_breakers.thresholds[0]') echo $CLUSTER_THRESHOLD MAX_CONNS=$(echo $CLUSTER_THRESHOLD | jq --raw-output '.max_connections') @@ -42,3 +42,11 @@ load helpers [ "$MAX_PENDING_REQS" = "4" ] [ "$MAX_REQS" = "5" ] } + +@test "s1 proxy should have been configured with passive_health_check" { + CLUSTER_CONFIG=$(get_envoy_cluster_config localhost:19000 s2.default.primary) + echo $CLUSTER_CONFIG + + [ "$(echo $CLUSTER_CONFIG | jq --raw-output '.outlier_detection.consecutive_5xx')" = "4" ] + [ "$(echo $CLUSTER_CONFIG | jq --raw-output '.outlier_detection.interval')" = "22s" ] +} diff --git a/test/integration/connect/envoy/helpers.bash b/test/integration/connect/envoy/helpers.bash index 94f4ca59f1..3f8cbd5cc9 100755 --- a/test/integration/connect/envoy/helpers.bash +++ b/test/integration/connect/envoy/helpers.bash @@ -156,7 +156,7 @@ function get_envoy_listener_filters { echo "$output" | jq --raw-output "$QUERY" } -function get_envoy_cluster_threshold { +function get_envoy_cluster_config { local HOSTPORT=$1 local CLUSTER_NAME=$2 run retry_default curl -s -f $HOSTPORT/config_dump @@ -164,7 +164,7 @@ function get_envoy_cluster_threshold { echo "$output" | jq --raw-output " .configs[1].dynamic_active_clusters[] | select(.cluster.name|startswith(\"${CLUSTER_NAME}\")) - | .cluster.circuit_breakers.thresholds[0] + | .cluster " }