Class RemoteWriteV2Encoder
java.lang.Object
org.mockserver.metrics.remotewrite.RemoteWriteV2Encoder
- All Implemented Interfaces:
RemoteWriteEncoder
Hand-encodes a
MetricSnapshots into a Prometheus Remote-Write 2.0
Request protobuf (package io.prometheus.write.v2), matching the
Prometheus text-exposition naming so the pushed series line up exactly with what
/mockserver/metrics serves. Pure and stateless — the interned symbol
table is local to a single encode(io.prometheus.metrics.model.snapshots.MetricSnapshots, long) call, no network, no global state —
so it is fully unit-testable.
Remote-Write 2.0 differs from v1 by interning every string (label names, label
values, and metadata help/unit) into a shared symbols table and
referencing them by uint32 index. Message shapes (field numbers are
NORMATIVE and DIFFERENT from v1):
Request { reserved 1..3; repeated string symbols = 4; repeated TimeSeries timeseries = 5; }
TimeSeries { repeated uint32 labels_refs = 1 [packed]; repeated Sample samples = 2; Metadata metadata = 5; int64 created_timestamp = 6; }
Sample { double value = 1; int64 timestamp = 2; }
Metadata { MetricType type = 1; uint32 help_ref = 3; uint32 unit_ref = 4; }
symbols[0] MUST be the empty string "" (a "no value" reference).
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
(and to a packed repeated field), 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
-
RemoteWriteV2Encoder
public RemoteWriteV2Encoder()
-
-
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
-