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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ wall clock) is refreshed. A repeated or lower `T` does nothing. The response is
`{"barrier_ms": B}`, the barrier in force. With several producers, send the
barrier only after all of them have written through `T`.

When no sample arrives at all, the last windows still close by wall-clock
time: event time is taken to advance with the wall clock from the newest
sample, so a window closes once no sample has come for `e - t` plus
`--allowed-lateness-ms` plus 1 s, `e` the window's end and `t` the newest
sample time; that time is measured on a monotonic clock, so a step of the
system clock does not shorten it. A stream behind the wall clock (a
replay) waits as long as a live one. A later sample for such a window is late. These windows are
counted in `asap_windows_closed_by_wall_clock_total`.

**Queries.** An instant query whose text is one of the plan's queries is
answered by one query run of its root at its evaluation time `T`
(`x-asap-execution: plan`). The run reads the views the root reaches,
Expand Down
7 changes: 6 additions & 1 deletion crates/data-plane/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use precompute::engine::{
IngestError, InstalledPrecompute, PersistedViews, PrecomputeEngine, PrecomputeMode,
PrecomputeOptions, SlowRefresh,
};
use precompute::ingestion::{IngestionOptions, IngestionStats};
use precompute::ingestion::{IngestionOptions, IngestionStats, WallClock};
use query::workers::InstalledQueries;
use query::{ExecutorQueryEngine, QueryOptions, Unanswered};
use storage::persist::{plan_hash, ViewRead};
Expand Down Expand Up @@ -135,6 +135,9 @@ pub struct EngineOptions {
/// (ms) panics.
#[doc(hidden)]
pub panic_in_combine_of_window_end_ms: Option<i64>,
/// For tests: the wall clock ingestion reads, set by the test.
#[doc(hidden)]
pub clock: WallClock,
}

/// The default `view_cache_idle_ms`: a minute, four 15 s dashboard
Expand Down Expand Up @@ -180,6 +183,7 @@ impl Default for EngineOptions {
precompute_memory_budget_bytes: None,
push_batching: precompute::push::MorselBatching::default(),
panic_in_combine_of_window_end_ms: None,
clock: WallClock::default(),
}
}
}
Expand Down Expand Up @@ -356,6 +360,7 @@ impl EngineOptions {
push_batching: self.push_batching,
precompute_memory_budget_bytes: self.precompute_memory_budget_bytes,
panic_in_combine_of_window_end_ms: self.panic_in_combine_of_window_end_ms,
clock: self.clock.clone(),
}
}

Expand Down
3 changes: 3 additions & 0 deletions crates/data-plane/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ struct Args {
#[arg(long, default_value = "0.0.0.0:8088")]
listen: String,
/// How long after the newest sample passes a window's end it is refreshed.
/// While no sample arrives, event time is taken to advance with the wall
/// clock: a window closes once no sample has come for its end less the
/// newest sample time, plus this, plus 1 s.
#[arg(long, default_value_t = IngestionOptions::default().allowed_lateness_ms)]
allowed_lateness_ms: u64,
/// Samples further ahead of the wall clock than this are dropped.
Expand Down
11 changes: 11 additions & 0 deletions crates/data-plane/src/metrics_endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,17 @@ pub(crate) fn render(metrics: &Metrics, gauges: &Gauges) -> String {
] {
let _ = writeln!(out, "asap_windows_total{{outcome=\"{outcome}\"}} {count}");
}
family(
&mut out,
"asap_windows_closed_by_wall_clock_total",
"counter",
"Refresh windows closed by wall-clock time while no sample arrived, ahead of the samples and barriers.",
);
let _ = writeln!(
out,
"asap_windows_closed_by_wall_clock_total {}",
stats.windows_closed_by_wall_clock
);

let gauge = |out: &mut String, name: &str, help: &str, value: f64| {
let _ = writeln!(
Expand Down
7 changes: 4 additions & 3 deletions crates/data-plane/src/test_support.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
//! Options and samples for the unit tests.

use precompute::ingestion::IngestionOptions;
use precompute::ingestion::{IngestionOptions, WallClock};
use storage::store::RawSample;

use crate::engine::EngineOptions;

/// Options that refresh every window: no allowed lateness, and the stream
/// starting at 0.
/// Options that refresh every window: no allowed lateness, the stream
/// starting at 0, and the clock stopped ([`WallClock::stopped`]).
pub(crate) fn options() -> EngineOptions {
EngineOptions {
clock: WallClock::stopped(),
ingestion: IngestionOptions {
allowed_lateness_ms: 0,
stream_start_ms: Some(0),
Expand Down
7 changes: 4 additions & 3 deletions crates/data-plane/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use control_plane::{plan_workload, DeploymentInputs};
use data_plane::engine::EngineOptions;
use data_plane::{DataPlane, EXECUTION_HEADER};
use http_body_util::BodyExt;
use precompute::ingestion::IngestionOptions;
use precompute::ingestion::{IngestionOptions, WallClock};
use prometheus_remote_write::{encode, TimeSeries, WriteRequest};
use serde_json::Value;
use tower::ServiceExt;
Expand Down Expand Up @@ -210,11 +210,12 @@ pub fn one_query_plan_json(query: &str, series: usize, extra: Value) -> String {
}

/// The engine options of a data plane that never forwards a query and
/// refreshes every window: no allowed lateness, and the producers' stream
/// starting at 0.
/// refreshes every window: no allowed lateness, the producers' stream
/// starting at 0, and the clock stopped (`WallClock::stopped`).
#[allow(dead_code)]
pub fn no_forward_options() -> EngineOptions {
EngineOptions {
clock: WallClock::stopped(),
no_forward: true,
ingestion: IngestionOptions {
allowed_lateness_ms: 0,
Expand Down
3 changes: 2 additions & 1 deletion crates/data-plane/tests/forward_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use data_plane::engine::EngineOptions;
use data_plane::raw_forward::RawForwardOptions;
use data_plane::{router, DataPlane, EXECUTION_HEADER};
use http_body_util::BodyExt;
use precompute::ingestion::IngestionOptions;
use precompute::ingestion::{IngestionOptions, WallClock};
use prometheus_remote_write::{encode, Label, Sample, TimeSeries, WriteRequest};
use serde_json::{json, Value};
use tokio::sync::Notify;
Expand All @@ -48,6 +48,7 @@ fn plan_json() -> String {

fn options() -> EngineOptions {
EngineOptions {
clock: WallClock::stopped(),
ingest_threads: 2,
ingestion: IngestionOptions {
allowed_lateness_ms: 0,
Expand Down
113 changes: 112 additions & 1 deletion crates/data-plane/tests/ingest_shards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use axum::Router;
use control_plane::plan_workload;
use data_plane::engine::EngineOptions;
use data_plane::{router, DataPlane};
use precompute::ingestion::IngestionOptions;
use precompute::ingestion::{IngestionOptions, WallClock};
use prometheus_remote_write::{encode, Label, Sample, TimeSeries, WriteRequest};
use serde_json::{json, Value};
use tower::ServiceExt;
Expand Down Expand Up @@ -533,3 +533,114 @@ async fn a_sample_beyond_the_time_range_is_dropped() {
assert_eq!(state.engine.stats().samples_dropped_late, 2);
answer(&app, 600).await;
}

/// A data plane of `QUERY` over two shards whose ingestion reads `clock`:
/// no allowed lateness, the stream starting at 0.
fn idle_data_plane(clock: &WallClock) -> (Router, Arc<DataPlane>) {
let options = EngineOptions {
ingest_threads: 2,
clock: clock.clone(),
..common::no_forward_options()
};
let state = Arc::new(
DataPlane::with_options(plan_json(), "http://127.0.0.1:1".into(), options).unwrap(),
);
(router(state.clone()), state)
}

/// One coordinator pass at the clock's time, flushing every shard, with
/// every window it closes committed when it returns: a barrier at 0, which
/// closes nothing itself.
async fn pass(app: &Router) {
common::barrier(app, 0).await;
}

/// Writes series `0..64` at 1..=40 s while the clock reads `written_ms`, and
/// runs them: the window `(30, 40]` is still open, as its end is the newest
/// sample.
async fn write_through_40s(app: &Router, clock: &WallClock, written_ms: i64) {
clock.set(written_ms);
write_seconds(app, 0..64, 1..=40).await;
pass(app).await;
assert_ne!(status_and_answer(app, 40).await.0, StatusCode::OK);
}

/// The window `(30, 40]` closed: answered from every sample at 1..=40 s.
/// Then one more pass, so the counters and the routing of the pass that
/// closed it are published (its refresh may commit before they are).
async fn wait_for_answer_at_40s(app: &Router, state: &DataPlane) {
let started = std::time::Instant::now();
while status_and_answer(app, 40).await.0 != StatusCode::OK {
assert!(
started.elapsed().as_secs() < 10,
"{:?}",
state.engine.stats()
);
tokio::time::sleep(std::time::Duration::from_millis(20)).await;
}
assert_eq!(common::per_job(&answer(app, 40).await), expected(40));
pass(app).await;
}

/// A stream that stops: once no sample has come for the allowed lateness
/// (0) and the 1 s grace past the last window's end, that window closes
/// without a sample or a barrier, and is answered.
#[tokio::test(flavor = "multi_thread")]
async fn the_last_window_of_a_stopped_stream_closes_by_wall_clock_time() {
let clock = WallClock::manual(0);
let (app, state) = idle_data_plane(&clock);
write_through_40s(&app, &clock, 40_000).await;
clock.set(41_000);
wait_for_answer_at_40s(&app, &state).await;
assert!(state.engine.stats().windows_closed_by_wall_clock > 0);
}

/// A replayed stream an hour behind the wall clock: its windows close by
/// wall-clock time counted from its newest sample, never by the wall clock
/// itself, so the window `(30, 40]` waits as long as for a live stream.
#[tokio::test(flavor = "multi_thread")]
async fn a_lagging_stream_closes_no_window_early() {
let hour_ms = 3_600_000;
let clock = WallClock::manual(0);
let (app, state) = idle_data_plane(&clock);
write_through_40s(&app, &clock, hour_ms + 40_000).await;
clock.set(hour_ms + 40_999);
pass(&app).await;
assert_ne!(status_and_answer(&app, 40).await.0, StatusCode::OK);
assert_eq!(state.engine.stats().windows_closed_by_wall_clock, 0);
clock.set(hour_ms + 41_000);
wait_for_answer_at_40s(&app, &state).await;
}

/// The system clock steps 15 min forward (NTP, a resumed VM) while real
/// time does not move: the idle time is measured on the monotonic clock,
/// so the window `(30, 40]` does not close early; it closes once 1 s of
/// real time has passed.
#[tokio::test(flavor = "multi_thread")]
async fn a_wall_clock_step_closes_no_window_early() {
let clock = WallClock::manual(0);
let (app, state) = idle_data_plane(&clock);
write_through_40s(&app, &clock, 40_000).await;
clock.step_wall_clock(40_000 + 15 * 60_000);
pass(&app).await;
assert_ne!(status_and_answer(&app, 40).await.0, StatusCode::OK);
assert_eq!(state.engine.stats().windows_closed_by_wall_clock, 0);
clock.set(41_000 + 15 * 60_000);
wait_for_answer_at_40s(&app, &state).await;
}

/// A sample for a window closed by wall-clock time is late: dropped and
/// counted, and the window keeps its answer.
#[tokio::test(flavor = "multi_thread")]
async fn a_sample_after_a_wall_clock_close_is_late() {
let clock = WallClock::manual(0);
let (app, state) = idle_data_plane(&clock);
write_through_40s(&app, &clock, 40_000).await;
clock.set(41_000);
wait_for_answer_at_40s(&app, &state).await;
let dropped = state.engine.stats().samples_dropped_late;
write_seconds(&app, 5..6, 35..=35).await;
pass(&app).await;
assert_eq!(state.engine.stats().samples_dropped_late, dropped + 1);
assert_eq!(common::per_job(&answer(&app, 40).await), expected(40));
}
3 changes: 2 additions & 1 deletion crates/data-plane/tests/planner_executor_parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use data_plane::{router, DataPlane, EXECUTION_HEADER};
use futures::{executor::block_on, StreamExt};
use http_body_util::BodyExt;
use precompute::engine::PrecomputeMode;
use precompute::ingestion::IngestionOptions;
use precompute::ingestion::{IngestionOptions, WallClock};
use prometheus_remote_write::{Label, Sample, TimeSeries};
use serde_json::Value as Json;
use tower::ServiceExt;
Expand Down Expand Up @@ -243,6 +243,7 @@ async fn data_plane_over(
Views::EveryReadCold => (Some(fresh_view_dir()), Some(0)),
};
let options = EngineOptions {
clock: WallClock::stopped(),
view_dir,
view_cache_max_bytes,
no_forward: true,
Expand Down
3 changes: 2 additions & 1 deletion crates/data-plane/tests/precompute_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use control_plane::plan_workload;
use data_plane::engine::EngineOptions;
use data_plane::{router, DataPlane};
use precompute::engine::SlowRefresh;
use precompute::ingestion::IngestionOptions;
use precompute::ingestion::{IngestionOptions, WallClock};
use prometheus_remote_write::{encode, Label, Sample, TimeSeries, WriteRequest};
use tower::ServiceExt;

Expand Down Expand Up @@ -144,6 +144,7 @@ fn requests(plan: &InstallablePlan, series: usize, from_ms: i64, to_ms: i64) ->

fn options(threads: usize, view_dir: Option<PathBuf>) -> EngineOptions {
EngineOptions {
clock: WallClock::stopped(),
no_forward: true,
precompute_threads: threads,
view_dir,
Expand Down
6 changes: 5 additions & 1 deletion crates/data-plane/tests/push_precompute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use data_plane::{router, DataPlane};
use http_body_util::BodyExt;
use pipelines::{combine_rules, CombineRule};
use precompute::engine::{PrecomputeMode, SlowRefresh};
use precompute::ingestion::IngestionOptions;
use precompute::ingestion::{IngestionOptions, WallClock};
use prometheus_remote_write::{encode, Label, Sample, TimeSeries, WriteRequest};
use serde_json::{json, Value};
use tower::ServiceExt;
Expand Down Expand Up @@ -117,6 +117,7 @@ fn workload_file(name: &str, series: usize) -> asap_planner::PlanningWorkload {
/// windows from 0, no lateness unless a test sets it.
fn options(mode: PrecomputeMode, shards: usize) -> EngineOptions {
EngineOptions {
clock: WallClock::stopped(),
no_forward: true,
ingest_threads: shards,
precompute_mode: mode,
Expand Down Expand Up @@ -834,6 +835,7 @@ async fn seal_is_exact_under_shard_skew() {
let (skewed, state) = install(
&plan,
EngineOptions {
clock: WallClock::stopped(),
shard_delay_ms: 20,
ingestion: IngestionOptions {
allowed_lateness_ms: 0,
Expand Down Expand Up @@ -953,6 +955,7 @@ async fn late_samples_count_in_the_window_paths_windows() {
let (app, _) = install(
&plan,
EngineOptions {
clock: WallClock::stopped(),
ingestion: IngestionOptions {
allowed_lateness_ms: 5_000,
stream_start_ms: Some(0),
Expand Down Expand Up @@ -1132,6 +1135,7 @@ async fn memory_reservations_wait_then_fail_only_a_lone_window() {
let (app, state) = install(
&plan,
EngineOptions {
clock: WallClock::stopped(),
precompute_memory_budget_bytes: Some((one_small * 1.5) as u64),
push_batching: per_request(),
ingestion: IngestionOptions {
Expand Down
3 changes: 2 additions & 1 deletion crates/data-plane/tests/query_protocols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use data_plane::engine::EngineOptions;
use data_plane::{router, DataPlane, EXECUTION_HEADER};
use elastic_http::fallback::ElasticHttpFallback;
use http_body_util::BodyExt;
use precompute::ingestion::IngestionOptions;
use precompute::ingestion::{IngestionOptions, WallClock};
use prometheus_remote_write::{Label, Sample, TimeSeries};
use serde_json::{json, Value};
use tower::ServiceExt;
Expand Down Expand Up @@ -82,6 +82,7 @@ async fn upstream(received: Received) -> String {
/// Forwarding allowed, every window refreshed.
fn options() -> EngineOptions {
EngineOptions {
clock: WallClock::stopped(),
ingestion: IngestionOptions {
allowed_lateness_ms: 0,
stream_start_ms: Some(0),
Expand Down
3 changes: 2 additions & 1 deletion crates/data-plane/tests/range_isolation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use control_plane::plan_workload;
use data_plane::engine::EngineOptions;
use data_plane::{router, DataPlane};
use http_body_util::BodyExt;
use precompute::ingestion::IngestionOptions;
use precompute::ingestion::{IngestionOptions, WallClock};
use prometheus_remote_write::{encode, Label, Sample, TimeSeries, WriteRequest};
use serde_json::json;
use tower::ServiceExt;
Expand Down Expand Up @@ -147,6 +147,7 @@ async fn range_requests_do_not_hold_up_instant_queries_or_writes() {
let dir = std::env::temp_dir().join(format!("range-isolation-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
let options = EngineOptions {
clock: WallClock::stopped(),
no_forward: true,
query_threads: std::env::var("RANGE_ISOLATION_QUERY_THREADS")
.map_or(8, |n| n.parse().unwrap()),
Expand Down
3 changes: 2 additions & 1 deletion crates/data-plane/tests/range_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use axum::Router;
use control_plane::plan_workload;
use data_plane::engine::EngineOptions;
use data_plane::{router, DataPlane};
use precompute::ingestion::IngestionOptions;
use precompute::ingestion::{IngestionOptions, WallClock};
use prometheus_remote_write::{Label, Sample, TimeSeries};
use serde_json::json;

Expand Down Expand Up @@ -189,6 +189,7 @@ async fn a_refreshed_range_reads_its_older_steps_from_the_result_cache() {
let plan = serde_json::to_string(&plan_workload(&workload, &inputs).unwrap().0).unwrap();
let start = || {
let options = EngineOptions {
clock: WallClock::stopped(),
no_forward: true,
ingestion: IngestionOptions {
allowed_lateness_ms: 0,
Expand Down
Loading