Skip to content

Commit

Permalink
Code refactoring (#9)
Browse files Browse the repository at this point in the history
* Code refactoring

* Adds metrics resource

* Adds an ability to store settings in RoadRunner KV

* Refctors metrics
- Adds an ability to get last points for metric
- Improved metrics creator
- Created metrics stores into a storage

* Refactors RPC manager
- Increases timeout for RR reconnection
- Adds Server DTO

Refctors metrics
- Improves chart creation panel

Refactors plugins UI
- stores collapsed state
  • Loading branch information
butschster authored Dec 8, 2022
1 parent e6f1f4f commit 40bf97a
Show file tree
Hide file tree
Showing 193 changed files with 2,397 additions and 822 deletions.
9 changes: 9 additions & 0 deletions .rr-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,24 @@ server:

service:
nginx:
service_name_in_log: true
remain_after_exit: true
restart_sec: 1
command: "/usr/sbin/nginx"
centrifuge:
service_name_in_log: true
remain_after_exit: true
restart_sec: 1
command: "./bin/centrifugo --config=centrifugo.json"
victoria-metrics:
service_name_in_log: true
remain_after_exit: true
restart_sec: 1
command: "./bin/victoria-metrics-prod -retentionPeriod=1d -opentsdbHTTPListenAddr=:4242"
snapshots:
service_name_in_log: true
remain_after_exit: true
restart_sec: 1
command: "php app.php take:snapshots --period=10"

centrifuge:
Expand Down
10 changes: 9 additions & 1 deletion .rr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,34 @@ server:
service:
frontend:
service_name_in_log: true
remain_after_exit: true
restart_sec: 1
command: "npm run dev"
env:
API_URL: http://127.0.0.1:8080
WS_URL: ws://127.0.0.1:8080/connection/websocket
centrifuge:
service_name_in_log: true
remain_after_exit: true
restart_sec: 1
command: "./bin/centrifugo --config=centrifugo.json"
victoria-metrics:
service_name_in_log: true
remain_after_exit: true
restart_sec: 1
command: "./bin/victoria-metrics-prod -retentionPeriod=1d -opentsdbHTTPListenAddr=:4242"
snapshots:
service_name_in_log: true
remain_after_exit: true
restart_sec: 1
command: "php app.php take:snapshots --period=15"

metrics:
address: 127.0.0.1:2112

centrifuge:
proxy_address: "tcp://127.0.0.1:10001"
grpc_api_address: "127.0.0.1:10000"
grpc_api_address: "tcp://127.0.0.1:10000"
pool:
reset_timeout: 10
num_workers: 2
2 changes: 1 addition & 1 deletion app.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

use App\App;
use App\Application\App;

// If you forgot to configure some of this in your php.ini file,
// then don't worry, we will set the standard environment
Expand Down
7 changes: 4 additions & 3 deletions app/config/centrifugo.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

declare(strict_types=1);

use App\Centrifuge\ConnectService;
use App\Centrifuge\RPCService;
use App\Centrifuge\SubscribeService;
use App\Centrifuge\Interceptor;
use App\Interfaces\Centrifuge\ConnectService;
use App\Interfaces\Centrifuge\RPCService;
use App\Interfaces\Centrifuge\SubscribeService;
use RoadRunner\Centrifugo\Request\RequestType;

$interceptors = [
Expand Down
9 changes: 9 additions & 0 deletions app/config/dataGrid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

return [
'writers' => [
\App\Application\Schema\DoctrineCollectionWriter::class
]
];
2 changes: 1 addition & 1 deletion app/config/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

return [
'interceptors' => [
\App\Event\Interceptor\BroadcastEventInterceptor::class
\App\Application\Event\Interceptor\BroadcastEventInterceptor::class
]
];
44 changes: 3 additions & 41 deletions app/config/monolog.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* Specify a default monolog handler
*/
'default' => env('MONOLOG_DEFAULT_CHANNEL', 'stderr'),
'default' => env('MONOLOG_DEFAULT_CHANNEL', 'default'),

/**
* Monolog supports the logging levels described by RFC 5424.
Expand All @@ -25,47 +25,9 @@
*/
'handlers' => [
'default' => [
[
'class' => 'log.rotate',
'options' => [
'filename' => directory('runtime') . 'logs/app.log',
'level' => Logger::DEBUG,
],
],
],
'stderr' => [
ErrorLogHandler::class,
],
'stdout' => [
[
'class' => SyslogHandler::class,
'options' => [
'ident' => 'app',
'facility' => LOG_USER,
],
],
\Spiral\RoadRunnerBridge\Logger\Handler::class,
],
],

/**
* Processors allows adding extra data for all records.
*
* @see https://github.com/Seldaek/monolog/blob/main/doc/02-handlers-formatters-processors.md#processors
*/
'processors' => [
'default' => [
// ...
],
'socket' => [
\Spiral\Telemetry\Monolog\TelemetryProcessor::class,
],
'stdout' => [
[
'class' => PsrLogMessageProcessor::class,
'options' => [
'dateFormat' => 'Y-m-d\TH:i:s.uP',
],
],
],
],
'processors' => [],
];
22 changes: 11 additions & 11 deletions app/src/App.php → app/src/Application/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

declare(strict_types=1);

namespace App;
namespace App\Application;

use App\Bootloader;
use App\Application\Bootloader;
use Spiral\Boot\Bootloader\CoreBootloader;
use Spiral\Bootloader as Framework;
use Spiral\Cqrs\Bootloader\CqrsBootloader;
use Spiral\DataGrid\Bootloader\GridBootloader;
use Spiral\DotEnv\Bootloader as DotEnv;
use Spiral\Framework\Kernel;
use Spiral\League\Event\Bootloader\EventBootloader;
use Spiral\Router\Bootloader\AnnotatedRoutesBootloader;
use Spiral\Nyholm\Bootloader as Nyholm;
use Spiral\RoadRunnerBridge\Bootloader as RoadRunnerBridge;
use Spiral\Serializer\Bootloader\SerializerBootloader;
use Spiral\Tokenizer\Bootloader\TokenizerBootloader;
use Spiral\Validation\Bootloader\ValidationBootloader;
use Spiral\Nyholm\Bootloader as Nyholm;
use Spiral\Validator\Bootloader\ValidatorBootloader;

class App extends Kernel
Expand All @@ -34,17 +34,20 @@ class App extends Kernel
Nyholm\NyholmBootloader::class,
RoadRunnerBridge\HttpBootloader::class,
RoadRunnerBridge\CacheBootloader::class,
RoadRunnerBridge\QueueBootloader::class,
RoadRunnerBridge\CentrifugoBootloader::class,
RoadRunnerBridge\LoggerBootloader::class,

EventBootloader::class,

// Logging and exceptions handling
Bootloader\LoggingBootloader::class,
Bootloader\ExceptionHandlerBootloader::class,

Framework\Http\RouterBootloader::class,
AnnotatedRoutesBootloader::class,
Framework\Http\JsonPayloadsBootloader::class,
Framework\Security\FiltersBootloader::class,
Framework\Security\GuardBootloader::class,
Bootloader\RoutesBootloader::class,

// Core Services
Framework\SnapshotsBootloader::class,
Expand All @@ -53,25 +56,22 @@ class App extends Kernel
Framework\Security\EncrypterBootloader::class,
ValidationBootloader::class,
ValidatorBootloader::class,
Framework\Security\FiltersBootloader::class,
Framework\Security\GuardBootloader::class,

// Framework commands
Framework\CommandBootloader::class,

// Debug and debug extensions
CqrsBootloader::class,
GridBootloader::class,
];

