benchttp / engine

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

feat: allow test suites for new metrics #41

Closed GregoryAlbouy closed 2 years ago

GregoryAlbouy commented 2 years ago

Description

Allow access of any Aggregate metrics using field IDs from tests configuration.

Changes

Field reference IDs

All previous field IDs (MEAN, FAILURE_COUNT, ...) have been renamed. See below.

Aggregate metrics access via Field

The issue with statically declared field IDs

The logics around Field have been entirely remade from scratch. In the previous version we had to bookkeep every possible metric field, which required to define manually for each:

Commit 1a46f90ebe1c8908078f0d0336fab9a01ee87ade gives an idea of the difficulty we'd have to maintain that system for all metrics, and it only added very basic stats (min, max, mean) for 3 request events (out of 8). Worse: how can we handle access to StatusCodesDistribution metrics with that system? A field id for each possible code?

New dynamic access system

That's why we had to switch for a more suitable, generic solution. It uses a Field id as a path representation from an Aggregate to its value: this ID is now semantically tied to Aggregate structure: it serves both as a reference name and as a getter. The type of the value doesn't need to be defined in advance anymore, it is dynamically retrieved as well.

It is also able to call a method and retrieve its result, so we can move implementation of XXX_COUNT functions (previously inlined as a getter in field definitions) in dedicated Aggregate methods, which makes more sense.

Implementation details
Usage

This unit test demonstrates how the new system is used: https://github.com/benchttp/engine/blob/560f0ee42268a424b2c7799834b186e0894ff062/runner/internal/metrics/metrics_test.go#L79-L150

Notes