Class RemoteWriteV1Encoder
java.lang.Object
org.mockserver.metrics.remotewrite.RemoteWriteV1Encoder
- All Implemented Interfaces:
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionThe HTTPContent-Typefor this protocol version (v1:application/x-protobuf).byte[]encode(io.prometheus.metrics.model.snapshots.MetricSnapshots snapshots, long timestampMillis) Encode the given metric snapshots into an uncompressed remote-write protobuf body.The value for theX-Prometheus-Remote-Write-Versionheader (v1:0.1.0).
-
Constructor Details
-
RemoteWriteV1Encoder
public RemoteWriteV1Encoder()
-
-
Method Details
-
encode
public byte[] encode(io.prometheus.metrics.model.snapshots.MetricSnapshots snapshots, long timestampMillis) Description copied from interface:RemoteWriteEncoderEncode the given metric snapshots into an uncompressed remote-write protobuf body. Every emitted sample carriestimestampMillis(unix epoch milliseconds) as its timestamp.- Specified by:
encodein interfaceRemoteWriteEncoder
-
contentType
Description copied from interface:RemoteWriteEncoderThe HTTPContent-Typefor this protocol version (v1:application/x-protobuf).- Specified by:
contentTypein interfaceRemoteWriteEncoder
-
protocolVersionHeader
Description copied from interface:RemoteWriteEncoderThe value for theX-Prometheus-Remote-Write-Versionheader (v1:0.1.0).- Specified by:
protocolVersionHeaderin interfaceRemoteWriteEncoder
-