updated stats for vectordb

This commit is contained in:
ArnabChatterjee20k committed 2025-12-08 20:27:30 +05:30
1 parent b15f2eed8f
commit f149ba33d4
21 files changed
+400 -69

No files matched your search

@@ -26,7 +26,7 @@ class Action extends AppwriteAction
$this->context = DATABASE_TYPE_DOCUMENTSDB;
}
if (\str_contains($path, '/vectordb')) {
$this->context = 'vectordb';
$this->context = DATABASE_TYPE_VECTORDB;
}
return parent::setHttpPath($path);
}
@@ -28,6 +28,8 @@ abstract class Action extends DatabasesAction
$this->context = ROWS;
} elseif (str_contains($path, '/documentsdb/')) {
$this->databaseType = DATABASE_TYPE_DOCUMENTSDB;
} elseif (str_contains($path, '/vectordb/')) {
$this->databaseType = DATABASE_TYPE_VECTORDB;
}
$contextId = '$' . $this->getCollectionsEventsContext() . 'Id';
@@ -32,6 +32,7 @@ class Get extends Action
{
$this->databaseType = match (true) {
str_contains($path, '/documentsdb') => DATABASE_TYPE_DOCUMENTSDB,
str_contains($path, '/vectordb') => DATABASE_TYPE_VECTORDB,
default => DATABASE_TYPE_LEGACY,
};
@@ -30,6 +30,7 @@ class XList extends Action
{
$this->databaseType = match (true) {
str_contains($path, '/documentsdb') => DATABASE_TYPE_DOCUMENTSDB,
str_contains($path, '/vectordb') => DATABASE_TYPE_VECTORDB,
default => DATABASE_TYPE_LEGACY,
};
@@ -24,6 +24,11 @@ class Get extends CollectionUsageGet
return UtopiaResponse::MODEL_USAGE_COLLECTION;
}
protected function getMetric(): string
{
return METRIC_DATABASE_ID_COLLECTION_ID_DOCUMENTS_VECTORDB;
}
public function __construct()
{
$this
@@ -141,39 +141,16 @@ class Create extends CreateDocumentAction
->dynamic($embeddings, $this->getBulkResponseModel());
$queueForStatsUsage
->addMetric(
\str_replace(
'{embeddingModel}',
$model,
METRIC_EMBEDDINGS_TEXT
),
\count($texts)
)
->addMetric(
\str_replace(
'{embeddingModel}',
$model,
METRIC_EMBEDDINGS_TEXT_TOTAL_TOKENS
),
$totalTokens
)
->addMetric(
\str_replace(
'{embeddingModel}',
$model,
METRIC_EMBEDDINGS_TEXT_TOTAL_DURATION
),
$totalDuration
)
->addMetric(
\str_replace(
'{embeddingModel}',
$model,
METRIC_EMBEDDINGS_TEXT_TOTAL_ERROR
),
$totalErrors
)
->addMetric(METRIC_EMBEDDINGS_TEXT, \count($texts))
->addMetric(\str_replace('{embeddingModel}', $model, METRIC_EMBEDDINGS_MODEL_TEXT), \count($texts))
->addMetric(METRIC_EMBEDDINGS_TEXT_TOTAL_TOKENS, $totalTokens)
->addMetric(\str_replace('{embeddingModel}', $model, METRIC_EMBEDDINGS_MODEL_TEXT_TOTAL_TOKENS), $totalTokens)
->addMetric(METRIC_EMBEDDINGS_TEXT_TOTAL_DURATION, $totalDuration)
->addMetric(\str_replace('{embeddingModel}', $model, METRIC_EMBEDDINGS_MODEL_TEXT_TOTAL_DURATION), $totalDuration)
->addMetric(METRIC_EMBEDDINGS_TEXT_TOTAL_ERROR, $totalErrors)
->addMetric(\str_replace('{embeddingModel}', $model, METRIC_EMBEDDINGS_MODEL_TEXT_TOTAL_ERROR), $totalErrors)
->trigger();
$queueForStatsUsage->reset();
}
}
@@ -19,6 +19,11 @@ class Get extends DatabaseUsageGet
return 'getVectorDBUsage';
}
public function getResponseModel(): string
{
return UtopiaResponse::MODEL_USAGE_VECTORDB;
}
public function __construct()
{
$this
@@ -38,7 +43,7 @@ class Get extends DatabaseUsageGet
responses: [
new SDKResponse(
code: SwooleResponse::STATUS_CODE_OK,
model: UtopiaResponse::MODEL_USAGE_DATABASE,
model: UtopiaResponse::MODEL_USAGE_VECTORDB,
)
],
contentType: ContentType::JSON,
@@ -18,6 +18,11 @@ class XList extends DatabaseUsageXList
return 'listVectorDBUsage';
}
public function getResponseModel(): string
{
return UtopiaResponse::MODEL_USAGE_VECTORDBS;
}
public function __construct()
{
$this
@@ -37,7 +42,7 @@ class XList extends DatabaseUsageXList
responses: [
new SDKResponse(
code: SwooleResponse::STATUS_CODE_OK,
model: UtopiaResponse::MODEL_USAGE_DATABASES,
model: UtopiaResponse::MODEL_USAGE_VECTORDBS,
)
],
contentType: ContentType::JSON
@@ -288,6 +288,8 @@ class Migrations extends Action
METRIC_DATABASES_OPERATIONS_WRITES,
METRIC_DATABASES_OPERATIONS_READS_DOCUMENTSDB,
METRIC_DATABASES_OPERATIONS_WRITES_DOCUMENTSDB,
METRIC_DATABASES_OPERATIONS_READS_VECTORDB,
METRIC_DATABASES_OPERATIONS_WRITES_VECTORDB,
METRIC_NETWORK_REQUESTS,
METRIC_NETWORK_INBOUND,
METRIC_NETWORK_OUTBOUND,
@@ -125,6 +125,7 @@ class StatsResources extends Action
$databases = $dbForProject->count('databases', [Query::equal('type', [DATABASE_TYPE_LEGACY, DATABASE_TYPE_TABLESDB])]);
$documentsdb = $dbForProject->count('databases', [Query::equal('type', [DATABASE_TYPE_DOCUMENTSDB])]);
$vectordb = $dbForProject->count('databases', [Query::equal('type', [DATABASE_TYPE_VECTORDB])]);
$buckets = $dbForProject->count('buckets');
$users = $dbForProject->count('users');
@@ -160,6 +161,7 @@ class StatsResources extends Action
$metrics = [
METRIC_DATABASES => $databases,
METRIC_DATABASES_DOCUMENTSDB => $documentsdb,
METRIC_DATABASES_VECTORDB => $vectordb,
METRIC_BUCKETS => $buckets,
METRIC_USERS => $users,
METRIC_FUNCTIONS => $functions,
@@ -268,8 +270,13 @@ class StatsResources extends Action
$totalDocumentsDocumentsdb = 0;
$totalDatabaseStorageDocumentsdb = 0;
// vectordb
$totalCollectionsVectordb = 0;
$totalDocumentsVectordb = 0;
$totalDatabaseStorageVectordb = 0;
$this->foreachDocument($dbForProject, 'databases', [], function ($database) use ($dbForProject, $getDatabasesDB, $region, &$totalCollections, &$totalDocuments, &$totalDatabaseStorage, &$totalCollectionsDocumentsdb, &$totalDocumentsDocumentsdb, &$totalDatabaseStorageDocumentsdb) {
$this->foreachDocument($dbForProject, 'databases', [], function ($database) use ($dbForProject, $getDatabasesDB, $region, &$totalCollections, &$totalDocuments, &$totalDatabaseStorage, &$totalCollectionsDocumentsdb, &$totalDocumentsDocumentsdb, &$totalDatabaseStorageDocumentsdb, &$totalCollectionsVectordb, &$totalDocumentsVectordb, &$totalDatabaseStorageVectordb) {
$dbForDatabases = $getDatabasesDB($database);
$collections = $dbForProject->count('database_' . $database->getSequence());
@@ -289,6 +296,11 @@ class StatsResources extends Action
$totalDocumentsDocumentsdb += $documents;
$totalCollectionsDocumentsdb += $collections;
break;
case DATABASE_TYPE_VECTORDB:
$totalDatabaseStorageVectordb += $storage;
$totalDocumentsVectordb += $documents;
$totalCollectionsVectordb += $collections;
break;
default:
$totalDatabaseStorage += $storage;
$totalDocuments += $documents;
@@ -303,6 +315,10 @@ class StatsResources extends Action
$this->createStatsDocuments($region, METRIC_COLLECTIONS_DOCUMENTSDB, $totalCollectionsDocumentsdb);
$this->createStatsDocuments($region, METRIC_DOCUMENTS_DOCUMENTSDB, $totalDocumentsDocumentsdb);
$this->createStatsDocuments($region, METRIC_DATABASES_STORAGE_DOCUMENTSDB, $totalDatabaseStorageDocumentsdb);
$this->createStatsDocuments($region, METRIC_COLLECTIONS_VECTORDB, $totalCollectionsVectordb);
$this->createStatsDocuments($region, METRIC_DOCUMENTS_VECTORDB, $totalDocumentsVectordb);
$this->createStatsDocuments($region, METRIC_DATABASES_STORAGE_VECTORDB, $totalDatabaseStorageVectordb);
}
protected function countForCollections(Database $dbForProject, Database $dbForDatabases, Document $database, string $region): array
{
+6
View File
@@ -145,6 +145,8 @@ use Appwrite\Utopia\Response\Model\UsageSites;
use Appwrite\Utopia\Response\Model\UsageStorage;
use Appwrite\Utopia\Response\Model\UsageTable;
use Appwrite\Utopia\Response\Model\UsageUsers;
use Appwrite\Utopia\Response\Model\UsageVectorDB;
use Appwrite\Utopia\Response\Model\UsageVectorDBs;
use Appwrite\Utopia\Response\Model\User;
use Appwrite\Utopia\Response\Model\Variable;
use Appwrite\Utopia\Response\Model\VcsContent;
@@ -179,6 +181,8 @@ class Response extends SwooleResponse
public const MODEL_USAGE_DATABASE = 'usageDatabase';
public const MODEL_USAGE_DOCUMENTSDBS = 'usageDocumentsDBs';
public const MODEL_USAGE_DOCUMENTSDB = 'usageDocumentsDB';
public const MODEL_USAGE_VECTORDBS = 'usageVectorDBs';
public const MODEL_USAGE_VECTORDB = 'usageVectorDB';
public const MODEL_USAGE_TABLE = 'usageTable';
public const MODEL_USAGE_COLLECTION = 'usageCollection';
public const MODEL_USAGE_USERS = 'usageUsers';
@@ -618,6 +622,8 @@ class Response extends SwooleResponse
->setModel(new UsageDatabase())
->setModel(new UsageDocumentsDBs())
->setModel(new UsageDocumentsDB())
->setModel(new UsageVectorDBs())
->setModel(new UsageVectorDB())
->setModel(new UsageTable())
->setModel(new UsageCollection())
->setModel(new UsageUsers())
@@ -267,33 +267,108 @@ class UsageProject extends Model
'default' => 0,
'example' => 0,
])
->addRule('embeddingsText', [
// VectorDB aggregates
->addRule('vectordbDatabasesTotal', [
'type' => self::TYPE_INTEGER,
'description' => 'Total aggregated number of VectorDB databases.',
'default' => 0,
'example' => 0,
])
->addRule('vectordbCollectionsTotal', [
'type' => self::TYPE_INTEGER,
'description' => 'Total aggregated number of VectorDB collections.',
'default' => 0,
'example' => 0,
])
->addRule('vectordbDocumentsTotal', [
'type' => self::TYPE_INTEGER,
'description' => 'Total aggregated number of VectorDB documents.',
'default' => 0,
'example' => 0,
])
->addRule('vectordbDatabasesStorageTotal', [
'type' => self::TYPE_INTEGER,
'description' => 'Total aggregated VectorDB storage (bytes).',
'default' => 0,
'example' => 0,
])
->addRule('vectordbDatabasesReadsTotal', [
'type' => self::TYPE_INTEGER,
'description' => 'Total aggregated number of VectorDB reads.',
'default' => 0,
'example' => 0,
])
->addRule('vectordbDatabasesWritesTotal', [
'type' => self::TYPE_INTEGER,
'description' => 'Total aggregated number of VectorDB writes.',
'default' => 0,
'example' => 0,
])
->addRule('vectordbDatabases', [
'type' => Response::MODEL_METRIC,
'description' => 'Aggregated number of text embedding calls per period.',
'description' => 'Aggregated VectorDB databases per period.',
'default' => [],
'example' => [],
'array' => true
])
->addRule('vectordbCollections', [
'type' => Response::MODEL_METRIC,
'description' => 'Aggregated VectorDB collections per period.',
'default' => [],
'example' => [],
'array' => true
])
->addRule('vectordbDocuments', [
'type' => Response::MODEL_METRIC,
'description' => 'Aggregated VectorDB documents per period.',
'default' => [],
'example' => [],
'array' => true
])
->addRule('vectordbDatabasesStorage', [
'type' => Response::MODEL_METRIC,
'description' => 'Aggregated VectorDB storage per period.',
'default' => [],
'example' => [],
'array' => true
])
->addRule('vectordbDatabasesReads', [
'type' => Response::MODEL_METRIC,
'description' => 'Aggregated VectorDB reads per period.',
'default' => [],
'example' => [],
'array' => true
])
->addRule('vectordbDatabasesWrites', [
'type' => Response::MODEL_METRIC,
'description' => 'Aggregated VectorDB writes per period.',
'default' => [],
'example' => [],
'array' => true
])
->addRule('embeddingsText', [
'type' => Response::MODEL_METRIC,
'description' => 'Aggregated number of text embedding calls per period.',
'default' => 0,
'example' => 0
])
->addRule('embeddingsTextTokens', [
'type' => Response::MODEL_METRIC,
'description' => 'Aggregated number of tokens processed by text embeddings per period.',
'default' => [],
'example' => [],
'array' => true
'default' => 0,
'example' => 0
])
->addRule('embeddingsTextDuration', [
'type' => Response::MODEL_METRIC,
'description' => 'Aggregated duration spent generating text embeddings per period.',
'default' => [],
'example' => [],
'array' => true
'default' => 0,
'example' => 0
])
->addRule('embeddingsTextErrors', [
'type' => Response::MODEL_METRIC,
'description' => 'Aggregated number of errors while generating text embeddings per period.',
'default' => [],
'example' => [],
'array' => true
'default' => 0,
'example' => 0
])
;
}
@@ -0,0 +1,96 @@
<?php
namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model;
class UsageVectorDB extends Model
{
public function __construct()
{
$this
->addRule('range', [
'type' => self::TYPE_STRING,
'description' => 'Time range of the usage stats.',
'default' => '',
'example' => '30d',
])
->addRule('collectionsTotal', [
'type' => self::TYPE_INTEGER,
'description' => 'Total aggregated number of collections.',
'default' => 0,
'example' => 0,
])
->addRule('documentsTotal', [
'type' => self::TYPE_INTEGER,
'description' => 'Total aggregated number of documents.',
'default' => 0,
'example' => 0,
])
->addRule('storageTotal', [
'type' => self::TYPE_INTEGER,
'description' => 'Total aggregated storage used in bytes.',
'default' => 0,
'example' => 0,
])
->addRule('databaseReadsTotal', [
'type' => self::TYPE_INTEGER,
'description' => 'Total number of database reads.',
'default' => 0,
'example' => 0,
])
->addRule('databaseWritesTotal', [
'type' => self::TYPE_INTEGER,
'description' => 'Total number of database writes.',
'default' => 0,
'example' => 0,
])
->addRule('collections', [
'type' => Response::MODEL_METRIC,
'description' => 'Aggregated number of collections per period.',
'default' => [],
'example' => [],
'array' => true
])
->addRule('documents', [
'type' => Response::MODEL_METRIC,
'description' => 'Aggregated number of documents per period.',
'default' => [],
'example' => [],
'array' => true
])
->addRule('storage', [
'type' => Response::MODEL_METRIC,
'description' => 'Aggregated storage used in bytes per period.',
'default' => [],
'example' => [],
'array' => true
])
->addRule('databaseReads', [
'type' => Response::MODEL_METRIC,
'description' => 'An array of aggregated number of database reads.',
'default' => [],
'example' => [],
'array' => true
])
->addRule('databaseWrites', [
'type' => Response::MODEL_METRIC,
'description' => 'An array of aggregated number of database writes.',
'default' => [],
'example' => [],
'array' => true
])
;
}
public function getName(): string
{
return 'UsageVectorDB';
}
public function getType(): string
{
return Response::MODEL_USAGE_VECTORDB;
}
}
@@ -0,0 +1,109 @@
<?php
namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model;
class UsageVectorDBs extends Model
{
public function __construct()
{
$this
->addRule('range', [
'type' => self::TYPE_STRING,
'description' => 'Time range of the usage stats.',
'default' => '',
'example' => '30d',
])
->addRule('databasesTotal', [
'type' => self::TYPE_INTEGER,
'description' => 'Total aggregated number of VectorDB databases.',
'default' => 0,
'example' => 0,
])
->addRule('collectionsTotal', [
'type' => self::TYPE_INTEGER,
'description' => 'Total aggregated number of collections.',
'default' => 0,
'example' => 0,
])
->addRule('documentsTotal', [
'type' => self::TYPE_INTEGER,
'description' => 'Total aggregated number of documents.',
'default' => 0,
'example' => 0,
])
->addRule('storageTotal', [
'type' => self::TYPE_INTEGER,
'description' => 'Total aggregated storage in bytes.',
'default' => 0,
'example' => 0,
])
->addRule('databasesReadsTotal', [
'type' => self::TYPE_INTEGER,
'description' => 'Total number of database reads.',
'default' => 0,
'example' => 0,
])
->addRule('databasesWritesTotal', [
'type' => self::TYPE_INTEGER,
'description' => 'Total number of database writes.',
'default' => 0,
'example' => 0,
])
->addRule('databases', [
'type' => Response::MODEL_METRIC,
'description' => 'Aggregated number of databases per period.',
'default' => [],
'example' => [],
'array' => true
])
->addRule('collections', [
'type' => Response::MODEL_METRIC,
'description' => 'Aggregated number of collections per period.',
'default' => [],
'example' => [],
'array' => true
])
->addRule('documents', [
'type' => Response::MODEL_METRIC,
'description' => 'Aggregated number of documents per period.',
'default' => [],
'example' => [],
'array' => true
])
->addRule('storage', [
'type' => Response::MODEL_METRIC,
'description' => 'Aggregated storage in bytes per period.',
'default' => [],
'example' => [],
'array' => true
])
->addRule('databasesReads', [
'type' => Response::MODEL_METRIC,
'description' => 'An array of aggregated number of database reads.',
'default' => [],
'example' => [],
'array' => true
])
->addRule('databasesWrites', [
'type' => Response::MODEL_METRIC,
'description' => 'An array of aggregated number of database writes.',
'default' => [],
'example' => [],
'array' => true
])
;
}
public function getName(): string
{
return 'UsageVectorDBs';
}
public function getType(): string
{
return Response::MODEL_USAGE_VECTORDBS;
}
}