prometheus / common

Go libraries shared across Prometheus components and libraries.
Apache License 2.0
259 stars 306 forks source link

fix(protobuf): Correctly decode multi-messages streams #616

Closed srebhan closed 2 months ago

srebhan commented 2 months ago

When sending multiple metric-family samples in one stream the current implementation only decodes the first of those messages, all other ones are lost. This is the case since #567 which switches to directly using the protodelim package. However, in the process or copying the code, the initialization of the reader moved to the Decode() function and as such, the buffered reader continues somewhere in the actual data-stream (usually at the end) leading to an EOF on the next Decode() call.

The malfunction is present since release v0.46.0.

This PR moves the initialization out of Decode() into the initialization of the decoder preventing the described issue. Furthermore, we add a unit-test including a multi-message data-sample verifying the issue is fixed.

stapelberg commented 2 months ago

Oh, I see the mistake! Sorry about that, and thanks for sending a fix which even increases test coverage :)