Add outlier_detection check to integration test

Fix decoding of time.Duration types.
pull/7713/head
Daniel Nephin 2020-05-05 16:17:24 -04:00
parent eaa05d623a
commit 5655d7f34e
8 changed files with 29 additions and 6 deletions

View File

@ -193,7 +193,18 @@ func (p PassiveHealthCheck) AsOutlierDetection() *envoycluster.OutlierDetection
func ParseUpstreamConfigNoDefaults(m map[string]interface{}) (UpstreamConfig, error) { func ParseUpstreamConfigNoDefaults(m map[string]interface{}) (UpstreamConfig, error) {
var cfg UpstreamConfig 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 return cfg, err
} }

View File

@ -249,7 +249,7 @@ func TestParseUpstreamConfig(t *testing.T) {
name: "passive health check map", name: "passive health check map",
input: map[string]interface{}{ input: map[string]interface{}{
"passive_health_check": map[string]interface{}{ "passive_health_check": map[string]interface{}{
"interval": 22 * time.Second, "interval": "22s",
"max_failures": 7, "max_failures": 7,
}, },
}, },

View File

@ -13,4 +13,4 @@ services {
} }
} }
} }
} }

View File

@ -14,6 +14,10 @@ services {
max_pending_requests = 4 max_pending_requests = 4
max_concurrent_requests = 5 max_concurrent_requests = 5
} }
passive_health_check {
interval = "22s"
max_failures = 4
}
} }
} }
] ]

View File

@ -27,7 +27,7 @@ load helpers
} }
@test "s1 proxy should have been configured with max_connections on the cluster" { @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 echo $CLUSTER_THRESHOLD
MAX_CONNS=$(echo $CLUSTER_THRESHOLD | jq --raw-output '.max_connections') MAX_CONNS=$(echo $CLUSTER_THRESHOLD | jq --raw-output '.max_connections')
@ -42,3 +42,11 @@ load helpers
[ "$MAX_PENDING_REQS" = "4" ] [ "$MAX_PENDING_REQS" = "4" ]
[ "$MAX_REQS" = "5" ] [ "$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" ]
}

View File

@ -156,7 +156,7 @@ function get_envoy_listener_filters {
echo "$output" | jq --raw-output "$QUERY" echo "$output" | jq --raw-output "$QUERY"
} }
function get_envoy_cluster_threshold { function get_envoy_cluster_config {
local HOSTPORT=$1 local HOSTPORT=$1
local CLUSTER_NAME=$2 local CLUSTER_NAME=$2
run retry_default curl -s -f $HOSTPORT/config_dump run retry_default curl -s -f $HOSTPORT/config_dump
@ -164,7 +164,7 @@ function get_envoy_cluster_threshold {
echo "$output" | jq --raw-output " echo "$output" | jq --raw-output "
.configs[1].dynamic_active_clusters[] .configs[1].dynamic_active_clusters[]
| select(.cluster.name|startswith(\"${CLUSTER_NAME}\")) | select(.cluster.name|startswith(\"${CLUSTER_NAME}\"))
| .cluster.circuit_breakers.thresholds[0] | .cluster
" "
} }