Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
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'
Ejemplo n.º 4
0
def test_varint_encode_negative_12345():
    assert pyrobuf_util.to_varint(-12345) == b'\xc7\x9f\xff\xff\xff\xff\xff\xff\xff\x01'
Ejemplo n.º 5
0
def test_varint_encode_0():
    assert pyrobuf_util.to_varint(0) == b'\x00'
Ejemplo n.º 6
0
def test_varint_encode_max_int64():
    assert pyrobuf_util.to_varint(2**63-1) == b'\xff\xff\xff\xff\xff\xff\xff\xff\x7f'
Ejemplo n.º 7
0
def test_varint_encode_negative_1():
    assert pyrobuf_util.to_varint(-1) == b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\x01'
Ejemplo n.º 8
0
def test_varint_encode_12345():
    assert pyrobuf_util.to_varint(12345) == b'\xb9`'
Ejemplo n.º 9
0
def test_varint_encode_max_int32():
    assert pyrobuf_util.to_varint(2**31-1) == b'\xff\xff\xff\xff\x07'
Ejemplo n.º 10
0
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'
Ejemplo n.º 11
0
def test_varint_encode_max_int32():
    assert pyrobuf_util.to_varint(2**31 - 1) == b'\xff\xff\xff\xff\x07'
Ejemplo n.º 12
0
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'
Ejemplo n.º 13
0
def test_varint_encode_1():
    assert pyrobuf_util.to_varint(1) == b'\x01'
Ejemplo n.º 14
0
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'
Ejemplo n.º 15
0
def test_varint_encode_0():
    assert pyrobuf_util.to_varint(0) == b'\x00'
Ejemplo n.º 16
0
def test_varint_encode_negative_12345():
    assert pyrobuf_util.to_varint(
        -12345) == b'\xc7\x9f\xff\xff\xff\xff\xff\xff\xff\x01'
Ejemplo n.º 17
0
def test_varint_encode_negative_1():
    assert pyrobuf_util.to_varint(
        -1) == b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\x01'
Ejemplo n.º 18
0
def test_varint_encode_max_int64():
    assert pyrobuf_util.to_varint(2**63 -
                                  1) == b'\xff\xff\xff\xff\xff\xff\xff\xff\x7f'
Ejemplo n.º 19
0
def test_varint_encode_1():
    assert pyrobuf_util.to_varint(1) == b'\x01'
Ejemplo n.º 20
0
def test_varint_encode_12345():
    assert pyrobuf_util.to_varint(12345) == b'\xb9`'