diff --git a/Cargo.lock b/Cargo.lock index 4149c4849..a526c9a89 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -972,20 +972,17 @@ dependencies = [ "control_plane", "form_urlencoded", "futures", - "hashbrown 0.15.5", "http-body-util", "internal_metrics", "libc", "precompute", - "prost", + "prometheus_http", + "prometheus_remote_write", "query", "reqwest", - "ryu", - "serde", "serde_json", "snap", "storage", - "thiserror 1.0.69", "tikv-jemallocator", "tokio", "tower", @@ -2871,6 +2868,35 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "prometheus_http" +version = "0.1.0" +dependencies = [ + "ahash", + "async-trait", + "axum", + "bytes", + "common", + "form_urlencoded", + "reqwest", + "ryu", + "serde", + "serde_json", + "thiserror 1.0.69", + "tokio", +] + +[[package]] +name = "prometheus_remote_write" +version = "0.1.0" +dependencies = [ + "ahash", + "hashbrown 0.15.5", + "prost", + "snap", + "thiserror 1.0.69", +] + [[package]] name = "promql-parser" version = "0.11.1" diff --git a/Cargo.toml b/Cargo.toml index b4abd52a3..db849d999 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,8 @@ [workspace] resolver = "2" members = [ + "crates/adapters/ingest/prometheus-remote-write", + "crates/adapters/query/prometheus-http", "crates/common", "crates/control-plane", "crates/data-plane", @@ -44,6 +46,8 @@ control_plane = { path = "crates/control-plane" } common = { path = "crates/common" } internal_metrics = { path = "crates/internal-metrics" } precompute = { path = "crates/precompute" } +prometheus_http = { path = "crates/adapters/query/prometheus-http" } +prometheus_remote_write = { path = "crates/adapters/ingest/prometheus-remote-write" } query = { path = "crates/query" } storage = { path = "crates/storage" } diff --git a/README.md b/README.md index 12090e55a..0c7caf824 100644 --- a/README.md +++ b/README.md @@ -236,6 +236,8 @@ not stored) with a Prometheus `execution` error (422, | `crates/query/` | package `query`: planned queries on the query workers, and the result cache | | `crates/storage/` | package `storage`: raw samples and views in memory, the view cache, segments, persistence and the persist threads | | `crates/internal-metrics/` | package `internal_metrics`: the backend's measurements of itself, exported on `/metrics` | +| `crates/adapters/ingest/prometheus-remote-write/` | package `prometheus_remote_write`: Remote Write v1 decoding and validation | +| `crates/adapters/query/prometheus-http/` | package `prometheus_http`: query parameters, response bodies and the fallback client of a Prometheus-compatible server | | `benchmarks/` | the backend alone: `micro/` benchmarks (examples of `data_plane`) and `scripts/` | | `eval/` | comparisons with other systems and the live demo; see [eval/README.md](eval/README.md) | | `deployment/monitoring/` | Prometheus, exporters and Grafana for the demo and the comparisons | diff --git a/benchmarks/micro/decode_bench.rs b/benchmarks/micro/decode_bench.rs index 93e721241..dab9813d2 100644 --- a/benchmarks/micro/decode_bench.rs +++ b/benchmarks/micro/decode_bench.rs @@ -12,9 +12,8 @@ static ALLOCATOR: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; use std::time::Instant; -use data_plane::remote_write::{ - decode_samples, encode, Label, Limits, Sample, TimeSeries, WriteRequest, -}; +use data_plane::remote_write::decode_samples; +use prometheus_remote_write::{encode, Label, Limits, Sample, TimeSeries, WriteRequest}; fn request(series: usize, samples_per_series: usize) -> Vec { let timeseries = (0..series) diff --git a/benchmarks/micro/ingest_bench.rs b/benchmarks/micro/ingest_bench.rs index 9a7021f0f..ecf2c460c 100644 --- a/benchmarks/micro/ingest_bench.rs +++ b/benchmarks/micro/ingest_bench.rs @@ -43,11 +43,11 @@ use axum::body::Body; use axum::http::{Request, StatusCode}; use control_plane::{plan_workload, DeploymentInputs}; use data_plane::engine::EngineOptions; -use data_plane::remote_write::{encode, Label, Sample, TimeSeries, WriteRequest}; use data_plane::{router, DataPlane}; use internal_metrics::thread_cpu_seconds; use precompute::engine::PrecomputeMode; use precompute::ingestion::IngestionOptions; +use prometheus_remote_write::{encode, Label, Sample, TimeSeries, WriteRequest}; use tower::ServiceExt; #[tokio::main(flavor = "multi_thread")] diff --git a/benchmarks/micro/matrix_bench.rs b/benchmarks/micro/matrix_bench.rs index 5bac5e637..880a51c31 100644 --- a/benchmarks/micro/matrix_bench.rs +++ b/benchmarks/micro/matrix_bench.rs @@ -8,8 +8,8 @@ use std::collections::BTreeMap; use std::sync::Arc; use std::time::Instant; -use data_plane::prometheus::range_response_body; -use query::ResultSample; +use common::ResultSample; +use prometheus_http::range_response_body; fn main() { let args: Vec = std::env::args() diff --git a/benchmarks/micro/offset_bench.rs b/benchmarks/micro/offset_bench.rs index 91ea7924a..851e527b8 100644 --- a/benchmarks/micro/offset_bench.rs +++ b/benchmarks/micro/offset_bench.rs @@ -17,10 +17,10 @@ use axum::http::{Request, StatusCode}; use axum::Router; use control_plane::plan_workload; use data_plane::engine::EngineOptions; -use data_plane::remote_write::{encode, Label, Sample, TimeSeries, WriteRequest}; use data_plane::{router, DataPlane}; use http_body_util::BodyExt; use precompute::ingestion::IngestionOptions; +use prometheus_remote_write::{encode, Label, Sample, TimeSeries, WriteRequest}; use serde_json::json; use tower::ServiceExt; diff --git a/benchmarks/micro/range_bench.rs b/benchmarks/micro/range_bench.rs index ae5ef47af..97557dd29 100644 --- a/benchmarks/micro/range_bench.rs +++ b/benchmarks/micro/range_bench.rs @@ -25,11 +25,11 @@ use axum::http::{Request, StatusCode}; use axum::Router; use control_plane::{plan_workload, DeploymentInputs}; use data_plane::engine::EngineOptions; -use data_plane::remote_write::{encode, Label, Sample, TimeSeries, WriteRequest}; use data_plane::{router, DataPlane, EXECUTION_HEADER}; use http_body_util::BodyExt; use internal_metrics::thread_cpu_seconds; use precompute::ingestion::IngestionOptions; +use prometheus_remote_write::{encode, Label, Sample, TimeSeries, WriteRequest}; use tower::ServiceExt; const STEP_MS: i64 = 15_000; diff --git a/benchmarks/micro/rw_corpus_bench.rs b/benchmarks/micro/rw_corpus_bench.rs index e101470b7..c0c52625b 100644 --- a/benchmarks/micro/rw_corpus_bench.rs +++ b/benchmarks/micro/rw_corpus_bench.rs @@ -29,8 +29,9 @@ static ALLOCATOR: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; use std::sync::mpsc; use std::time::Instant; -use data_plane::remote_write::{decode_samples, Limits}; +use data_plane::remote_write::decode_samples; use internal_metrics::thread_cpu_ns; +use prometheus_remote_write::Limits; use storage::store::RawSample; fn main() { diff --git a/benchmarks/micro/tier_bench.rs b/benchmarks/micro/tier_bench.rs index 0d974e0ba..474c3927a 100644 --- a/benchmarks/micro/tier_bench.rs +++ b/benchmarks/micro/tier_bench.rs @@ -38,10 +38,10 @@ use axum::http::{Request, StatusCode}; use axum::Router; use control_plane::{plan_workload, DeploymentInputs}; use data_plane::engine::EngineOptions; -use data_plane::remote_write::{encode, Label, Sample, TimeSeries, WriteRequest}; use data_plane::{router, DataPlane}; use http_body_util::BodyExt; use precompute::ingestion::IngestionOptions; +use prometheus_remote_write::{encode, Label, Sample, TimeSeries, WriteRequest}; use storage::persist::ViewRead; use tower::ServiceExt; diff --git a/crates/adapters/ingest/prometheus-remote-write/Cargo.toml b/crates/adapters/ingest/prometheus-remote-write/Cargo.toml new file mode 100644 index 000000000..9224d9faa --- /dev/null +++ b/crates/adapters/ingest/prometheus-remote-write/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "prometheus_remote_write" +version.workspace = true +edition.workspace = true + +# Prometheus Remote Write v1: request decoding and validation. An adapter: +# no workspace dependency, so it never sees an engine or a store. The +# caller interns each series into its own series type (`Decoder`). +[dependencies] +prost = "0.13" +snap = "1.1" +# The decoder's series cache (a table of indices hashed by the keys they +# point to). +ahash = "0.8" +hashbrown = "0.15" +thiserror.workspace = true diff --git a/crates/adapters/ingest/prometheus-remote-write/src/lib.rs b/crates/adapters/ingest/prometheus-remote-write/src/lib.rs new file mode 100644 index 000000000..e4bbcab72 --- /dev/null +++ b/crates/adapters/ingest/prometheus-remote-write/src/lib.rs @@ -0,0 +1,886 @@ +//! Prometheus Remote Write v1 decoding and validation. +//! +//! [`Decoder`] walks a request body into samples without building a +//! [`WriteRequest`]. It knows no engine type: the caller's [`SampleBuilder`] +//! interns each new series into its own series handle (any `Copy` value, +//! such as an interned `&'static` series) and builds its own sample from +//! the handle, timestamp and value, so samples are decoded straight into +//! the engine's type with no copy. + +use prost::Message; + +#[derive(Clone, PartialEq, Message)] +pub struct WriteRequest { + #[prost(message, repeated, tag = "1")] + pub timeseries: Vec, +} + +#[derive(Clone, PartialEq, Message)] +pub struct TimeSeries { + #[prost(message, repeated, tag = "1")] + pub labels: Vec