Fix usage tests
This commit is contained in:
parent
78f65401e8
commit
60a4563908
|
@ -1109,7 +1109,7 @@ App::get('/v1/users/usage')
|
|||
];
|
||||
|
||||
$metrics = [
|
||||
'users.$all.requests.count',
|
||||
'users.$all.count.total',
|
||||
'users.$all.requests.create',
|
||||
'users.$all.requests.read',
|
||||
'users.$all.requests.update',
|
||||
|
@ -1161,7 +1161,7 @@ App::get('/v1/users/usage')
|
|||
|
||||
$usage = new Document([
|
||||
'range' => $range,
|
||||
'usersCount' => $stats['users.$all.requests.count'] ?? [],
|
||||
'usersCount' => $stats['users.$all.count.total'] ?? [],
|
||||
'usersCreate' => $stats['users.$all.requests.create'] ?? [],
|
||||
'usersRead' => $stats['users.$all.requests.read'] ?? [],
|
||||
'usersUpdate' => $stats['users.$all.requests.update'] ?? [],
|
||||
|
|
|
@ -298,7 +298,7 @@ class TimeSeries extends Calculator
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
private function createOrUpdateMetric(string $projectId, int $time, string $period, string $metric, int $value, int $type): void
|
||||
private function createOrUpdateMetric(string $projectId, string $time, string $period, string $metric, int $value, int $type): void
|
||||
{
|
||||
$id = \md5("{$time}_{$period}_{$metric}");
|
||||
$this->database->setNamespace('_console');
|
||||
|
@ -347,9 +347,9 @@ class TimeSeries extends Calculator
|
|||
{
|
||||
$start = DateTime::createFromFormat('U', \strtotime($period['startTime']))->format(DateTime::RFC3339);
|
||||
if (!empty($this->latestTime[$metric][$period['key']])) {
|
||||
$start = DateTime::createFromFormat('U', $this->latestTime[$metric][$period['key']])->format(DateTime::RFC3339);
|
||||
$start = $this->latestTime[$metric][$period['key']];
|
||||
}
|
||||
$end = DateTime::createFromFormat('U', \strtotime('now'))->format(DateTime::RFC3339);
|
||||
$end = (new DateTime())->format(DateTime::RFC3339);
|
||||
|
||||
$table = $options['table']; //Which influxdb table to query for this metric
|
||||
$groupBy = empty($options['groupBy']) ? '' : ', ' . implode(', ', array_map(fn($groupBy) => '"' . $groupBy . '" ', $options['groupBy'])); //Some sub level metrics may be grouped by other tags like collectionId, bucketId, etc
|
||||
|
@ -387,12 +387,11 @@ class TimeSeries extends Calculator
|
|||
}
|
||||
}
|
||||
|
||||
$time = DateTime::createFromFormat('U', \strtotime($point['time']))->format(DateTime::RFC3339);
|
||||
$value = (!empty($point['value'])) ? $point['value'] : 0;
|
||||
|
||||
$this->createOrUpdateMetric(
|
||||
$projectId,
|
||||
$time,
|
||||
$point['time'],
|
||||
$period['key'],
|
||||
$metricUpdated,
|
||||
$value,
|
||||
|
|
|
@ -8,6 +8,9 @@ use Tests\E2E\Scopes\Scope;
|
|||
use Tests\E2E\Scopes\SideServer;
|
||||
use CURLFile;
|
||||
use Tests\E2E\Services\Functions\FunctionsBase;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\Permission;
|
||||
use Utopia\Database\Role;
|
||||
|
||||
class UsageTest extends Scope
|
||||
{
|
||||
|
@ -291,9 +294,13 @@ class UsageTest extends Scope
|
|||
$res = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', $headers, [
|
||||
'collectionId' => 'unique()',
|
||||
'name' => $name,
|
||||
'permission' => 'collection',
|
||||
'read' => ['role:all'],
|
||||
'write' => ['role:all']
|
||||
'documentSecurity' => false,
|
||||
'permissions' => [
|
||||
Permission::read(Role::any()),
|
||||
Permission::create(Role::any()),
|
||||
Permission::update(Role::any()),
|
||||
Permission::delete(Role::any()),
|
||||
],
|
||||
]);
|
||||
$this->assertEquals($name, $res['body']['name']);
|
||||
$this->assertNotEmpty($res['body']['$id']);
|
||||
|
@ -472,7 +479,7 @@ class UsageTest extends Scope
|
|||
|
||||
$this->assertEquals(202, $deployment['headers']['status-code']);
|
||||
$this->assertNotEmpty($deployment['body']['$id']);
|
||||
$this->assertIsInt($deployment['body']['$createdAt']);
|
||||
$this->assertEquals(true, DateTime::isValid($deployment['body']['$createdAt']));
|
||||
$this->assertEquals('index.php', $deployment['body']['entrypoint']);
|
||||
|
||||
// Wait for deployment to build.
|
||||
|
@ -482,8 +489,8 @@ class UsageTest extends Scope
|
|||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertNotEmpty($response['body']['$id']);
|
||||
$this->assertIsInt($response['body']['$createdAt']);
|
||||
$this->assertIsInt($response['body']['$updatedAt']);
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['$createdAt']));
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['$updatedAt']));
|
||||
$this->assertEquals($deploymentId, $response['body']['deployment']);
|
||||
|
||||
$execution = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/executions', $headers, [
|
||||
|
|
Loading…
Reference in a new issue