micrometer-metrics / micrometer

An application observability facade for the most popular observability tools. Think SLF4J, but for observability.
https://micrometer.io
Apache License 2.0
4.46k stars 990 forks source link

micrometer-observation-test support for assertions on events #5576

Open wabrit opened 3 weeks ago

wabrit commented 3 weeks ago

Please describe the feature request. The micrometer-observation-test dependency does not appear to offer a simple way of asserting on observation events in tests

Rationale The TestObservationRegistryAssert class handles assertions on what observations have been made, the key values associated with an observation, etc. But it does not appear to provide support for asserting that particular calls to Observation#event(...) have been made.

This is necessary to provide test coverage for observations which raise events.

Additional context This is based on using version 1.13.2 of io.micrometer:micrometer-observation-test

shakuzen commented 3 weeks ago

@wabrit thanks for opening the issue. It sounds like a useful enhancement. Would you be interested in contributing a pull request for this?

wabrit commented 3 weeks ago

Hi @shakuzen - I'd be happy to try, and I do have my own "workaround", but perhaps it would be a good idea to submit some kind of API design proposal first before a PR? Is here the right place to do that?

shakuzen commented 3 weeks ago

Sure, here is fine. Leave a comment with what you have in mind.

wabrit commented 3 weeks ago

What I envisaged would be to extend the TestObservationRegistryAssert class (and supporting classes) to support this:

TestObservationRegistryAssert.assertThat(observationRegistry)
        .hasObservationWithNameEqualTo("foo")
        .that()
        .hasEvent("event1") /* event with name event1 exists in observation */
        .doesNotHaveEvent("event2") /* no event with name event2 in observation */
        ....
wabrit commented 1 week ago

Hi all - does the above proposal sound ok before I embark on a PR, and (not having committed to this project before) is there a guide to that process? (I assume I need to fork the repo and create a branch on the fork to submit the PR against)

shakuzen commented 1 week ago

Your proposal looks reasonable to me. As for contributing, check the contributing guide. Yes, forking the repo and committing the changes to a branch in that fork and submitting a pull request would be the right process.

wabrit commented 1 week ago

PR raised: https://github.com/micrometer-metrics/micrometer/pull/5605