1
0
Fork 0
mirror of synced 2024-07-05 06:31:08 +12:00

Merge pull request #7319 from appwrite/update-console

chore: update console
This commit is contained in:
Christy Jacob 2023-12-22 10:30:18 +01:00 committed by GitHub
commit 0ae5712bb6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 80 additions and 77 deletions

2
.gitmodules vendored
View file

@ -1,4 +1,4 @@
[submodule "app/console"] [submodule "app/console"]
path = app/console path = app/console
url = https://github.com/appwrite/console url = https://github.com/appwrite/console
branch = 3.3.9 branch = 3.3.10

@ -1 +1 @@
Subproject commit c83f5e4ea0e98219333aa6027289058de0ff6827 Subproject commit 167d0e2d49d8a40e67ba7b774736c5a4447510bf

View file

@ -112,7 +112,9 @@ class CalcTierStats extends Action
Console::error('[Error] Line: ' . $th->getLine()); Console::error('[Error] Line: ' . $th->getLine());
} }
} }
$queries = [];
$queries = [];
if (!empty($after)) { if (!empty($after)) {
Console::info("Iterating remaining projects after project with ID {$after}"); Console::info("Iterating remaining projects after project with ID {$after}");
$project = $dbForConsole->getDocument('projects', $after); $project = $dbForConsole->getDocument('projects', $after);
@ -120,21 +122,22 @@ class CalcTierStats extends Action
} else { } else {
Console::info("Iterating all projects"); Console::info("Iterating all projects");
} }
$this->foreachDocument($dbForConsole, 'projects', $queries, function (Document $project) use ($getProjectDB, $dbForConsole, $csv) {
$projectId = $project->getId(); $this->foreachDocument($dbForConsole, 'projects', $queries, function (Document $project) use ($getProjectDB, $dbForConsole, $csv) {
console::log("Project " . $projectId); $projectId = $project->getId();
try { console::log("Project " . $projectId);
$dbForProject = call_user_func($getProjectDB, $project); try {
$data = $this->getData($project, $dbForConsole, $dbForProject); $dbForProject = call_user_func($getProjectDB, $project);
$csv->insertOne($data); $data = $this->getData($project, $dbForConsole, $dbForProject);
} catch (\Throwable $th) { $csv->insertOne($data);
Console::error("Unexpected error occured with Project ID {$projectId}"); } catch (\Throwable $th) {
Console::error('[Error] Type: ' . get_class($th)); Console::error("Unexpected error occured with Project ID {$projectId}");
Console::error('[Error] Message: ' . $th->getMessage()); Console::error('[Error] Type: ' . get_class($th));
Console::error('[Error] File: ' . $th->getFile()); Console::error('[Error] Message: ' . $th->getMessage());
Console::error('[Error] Line: ' . $th->getLine()); Console::error('[Error] File: ' . $th->getFile());
} Console::error('[Error] Line: ' . $th->getLine());
}); }
});
$this->sendMail($register); $this->sendMail($register);
} }
@ -206,10 +209,10 @@ class CalcTierStats extends Action
private function getData(Document $project, Database $dbForConsole, Database $dbForProject): array private function getData(Document $project, Database $dbForConsole, Database $dbForProject): array
{ {
$stats['Project ID'] = $project->getId(); $stats['Project ID'] = $project->getId();
$stats['Organization ID'] = $project->getAttribute('teamId', null); $stats['Organization ID'] = $project->getAttribute('teamId', null);
$teamInternalId = $project->getAttribute('teamInternalId', 0); $teamInternalId = $project->getAttribute('teamInternalId', 0);
if ($teamInternalId) { if ($teamInternalId) {
$membership = $dbForConsole->findOne('memberships', [ $membership = $dbForConsole->findOne('memberships', [
@ -229,8 +232,8 @@ class CalcTierStats extends Action
Console::error("Email was not found for this Organization ID :{$teamInternalId}"); Console::error("Email was not found for this Organization ID :{$teamInternalId}");
} }
/** Get Total Members */ /** Get Total Members */
$teamInternalId = $project->getAttribute('teamInternalId', null); $teamInternalId = $project->getAttribute('teamInternalId', null);
if ($teamInternalId) { if ($teamInternalId) {
$stats['Organization Members'] = $dbForConsole->count('memberships', [ $stats['Organization Members'] = $dbForConsole->count('memberships', [
Query::equal('$internalId', [(string)$teamInternalId]) Query::equal('$internalId', [(string)$teamInternalId])
@ -239,70 +242,70 @@ class CalcTierStats extends Action
$stats['Organization Members'] = 0; $stats['Organization Members'] = 0;
} }
/** Get Total internal Teams */ /** Get Total internal Teams */
try { try {
$stats['Teams'] = $dbForProject->count('teams', []); $stats['Teams'] = $dbForProject->count('teams', []);
} catch (\Throwable) { } catch (\Throwable) {
$stats['Teams'] = 0; $stats['Teams'] = 0;
} }
/** Get Total users */ /** Get Total users */
try { try {
$stats['Users'] = $dbForProject->count('users', []); $stats['Users'] = $dbForProject->count('users', []);
} catch (\Throwable) { } catch (\Throwable) {
$stats['Users'] = 0; $stats['Users'] = 0;
} }
/** Get Usage stats */ /** Get Usage stats */
$range = '30d'; $range = '30d';
$periods = [ $periods = [
'30d' => [ '30d' => [
'period' => '1d', 'period' => '1d',
'limit' => 30, 'limit' => 30,
] ]
]; ];
$tmp = []; $tmp = [];
$metrics = $this->usageStats; $metrics = $this->usageStats;
Authorization::skip(function () use ($dbForProject, $periods, $range, $metrics, &$tmp) { Authorization::skip(function () use ($dbForProject, $periods, $range, $metrics, &$tmp) {
foreach ($metrics as $metric => $name) { foreach ($metrics as $metric => $name) {
$limit = $periods[$range]['limit']; $limit = $periods[$range]['limit'];
$period = $periods[$range]['period']; $period = $periods[$range]['period'];
$requestDocs = $dbForProject->find('stats_v2', [ $requestDocs = $dbForProject->find('stats_v2', [
Query::equal('metric', [$metric]), Query::equal('metric', [$metric]),
Query::equal('period', [$period]), Query::equal('period', [$period]),
Query::limit($limit), Query::limit($limit),
Query::orderDesc('time'), Query::orderDesc('time'),
]); ]);
$tmp[$metric] = []; $tmp[$metric] = [];
foreach ($requestDocs as $requestDoc) { foreach ($requestDocs as $requestDoc) {
if (empty($requestDoc)) { if (empty($requestDoc)) {
continue; continue;
}
$tmp[$metric][] = [
'value' => $requestDoc->getAttribute('value'),
'date' => $requestDoc->getAttribute('time'),
];
} }
$tmp[$metric] = array_reverse($tmp[$metric]); $tmp[$metric][] = [
$tmp[$metric] = array_sum(array_column($tmp[$metric], 'value')); 'value' => $requestDoc->getAttribute('value'),
'date' => $requestDoc->getAttribute('time'),
];
} }
});
$tmp[$metric] = array_reverse($tmp[$metric]);
$tmp[$metric] = array_sum(array_column($tmp[$metric], 'value'));
}
});
foreach ($tmp as $key => $value) { foreach ($tmp as $key => $value) {
$stats[$metrics[$key]] = $value; $stats[$metrics[$key]] = $value;
} }
/** /**
* Workaround to combine network.inbound+network.outbound as network. * Workaround to combine network.inbound+network.outbound as network.
*/ */
$stats['Network'] = ($stats['Inbound'] ?? 0) + ($stats['Outbound'] ?? 0); $stats['Network'] = ($stats['Inbound'] ?? 0) + ($stats['Outbound'] ?? 0);
unset($stats['Inbound']); unset($stats['Inbound']);
unset($stats['Outbound']); unset($stats['Outbound']);
try { try {
/** Get Domains */ /** Get Domains */
@ -340,11 +343,11 @@ class CalcTierStats extends Action
$stats['Platforms'] = 0; $stats['Platforms'] = 0;
} }
/** Get Files & Buckets */ /** Get Files & Buckets */
$filesCount = 0; $filesCount = 0;
$filesSum = 0; $filesSum = 0;
$maxFileSize = 0; $maxFileSize = 0;
$counter = 0; $counter = 0;
try { try {
$buckets = $dbForProject->find('buckets', []); $buckets = $dbForProject->find('buckets', []);
foreach ($buckets as $bucket) { foreach ($buckets as $bucket) {
@ -362,10 +365,10 @@ class CalcTierStats extends Action
} catch (\Throwable $t) { } catch (\Throwable $t) {
Console::error("Error while counting buckets: {$project->getId()}"); Console::error("Error while counting buckets: {$project->getId()}");
} }
$stats['Buckets'] = $counter; $stats['Buckets'] = $counter;
$stats['Files'] = $filesCount; $stats['Files'] = $filesCount;
$stats['Storage (bytes)'] = $filesSum; $stats['Storage (bytes)'] = $filesSum;
$stats['Max File Size (bytes)'] = $maxFileSize; $stats['Max File Size (bytes)'] = $maxFileSize;
try { try {
@ -375,28 +378,28 @@ class CalcTierStats extends Action
$stats['Databases'] = 0; $stats['Databases'] = 0;
} }
/** Get Total Functions */ /** Get Total Functions */
try { try {
$stats['Functions'] = $dbForProject->count('functions', []); $stats['Functions'] = $dbForProject->count('functions', []);
} catch (\Throwable) { } catch (\Throwable) {
$stats['Functions'] = 0; $stats['Functions'] = 0;
} }
/** Get Total Deployments */ /** Get Total Deployments */
try { try {
$stats['Deployments'] = $dbForProject->count('deployments', []); $stats['Deployments'] = $dbForProject->count('deployments', []);
} catch (\Throwable) { } catch (\Throwable) {
$stats['Deployments'] = 0; $stats['Deployments'] = 0;
} }
/** Get Total Executions */ /** Get Total Executions */
try { try {
$stats['Executions'] = $dbForProject->count('executions', []); $stats['Executions'] = $dbForProject->count('executions', []);
} catch (\Throwable) { } catch (\Throwable) {
$stats['Executions'] = 0; $stats['Executions'] = 0;
} }
/** Get Total Migrations */ /** Get Total Migrations */
try { try {
$stats['Migrations'] = $dbForProject->count('migrations', []); $stats['Migrations'] = $dbForProject->count('migrations', []);
} catch (\Throwable) { } catch (\Throwable) {