Class RemoteWriteV1Encoder

java.lang.Object
org.mockserver.metrics.remotewrite.RemoteWriteV1Encoder
All Implemented Interfaces:
RemoteWriteEncoder

public class RemoteWriteV1Encoder extends Object implements RemoteWriteEncoder
Hand-encodes a MetricSnapshots into a Prometheus Remote-Write v1 WriteRequest protobuf, matching the Prometheus text-exposition naming so the pushed series line up exactly with what /mockserver/metrics serves. Pure and stateless — no network, no global state — so it is fully unit-testable.

Message shapes (field numbers are normative for the remote-write protocol):

 WriteRequest { repeated TimeSeries timeseries = 1; }
 TimeSeries   { repeated Label labels = 1; repeated Sample samples = 2; }
 Label        { string name = 1; string value = 2; }
 Sample       { double value = 1; int64 timestamp = 2; }
 
Each nested message is built into its own byte[] and embedded in the parent via CodedOutputStream.writeByteArray(int, byte[]) — a length-delimited bytes field is wire-identical to an embedded message, which sidesteps manual size arithmetic.
  • Constructor Details

    • RemoteWriteV1Encoder

      public RemoteWriteV1Encoder()
  • Method Details

    • encode

      public byte[] encode(io.prometheus.metrics.model.snapshots.MetricSnapshots snapshots, long timestampMillis)
      Description copied from interface: RemoteWriteEncoder
      Encode the given metric snapshots into an uncompressed remote-write protobuf body. Every emitted sample carries timestampMillis (unix epoch milliseconds) as its timestamp.
      Specified by:
      encode in interface RemoteWriteEncoder
    • contentType

      public String contentType()
      Description copied from interface: RemoteWriteEncoder
      The HTTP Content-Type for this protocol version (v1: application/x-protobuf).
      Specified by:
      contentType in interface RemoteWriteEncoder
    • protocolVersionHeader

      public String protocolVersionHeader()
      Description copied from interface: RemoteWriteEncoder
      The value for the X-Prometheus-Remote-Write-Version header (v1: 0.1.0).
      Specified by:
      protocolVersionHeader in interface RemoteWriteEncoder