k6
k6 copied to clipboard
Make metrics.Metric be immutable
What?
Basically the TODO here:
https://github.com/grafana/k6/blob/55eb8bca07286ccf4f14e417e07de491f5912acc/metrics/metric.go#L11-L26
The current metric has a bunch of fields used by the ingester, summary and engine to:
- aggregate metric samples for the summary and thresholds
- evelaute thresholds and it subthresholds
None of those are essentials to hte metrics and the current users of the code need to know to not touch those values.
Arguably also those fields shouldn't be exported at all
How?
Move all of those fields in the places where they are useful as well as the type definitions. Probably make them internal.
In the past users (and core developers) have used those to implement metric outputs among other things, and while it might work for some cases, it has also introduced complex bugs and have always fell short. As well that isn't the intended purpose.
Related issues/PRs:
https://github.com/grafana/k6/issues/2735 will be part of this https://github.com/grafana/k6/issues/2320 will likely be closed as part of this as well