Crates.io | prom-remote-api |
lib.rs | prom-remote-api |
version | 0.3.0 |
source | src |
created_at | 2023-01-16 13:28:32.02654 |
updated_at | 2023-05-27 12:03:30.438943 |
description | Prometheus remote storage API for Rust |
homepage | https://github.com/jiacai2050/prom-remote-api |
repository | https://github.com/jiacai2050/prom-remote-api |
max_upload_size | |
id | 760166 |
size | 91,123 |
Prometheus remote storage API for Rust.
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:
warp
actix
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.