diff --git a/.github/workflows/build-engines.yml b/.github/workflows/build-engines.yml index dbe9056a11b7..3b7f7adbdefa 100644 --- a/.github/workflows/build-engines.yml +++ b/.github/workflows/build-engines.yml @@ -10,8 +10,8 @@ on: - '*.*.x' - 'integration/*' paths-ignore: - - '!.github/workflows/build-engines*' - '.github/**' + - '!.github/workflows/build-engines*' - '*.md' - 'LICENSE' - 'CODEOWNERS' diff --git a/.github/workflows/build-prisma-schema-wasm.yml b/.github/workflows/build-prisma-schema-wasm.yml index 28f5429a8702..2b299fdfaa02 100644 --- a/.github/workflows/build-prisma-schema-wasm.yml +++ b/.github/workflows/build-prisma-schema-wasm.yml @@ -5,9 +5,9 @@ on: - main pull_request: paths-ignore: + - '.github/**' - '!.github/workflows/build-prisma-schema-wasm.yml' - '!.github/workflows/include/rust-wasm-setup/action.yml' - - '.github/**' - '*.md' - 'LICENSE' - 'CODEOWNERS' diff --git a/.github/workflows/include/rust-wasm-setup/action.yml b/.github/workflows/include/rust-wasm-setup/action.yml index 3f217182e989..34a0d08074a0 100644 --- a/.github/workflows/include/rust-wasm-setup/action.yml +++ b/.github/workflows/include/rust-wasm-setup/action.yml @@ -21,8 +21,8 @@ runs: uses: jaxxstorm/action-install-gh-release@v1.14.0 with: repo: WebAssembly/binaryen - tag: version_122 - binaries-location: binaryen-version_122/bin + tag: version_124 + binaries-location: binaryen-version_124/bin cache: true - name: Install bc diff --git a/.github/workflows/test-compilation.yml b/.github/workflows/test-compilation.yml index 425dd5cd24da..523214cee8a5 100644 --- a/.github/workflows/test-compilation.yml +++ b/.github/workflows/test-compilation.yml @@ -2,9 +2,9 @@ name: 'All crates' on: pull_request: paths-ignore: + - '.github/**' - '!.github/workflows/test-compilation.yml' - '!.github/workflows/test-compilation-template.yml' - - '.github/**' - '*.md' - 'LICENSE' - 'CODEOWNERS' diff --git a/.github/workflows/test-quaint.yml b/.github/workflows/test-quaint.yml index bef360e9916c..d93ddadd4e1d 100644 --- a/.github/workflows/test-quaint.yml +++ b/.github/workflows/test-quaint.yml @@ -6,7 +6,7 @@ on: pull_request: paths: - 'quaint/**' - - '!.github/workflows/test-quaint.yml' + - '.github/workflows/test-quaint.yml' jobs: tests: @@ -23,7 +23,7 @@ jobs: TEST_MYSQL_MARIADB: 'mysql://root:prisma@localhost:3308/prisma' TEST_PSQL: 'postgres://postgres:prisma@localhost:5432/postgres' TEST_MSSQL: 'jdbc:sqlserver://localhost:1433;database=master;user=SA;password=;trustServerCertificate=true;isolationLevel=READ UNCOMMITTED' - TEST_CRDB: 'postgresql://prisma@127.0.0.1:26259/postgres' + TEST_CRDB: 'postgresql://root@127.0.0.1:26259/postgres' steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/test-query-compiler.yml b/.github/workflows/test-query-compiler.yml index 8ef8bbe4e9f4..d323dcc7aea4 100644 --- a/.github/workflows/test-query-compiler.yml +++ b/.github/workflows/test-query-compiler.yml @@ -8,6 +8,7 @@ on: - '.github/**' - '!.github/workflows/test-query-compiler.yml' - '!.github/workflows/test-query-compiler-template.yml' + - '!.github/workflows/include/rust-wasm-setup/action.yml' - '*.md' - 'LICENSE' - 'CODEOWNERS' diff --git a/.github/workflows/test-query-engine-black-box.yml b/.github/workflows/test-query-engine-black-box.yml index ca1126827e91..4d1d9c082552 100644 --- a/.github/workflows/test-query-engine-black-box.yml +++ b/.github/workflows/test-query-engine-black-box.yml @@ -5,8 +5,8 @@ on: - main pull_request: paths-ignore: - - '!.github/workflows/test-query-engine-black-box.yml' - '.github/**' + - '!.github/workflows/test-query-engine-black-box.yml' - '*.md' - 'LICENSE' - 'CODEOWNERS' diff --git a/.github/workflows/test-query-engine.yml b/.github/workflows/test-query-engine.yml index 30b1eb174982..f1ba35242aa9 100644 --- a/.github/workflows/test-query-engine.yml +++ b/.github/workflows/test-query-engine.yml @@ -84,9 +84,6 @@ jobs: - name: 'mysql_5_7' version: '5.7' relation_load_strategy: '["query"]' - - name: 'mysql_5_6' - version: '5.6' - relation_load_strategy: '["query"]' - name: 'mysql_mariadb' version: 'mariadb' relation_load_strategy: '["query"]' @@ -109,12 +106,12 @@ jobs: fail-fast: false matrix: database: - - name: 'cockroach_23_1' - version: '23.1' - - name: 'cockroach_22_2' - version: '22.2' - - name: 'cockroach_22_1_0' - version: '22.1' + - name: 'cockroach_24_3' + version: '24.3' + - name: 'cockroach_25_1' + version: '25.1' + - name: 'cockroach_25_2' + version: '25.2' name: 'CockroachDB v${{ matrix.database.version}}' uses: ./.github/workflows/test-query-engine-template.yml with: diff --git a/.github/workflows/test-schema-engine.yml b/.github/workflows/test-schema-engine.yml index 98f3058a5f9a..fb62c2853382 100644 --- a/.github/workflows/test-schema-engine.yml +++ b/.github/workflows/test-schema-engine.yml @@ -94,8 +94,6 @@ jobs: database: - name: mssql_2019 url: 'sqlserver://localhost:1433;database=master;user=SA;password=;trustServerCertificate=true;socket_timeout=60;isolationLevel=READ UNCOMMITTED' - - name: mysql_5_6 - url: 'mysql://root:prisma@localhost:3309' - name: mysql_5_7 url: 'mysql://root:prisma@localhost:3306' - name: mysql_mariadb @@ -108,12 +106,14 @@ jobs: url: 'postgresql://postgres:prisma@localhost:5437' - name: postgres15 url: 'postgresql://postgres:prisma@localhost:5438' - - name: cockroach_23_1 - url: 'postgresql://prisma@localhost:26260' - - name: cockroach_22_2 - url: 'postgresql://prisma@localhost:26259' - - name: cockroach_22_1_0 - url: 'postgresql://prisma@localhost:26257' + - name: postgres16 + url: 'postgresql://postgres:prisma@localhost:5439' + - name: cockroach_24_3 + url: 'postgresql://root@localhost:26260' + - name: cockroach_25_1 + url: 'postgresql://root@localhost:26261' + - name: cockroach_25_2 + url: 'postgresql://root@localhost:26262' - name: vitess_8_0 url: 'mysql://root:prisma@localhost:33807/test' shadow_database_url: 'mysql://root:prisma@localhost:33808/shadow' diff --git a/.test_database_urls/cockroachdb_22_1 b/.test_database_urls/cockroachdb_22_1 deleted file mode 100644 index cfb70d32b10c..000000000000 --- a/.test_database_urls/cockroachdb_22_1 +++ /dev/null @@ -1,2 +0,0 @@ -export TEST_DATABASE_URL="postgresql://prisma@localhost:26257" -unset TEST_SHADOW_DATABASE_URL diff --git a/.test_database_urls/cockroachdb_22_2 b/.test_database_urls/cockroachdb_22_2 deleted file mode 100644 index 20aca4dfb9a6..000000000000 --- a/.test_database_urls/cockroachdb_22_2 +++ /dev/null @@ -1,2 +0,0 @@ -export TEST_DATABASE_URL="postgresql://prisma@localhost:26259" -unset TEST_SHADOW_DATABASE_URL diff --git a/.test_database_urls/cockroachdb_23_1 b/.test_database_urls/cockroachdb_23_1 deleted file mode 100644 index f3c5b1b50190..000000000000 --- a/.test_database_urls/cockroachdb_23_1 +++ /dev/null @@ -1,2 +0,0 @@ -export TEST_DATABASE_URL="postgresql://prisma@localhost:26260" -unset TEST_SHADOW_DATABASE_URL diff --git a/.test_database_urls/cockroachdb_24_3 b/.test_database_urls/cockroachdb_24_3 new file mode 100644 index 000000000000..9af17446e252 --- /dev/null +++ b/.test_database_urls/cockroachdb_24_3 @@ -0,0 +1,2 @@ +export TEST_DATABASE_URL="postgresql://root@localhost:26260" +unset TEST_SHADOW_DATABASE_URL diff --git a/.test_database_urls/cockroachdb_25_1 b/.test_database_urls/cockroachdb_25_1 new file mode 100644 index 000000000000..d235aea0095c --- /dev/null +++ b/.test_database_urls/cockroachdb_25_1 @@ -0,0 +1,2 @@ +export TEST_DATABASE_URL="postgresql://root@localhost:26261" +unset TEST_SHADOW_DATABASE_URL diff --git a/.test_database_urls/cockroachdb_25_2 b/.test_database_urls/cockroachdb_25_2 new file mode 100644 index 000000000000..8a5529c6878a --- /dev/null +++ b/.test_database_urls/cockroachdb_25_2 @@ -0,0 +1,2 @@ +export TEST_DATABASE_URL="postgresql://root@localhost:26262" +unset TEST_SHADOW_DATABASE_URL diff --git a/.test_database_urls/mysql_5_6 b/.test_database_urls/mysql_5_6 deleted file mode 100644 index 2da70d99c3fb..000000000000 --- a/.test_database_urls/mysql_5_6 +++ /dev/null @@ -1,2 +0,0 @@ -export TEST_DATABASE_URL="mysql://root:prisma@localhost:3309" -unset TEST_SHADOW_DATABASE_URL diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 000000000000..165218467ecd --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,185 @@ +# Agent Playbook — Prisma Engines + +## 1. Big Picture +- This repo hosts the **Prisma Engines**: PSL (schema parser/validator), schema-engine (migrate, introspect), query components (legacy query engine, new query compiler), driver adapters, and utilities shared with Prisma Client. +- Prisma 7 roadmap status: + - `directUrl` and `shadowDatabaseUrl` are **invalid** in PSL. + - `url` remains temporarily (legacy query engine still consumes it); removal is a follow-up. + - CLI/tests override connection info via schema-engine CLI (`--datasource`) or shared `TestApi::new_engine_with_connection_strings`. + - Reference commit: `34b5a692b7bd79939a9a2c3ef97d816e749cda2f` (driver adapter override plumbing). +- Prisma is deprecating the **native Rust query engine** in favor of the **Query Compiler (QC)** architecture: + - Query planning happens in Rust (`query-compiler` crate). Output: an expression tree (“query plan”). + - Query interpretation/execution runs in Prisma Client TypeScript using driver adapters. The interpreter has no knowledge of connection strings or even whether it talks to a real DB. + - A compatibility harness (`qc-test-runner.ts` in the main repo) emulates legacy query engine behavior for the test suite until QE removal is complete. + - MongoDB support is not yet implemented for QC; Prisma 7 will ship without MongoDB, to be added later. + +--- + +## 2. Repository Orientation +Key directories: +- `psl/` – Prisma Schema Language parser, validator, config tooling. +- `schema-engine/` – Migration/introspection engine plus test suites. +- `prisma-fmt/` – Language server & formatter entry point (tests rely on `expect!` snapshots). +- `schema-engine/sql-migration-tests` / `sql-introspection-tests` – Heavy integration suites (require DBs). +- `query-engine/` – Legacy query execution stack (Rust). +- `query-compiler/` – New query planner + associated WASM + playground. +- `libs/` – Shared libraries (value types, driver adapters, test setup). +- `driver-adapters/` – Rust-side adapter utilities for the new query interpreter. + +Supporting infra: +- Tests use Rust `cargo test`. Some suites expect database URLs in env (see §5). +- `test-setup` crate provisions databases when env vars are defined (Docker-based in CI). +- `UPDATE_EXPECT=1 cargo test …` regenerates `expect!` snapshots (common when diagnostics shift). + +--- + +## 3. Current Domain Knowledge +### Datasource URLs +- PSL rejects `directUrl`/`shadowDatabaseUrl` with targeted diagnostics (`DatamodelError::new_datasource_*_removed_error`). +- Parser still records `url` (and uses span for override fallbacks). +- `Datasource::override_urls()` now fakes spans because overrides bypass PSL parsing. +- Schema-engine tests must supply overrides via `TestApi::new_engine_with_connection_strings(connection_string, Some(shadow_connection))`. The wrapper returns an `EngineTestApi`. +- Old fixtures relying on `directUrl` inside PSL must be rewritten or deleted. +- Query compiler already assumes datasource URLs are supplied externally (from Prisma Client). + +### Text Completions +- `prisma-fmt` completions now only offer `url` (no more direct/shadow suggestions). +- Completion scenarios removed for the deprecated properties. Expect JSON fixtures to change if docs/completions change again. + +### Diagnostics / Tests +- Many tests assert on colored output via `expect!`. Always regenerate expectations when diagnostics wording changes. +- Integration tests around multi-schema migrations still need real DB URLs; without them they skip/fail early. +- Query compiler tests use insta snapshots (`query-compiler/tests`). Regenerate with `UPDATE_EXPECT=1 cargo test -p query-compiler`. +- Query engine connector tests rely on `cargo insta` snapshots too (see `connector-test-kit-rs` README). + +--- + +## 4. Typical Workflows +### Linting / Formatting +- Rustfmt + cargo fmt (standard). JSON fixtures kept raw (no formatter). +- Full lint pass (formatting + clippy warnings as errors): + ```bash + make pedantic + ``` + This runs `cargo fmt -- --check` and `cargo clippy --all-features --all-targets -Dwarnings`. Fix the compiler/clippy diagnostics first, then formatting. + +### Running Tests +1. **Fast PSL/LSP suites** + ```bash + cargo test -p prisma-fmt -F psl/all + ``` + Use `UPDATE_EXPECT=1` to refresh snapshots. + +2. **Unit tests in PSL** + ```bash + cargo test -p psl -F all + ``` + +3. **Unit tests for the whole workspace** + ```bash + make test-unit + ``` + Use this one if you can't figure out the correct cargo features for a specific crate. + Some library crates may be tricky to compile in isolation without feature unification. + Unit tests are very fast so there's no problem running them for the whole workspace. + Note that `cargo test` for the whole workspace won't work because of the Node-API + symbol dependencies in the `query-engine-node-api` crate, use the makefile target. + +3. **Schema engine SQL tests** + Require DB env vars (see `.test_database_urls/` in repo root). Example: + ```bash + source .test_database_urls/postgres + cargo test -p sql-migration-tests migration_with_shadow_database -- --nocapture + ``` + +4. **Schema engine integration** + Similar pattern; rely on generated DB URLs. Without env vars tests will refuse to run (by design). + +5. **Query compiler snapshots** + ```bash + UPDATE_EXPECT=1 cargo test -p query-compiler + ``` + Graphviz (`dot`) optional; set `RENDER_DOT_TO_PNG` for visuals (requires Graphviz installed). + +6. **Query engine connector tests** + ```bash + make dev-postgres15 # or appropriate make target to spin up DB & config + cargo test -p query-engine-tests -- --nocapture + ``` + Requires `.test_config` or env vars; see `query-engine/connector-test-kit-rs/README.md`. + +7. **Query engine Node API / C-ABI builds** + - Node addon: `cargo build -p query-engine-node-api`. + - C-ABI (used by React Native): `cargo build -p query-engine-c-abi`. + +### Updating expect! snapshots +```bash +UPDATE_EXPECT=1 cargo test -p prisma-fmt [optional::test::path] +``` +Ensure diffs make sense and rerun without `UPDATE_EXPECT` to confirm. + +--- + +## 5. Environment Essentials +- **Databases**: env vars follow `TEST_DATABASE_URL`, `TEST_SHADOW_DATABASE_URL`, etc. Use the `.test_database_urls/` helper scripts or docker-compose setup from team docs. +- **Linear tickets**: two key Prisma 7 projects – *Breaking Changes* and *New Features*. Search via Linear MCP server if context needed. +- **Feature flags**: driver adapters live behind configuration (`prisma.config.ts` with `engine: 'classic' | 'js'`). Schema engine CLI accepts `--datasource` JSON payload – reuse the structure from commit `34b5a69…`. +- **Graphviz (`dot`)**: optional but useful for rendering query graphs (required if `RENDER_DOT_TO_PNG` set in QC tests/playground). +- **Node.js**: required when working with query-engine Node bindings or QC interpreter harness. +- **Docker**: used for local DBs via `docker-compose.yml`; make targets (`make dev-postgres15`, `make start-mongo6`, etc.) orchestrate containers + config files. + +--- + +## 6. Common Gotchas +- Running prisma-fmt tests after updating diagnostics **without** refreshing expect files will cause failures. Always run with `UPDATE_EXPECT=1`. +- Some fixtures expect **CRLF** endings (`create_missing_block_composite_type_crlf`). Avoid rewriting line endings when not necessary. If Git warns, restore file from `HEAD`. +- Integration tests bail with “Missing TEST_DATABASE_URL”. Set env vars or skip running them locally. +- `TestApi` inside `sql-migration-tests` exposes `new_engine_with_connection_strings`; use it to pass overrides. +- When touching overrides, update both PSL and schema-engine sides; they share assumptions about spans and optional URLs. +- Query compiler shares substantial code with query engine (e.g., `query_core`, `query_structure`). Changes in shared crates affect both paths—be mindful of feature flags. +- Many query engine tests still assume native QE; the `qc-test-runner` harness (in main repo) ensures QC behaves like QE for now. Expect follow-up cleanup once QE removal completes. +- MongoDB currently runs only on legacy QE; QC MongoDB support is pending. Avoid regressing existing QE tests until QC parity is achieved. + +--- + +## 7. Useful Commands & Snippets +- Show diff for specific file: + `git diff path/to/file.rs` +- Re-run single Rust test: + `cargo test -p prisma-fmt validate::tests::validate_direct_url_direct_empty -- --nocapture` +- Search for legacy attributes: + `rg "directUrl"`, `rg "shadowDatabaseUrl"` +- Build schema-engine CLI: + `cargo build -p schema-engine-cli` +- Build query compiler WASM: + `make build-qc-wasm` +- Build legacy query engine binary: + `cargo build -p query-engine` +- Query compiler playground (generate plan + graph): + `cargo run -p query-compiler-playground` + +Prefer using Makefile targets that take care of setting up the environment correctly or running prerequisite commands. + +--- + +## 8. Open Themes / Future Tasks +- Removing `url` from PSL will be a follow-up; expect similar pattern (PSL error + override path). +- Query engine removal: remaining QE dependencies/tests need to migrate to QC or be deleted once QE is gone. +- Additional schema-engine tests may need migration to the new override helper. +- Documentation updates (internal + public) should mirror code changes; check when editing diagnostics to keep docs consistent. +- Query compiler MongoDB support: implement translation path + driver adapters, update tests once ready. +- Post-QE cleanup: strip QE-specific branches in shared crates (`query_core`, `query_structure`), simplify driver adapter plumbing. + +--- + +## 9. External References +- Prisma Config (`prisma.config.ts`) implementation lives in the main Prisma repo (`@prisma/config` package). +- Linear roadmap items for Prisma 7 (Breaking Changes, New Features) hold context. +- Commit `34b5a69…` – canonical example for datasource override wiring. +- Query engine connector test guide: `query-engine/connector-test-kit-rs/README.md`. +- QC playground usage: `query-compiler/query-compiler-playground/`. +- QC harness in Prisma repo: `packages/cli/src/__tests__/queryCompiler/qc-test-runner.ts` (mirrors QE behavior). + +--- + +**When modifying anything involving diagnostics or fixtures:** run relevant tests, refresh expectations, and ensure Git diffs are readable (no accidental CRLF/encoding swaps). Keep this file updated whenever we discover new traps.*** diff --git a/Cargo.lock b/Cargo.lock index 25e92d6dc0af..28b15ae95b6e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -343,7 +343,6 @@ dependencies = [ "enumflags2", "indoc", "insta", - "prisma-metrics", "query-engine-tests", "query-tests-setup", "regex", @@ -1261,7 +1260,6 @@ dependencies = [ "napi-derive", "panic-utils", "pin-project", - "prisma-metrics", "quaint", "serde", "serde-wasm-bindgen", @@ -1300,12 +1298,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "endian-type" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" - [[package]] name = "enum-as-inner" version = "0.6.0" @@ -2258,9 +2250,12 @@ dependencies = [ [[package]] name = "indoc" -version = "2.0.6" +version = "2.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4c7245a08504955605670dbf141fceab975f15ca21570696aebe9d2e71576bd" +checksum = "79cf5c93f93228cf8efb3ba362535fb11199ac548a09ce117c9b1adc3030d706" +dependencies = [ + "rustversion", +] [[package]] name = "insta" @@ -2691,39 +2686,6 @@ dependencies = [ "portable-atomic", ] -[[package]] -name = "metrics-exporter-prometheus" -version = "0.15.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4f0c8427b39666bf970460908b213ec09b3b350f20c0c2eabcbba51704a08e6" -dependencies = [ - "base64 0.22.1", - "indexmap 2.10.0", - "metrics", - "metrics-util", - "quanta", - "thiserror 1.0.69", -] - -[[package]] -name = "metrics-util" -version = "0.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4259040465c955f9f2f1a4a8a16dc46726169bca0f88e8fb2dbeced487c3e828" -dependencies = [ - "aho-corasick", - "crossbeam-epoch", - "crossbeam-utils", - "hashbrown 0.14.5", - "indexmap 2.10.0", - "metrics", - "num_cpus", - "ordered-float", - "quanta", - "radix_trie", - "sketches-ddsketch", -] - [[package]] name = "mime" version = "0.3.17" @@ -2904,7 +2866,6 @@ dependencies = [ "mongodb", "mongodb-client", "pretty_assertions", - "prisma-metrics", "prisma-value", "psl", "query-connector", @@ -3126,15 +3087,6 @@ dependencies = [ "tempfile", ] -[[package]] -name = "nibble_vec" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77a5d83df9f36fe23f0c3648c6bbb8b0298bb5f1939c8f2704431371f4b84d43" -dependencies = [ - "smallvec", -] - [[package]] name = "nom" version = "7.1.3" @@ -3335,15 +3287,6 @@ dependencies = [ "url", ] -[[package]] -name = "ordered-float" -version = "4.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d501f1a72f71d3c063a6bbc8f7271fa73aa09fe5d6283b6571e2ed176a2537" -dependencies = [ - "num-traits", -] - [[package]] name = "os_str_bytes" version = "6.5.1" @@ -3713,26 +3656,6 @@ dependencies = [ "structopt", ] -[[package]] -name = "prisma-metrics" -version = "0.1.0" -dependencies = [ - "derive_more", - "expect-test", - "futures", - "metrics", - "metrics-exporter-prometheus", - "metrics-util", - "parking_lot", - "pin-project", - "serde", - "serde_json", - "tokio", - "tracing", - "tracing-futures", - "tracing-subscriber", -] - [[package]] name = "prisma-schema-build" version = "0.1.0" @@ -3908,7 +3831,6 @@ dependencies = [ "pin-project", "postgres-native-tls", "postgres-types", - "prisma-metrics", "quaint-test-macros", "quaint-test-setup", "query-template", @@ -3953,21 +3875,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "quanta" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e5167a477619228a0b284fac2674e3c388cba90631d7b7de620e6f1fcd08da5" -dependencies = [ - "crossbeam-utils", - "libc", - "once_cell", - "raw-cpuid", - "wasi 0.11.0+wasi-snapshot-preview1", - "web-sys", - "winapi", -] - [[package]] name = "query-builder" version = "0.1.0" @@ -4073,7 +3980,6 @@ dependencies = [ "itertools 0.13.0", "lru 0.7.8", "petgraph", - "prisma-metrics", "psl", "query-builder", "query-connector", @@ -4110,7 +4016,6 @@ dependencies = [ "indoc", "mongodb-query-connector", "panic-utils", - "prisma-metrics", "psl", "quaint", "query-connector", @@ -4172,7 +4077,6 @@ dependencies = [ "async-trait", "connection-string", "napi", - "prisma-metrics", "psl", "query-connector", "query-core", @@ -4202,7 +4106,6 @@ dependencies = [ "napi", "napi-build", "napi-derive", - "prisma-metrics", "psl", "quaint", "query-compiler", @@ -4239,7 +4142,6 @@ dependencies = [ "insta", "itertools 0.13.0", "paste", - "prisma-metrics", "prisma-value", "psl", "query-test-macros", @@ -4343,7 +4245,6 @@ dependencies = [ "nom", "panic-utils", "parse-hyperlinks", - "prisma-metrics", "psl", "qe-setup", "quaint", @@ -4393,16 +4294,6 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" -[[package]] -name = "radix_trie" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c069c179fcdc6a2fe24d8d18305cf085fdbd4f922c041943e203685d6a1c58fd" -dependencies = [ - "endian-type", - "nibble_vec", -] - [[package]] name = "rand" version = "0.3.23" @@ -4541,15 +4432,6 @@ dependencies = [ "rand_core 0.5.1", ] -[[package]] -name = "raw-cpuid" -version = "11.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ab240315c661615f2ee9f0f2cd32d5a7343a84d5ebcccb99d46e6637565e7b0" -dependencies = [ - "bitflags 2.9.1", -] - [[package]] name = "rayon" version = "1.7.0" @@ -5342,12 +5224,6 @@ version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" -[[package]] -name = "sketches-ddsketch" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85636c14b73d81f541e525f585c0a2109e6744e1565b5c1668e31c70c10ed65c" - [[package]] name = "slab" version = "0.4.8" diff --git a/Cargo.toml b/Cargo.toml index 307dd8c72f1a..43265d671290 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -87,9 +87,6 @@ log = "0.4" lru = "0.7" lru-cache = "0.1" lsp-types = "0.95" -metrics = "0.23.0" -metrics-util = "0.17.0" -metrics-exporter-prometheus = { version = "0.15.3", default-features = false } mobc = "0.8" mongodb = { version = "3", features = [ "zstd-compression", @@ -108,7 +105,6 @@ napi-derive = "2" native-tls = "0.2" nom = "7" num_cpus = "1" -parking_lot = "0.12" parse-hyperlinks = "0.23" paste = "1" percent-encoding = "2" @@ -194,7 +190,6 @@ prisma-fmt.path = "./prisma-fmt" build-utils.path = "./libs/build-utils" crosstarget-utils.path = "./libs/crosstarget-utils" panic-utils.path = "./libs/panic-utils" -prisma-metrics.path = "./libs/metrics" prisma-value.path = "./libs/prisma-value" telemetry.path = "./libs/telemetry" user-facing-errors.path = "./libs/user-facing-errors" diff --git a/Makefile b/Makefile index a7c7eca45f2d..5e4e1f3646f0 100644 --- a/Makefile +++ b/Makefile @@ -145,7 +145,7 @@ test-qe-st: test-qe-verbose-st: cargo test --package query-engine-tests -- --nocapture --test-threads 1 -# Black-box tests, exercising the query engine HTTP apis (metrics, tracing, etc) +# Black-box tests, exercising the query engine HTTP apis test-qe-black-box: build-qe cargo test --package black-box-tests -- --test-threads 1 @@ -261,12 +261,12 @@ start-pg-bench: setup-pg-bench: start-pg-bench build-qe-napi build-qe-wasm build-driver-adapters-kit-qe -dev-pg-cockroachdb-wasm: start-cockroach_23_1 build-qe-wasm build-driver-adapters-kit-qe +dev-pg-cockroachdb-wasm: start-cockroach_25_2 build-qe-wasm build-driver-adapters-kit-qe cp $(CONFIG_PATH)/pg-cockroachdb-wasm $(CONFIG_FILE) test-pg-cockroachdb-wasm: dev-pg-cockroachdb-wasm test-qe-st -dev-pg-cockroachdb-qc: start-cockroach_23_1 build-qc-wasm build-driver-adapters-kit-qc +dev-pg-cockroachdb-qc: start-cockroach_25_2 build-qc-wasm build-driver-adapters-kit-qc cp $(CONFIG_PATH)/pg-cockroachdb-qc $(CONFIG_FILE) dev-pg-cockroachdb-qc-join: @@ -335,32 +335,26 @@ start-postgres16: dev-postgres16: start-postgres16 cp $(CONFIG_PATH)/postgres16 $(CONFIG_FILE) -start-cockroach_23_1: - docker compose -f docker-compose.yml up --wait -d --remove-orphans cockroach_23_1 +start-cockroach_24_3: + docker compose -f docker-compose.yml up --wait -d --remove-orphans cockroach_24_3 -dev-cockroach_23_1: start-cockroach_23_1 - cp $(CONFIG_PATH)/cockroach_23_1 $(CONFIG_FILE) +dev-cockroach_24_3: start-cockroach_24_3 + cp $(CONFIG_PATH)/cockroach_24_3 $(CONFIG_FILE) -start-cockroach_22_2: - docker compose -f docker-compose.yml up --wait -d --remove-orphans cockroach_22_2 +start-cockroach_25_1: + docker compose -f docker-compose.yml up --wait -d --remove-orphans cockroach_25_1 -dev-cockroach_22_2: start-cockroach_22_2 - cp $(CONFIG_PATH)/cockroach_22_2 $(CONFIG_FILE) +dev-cockroach_25_1: start-cockroach_25_1 + cp $(CONFIG_PATH)/cockroach_25_1 $(CONFIG_FILE) -start-cockroach_22_1_0: - docker compose -f docker-compose.yml up --wait -d --remove-orphans cockroach_22_1_0 +start-cockroach_25_2: + docker compose -f docker-compose.yml up --wait -d --remove-orphans cockroach_25_2 -dev-cockroach_22_1_0: start-cockroach_22_1_0 - cp $(CONFIG_PATH)/cockroach_22_1 $(CONFIG_FILE) - -start-cockroach_21_2_0_patched: - docker compose -f docker-compose.yml up --wait -d --remove-orphans cockroach_21_2_0_patched - -dev-cockroach_21_2_0_patched: start-cockroach_21_2_0_patched - cp $(CONFIG_PATH)/cockroach_21_2_0_patched $(CONFIG_FILE) +dev-cockroach_25_2: start-cockroach_25_2 + cp $(CONFIG_PATH)/cockroach_25_2 $(CONFIG_FILE) dev-pgbouncer: - docker compose -f docker-compose.yml up --wait -d --remove-orphans pgbouncer postgres11 + docker compose -f docker-compose.yml up --wait -d --remove-orphans pgbouncer postgres13 start-mysql_5_7: docker compose -f docker-compose.yml up --wait -d --remove-orphans mysql-5-7 @@ -368,12 +362,6 @@ start-mysql_5_7: dev-mysql: start-mysql_5_7 cp $(CONFIG_PATH)/mysql57 $(CONFIG_FILE) -start-mysql_5_6: - docker compose -f docker-compose.yml up --wait -d --remove-orphans mysql-5-6 - -dev-mysql_5_6: start-mysql_5_6 - cp $(CONFIG_PATH)/mysql56 $(CONFIG_FILE) - start-mysql_8: docker compose -f docker-compose.yml up --wait -d --remove-orphans mysql-8-0 @@ -552,10 +540,10 @@ ensure-prisma-present: fi; qe: - cargo run --bin query-engine -- --engine-protocol json --enable-raw-queries --enable-metrics --enable-open-telemetry --enable-telemetry-in-response + cargo run --bin query-engine -- --engine-protocol json --enable-raw-queries --enable-open-telemetry --enable-telemetry-in-response qe-graphql: - cargo run --bin query-engine -- --engine-protocol graphql --enable-playground --enable-raw-queries --enable-metrics --enable-open-telemetry --enable-telemetry-in-response + cargo run --bin query-engine -- --engine-protocol graphql --enable-playground --enable-raw-queries --enable-open-telemetry --enable-telemetry-in-response qe-dmmf: cargo run --bin query-engine -- cli dmmf > dmmf.json @@ -563,9 +551,6 @@ qe-dmmf: qe-dev-mongo_4_4: start-mongodb_4_4 cp $(SCHEMA_EXAMPLES_PATH)/generic_mongo4.prisma $(DEV_SCHEMA_FILE) -show-metrics: - docker compose -f docker-compose.yml up --wait -d --remove-orphans grafana prometheus - ## OpenTelemetry otel: docker compose up --remove-orphans -d otel diff --git a/README.md b/README.md index 4d17304de69d..1aad3ffecc21 100644 --- a/README.md +++ b/README.md @@ -145,13 +145,6 @@ whatever command that starts with `./query-engine` with `cargo run --bin query-e You can also pass `--help` to find out more options to run the engine. -### Metrics - -Running `make show-metrics` will start Prometheus and Grafana with a default metrics dashboard. -Prometheus will scrape the `/metrics` endpoint to collect the engine's metrics - -Navigate to `http://localhost:3000` to view the Grafana dashboard. - ## Schema Engine The _Schema Engine_ does a couple of things: @@ -249,7 +242,11 @@ tests: - `make dev-mariadb11`: MariaDB 11 - `make dev-mysql`: MySQL 5.7 - `make dev-mysql8`: MySQL 8 -- `make dev-postgres`: PostgreSQL 10 +- `make dev-postgres12`: PostgreSQL 12 +- `make dev-postgres13`: PostgreSQL 13 +- `make dev-postgres14`: PostgreSQL 14 +- `make dev-postgres15`: PostgreSQL 15 +- `make dev-postgres16`: PostgreSQL 16 - `make dev-sqlite`: SQLite - `make dev-mongodb_5`: MongoDB 5 diff --git a/docker-compose.yml b/docker-compose.yml index c4574ccc61e0..db2c8b255941 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,39 +1,29 @@ version: '3' services: - cockroach_23_1: - image: prismagraphql/cockroachdb-custom:23.1@sha256:c5a97355d56a7692ed34d835dfd8e3663d642219ea90736658a24840ea26862d - restart: unless-stopped - command: | - start-single-node --insecure - ports: - - '26260:26257' - networks: - - databases - - cockroach_22_2: - image: prismagraphql/cockroachdb-custom:22.2 + cockroach_24_3: + image: cockroachdb/cockroach:v24.3.0 restart: unless-stopped command: start-single-node --insecure ports: - - '26259:26257' + - '26260:26257' networks: - databases - cockroach_22_1_0: - image: prismagraphql/cockroachdb-custom:22.1.0 + cockroach_25_1: + image: cockroachdb/cockroach:v25.1.0 restart: unless-stopped command: start-single-node --insecure ports: - - '26257:26257' + - '26261:26257' networks: - databases - cockroach_21_2_0_patched: - image: prismagraphql/cockroachdb-custom:21.2.0-patched + cockroach_25_2: + image: cockroachdb/cockroach:v25.2.0 restart: unless-stopped command: start-single-node --insecure ports: - - '26258:26257' + - '26262:26257' networks: - databases @@ -41,7 +31,8 @@ services: image: brainsam/pgbouncer:latest restart: unless-stopped environment: - DB_HOST: 'postgres11' + # Use the PostgreSQL 13 service as the upstream target for PgBouncer tests. + DB_HOST: 'postgres13' DB_PORT: '5432' DB_USER: 'postgres' DB_PASSWORD: 'prisma' @@ -207,26 +198,6 @@ services: - '5439:5432' networks: - databases - - mysql-5-6: - image: mysql:5.6.50 - command: mysqld --table_definition_cache=2000 - restart: unless-stopped - platform: linux/x86_64 - environment: - MYSQL_USER: root - MYSQL_ROOT_PASSWORD: prisma - MYSQL_DATABASE: prisma - ports: - - '3309:3306' - networks: - - databases - tmpfs: /var/lib/mysql - healthcheck: - test: ['CMD', 'mysqladmin', 'ping', '-h', 'localhost'] - timeout: 20s - retries: 10 - mysql-5-7: image: mysql:5.7.44 command: mysqld @@ -477,21 +448,5 @@ services: - 14269:14269 - 9411:9411 - prometheus: - image: prom/prometheus - restart: unless-stopped - volumes: - - ${PWD}/metrics/prometheus:/prometheus-data - command: --config.file=/prometheus-data/prometheus.yml - ports: - - 9090:9090 - grafana: - image: grafana/grafana - volumes: - - ${PWD}/metrics/grafana/datasources:/etc/grafana/provisioning/datasources/ - - ${PWD}/metrics/grafana/dashboards:/etc/grafana/provisioning/dashboards/ - ports: - - 3000:3000 - networks: databases: null diff --git a/libs/driver-adapters/Cargo.toml b/libs/driver-adapters/Cargo.toml index 3448588f7d1f..9c1d3c5faeca 100644 --- a/libs/driver-adapters/Cargo.toml +++ b/libs/driver-adapters/Cargo.toml @@ -16,7 +16,6 @@ workspace = true async-trait.workspace = true futures.workspace = true panic-utils.workspace = true -prisma-metrics.workspace = true serde.workspace = true serde_json.workspace = true telemetry.workspace = true diff --git a/libs/driver-adapters/executor/src/driver-adapters-manager/better-sqlite3.ts b/libs/driver-adapters/executor/src/driver-adapters-manager/better-sqlite3.ts index 820abe8c1aa1..4b20517387a1 100644 --- a/libs/driver-adapters/executor/src/driver-adapters-manager/better-sqlite3.ts +++ b/libs/driver-adapters/executor/src/driver-adapters-manager/better-sqlite3.ts @@ -1,4 +1,4 @@ -import { PrismaBetterSQLite3 } from '@prisma/adapter-better-sqlite3' +import { PrismaBetterSqlite3 } from '@prisma/adapter-better-sqlite3' import type { SqlDriverAdapter, SqlMigrationAwareDriverAdapterFactory, @@ -20,7 +20,7 @@ export class BetterSQLite3Manager implements DriverAdaptersManager { private env: EnvForAdapter, { url }: SetupDriverAdaptersInput, ) { - this.#factory = new PrismaBetterSQLite3({ + this.#factory = new PrismaBetterSqlite3({ url, }) } diff --git a/libs/driver-adapters/executor/src/driver-adapters-manager/libsql.ts b/libs/driver-adapters/executor/src/driver-adapters-manager/libsql.ts index 2ebbfe9d9837..fd24409eeed5 100644 --- a/libs/driver-adapters/executor/src/driver-adapters-manager/libsql.ts +++ b/libs/driver-adapters/executor/src/driver-adapters-manager/libsql.ts @@ -1,4 +1,4 @@ -import { PrismaLibSQL } from '@prisma/adapter-libsql' +import { PrismaLibSql } from '@prisma/adapter-libsql' import type { SqlDriverAdapter, SqlMigrationAwareDriverAdapterFactory, @@ -20,7 +20,7 @@ export class LibSQLManager implements DriverAdaptersManager { private env: EnvForAdapter, { url }: SetupDriverAdaptersInput, ) { - this.#factory = new PrismaLibSQL({ + this.#factory = new PrismaLibSql({ url, intMode: 'bigint', }) diff --git a/libs/driver-adapters/executor/src/engines/Library.ts b/libs/driver-adapters/executor/src/engines/Library.ts index 61bf57495b91..95100f58ff24 100644 --- a/libs/driver-adapters/executor/src/engines/Library.ts +++ b/libs/driver-adapters/executor/src/engines/Library.ts @@ -31,7 +31,6 @@ export type QueryEngineInstance = { traceHeaders: string, requestId: string, ): Promise - metrics(options: string): Promise } export interface QueryEngineConstructor { diff --git a/libs/driver-adapters/pnpm-workspace.yaml b/libs/driver-adapters/pnpm-workspace.yaml index a5e4d6ed64cf..8abd23361327 100644 --- a/libs/driver-adapters/pnpm-workspace.yaml +++ b/libs/driver-adapters/pnpm-workspace.yaml @@ -9,6 +9,7 @@ packages: - '../../../prisma/packages/adapter-mariadb' - '../../../prisma/packages/bundled-js-drivers' - '../../../prisma/packages/client-engine-runtime' + - '../../../prisma/packages/client-runtime-utils' - '../../../prisma/packages/debug' - '../../../prisma/packages/driver-adapter-utils' - './executor' diff --git a/libs/driver-adapters/src/proxy.rs b/libs/driver-adapters/src/proxy.rs index 0c0818dd7e02..d7a0daa97cfe 100644 --- a/libs/driver-adapters/src/proxy.rs +++ b/libs/driver-adapters/src/proxy.rs @@ -8,7 +8,6 @@ use crate::{ use crate::{conversion::MaybeDefined, queryable::JsQueryable}; use futures::Future; -use prisma_metrics::gauge; use quaint::connector::{AdapterName, AdapterProvider, IsolationLevel}; use std::sync::atomic::{AtomicBool, Ordering}; @@ -161,11 +160,6 @@ impl DriverProxy { .call_as_async(isolation.map(|lvl| lvl.to_string()).into()) .await?; - // Decrement for this gauge is done in JsTransaction::commit/JsTransaction::rollback - // Previously, it was done in JsTransaction::new, similar to the native Transaction. - // However, correct Dispatcher is lost there and increment does not register, so we moved - // it here instead. - gauge!("prisma_client_queries_active").increment(1.0); Ok(Box::new(tx)) } diff --git a/libs/driver-adapters/src/queryable.rs b/libs/driver-adapters/src/queryable.rs index e6af427bfd4c..be4cc6f4d074 100644 --- a/libs/driver-adapters/src/queryable.rs +++ b/libs/driver-adapters/src/queryable.rs @@ -8,7 +8,7 @@ use async_trait::async_trait; use futures::Future; use quaint::connector::{AdapterName, DescribedQuery, ExternalConnectionInfo, ExternalConnector}; use quaint::{ - connector::{IsolationLevel, Transaction, metrics}, + connector::{IsolationLevel, Transaction, trace}, prelude::{Query as QuaintQuery, Queryable as QuaintQueryable, ResultSet, TransactionCapable}, visitor::{self, Visitor}, }; @@ -97,7 +97,7 @@ impl QuaintQueryable for JsBaseQueryable { } async fn query_raw(&self, sql: &str, params: &[quaint::Value<'_>]) -> quaint::Result { - metrics::query("js.query_raw", self.db_system_name, sql, params, move || async move { + trace::query(self.db_system_name, sql, params, move || async move { self.do_query_raw(sql, params).await }) .await @@ -117,7 +117,7 @@ impl QuaintQueryable for JsBaseQueryable { } async fn execute_raw(&self, sql: &str, params: &[quaint::Value<'_>]) -> quaint::Result { - metrics::query("js.execute_raw", self.db_system_name, sql, params, move || async move { + trace::query(self.db_system_name, sql, params, move || async move { self.do_execute_raw(sql, params).await }) .await @@ -129,7 +129,7 @@ impl QuaintQueryable for JsBaseQueryable { async fn raw_cmd(&self, cmd: &str) -> quaint::Result<()> { let params = &[]; - metrics::query("js.raw_cmd", self.db_system_name, cmd, params, move || async move { + trace::query(self.db_system_name, cmd, params, move || async move { self.do_execute_raw(cmd, params).await?; Ok(()) }) diff --git a/libs/driver-adapters/src/transaction.rs b/libs/driver-adapters/src/transaction.rs index 61387ea910c1..60b88de1840c 100644 --- a/libs/driver-adapters/src/transaction.rs +++ b/libs/driver-adapters/src/transaction.rs @@ -1,5 +1,4 @@ use async_trait::async_trait; -use prisma_metrics::gauge; use quaint::{ Value, connector::{DescribedQuery, IsolationLevel, Transaction as QuaintTransaction}, @@ -29,23 +28,13 @@ impl JsTransaction { pub async fn raw_phantom_cmd(&self, cmd: &str) -> quaint::Result<()> { let params = &[]; - quaint::connector::metrics::query( - "js.raw_phantom_cmd", - self.inner.db_system_name, - cmd, - params, - move || async move { Ok(()) }, - ) - .await + quaint::connector::trace::query(self.inner.db_system_name, cmd, params, move || async move { Ok(()) }).await } } #[async_trait] impl QuaintTransaction for JsTransaction { async fn commit(&self) -> quaint::Result<()> { - // increment of this gauge is done in DriverProxy::startTransaction - gauge!("prisma_client_queries_active").decrement(1.0); - let commit_stmt = "COMMIT"; if self.options().use_phantom_query { @@ -59,9 +48,6 @@ impl QuaintTransaction for JsTransaction { } async fn rollback(&self) -> quaint::Result<()> { - // increment of this gauge is done in DriverProxy::startTransaction - gauge!("prisma_client_queries_active").decrement(1.0); - let rollback_stmt = "ROLLBACK"; if self.options().use_phantom_query { diff --git a/libs/metrics/Cargo.toml b/libs/metrics/Cargo.toml deleted file mode 100644 index 2674e70fe381..000000000000 --- a/libs/metrics/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "prisma-metrics" -version = "0.1.0" -edition.workspace = true - -[dependencies] -futures.workspace = true -derive_more.workspace = true -metrics.workspace = true -metrics-util.workspace = true -metrics-exporter-prometheus.workspace = true -serde.workspace = true -serde_json.workspace = true -tracing.workspace = true -tracing-futures.workspace = true -tracing-subscriber.workspace = true -parking_lot.workspace = true -pin-project.workspace = true - -[dev-dependencies] -expect-test.workspace = true -tokio = { workspace = true, features = ["rt-multi-thread"] } diff --git a/libs/metrics/src/common.rs b/libs/metrics/src/common.rs deleted file mode 100644 index 92c76ffba962..000000000000 --- a/libs/metrics/src/common.rs +++ /dev/null @@ -1,137 +0,0 @@ -use std::collections::HashMap; - -use metrics::{Key, Label}; -use serde::{Deserialize, Serialize}; - -#[derive(Serialize, Deserialize)] -pub(crate) struct KeyLabels { - name: String, - labels: HashMap, -} - -#[derive(Debug)] -pub(crate) enum MetricType { - Counter, - Gauge, - Histogram, // Histograms are cumulative - Description, -} - -#[derive(Debug)] -pub(crate) enum MetricAction { - Increment(u64), - Absolute(u64), - GaugeSet(f64), - GaugeInc(f64), - GaugeDec(f64), - HistRecord(f64), - Description(String), -} - -#[derive(Serialize, Clone)] -pub(crate) struct Histogram { - pub buckets: Vec<(f64, u64)>, - pub sum: f64, - pub count: u64, -} - -#[derive(Serialize, Clone)] -#[serde(untagged)] -pub(crate) enum MetricValue { - Counter(u64), - Gauge(f64), - Histogram(Histogram), -} - -#[derive(Serialize, Clone)] -pub(crate) struct Metric { - pub key: String, - pub labels: HashMap, - pub value: MetricValue, - pub description: String, -} - -impl Metric { - pub(crate) fn renamed( - key: Key, - descriptions: &HashMap, - value: MetricValue, - global_labels: &HashMap, - ) -> Self { - match crate::METRIC_RENAMES.get(key.name()) { - Some((new_key, new_description)) => Self::new( - Key::from_parts(new_key.to_string(), key.labels()), - new_description.to_string(), - value, - global_labels.clone(), - ), - None => { - let description = descriptions.get(key.name()).map(|s| s.to_string()).unwrap_or_default(); - Self::new(key, description, value, global_labels.clone()) - } - } - } - - fn new(key: Key, description: String, value: MetricValue, global_labels: HashMap) -> Self { - let (name, labels) = key.into_parts(); - - let mut labels_map: HashMap = labels - .into_iter() - .map(|label| (label.key().to_string(), label.value().to_string())) - .collect(); - - labels_map.extend(global_labels); - - Self { - key: name.as_str().to_string(), - value, - description, - labels: labels_map, - } - } -} - -// The idea of this snapshot is take from -// https://github.com/metrics-rs/metrics/blob/558a3f93a4bb3958379ae6227c613a222aa813b5/metrics-exporter-prometheus/src/common.rs#L79 -#[derive(Serialize)] -pub(crate) struct Snapshot { - pub counters: Vec, - pub gauges: Vec, - pub histograms: Vec, -} - -impl From for KeyLabels { - fn from(key: Key) -> Self { - let mut kl = KeyLabels { - name: key.name().to_string(), - labels: Default::default(), - }; - - kl.labels - .extend(key.labels().map(|l| (l.key().to_string(), l.value().to_string()))); - - kl - } -} - -impl From for Key { - fn from(kl: KeyLabels) -> Self { - let labels: Vec