gorilla

    Gorilla 压缩归档与 MoonPromQL 查询数据源适配

    Download zip
    Author
    Version
    0.7.0
    License
    MIT AND Apache-2.0
    Last updated
    5 hours ago
    Downloads
    3

    Dependencies

    #可执行 API 示例

    增加闭区间时间查询,保留原始样本顺序。这些例子调用公开 API,并随 moon test 执行。

    ///|
    test "closed range query filters decoded points" {
    let b = @gorilla.encode([
    { timestamp: 1L, bits: 0UL, },
    { timestamp: 2L, bits: 1UL, },
    { timestamp: 3L, bits: 2UL, },
    ])
    assert_eq(@gorilla.decode_range(b, 2L, 2L), [{ timestamp: 2L, bits: 1UL, }])
    assert_eq(@gorilla.decode_range(b, 4L, 5L), [])
    assert_true(
    try {
    ignore(@gorilla.decode_range(b, 5L, 4L))
    false
    } catch {
    _ => true
    },
    )
    }

    本例的 GOR1 decode_range 会顺序解码整个块;另有 GOR2 ArchiveIndex 范围索引和 Node 文件读写宿主,见 README.md。GOR2 是自定义容器,不是 Prometheus TSDB segment/block/WAL 格式,也不提供数据库查询规划。

    CodecError

    pub suberror CodecError {
    Invalid(String)
    } derive(
    Debug
    )

    ArchiveDecoder

    pub struct ArchiveDecoder {
    // private fields
    }

    Incremental GOR2 input. feed() checks each emitted block; finish() is required to establish that the final index/trailer agree with the entire stream.

    ArchiveDecoder::buffered_bytes

    fn ArchiveDecoder::buffered_bytes(self : ArchiveDecoder) -> Int

    ArchiveDecoder::feed

    fn ArchiveDecoder::feed(self : ArchiveDecoder, data : Bytes) -> Array[Sample] raise CodecError

    ArchiveDecoder::finish

    fn ArchiveDecoder::finish(self : ArchiveDecoder) -> Unit raise CodecError

    ArchiveDecoder::is_verified

    fn ArchiveDecoder::is_verified(self : ArchiveDecoder) -> Bool

    ArchiveDecoder::new

    ArchiveEncoder

    pub struct ArchiveEncoder {
    // private fields
    }

    ArchiveEncoder::append

    fn ArchiveEncoder::append(self : ArchiveEncoder, sample : Sample) -> Bytes? raise CodecError

    Return a completed block when full. The caller writes archive_header() once, each returned block immediately, then finish()'s final block/index/trailer.

    ArchiveEncoder::blocks_written

    fn ArchiveEncoder::blocks_written(self : ArchiveEncoder) -> Int

    ArchiveEncoder::finish

    fn ArchiveEncoder::finish(self : ArchiveEncoder) -> Bytes

    ArchiveEncoder::new

    fn ArchiveEncoder::new(block_size? : Int) -> ArchiveEncoder raise CodecError

    ArchiveIndex

    pub struct ArchiveIndex {
    // private fields
    }

    ArchiveIndex::decode_block

    fn ArchiveIndex::decode_block(self : ArchiveIndex, index : Int, frame : Bytes) -> Array[Sample] raise CodecError

    ArchiveIndex::entries

    fn ArchiveIndex::entries(self : ArchiveIndex) -> Array[BlockInfo]

    ArchiveIndex::file_size

    fn ArchiveIndex::file_size(self : ArchiveIndex) -> UInt64

    ArchiveIndex::new

    fn ArchiveIndex::new(index : Bytes, file_size : UInt64) -> ArchiveIndex raise CodecError

    ArchiveIndex::select

    fn ArchiveIndex::select(self : ArchiveIndex, start : Int64, end : Int64) -> Array[Int] raise CodecError

    Closed timestamp interval. Binary search skips blocks ending before start.

    BlockInfo

    pub(all) struct BlockInfo {
    offset : UInt64
    length : Int
    count : Int
    first : Int64
    last : Int64
    checksum : UInt
    } derive(Eq,
    Debug
    )

    One independently checksummed Prometheus XOR payload in a GOR2 archive.

    BlockInfo::equal

    fn BlockInfo::equal(BlockInfo, BlockInfo) -> Bool

    BlockInfo::not_equal

    fn BlockInfo::not_equal(x : BlockInfo, y : BlockInfo) -> Bool

    Decoder

    pub struct Decoder {
    // private fields
    }

    Iterates over a complete GOR1 byte block using constant decoder state. This is a sample iterator, not a transport that accepts partial byte chunks.

    Decoder::finish

    fn Decoder::finish(self : Decoder) -> Unit raise CodecError

    Drain remaining samples without retaining them; validates all remaining bytes.

    Decoder::is_verified

    fn Decoder::is_verified(self : Decoder) -> Bool

    Decoder::new

    fn Decoder::new(data : Bytes) -> Decoder raise CodecError

    Decoder::next

    fn Decoder::next(self : Decoder) -> Sample? raise CodecError

    Decoder::remaining

    fn Decoder::remaining(self : Decoder) -> Int

    Encoder

    pub struct Encoder {
    // private fields
    }

    Appends directly to packed bytes; does not retain a Sample array or one Int per bit.

    Encoder::append

    fn Encoder::append(self : Encoder, sample : Sample) -> Unit raise CodecError

    Rejected samples leave the encoder unchanged; finish seals further appends.

    Encoder::encoded_size

    fn Encoder::encoded_size(self : Encoder) -> Int

    Encoder::finish

    fn Encoder::finish(self : Encoder) -> Bytes

    Encoder::length

    fn Encoder::length(self : Encoder) -> Int

    Encoder::new

    fn Encoder::new() -> Encoder

    Encoder::snapshot

    fn Encoder::snapshot(self : Encoder) -> Bytes

    Independent, padded GOR1 snapshot. Continuing to append cannot mutate a prior snapshot.

    Sample

    pub(all) struct Sample {
    timestamp : Int64
    bits : UInt64
    } derive(Eq,
    Debug
    )

    Sample::equal

    fn Sample::equal(Sample, Sample) -> Bool

    Sample::not_equal

    fn Sample::not_equal(x : Sample, y : Sample) -> Bool

    Sample::to_repr

    XorDecoder

    pub struct XorDecoder {
    // private fields
    }

    XorDecoder::finish

    fn XorDecoder::finish(self : XorDecoder) -> Unit raise CodecError

    XorDecoder::is_verified

    fn XorDecoder::is_verified(self : XorDecoder) -> Bool

    XorDecoder::new

    fn XorDecoder::new(data : Bytes, strict? : Bool) -> XorDecoder raise CodecError

    strict=true rejects nonzero padding/trailing bytes. The reference iterator stops at the sample count; strict=false retains that framing behavior.

    XorDecoder::next

    fn XorDecoder::next(self : XorDecoder) -> Sample? raise CodecError

    XorDecoder::remaining

    fn XorDecoder::remaining(self : XorDecoder) -> Int

    XorEncoder

    pub struct XorEncoder {
    // private fields
    }

    Prometheus XOR chunk, with its two-byte sample count and no segment wrapper.

    XorEncoder::append

    fn XorEncoder::append(self : XorEncoder, sample : Sample) -> Unit raise CodecError

    Uses signed 64-bit timestamps and bit-exact values; ordering is not imposed. Like the reference chunk codec, delta arithmetic wraps modulo 2^64.

    XorEncoder::encoded_size

    fn XorEncoder::encoded_size(self : XorEncoder) -> Int

    XorEncoder::finish

    fn XorEncoder::finish(self : XorEncoder) -> Bytes

    XorEncoder::length

    fn XorEncoder::length(self : XorEncoder) -> Int

    XorEncoder::new

    fn XorEncoder::new() -> XorEncoder

    XorEncoder::snapshot

    fn XorEncoder::snapshot(self : XorEncoder) -> Bytes

    archive_header

    fn archive_header() -> Bytes

    archive_index_length

    fn archive_index_length(trailer : Bytes) -> Int raise CodecError

    Parse the last 12 bytes without trusting an unchecked length for allocation.

    crc32

    fn crc32(bytes : Bytes) -> UInt

    IEEE CRC-32, matching the standard zlib/ZIP CRC polynomial and initialization.

    decode

    fn decode(data : Bytes) -> Array[Sample] raise CodecError

    decode_range

    fn decode_range(data : Bytes, start : Int64, end : Int64) -> Array[Sample] raise CodecError

    Decode and filter a closed timestamp range. This is a full sequential decode.

    decode_xor

    fn decode_xor(data : Bytes, strict? : Bool) -> Array[Sample] raise CodecError

    encode

    fn encode(samples : Array[Sample]) -> Bytes raise CodecError

    encode_xor

    fn encode_xor(samples : Array[Sample]) -> Bytes raise CodecError