#remote #prometheus #storage-api #api #storage

prom-remote-api

Prometheus remote storage API for Rust

5 unstable releases

0.3.0 May 27, 2023
0.2.2 May 9, 2023
0.2.1 Jan 22, 2023
0.2.0 Jan 21, 2023
0.1.0 Jan 16, 2023

#18 in #storage-api

Download history 574/week @ 2023-11-24 768/week @ 2023-12-01 402/week @ 2023-12-08 480/week @ 2023-12-15 429/week @ 2023-12-22 498/week @ 2023-12-29 507/week @ 2024-01-05 421/week @ 2024-01-12 607/week @ 2024-01-19 448/week @ 2024-01-26 272/week @ 2024-02-02 158/week @ 2024-02-09 276/week @ 2024-02-16 239/week @ 2024-02-23 251/week @ 2024-03-01 183/week @ 2024-03-08

971 downloads per month

Apache-2.0

27KB
231 lines

prom-remote-api

Crates.io docs.rs

Prometheus remote storage API for Rust.

Usage

There are two interfaces in Prometheus remote storage API: write/read.

Both interfaces use a snappy-compressed protocol buffer encoding over HTTP.

This crate provides:

Any third-party storage can integrate with Prometheus by implementing RemoteStorage trait.

pub trait RemoteStorage: Sync {
    type Err: Send;
    type Context: Send + Sync;

    /// Write samples to remote storage.
    async fn write(&self, ctx: Self::Context, req: WriteRequest) -> Result<(), Self::Err>;

    /// Process one query within [ReadRequest](crate::types::ReadRequest).
    ///
    /// Note: Prometheus remote protocol sends multiple queries by default,
    /// use [read](crate::types::RemoteStorage::read) to serve ReadRequest.
    async fn process_query(
        &self,
        ctx: &Self::Context,
        q: Query,
    ) -> Result<QueryResult, Self::Err>;

    /// Read samples from remote storage.
    ///
    /// [ReadRequest](crate::types::ReadRequest) may contain more than one sub [queries](crate::types::Query).
    async fn read(
        &self,
        ctx: Self::Context,
        req: ReadRequest,
    ) -> Result<ReadResponse, Self::Err> {
        let results = futures::future::join_all(
            req.queries
                .into_iter()
                .map(|q| async { self.process_query(&ctx, q).await }),
        )
        .await
        .into_iter()
        .collect::<Result<Vec<_>, Self::Err>>()?;

        Ok(ReadResponse { results })
    }
}

See warp-demo.rs, actix-demo.rs to learn how to build a remote storage.

Dependencies

~5–20MB
~272K SLoC