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