Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds projects support #150

Merged
merged 21 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Code refactoring:
1. Adds events mapper for broadcasting
2. SMTP service refactoring.
3. Improved tests. Use sqlite for tests instead of in-memory.
  • Loading branch information
butschster committed Apr 28, 2024
commit 616d87a73f3d75df88e504abf681748cb6c26561
1 change: 1 addition & 0 deletions app/config/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'projects' => ['storage' => $defaultStorage, 'prefix' => 'projects:'],
'webhooks' => ['storage' => $defaultStorage, 'prefix' => 'webhooks:'],
'local' => ['storage' => $defaultStorage, 'prefix' => 'local:'],
'smtp' => ['storage' => $defaultStorage, 'prefix' => 'smtp:'],
],
'storages' => [
'array' => [
Expand Down
19 changes: 0 additions & 19 deletions app/config/cycle.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,6 @@
'factories' => ['doctrine' => new DoctrineCollectionFactory()],
],
'generators' => null,
// 'generators' => [
// \Cycle\Annotated\Embeddings::class,
// \Cycle\Annotated\Entities::class,
// \Cycle\Annotated\MergeColumns::class,
// \Cycle\Schema\Generator\ResetTables::class,
// \Cycle\Schema\Generator\GenerateRelations::class,
// \Cycle\Schema\Generator\ValidateEntities::class,
// \Cycle\Schema\Generator\RenderTables::class,
// \Cycle\Schema\Generator\RenderRelations::class,
// \Cycle\Annotated\TableInheritance::class,
// \Cycle\Annotated\MergeIndexes::class
// \Cycle\Schema\Generator\GenerateTypecast::class,
// ],
],
'warmup' => env('CYCLE_SCHEMA_WARMUP', false),
'customRelations' => [
// \Cycle\ORM\Relation::EMBEDDED => [
// \Cycle\ORM\Config\RelationConfig::LOADER => \Cycle\ORM\Select\Loader\EmbeddedLoader::class,
// \Cycle\ORM\Config\RelationConfig::RELATION => \Cycle\ORM\Relation\Embedded::class,
// ]
],
];
9 changes: 9 additions & 0 deletions app/config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,14 @@
'logQueryParameters' => env('DB_LOG_QUERY_PARAMETERS', false),
],
),

// Only for testing purposes
// SQLite does not support multiple connections in the same time
'sqlite' => new Config\SQLiteDriverConfig(
connection: new Config\SQLite\MemoryConnectionConfig(),
options: [
'logQueryParameters' => env('DB_LOG_QUERY_PARAMETERS', false),
],
),
],
];
73 changes: 73 additions & 0 deletions app/database/Factory/EventFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

declare(strict_types=1);

namespace Database\Factory;

use App\Application\Domain\Entity\Json;
use App\Application\Domain\ValueObjects\Uuid;
use Database\Factory\Partials\InspectorType;
use Database\Factory\Partials\MonologType;
use Database\Factory\Partials\ProfilerType;
use Database\Factory\Partials\RayType;
use Database\Factory\Partials\SentryType;
use Database\Factory\Partials\SmtpType;
use Database\Factory\Partials\VarDumperType;
use Modules\Events\Domain\Event;
use Modules\Projects\Domain\ValueObject\Key;
use Spiral\DatabaseSeeder\Factory\AbstractFactory;

/**
* @implements AbstractFactory<Event>
*/
final class EventFactory extends AbstractFactory
{
use SmtpType,
ProfilerType,
SentryType,
MonologType,
InspectorType,
VarDumperType,
RayType;

public function entity(): string
{
return Event::class;
}

public function definition(): array
{
$type = $this->faker->randomElement(['sentry', 'monolog', 'var-dump', 'inspector', 'ray', 'profiler']);

$payload = match ($type) {
'sentry' => self::getSentryPayload(),
'monolog' => self::getMonologPayload(),
'var-dump' => self::getVarDumperPayload(),
'inspector' => self::getInspectorPayload(),
'ray' => self::getRayPayload(),
'profiler' => self::getProfilerPayload(),
'smtp' => self::getSmtpPayload(),
default => ['foo' => 'bar'],
};

return [
'uuid' => Uuid::generate(),
'type' => $this->faker->randomElement(['sentry', 'monolog', 'var-dump', 'inspector', 'ray', 'profiler']),
'payload' => new Json($payload),
'timestamp' => \microtime(true),
'project' => null,
];
}


public function makeEntity(array $definition): object
{
return new Event(
uuid: $definition['uuid'],
type: $definition['type'],
payload: $definition['payload'],
timestamp: $definition['timestamp'],
project: $definition['project'] ? Key::create($definition['project']) : null,
);
}
}
48 changes: 48 additions & 0 deletions app/database/Factory/Partials/InspectorType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace Database\Factory\Partials;

trait InspectorType
{
protected static function getInspectorPayload(): array
{
return [
[
'model' => 'transaction',
'name' => '/foo',
'type' => 'process',
'hash' => '979ffbcecfcd3a72c1c4d536aa1fe85b3e996df1d7093755b9b4a1ded8e33b5c',
'host' =>
[
'hostname' => 'ButschsterLpp',
'ip' => '127.0.1.1',
'os' => 'Linux',
],
'timestamp' => 1701464039.650622,
'memory_peak' => 15.53,
'duration' => 0.22,
],
[
'model' => 'segment',
'type' => 'my-process',
'host' =>
[
'hostname' => 'ButschsterLpp',
'ip' => '127.0.1.1',
'os' => 'Linux',
],
'transaction' =>
[
'name' => '/foo',
'hash' => '979ffbcecfcd3a72c1c4d536aa1fe85b3e996df1d7093755b9b4a1ded8e33b5c',
'timestamp' => 1701464039.650622,
],
'start' => 0.2,
'timestamp' => 1701464039.650826,
'duration' => 0.01,
],
];
}
}
23 changes: 23 additions & 0 deletions app/database/Factory/Partials/MonologType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace Database\Factory\Partials;

trait MonologType
{
protected static function getMonologPayload(): array
{
return [
'message' => 'Some message',
'context' => [
'project' => 'default',
],
'level' => 400,
'level_name' => 'ERROR',
'channel' => 'socket',
'datetime' => '2024-04-28T06:53:07.674031+00:00',
'extra' => [],
];
}
}
Loading
Loading