When configuring a test case on a metric accessed through a field which is a map or a slice, and if that map's key or slice's index does not exist on the Aggregate (expected behavior, see example), accessing that value through reflectpath.Resolver.ResolveValue panics.
As this is an expected usecase, panicking is a runtime bug.
Example
"tests": [
{
"name": "My endpoint has no latency",
"field": "RequestEventTimes.ConnectDone.Max", // expected to always exist
"predicate": "LT",
"target": "250ms"
},
{
"name": "My endpoint has enough teapots",
"field": "StatusCodesDistribution.418", // expected to not exist if remote server does not return 418
"predicate": "GT",
"target": 10
}
]
Changes
Only panic when reading a key of unsupported type, this is done as the default case when switching on host.Type().Key().Kind().
Return the zero value of the type of the map/slice's element to work with metrics.Metric.Compare
// Not returning element's zero value
val := metrics.MetricOf("StatusCodesDistribution.418")
// val == reflect.Value{}
res := val.Compare(10)
// panic: "unhandled comparison: 10 (int) and invalid (reflect.Value)"
// Returning element's zero value
val := metrics.MetricOf("StatusCodesDistribution.418")
// val == 0 as host.418 does not exist
res := val.Compare(10)
// res == metrics.INF
Description
When configuring a test case on a metric accessed through a field which is a map or a slice, and if that map's key or slice's index does not exist on the
Aggregate
(expected behavior, see example), accessing that value throughreflectpath.Resolver.ResolveValue
panics.As this is an expected usecase, panicking is a runtime bug.
Example
Changes
default
case when switching onhost.Type().Key().Kind()
.metrics.Metric.Compare
// Returning element's zero value val := metrics.MetricOf("StatusCodesDistribution.418") // val == 0 as host.418 does not exist res := val.Compare(10) // res == metrics.INF