Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ default 1 GiB) and queued requests.
**Measurements.** `GET /metrics` exports, in the Prometheus text format,
the thread CPU and wall time of each phase
(`asap_phase_cpu_seconds_total{phase=...}`: `remote_write_decode`,
`append`, `precompute` per refresh group, `query` per query text), query
`otlp_decode`, `append`, `precompute` per refresh group, `query` per query text), query
latency, sample and window counters, the backlogs, the watermark lag, the
bytes held by raw panes and views, RSS, and each thread's CPU time by
name; the view tier and push precompute add `asap_view_cache_*`,
Expand Down Expand Up @@ -207,9 +207,22 @@ Remote Write (the same protobuf, zstd-compressed) on `/api/v1/import` and
OTLP/HTTP metrics (protobuf, optionally gzip) on `/v1/metrics`, the routes
ASAPQuery serves them on. An OTLP data point becomes a sample of the series
named by its metric (`<name>_sum` and `<name>_count` for histograms and
summaries) and labeled by its scope's, resource's and own attributes. Both
routes answer as Remote Write does (400, 503, 500), and are not served in
forward mode, which delivers only Remote Write bodies to the raw store.
summaries), labeled as Prometheus' OTLP receiver labels it by default: the
point's attributes, their names escaped (`http.method` is `http_method`),
plus `job` from the resource's `service.namespace`/`service.name` and
`instance` from its `service.instance.id`. Other resource attributes are
labels only when named by `--otlp-promote-resource-attributes a,b` (as
Prometheus' `promote_resource_attributes`); scope attributes are not labels.
Sums with DELTA temporality are rejected, counted on `/metrics`
(`asap_otlp_rejected_points_total`); a point flagged "no recorded value"
gives Prometheus' stale marker, as Prometheus writes it and as Remote Write
stale markers are kept. The `otlp` crate's docs list the rules and where
they differ from Prometheus. `/api/v1/import` answers as
Remote Write does (400, 503, 500); `/v1/metrics` answers as OTLP/HTTP asks:
200 with a protobuf `ExportMetricsServiceResponse` (its `partial_success`
counting rejected points), or a `google.rpc.Status` body with 400, 415
(OTLP/JSON, not decoded), 503 or 500. Neither route is served in forward
mode, which delivers only Remote Write bodies to the raw store.

`--deployment-capabilities caps.json` replaces the default
`DeploymentCapabilities`: every summary the Planner's executor builds, raw
Expand Down Expand Up @@ -260,9 +273,9 @@ 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/ingest/prometheus-remote-write/` | package `prometheus_remote_write`: Remote Write v1 decoding and validation; its protobuf reader and series cache also serve `otlp` |
| `crates/adapters/ingest/victoriametrics-remote-write/` | package `victoriametrics_remote_write`: VictoriaMetrics Remote Write (the Remote Write protobuf, zstd-compressed), `POST /api/v1/import` |
| `crates/adapters/ingest/otlp/` | package `otlp`: OTLP/HTTP metrics decoding into samples, `POST /v1/metrics` |
| `crates/adapters/ingest/otlp/` | package `otlp`: OTLP/HTTP metrics decoding into samples, and the OTLP/HTTP replies, `POST /v1/metrics` |
| `crates/adapters/query/clickhouse-http/` | package `clickhouse_http`: the `query` parameter, TabSeparated bodies and the fallback client of a ClickHouse server, `/clickhouse/query` |
| `crates/adapters/query/elastic-http/` | package `elastic_http`: `_sql` and `_search` bodies and the fallback client of an Elasticsearch server, `POST /_sql`, `POST /_search` |
| `crates/adapters/query/prometheus-http/` | package `prometheus_http`: query parameters, response bodies and the fallback client of a Prometheus-compatible server |
Expand Down
124 changes: 93 additions & 31 deletions benchmarks/micro/decode_bench.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
//! Remote Write decode cost, in process: decodes the same request
//! repeatedly into interned samples, as the write handler does, and prints
//! microseconds per sample for two request shapes: one series per sample
//! (10,000 series with one sample each, as a paced feeder sends) and
//! Prometheus' shape (100 series with 100 samples each).
//! Ingest decode cost, in process: decodes the same request repeatedly
//! into interned samples, as the write handlers do, and prints
//! microseconds per sample for Remote Write and OTLP, each in two request
//! shapes: one series per sample (10,000 series with one sample each, as
//! a paced feeder sends) and Prometheus' shape (100 series with 100
//! samples each). The OTLP request holds the same series and samples as
//! the Remote Write one: one gauge, each label but `__name__` a point
//! attribute (uncompressed protobuf, as an OpenTelemetry SDK sends it by
//! default).
//!
//! `cargo run --release -p data_plane --example decode_bench`

Expand All @@ -12,25 +16,34 @@ static ALLOCATOR: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;

use std::time::Instant;

use data_plane::remote_write::decode_samples;
use data_plane::remote_write::{decode_otlp_samples, decode_samples};
use otlp::proto::collector::metrics::v1::ExportMetricsServiceRequest;
use otlp::proto::common::v1::{any_value, AnyValue, KeyValue};
use otlp::proto::metrics::v1::{
metric::Data, number_data_point, Gauge, Metric, NumberDataPoint, ResourceMetrics, ScopeMetrics,
};
use prometheus_remote_write::{encode, Label, Limits, Sample, TimeSeries, WriteRequest};

fn request(series: usize, samples_per_series: usize) -> Vec<u8> {
fn labels(i: usize) -> [(&'static str, String); 5] {
[
("__name__", "data".to_string()),
("instance", format!("i{i}")),
("job", format!("job{}", i % 16)),
("region", format!("r{}", i % 4)),
("service", format!("s{}", i % 8)),
]
}

fn remote_write_request(series: usize, samples_per_series: usize) -> Vec<u8> {
let timeseries = (0..series)
.map(|i| TimeSeries {
labels: [
("__name__", "data".to_string()),
("instance", format!("i{i}")),
("job", format!("job{}", i % 16)),
("region", format!("r{}", i % 4)),
("service", format!("s{}", i % 8)),
]
.into_iter()
.map(|(name, value)| Label {
name: name.into(),
value,
})
.collect(),
labels: labels(i)
.into_iter()
.map(|(name, value)| Label {
name: name.into(),
value,
})
.collect(),
samples: (0..samples_per_series)
.map(|t| Sample {
timestamp: 1_000 * t as i64,
Expand All @@ -42,24 +55,73 @@ fn request(series: usize, samples_per_series: usize) -> Vec<u8> {
encode(&WriteRequest { timeseries })
}

fn otlp_request(series: usize, samples_per_series: usize) -> Vec<u8> {
let data_points = (0..series)
.flat_map(|i| {
let attributes: Vec<KeyValue> = labels(i)[1..]
.iter()
.map(|(name, value)| KeyValue {
key: name.to_string(),
value: Some(AnyValue {
value: Some(any_value::Value::StringValue(value.clone())),
}),
})
.collect();
(0..samples_per_series).map(move |t| NumberDataPoint {
attributes: attributes.clone(),
time_unix_nano: 1_000_000_000 * t as u64,
value: Some(number_data_point::Value::AsDouble(t as f64)),
..Default::default()
})
})
.collect();
let request = ExportMetricsServiceRequest {
resource_metrics: vec![ResourceMetrics {
scope_metrics: vec![ScopeMetrics {
metrics: vec![Metric {
name: "data".into(),
data: Some(Data::Gauge(Gauge { data_points })),
..Default::default()
}],
..Default::default()
}],
..Default::default()
}],
};
prost::Message::encode_to_vec(&request)
}

/// Microseconds per sample of `decode` over `body`, after one decode that
/// interns the series, as a steady stream would.
fn per_sample<T>(body: &[u8], samples: usize, decode: impl Fn(&[u8]) -> Vec<T>) -> f64 {
assert_eq!(decode(body).len(), samples);
let rounds = 200;
let started = Instant::now();
for _ in 0..rounds {
std::hint::black_box(decode(body));
}
started.elapsed().as_secs_f64() * 1e6 / (rounds * samples) as f64
}

fn main() {
let limits = Limits::default();
let options = otlp::LabelOptions::default();
for (name, series, per_series) in [
("one series per sample", 10_000, 1),
("100 samples per series", 100, 100),
] {
let body = request(series, per_series);
// Interns the series once, as a steady stream would.
decode_samples(&body, &limits).unwrap();
let rounds = 200;
let started = Instant::now();
for _ in 0..rounds {
std::hint::black_box(decode_samples(&body, &limits).unwrap());
}
let samples = (rounds * series * per_series) as f64;
let samples = series * per_series;
let remote_write = per_sample(&remote_write_request(series, per_series), samples, |b| {
decode_samples(b, &limits).unwrap()
});
let otlp = per_sample(&otlp_request(series, per_series), samples, |b| {
decode_otlp_samples(b, None, &options, &limits)
.unwrap()
.samples
});
println!(
"{name}: {:.3} µs/sample",
started.elapsed().as_secs_f64() * 1e6 / samples
"{name}: Remote Write {remote_write:.3} µs/sample, OTLP {otlp:.3} µs/sample ({:.2}x)",
otlp / remote_write
);
}
}
15 changes: 10 additions & 5 deletions crates/adapters/ingest/otlp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ name = "otlp"
version.workspace = true
edition.workspace = true

# OTLP (OpenTelemetry) metrics over HTTP: request decoding into data
# points. An adapter: no workspace dependency, so it never sees an engine
# or a store.
# OTLP (OpenTelemetry) metrics over HTTP: request decoding into the
# caller's samples, and the replies. An adapter: it never sees an engine or
# a store. It depends on `prometheus-remote-write` alone, for the caller's
# sample types (`SampleBuilder`), the in-place protobuf reader and the
# series cache its decoder shares.
[dependencies]
# The OTLP protobuf messages (no gRPC server; the crate still builds
# tonic's codegen types and the OpenTelemetry SDK it depends on).
prometheus_remote_write.workspace = true
# The OTLP protobuf messages, for senders, tests and the replies (no gRPC
# server; the crate still builds tonic's codegen types and the
# OpenTelemetry SDK it depends on).
opentelemetry-proto = { version = "0.28", default-features = false, features = ["gen-tonic-messages", "metrics"] }
prost = "0.13"
flate2 = "1.0"
serde_json.workspace = true
thiserror.workspace = true
Loading