Skip to content

Feature request: Change MetricsInterface.singleMetric() to have return type MetricsInterface #3132

Closed
@mikebroberts

Description

@mikebroberts

Use case

Metrics doesn't (currently) have a good way to silence all output during unit tests (it requires configuration changes outside the scope of the unit test code.) To work around this I was going to use a fake implementation of the MetricsInterface interface, and pass that to actual code that generates metrics, instead of passing a reference to the concrete Metrics class. At unit test time I can instead pass a fake implementation of this interface that just silently swallows all requests. The problem with this workaround is that the MetricsInterface.singleMetric() method has to return a concrete implementation of Metrics.

Solution/User Experience

Change MetricsInterface.singleMetric() to return MetricsInterface . I don't think (?) this should break anything, and will allow me to replace the concrete implementation at unit test time.

Alternative solutions

Add functionality to the MetricsOptions interface (used in the Metrics class constructor) to take an option something like "silent" which tells the implementation not to log. Or allow passing a custom output sink. I think these are both better options long term, but my suggestion I think is a one-liner that probably fits better with the design anyway (it's typically best to not have interfaces have types that return concretions).

Acknowledgment

Future readers

Please react with 👍 and your use case to help us understand customer demand.

Metadata

Metadata

Assignees

Labels

completedThis item is complete and has been merged/shippedfeature-requestThis item refers to a feature request for an existing or new utilitymetricsThis item relates to the Metrics Utility

Type

No type

Projects

Status

Shipped

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions