Skip to content

refactor(query-engine): extract asap-adapters crate - #936

Draft
milindsrivastava1997 wants to merge 2 commits into
mainfrom
refactor/asap-adapters-crate
Draft

milindsrivastava1997 wants to merge 2 commits into
mainfrom
refactor/asap-adapters-crate

Conversation

@milindsrivastava1997

Copy link
Copy Markdown
Contributor

Plan step 1 of .design_docs/asapplanner-engine-boundaries.md (decision 46): extract asap-adapters as a pure move.

What moved to asap-adapters

  • drivers/query/ (protocol adapters, fallback clients, HttpServer) and drivers/ingest/otel.rs (OtlpReceiver)
  • query_tracker/, planner_client.rs (with the asap-planner-rs dependency)
  • main.rs, engine_config.rs (only used by main.rs) and every src/bin/* binary. Binary names are unchanged.
  • The unit tests that drive HttpServer: rqe_query_tests, {prometheus,clickhouse,elastic}_forwarding_tests

asap-query-engine is now a library and no longer depends on asap-planner-rs.

Deviations from the plan

  • The remote-write decoders stay in the engine crate (drivers/ingest/{prometheus_remote_write,victoriametrics_remote_write}.rs). precompute_engine/{ingest_source,csv_ingest,json_ingest,ingest_handler}.rs use DecodedSample and the decoders, and they also use precompute internals (SeriesRouter, pub(crate) route_decoded_samples). Moving the decoders would create a crate cycle, and moving the ingest sources would require visibility changes. Both move together in the wiring step, as the plan already says for the ingest sources.
  • tests/sql_query_support.rs and tests/e2e_precompute_equivalence.rs move to asap-adapters/tests/. The alternative was to keep asap-planner-rs as an engine dev-dependency. Moving them keeps the engine crate free of any planner dependency, as decision 46 requires. Both tests use only public engine APIs.
  • asap-adapters/src/bin/run.sh gets a shebang so shellcheck passes on the moved file. It refers to a binary that no longer exists, so it is dead either way.

Other changes (build config only)

  • Workspace Cargo.toml: new member, plus a query_engine_rust workspace dependency.
  • Crate-specific dependencies used only by moved code move from the engine manifest to the adapters manifest. Unused ones (rusqlite, uuid, structopt) stay in the engine manifest untouched.
  • asap-adapters forwards native_query_legacy_test_support to the engine. The default jemalloc feature stays on the engine library.
  • asap-query-engine/Dockerfile builds from asap-adapters with stubs for the new layout. asap-planner-rs/Dockerfile stubs the new member.
  • asap-query-engine/installation/install.sh: -p query_engine_rust → -p asap-adapters.
  • CI path filters include asap-adapters/**.
  • asap-quickstart/Dockerfile.queryengine-local is unchanged: it copies a prebuilt query_engine_rust binary, and that name is the same.

No logic changes. Imports were rewritten from crate:: to query_engine_rust::/asap_adapters::, and cargo fmt reordered them.

Verification

  • cargo fmt --all -- --check and cargo clippy --workspace --all-targets --all-features --locked -- -D warnings pass.
  • cargo test --workspace --locked: 1529 passed, 0 failed, the same count as main.
  • docker build -f asap-query-engine/Dockerfile . and -f asap-planner-rs/Dockerfile . both succeed. The image contains /usr/local/bin/query_engine_rust and --help runs.

Follow-ups (not in this PR)

  • asap-query-engine/docs/adding-{protocol-adapter,protocol-server,fallback-backend}.md and docs/README.md still give src/drivers/... paths relative to the engine crate.
  • Optional: narrow engine internals with pub(crate).

🤖 Generated with Claude Code

milindsrivastava1997 and others added 2 commits November 24, 2026 09:58
Move protocol adapters, fallback clients, the OTLP receiver, the query
tracker, planner client and every binary into a new workspace crate that
depends on the engine crate. The engine crate becomes a library and no
longer depends on asap-planner-rs.

The Prometheus and VictoriaMetrics remote-write decoders stay in the
engine crate: precompute_engine's ingest sources use DecodedSample and
the decoders, and those sources use precompute internals.

Imports, manifests, Dockerfiles, install script and CI path filters only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…aths

Remove reqwest, rusqlite, uuid and structopt from the engine manifest;
nothing in the crate uses them. Point asap-tools build/edit instructions
at asap-adapters and the manual-stack docs at the workspace target dir.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@milindsrivastava1997 milindsrivastava1997 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review findings (Claude Code). Comments that couldn't be anchored to diff lines:

  • [nit] asap-tools/docs/deployment.md: line 234 still says cd asap-query-engine; cargo build --release # Compile Rust binary, and line 308 says cd $REPO_ROOT/asap-query-engine; touch src/main.rs to force a rebuild. asap-query-engine no longer has a binary or a src/main.rs, and the touch would create a stray file that cargo picks up as a new bin target. Point both at asap-adapters.
  • [nit] Stale engine_config.rs / driver references: asap-tools/experiments/experiment_utils/services/query_engine.py (lines 135, 277) and asap-tools/experiments/config/config.yaml (line 78) still point at asap-query-engine/src/engine_config.rs, which now lives in asap-adapters/src/engine_config.rs. asap-query-engine/docs/adding-fallback-backend.md and adding-protocol-server.md still describe crate::drivers::query code that is now in asap-adapters.

Comment thread Cargo.toml
"asap-common/tests/compare_matched_tokens/rust_tests",
"asap-common/tests/compare_patterns",
"asap-query-engine",
"asap-adapters",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[important] CloudLab deploys can no longer build any Rust crate. asap-adapters is now a workspace member, but it isn't in asap-tools/components.conf, so rsync.sh / deploy_changes.sh never sync it. The root Cargo.toml is synced (via root_files.conf), so on the node cargo build --release -p asap-adapters in asap-query-engine/installation/install.sh fails with failed to load manifest for workspace member asap-adapters. The asap-planner-rs and rqe-optimizer installs fail the same way. Editing asap-adapters/src/main.rs also never triggers a reinstall, contrary to the updated README flow.

Fix: add asap-adapters to components.conf and give it an installation/install.sh, or make a change to asap-adapters reinstall asap-query-engine.


2. Ensure the release binaries are built on the CloudLab node:
cargo build --release (in ~/code/asap-query-engine)
cargo build --release (in ~/code/asap-adapters)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[important] This docstring says to run cargo build --release in ~/code/asap-adapters on the CloudLab node. That directory is never synced there because it is missing from components.conf (see the comment on root Cargo.toml), so cd ~/code/asap-adapters fails on a freshly synced node.

Comment thread asap-adapters/Cargo.toml
[dev-dependencies]
serde_yaml.workspace = true

[features]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[important] You can no longer turn the query_engine_rust cargo features on or off from the server binaries. asap-adapters depends on query_engine_rust with its default features and only forwards native_query_legacy_test_support. So cargo build -p asap-adapters --features lock_profiling errors with 'does not have feature', and --no-default-features still links jemalloc. Both worked with -p query_engine_rust before this PR.

Fix: add forwarding features and depend with default-features = false:

[features]
default = ["jemalloc"]
jemalloc = ["query_engine_rust/jemalloc"]
lock_profiling = ["query_engine_rust/lock_profiling"]
extra_debugging = ["query_engine_rust/extra_debugging"]

# Build dependencies (this layer will be cached)
WORKDIR /code/asap-query-engine
RUN cargo build --release && rm -rf src/
WORKDIR /code/asap-adapters

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] cargo now runs from /code/asap-adapters, so builds there (local and CloudLab, per the updated HANDOFF.md / sweep.py) no longer pick up asap-query-engine/.cargo/config.toml (git-fetch-with-cli = true). Consider moving that setting to a workspace-root .cargo/config.toml.

## Prerequisites

- asap-query-engine built at `~/code/asap-query-engine/target/release/query_engine_rust`
- asap-query-engine built at `~/code/target/release/query_engine_rust` (workspace target dir)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] This line now points at ~/code/target/release/query_engine_rust, but later steps here (~line 153) and in manual-stack-run-clickhouse.md (~line 172) still run cd ~/code/asap-query-engine && ./target/release/query_engine_rust. That path no longer exists, so those commands fail.

Comment thread asap-adapters/Cargo.toml
tracing-appender = "0.2"
figment = { version = "0.10", features = ["yaml"] }

[[bin]]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] The bin target query_engine_rust has the same name as the lib dependency query_engine_rust, so cargo doc --workspace warns about an output filename collision, and one crate's docs overwrite the other's. Setting doc = false on the bin targets avoids it.

@@ -1 +1,2 @@
#!/bin/bash
cargo run --bin test_offline_precomputes -- --input-file <msgpack_file_path> --mode merge --pattern-type temporal --aggregation-type DatasketchesKLL --window-size 90 --iterations 10 --slide-step 5

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[pre-existing] This script runs cargo run --bin test_offline_precomputes, and no such binary exists in either crate. Consider deleting the script or pointing it at a real binary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant