Repository navigation
Fix database operation usage resource attribution - #13523
Merged
Merged
Conversation
Contributor
Greptile SummaryThis PR corrects database-operation usage attribution by recording each database’s public resource ID alongside its internal sequence.
Confidence Score: 5/5The PR appears safe to merge with no actionable new findings. No blocking correctness, security, or repository-rule issues remain in the current changeset. Important Files Changed
Reviews (3): Last reviewed commit: "Merge branch 'main' into fix/database-op..." | Re-trigger Greptile |
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
loks0n
approved these changes
Sep 8, 2026
2 of 4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix empty database-card operation statistics reported in the self-hosted 2.0.0 testing thread.
Database operation handlers set
resourceType=databaseand the internal database sequence, but leaveresourceIdempty. Request shutdown fills that empty field with the project ID. Project totals remain correct, while queries filtered by the actual database ID return no operations.addMetric()snapshots metadata for document/row CRUD, list, bulk operations, and increment/decrement.This fixes newly recorded events; it does not backfill historical usage.
Verification
Tested a disposable local self-hosted stack with PHP 8.5.10, PostgreSQL, Redis, ClickHouse, and the 2.0.0 console, running the changed source. Requests traversed the HTTP API → usage queue → stats worker → ClickHouse → usage API; no usage events were injected directly.
tests/e2e/Services/Usage/UsageCustomServerTest.phpgit diff --checkThe regression covers legacy documents and TablesDB rows, empty/nonempty lists, CRUD/upsert, increment/decrement, bulk create/update/upsert/delete, and a transaction spanning two databases. It checks each database's exact reads/writes, unchanged project totals, and zero matches for project/unknown IDs.
Commands inside the local appwrite container:
Local test topology used a dedicated
stats-usageworker following the supported separate-worker pattern; the combined worker excluded that queue. This avoided local combined-worker backlog. ClickHouse settings were restored to defaults before the final before/after runs. Existing instances and repository deployment configuration were not changed. This is focused regression verification, not a full release/service-matrix run; separate DocumentsDB/MongoDB and VectorsDB adapters were not exercised. Independent source/test review found no issues.Console screenshots
Actual browser captures from the local stack after generating different workloads through the API.
Database grid: both cards have their own nonzero usage
Usage Alpha: 230 reads / 20 writes. Usage Beta: 35 reads / 7 writes. Reads count returned rows, not just HTTP requests.
Usage → Databases: breakdown resolves the real database names
Project reads total 265, correctly split into 230 + 35 rather than attributed to the project ID.