benchttp / engine

Benchttp library in Go to run performance tests on HTTP endpoints.
Other
4 stars 1 forks source link

fix: reflectpath.Resolver.ResolveValue incorrectly panics #45

Closed moreirathomas closed 2 years ago

moreirathomas commented 2 years ago

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 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

// 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