Esempio 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)
Esempio 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)
Esempio 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'
Esempio 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'
Esempio n. 5
0
def test_varint_encode_0():
    assert pyrobuf_util.to_varint(0) == b'\x00'
Esempio 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'
Esempio 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'
Esempio n. 8
0
def test_varint_encode_12345():
    assert pyrobuf_util.to_varint(12345) == b'\xb9`'
Esempio n. 9
0
def test_varint_encode_max_int32():
    assert pyrobuf_util.to_varint(2**31-1) == b'\xff\xff\xff\xff\x07'
Esempio 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'
Esempio n. 11
0
def test_varint_encode_max_int32():
    assert pyrobuf_util.to_varint(2**31 - 1) == b'\xff\xff\xff\xff\x07'
Esempio 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'
Esempio n. 13
0
def test_varint_encode_1():
    assert pyrobuf_util.to_varint(1) == b'\x01'
Esempio 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'
Esempio n. 15
0
def test_varint_encode_0():
    assert pyrobuf_util.to_varint(0) == b'\x00'
Esempio 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'
Esempio 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'
Esempio 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'
Esempio n. 19
0
def test_varint_encode_1():
    assert pyrobuf_util.to_varint(1) == b'\x01'
Esempio n. 20
0
def test_varint_encode_12345():
    assert pyrobuf_util.to_varint(12345) == b'\xb9`'