/*
* Application specific services and extensions.
*/
protected const APP = [
Bootloader\RPCBootloader::class,
Bootloader\RoutesBootloader::class,
Bootloader\HttpClientBootloader::class,
Bootloader\PrometheusParserBootloader::class,
Bootloader\ValidatorBootloader::class,
Bootloader\VictoriaMetricsBootloader::class,
Bootloader\AppBootloader::class,
];
}
100 changes: 100 additions & 0 deletions app/src/Application/AppDirectories.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php

declare(strict_types=1);

namespace App\Application;

use Spiral\Boot\DirectoriesInterface;

final class AppDirectories
{
public function __construct(
private readonly DirectoriesInterface $directories
) {
}

/**
* Application root directory.
*
* @return non-empty-string
*/
public function getRoot(?string $path = null): string
{
return $this->buildPath('root', $path);
}

/**
* Application directory.
*
* @return non-empty-string
*/
public function getApp(?string $path = null): string
{
return $this->buildPath('app', $path);
}

/**
* Public directory.
*
* @return non-empty-string
*/
public function getPublic(?string $path = null): string
{
return $this->buildPath('public', $path);
}

/**
* Runtime directory.
*
* @return non-empty-string
*/
public function getRuntime(?string $path = null): string
{
return $this->buildPath('runtime', $path);
}

/**
* Runtime cache directory.
*
* @return non-empty-string
*/
public function getCache(?string $path = null): string
{
return $this->buildPath('cache', $path);
}

/**
* Vendor libraries directory.
*
* @return non-empty-string
*/
public function getVendor(?string $path = null): string
{
return $this->buildPath('vendor', $path);
}

/**
* Config directory.
*
* @return non-empty-string
*/
public function getConfig(?string $path = null): string
{
return $this->buildPath('config', $path);
}

/**
* Resources directory.
*
* @return non-empty-string
*/
public function getResources(?string $path = null): string
{
return $this->buildPath('resources', $path);
}

private function buildPath(string $key, ?string $path = null): string
{
return \rtrim($this->directories->get($key), '/') . ($path ? '/' . \ltrim($path, '/') : '');
}
}
23 changes: 23 additions & 0 deletions app/src/Application/Bootloader/AppBootloader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace App\Application\Bootloader;

use App\Application\HTTP\Response\JsonResourceInterceptor;
use App\Application\Persistance\CacheSettingsRepository;
use App\Module\Settings\SettingsRepositoryInterface;
use Spiral\Bootloader\DomainBootloader;
use Spiral\Core\CoreInterface;

final class AppBootloader extends DomainBootloader
{
protected const INTERCEPTORS = [
JsonResourceInterceptor::class,
];

protected const SINGLETONS = [
SettingsRepositoryInterface::class => CacheSettingsRepository::class,
CoreInterface::class => [self::class, 'domainCore'],
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Bootloader;
namespace App\Application\Bootloader;

use Spiral\Boot\Bootloader\Bootloader;
use Spiral\Exceptions\ExceptionHandlerInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Bootloader;
namespace App\Application\Bootloader;

use Spiral\Boot\Bootloader\Bootloader;
use Symfony\Component\HttpClient\NativeHttpClient;
Expand Down
Loading

0 comments on commit 40bf97a

Please sign in to comment.