mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Fix usage attribution for database read endpoints
Usage is attributed to a resource via the per-route `usage.resource`
label, which is rendered into a resourcePath and parsed back into
resourceType/resourceId by the stats worker. The parser only caps a
database path to the table/collection level when the rendered path
carries a `table`/`collection` segment; otherwise it falls back to the
database.
The TablesDB, DocumentsDB, VectorsDB and legacy Databases read endpoints
(Get/List of tables, collections, rows, documents, columns, indexes,
attributes) declared only `database/{databaseId}`, omitting the table or
collection they operate on even though the id is present in the route.
As a result these high-volume reads were bucketed under the parent
database instead of the actual table/collection, while the write
endpoints attributed correctly.
Add the missing `/table/{tableId}` and `/collection/{collectionId}`
segments to those reads, and fix two related label defects:
- VectorsDB index create referenced `{request.tableId}` where the route
param is `collectionId`.
- Legacy collection update used the plural `collections` segment, which
the parser does not recognise, so it fell back to the database.
Container-level operations (get/delete a database, list its tables or
collections) are left at database scope, which is correct.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W2kBd7MvABcRZEA9uXhduY
This commit is contained in:
24 files changed
+24
-24
No files matched your search
+1
-1
@@ -45,7 +45,7 @@ class Get extends Action
|
||||
->desc('Get attribute')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', 'collections.read')
|
||||
->label('usage.resource', 'database/{request.databaseId}')
|
||||
->label('usage.resource', 'database/{request.databaseId}/collection/{request.collectionId}')
|
||||
->label('resourceType', RESOURCE_TYPE_DATABASES)
|
||||
->label('sdk', new Method(
|
||||
namespace: $this->getSDKNamespace(),
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ class XList extends Action
|
||||
->desc('List attributes')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', 'collections.read')
|
||||
->label('usage.resource', 'database/{request.databaseId}')
|
||||
->label('usage.resource', 'database/{request.databaseId}/collection/{request.collectionId}')
|
||||
->label('resourceType', RESOURCE_TYPE_DATABASES)
|
||||
->label('sdk', new Method(
|
||||
namespace: $this->getSDKNamespace(),
|
||||
|
||||
@@ -34,7 +34,7 @@ class Get extends Action
|
||||
->desc('Get collection')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', 'collections.read')
|
||||
->label('usage.resource', 'database/{request.databaseId}')
|
||||
->label('usage.resource', 'database/{request.databaseId}/collection/{request.collectionId}')
|
||||
->label('resourceType', RESOURCE_TYPE_DATABASES)
|
||||
->label('sdk', new Method(
|
||||
namespace: 'databases',
|
||||
|
||||
@@ -35,7 +35,7 @@ class Get extends Action
|
||||
->desc('Get index')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', 'collections.read')
|
||||
->label('usage.resource', 'database/{request.databaseId}')
|
||||
->label('usage.resource', 'database/{request.databaseId}/collection/{request.collectionId}')
|
||||
->label('resourceType', RESOURCE_TYPE_DATABASES)
|
||||
->label('sdk', new Method(
|
||||
namespace: $this->getSDKNamespace(),
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ class XList extends Action
|
||||
->desc('List indexes')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', 'collections.read')
|
||||
->label('usage.resource', 'database/{request.databaseId}')
|
||||
->label('usage.resource', 'database/{request.databaseId}/collection/{request.collectionId}')
|
||||
->label('resourceType', RESOURCE_TYPE_DATABASES)
|
||||
->label('sdk', new Method(
|
||||
namespace: $this->getSDKNamespace(),
|
||||
|
||||
@@ -44,7 +44,7 @@ class Update extends Action
|
||||
->label('event', 'databases.[databaseId].collections.[collectionId].update')
|
||||
->label('audits.event', 'collection.update')
|
||||
->label('audits.resource', 'database/{request.databaseId}/collections/{request.collectionId}')
|
||||
->label('usage.resource', 'database/{request.databaseId}/collections/{request.collectionId}')
|
||||
->label('usage.resource', 'database/{request.databaseId}/collection/{request.collectionId}')
|
||||
->label('sdk', new Method(
|
||||
namespace: 'databases',
|
||||
group: $this->getSDKGroup(),
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ class Get extends DocumentGet
|
||||
->desc('Get document')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', 'documents.read')
|
||||
->label('usage.resource', 'database/{request.databaseId}')
|
||||
->label('usage.resource', 'database/{request.databaseId}/collection/{request.collectionId}')
|
||||
->label('resourceType', RESOURCE_TYPE_DATABASES)
|
||||
->label('sdk', new Method(
|
||||
namespace: 'documentsDB',
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ class XList extends DocumentXList
|
||||
->desc('List documents')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', 'documents.read')
|
||||
->label('usage.resource', 'database/{request.databaseId}')
|
||||
->label('usage.resource', 'database/{request.databaseId}/collection/{request.collectionId}')
|
||||
->label('resourceType', RESOURCE_TYPE_DATABASES)
|
||||
->label('sdk', new Method(
|
||||
namespace: 'documentsDB',
|
||||
|
||||
@@ -31,7 +31,7 @@ class Get extends CollectionGet
|
||||
->desc('Get collection')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', 'collections.read')
|
||||
->label('usage.resource', 'database/{request.databaseId}')
|
||||
->label('usage.resource', 'database/{request.databaseId}/collection/{request.collectionId}')
|
||||
->label('resourceType', RESOURCE_TYPE_DATABASES)
|
||||
->label('sdk', new Method(
|
||||
namespace: 'documentsDB',
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ class Get extends IndexGet
|
||||
->desc('Get index')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', 'collections.read')
|
||||
->label('usage.resource', 'database/{request.databaseId}')
|
||||
->label('usage.resource', 'database/{request.databaseId}/collection/{request.collectionId}')
|
||||
->label('resourceType', RESOURCE_TYPE_DATABASES)
|
||||
->label('sdk', new Method(
|
||||
namespace: 'documentsDB',
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ class XList extends IndexXList
|
||||
->desc('List indexes')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', 'collections.read')
|
||||
->label('usage.resource', 'database/{request.databaseId}')
|
||||
->label('usage.resource', 'database/{request.databaseId}/collection/{request.collectionId}')
|
||||
->label('resourceType', RESOURCE_TYPE_DATABASES)
|
||||
->label('sdk', new Method(
|
||||
namespace: 'documentsDB',
|
||||
|
||||
@@ -43,7 +43,7 @@ class Get extends AttributesGet
|
||||
->desc('Get column')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', ['tables.read', 'collections.read', 'columns.read', 'attributes.read'])
|
||||
->label('usage.resource', 'database/{request.databaseId}')
|
||||
->label('usage.resource', 'database/{request.databaseId}/table/{request.tableId}')
|
||||
->label('resourceType', RESOURCE_TYPE_DATABASES)
|
||||
->label('sdk', new Method(
|
||||
namespace: $this->getSDKNamespace(),
|
||||
|
||||
@@ -34,7 +34,7 @@ class XList extends AttributesXList
|
||||
->desc('List columns')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', ['tables.read', 'collections.read', 'columns.read', 'attributes.read'])
|
||||
->label('usage.resource', 'database/{request.databaseId}')
|
||||
->label('usage.resource', 'database/{request.databaseId}/table/{request.tableId}')
|
||||
->label('resourceType', RESOURCE_TYPE_DATABASES)
|
||||
->label('sdk', new Method(
|
||||
namespace: $this->getSDKNamespace(),
|
||||
|
||||
@@ -32,7 +32,7 @@ class Get extends CollectionGet
|
||||
->desc('Get table')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', ['tables.read', 'collections.read'])
|
||||
->label('usage.resource', 'database/{request.databaseId}')
|
||||
->label('usage.resource', 'database/{request.databaseId}/table/{request.tableId}')
|
||||
->label('resourceType', RESOURCE_TYPE_DATABASES)
|
||||
->label('sdk', new Method(
|
||||
namespace: $this->getSDKNamespace(),
|
||||
|
||||
@@ -33,7 +33,7 @@ class Get extends IndexGet
|
||||
->desc('Get index')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', ['tables.read', 'collections.read', 'indexes.read'])
|
||||
->label('usage.resource', 'database/{request.databaseId}')
|
||||
->label('usage.resource', 'database/{request.databaseId}/table/{request.tableId}')
|
||||
->label('resourceType', RESOURCE_TYPE_DATABASES)
|
||||
->label('sdk', new Method(
|
||||
namespace: $this->getSDKNamespace(),
|
||||
|
||||
@@ -34,7 +34,7 @@ class XList extends IndexXList
|
||||
->desc('List indexes')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', ['tables.read', 'collections.read', 'indexes.read'])
|
||||
->label('usage.resource', 'database/{request.databaseId}')
|
||||
->label('usage.resource', 'database/{request.databaseId}/table/{request.tableId}')
|
||||
->label('resourceType', RESOURCE_TYPE_DATABASES)
|
||||
->label('sdk', new Method(
|
||||
namespace: $this->getSDKNamespace(),
|
||||
|
||||
@@ -35,7 +35,7 @@ class Get extends DocumentGet
|
||||
->desc('Get row')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', ['rows.read', 'documents.read'])
|
||||
->label('usage.resource', 'database/{request.databaseId}')
|
||||
->label('usage.resource', 'database/{request.databaseId}/table/{request.tableId}')
|
||||
->label('resourceType', RESOURCE_TYPE_DATABASES)
|
||||
->label('sdk', new Method(
|
||||
namespace: $this->getSDKNamespace(),
|
||||
|
||||
@@ -37,7 +37,7 @@ class XList extends DocumentXList
|
||||
->desc('List rows')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', ['rows.read', 'documents.read'])
|
||||
->label('usage.resource', 'database/{request.databaseId}')
|
||||
->label('usage.resource', 'database/{request.databaseId}/table/{request.tableId}')
|
||||
->label('resourceType', RESOURCE_TYPE_DATABASES)
|
||||
->label('sdk', new Method(
|
||||
namespace: $this->getSDKNamespace(),
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ class Get extends DocumentGet
|
||||
->desc('Get document')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', 'documents.read')
|
||||
->label('usage.resource', 'database/{request.databaseId}')
|
||||
->label('usage.resource', 'database/{request.databaseId}/collection/{request.collectionId}')
|
||||
->label('resourceType', RESOURCE_TYPE_DATABASES)
|
||||
->label('sdk', new Method(
|
||||
namespace: 'vectorsDB',
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ class XList extends DocumentXList
|
||||
->desc('List documents')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', 'documents.read')
|
||||
->label('usage.resource', 'database/{request.databaseId}')
|
||||
->label('usage.resource', 'database/{request.databaseId}/collection/{request.collectionId}')
|
||||
->label('resourceType', RESOURCE_TYPE_DATABASES)
|
||||
->label('sdk', new Method(
|
||||
namespace: 'vectorsDB',
|
||||
|
||||
@@ -31,7 +31,7 @@ class Get extends CollectionGet
|
||||
->desc('Get collection')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', 'collections.read')
|
||||
->label('usage.resource', 'database/{request.databaseId}')
|
||||
->label('usage.resource', 'database/{request.databaseId}/collection/{request.collectionId}')
|
||||
->label('resourceType', RESOURCE_TYPE_DATABASES)
|
||||
->label('sdk', new Method(
|
||||
namespace: 'vectorsDB',
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ class Create extends IndexCreate
|
||||
->label('resourceType', RESOURCE_TYPE_DATABASES)
|
||||
->label('audits.event', 'index.create')
|
||||
->label('audits.resource', 'database/{request.databaseId}/collection/{request.tableId}')
|
||||
->label('usage.resource', 'database/{request.databaseId}/collection/{request.tableId}')
|
||||
->label('usage.resource', 'database/{request.databaseId}/collection/{request.collectionId}')
|
||||
->label('sdk', new Method(
|
||||
namespace: 'vectorsDB',
|
||||
group: $this->getSdkGroup(),
|
||||
|
||||
@@ -32,7 +32,7 @@ class Get extends IndexGet
|
||||
->desc('Get index')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', 'collections.read')
|
||||
->label('usage.resource', 'database/{request.databaseId}')
|
||||
->label('usage.resource', 'database/{request.databaseId}/collection/{request.collectionId}')
|
||||
->label('resourceType', RESOURCE_TYPE_DATABASES)
|
||||
->label('sdk', new Method(
|
||||
namespace: 'vectorsDB',
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ class XList extends IndexXList
|
||||
->desc('List indexes')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', 'collections.read')
|
||||
->label('usage.resource', 'database/{request.databaseId}')
|
||||
->label('usage.resource', 'database/{request.databaseId}/collection/{request.collectionId}')
|
||||
->label('resourceType', RESOURCE_TYPE_DATABASES)
|
||||
->label('sdk', new Method(
|
||||
namespace: 'vectorsDB',
|
||||
|
||||
Reference in new issue
Block a user