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.47k stars 990 forks source link

TCP reporter in StatsdMeterRegistry doesn't seem to respect buffering flag #2909

Open hdv opened 2 years ago

hdv commented 2 years ago

Describe the bug Run StatsdMeterRegistryPublishTest.receiveParallelMetricsSuccessfully test and inspect console output. StatsdMeterRegistry is configured to be unbuffered (new StatsdMeterRegistry(getUnbufferedConfig(protocol, port), Clock.SYSTEM);) For both UDP and UDS_DATAGRAM modes samples are reported one by one. For TCP they are batched.

Environment

To Reproduce How to reproduce the bug: Run StatsdMeterRegistryPublishTest.receiveParallelMetricsSuccessfully test and inspect console output

Expected behavior For TCP mode samples should be reported separately, one by one

Additional context Discovered during https://github.com/micrometer-metrics/micrometer/issues/2880

marcingrzejszczak commented 10 months ago

Is this still a problem with the latest versions?

shakuzen commented 10 months ago

The behavior you're seeing is I believe how Reactor Netty's TcpClient works. We are using a publisher that will publish each line individually (unbuffered), but I think buffering is happening in the TcpClient after that. Maybe @violetagg can confirm. https://github.com/micrometer-metrics/micrometer/blob/d00abb9ae5b166c421803d9fa2060c15f3e62189/implementations/micrometer-registry-statsd/src/main/java/io/micrometer/statsd/StatsdMeterRegistry.java#L263-L266 Where the publisher is a DirectProcessor.create() when our buffered config is false: https://github.com/micrometer-metrics/micrometer/blob/225234755f1ad70cd67eea167862c1cedddc0cd2/implementations/micrometer-registry-statsd/src/main/java/io/micrometer/statsd/StatsdMeterRegistry.java#L91 https://github.com/micrometer-metrics/micrometer/blob/d00abb9ae5b166c421803d9fa2060c15f3e62189/implementations/micrometer-registry-statsd/src/main/java/io/micrometer/statsd/StatsdMeterRegistry.java#L221-L229