def marshall(self, registry: CollectorRegistry) -> bytes: ''' Marshall the collectors in the registry into binary protocol buffer format. The Prometheus metrics parser expects each metric (MetricFamily) to be prefixed with a varint containing the size of the encoded metric. :returns: bytes ''' payload = [] for i in registry.get_all(): encoded_metric = self.marshall_collector(i).SerializeToString() length = pyrobuf_util.to_varint(len(encoded_metric)) payload.append(length + encoded_metric) return b"".join(payload)
def marshall(self, registry: CollectorRegistry) -> bytes: """ Marshall the collectors in the registry into binary protocol buffer format. The Prometheus metrics parser expects each metric (MetricFamily) to be prefixed with a varint containing the size of the encoded metric. :returns: bytes """ payload = [] for i in registry.get_all(): encoded_metric = self.marshall_collector(i).SerializeToString() length = pyrobuf_util.to_varint(len(encoded_metric)) payload.append(length + encoded_metric) return b"".join(payload)
def test_varint_encode_negative_max_int32(): assert pyrobuf_util.to_varint(-2**31) == b'\x80\x80\x80\x80\xf8\xff\xff\xff\xff\x01'
def test_varint_encode_negative_12345(): assert pyrobuf_util.to_varint(-12345) == b'\xc7\x9f\xff\xff\xff\xff\xff\xff\xff\x01'
def test_varint_encode_0(): assert pyrobuf_util.to_varint(0) == b'\x00'
def test_varint_encode_max_int64(): assert pyrobuf_util.to_varint(2**63-1) == b'\xff\xff\xff\xff\xff\xff\xff\xff\x7f'
def test_varint_encode_negative_1(): assert pyrobuf_util.to_varint(-1) == b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\x01'
def test_varint_encode_12345(): assert pyrobuf_util.to_varint(12345) == b'\xb9`'
def test_varint_encode_max_int32(): assert pyrobuf_util.to_varint(2**31-1) == b'\xff\xff\xff\xff\x07'
def test_varint_encode_negative_max_int64(): assert pyrobuf_util.to_varint(-2**63) == b'\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01'
def test_varint_encode_max_int32(): assert pyrobuf_util.to_varint(2**31 - 1) == b'\xff\xff\xff\xff\x07'
def test_varint_encode_negative_max_int64(): assert pyrobuf_util.to_varint( -2**63) == b'\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01'
def test_varint_encode_1(): assert pyrobuf_util.to_varint(1) == b'\x01'
def test_varint_encode_negative_max_int32(): assert pyrobuf_util.to_varint( -2**31) == b'\x80\x80\x80\x80\xf8\xff\xff\xff\xff\x01'
def test_varint_encode_negative_12345(): assert pyrobuf_util.to_varint( -12345) == b'\xc7\x9f\xff\xff\xff\xff\xff\xff\xff\x01'
def test_varint_encode_negative_1(): assert pyrobuf_util.to_varint( -1) == b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\x01'
def test_varint_encode_max_int64(): assert pyrobuf_util.to_varint(2**63 - 1) == b'\xff\xff\xff\xff\xff\xff\xff\xff\x7f'