diff --git a/app/Actions/Database/StartMariadb.php b/app/Actions/Database/StartMariadb.php index 3e32c2481..c6b243381 100644 --- a/app/Actions/Database/StartMariadb.php +++ b/app/Actions/Database/StartMariadb.php @@ -69,7 +69,7 @@ public function handle(StandaloneMariadb $database) ] ] ]; - if ($this->database->destination->server->isDrainLogActivated()) { + if ($this->database->destination->server->isLogDrainEnabled() && $this->database->isLogDrainEnabled()) { $docker_compose['services'][$container_name]['logging'] = [ 'driver' => 'fluentd', 'options' => [ diff --git a/app/Actions/Database/StartMongodb.php b/app/Actions/Database/StartMongodb.php index 4ebbb9ec4..9eb884dbe 100644 --- a/app/Actions/Database/StartMongodb.php +++ b/app/Actions/Database/StartMongodb.php @@ -76,7 +76,7 @@ public function handle(StandaloneMongodb $database) ] ] ]; - if ($this->database->destination->server->isDrainLogActivated()) { + if ($this->database->destination->server->isLogDrainEnabled() && $this->database->isLogDrainEnabled()) { $docker_compose['services'][$container_name]['logging'] = [ 'driver' => 'fluentd', 'options' => [ diff --git a/app/Actions/Database/StartMysql.php b/app/Actions/Database/StartMysql.php index c3f04dc9f..761832525 100644 --- a/app/Actions/Database/StartMysql.php +++ b/app/Actions/Database/StartMysql.php @@ -69,7 +69,7 @@ public function handle(StandaloneMysql $database) ] ] ]; - if ($this->database->destination->server->isDrainLogActivated()) { + if ($this->database->destination->server->isLogDrainEnabled() && $this->database->isLogDrainEnabled()) { $docker_compose['services'][$container_name]['logging'] = [ 'driver' => 'fluentd', 'options' => [ diff --git a/app/Actions/Database/StartPostgresql.php b/app/Actions/Database/StartPostgresql.php index 1acdcf957..b88da5e4f 100644 --- a/app/Actions/Database/StartPostgresql.php +++ b/app/Actions/Database/StartPostgresql.php @@ -79,7 +79,8 @@ public function handle(StandalonePostgresql $database) ] ] ]; - if ($this->database->destination->server->isDrainLogActivated()) { + if ($this->database->destination->server->isLogDrainEnabled() && $this->database->isLogDrainEnabled()) { + ray('Log Drain Enabled'); $docker_compose['services'][$container_name]['logging'] = [ 'driver' => 'fluentd', 'options' => [ diff --git a/app/Actions/Database/StartRedis.php b/app/Actions/Database/StartRedis.php index 0cbd01f63..fab055f20 100644 --- a/app/Actions/Database/StartRedis.php +++ b/app/Actions/Database/StartRedis.php @@ -78,7 +78,7 @@ public function handle(StandaloneRedis $database) ] ] ]; - if ($this->database->destination->server->isDrainLogActivated()) { + if ($this->database->destination->server->isLogDrainEnabled() && $this->database->isLogDrainEnabled()) { $docker_compose['services'][$container_name]['logging'] = [ 'driver' => 'fluentd', 'options' => [ @@ -166,6 +166,5 @@ private function add_custom_redis() $content = $this->database->redis_conf; $content_base64 = base64_encode($content); $this->commands[] = "echo '{$content_base64}' | base64 -d > $this->configuration_dir/{$filename}"; - } } diff --git a/app/Actions/Server/InstallLogDrain.php b/app/Actions/Server/InstallLogDrain.php index 5ea1d5e43..4db355aa8 100644 --- a/app/Actions/Server/InstallLogDrain.php +++ b/app/Actions/Server/InstallLogDrain.php @@ -127,6 +127,7 @@ public function handle(Server $server, string $type) - ./parsers.conf:/parsers.conf ports: - 127.0.0.1:24224:24224 + restart: unless-stopped "); $readme = base64_encode('# New Relic Log Drain This log drain is based on [Fluent Bit](https://fluentbit.io/) and New Relic Log Forwarder. diff --git a/app/Http/Livewire/Project/Application/General.php b/app/Http/Livewire/Project/Application/General.php index bc853108f..63dbeba23 100644 --- a/app/Http/Livewire/Project/Application/General.php +++ b/app/Http/Livewire/Project/Application/General.php @@ -32,7 +32,7 @@ class General extends Component public bool $is_preview_deployments_enabled; public bool $is_auto_deploy_enabled; public bool $is_force_https_enabled; - + public bool $is_log_drain_enabled; protected $rules = [ 'application.name' => 'required', @@ -101,6 +101,7 @@ public function mount() $this->is_preview_deployments_enabled = $this->application->settings->is_preview_deployments_enabled; $this->is_auto_deploy_enabled = $this->application->settings->is_auto_deploy_enabled; $this->is_force_https_enabled = $this->application->settings->is_force_https_enabled; + $this->is_log_drain_enabled = $this->application->settings->is_log_drain_enabled; } $this->checkLabelUpdates(); } @@ -136,6 +137,14 @@ public function instantSave() $this->application->settings->is_preview_deployments_enabled = $this->is_preview_deployments_enabled; $this->application->settings->is_auto_deploy_enabled = $this->is_auto_deploy_enabled; $this->application->settings->is_force_https_enabled = $this->is_force_https_enabled; + $this->application->settings->is_log_drain_enabled = $this->is_log_drain_enabled; + if ($this->is_log_drain_enabled) { + if (!$this->application->destination->server->isLogDrainEnabled()) { + $this->application->settings->is_log_drain_enabled = $this->is_log_drain_enabled = false; + $this->emit('error', 'Log drain is not enabled on the server. Please enable it first.'); + return; + } + } $this->application->settings->save(); $this->application->save(); $this->application->refresh(); diff --git a/app/Http/Livewire/Project/Database/Mariadb/General.php b/app/Http/Livewire/Project/Database/Mariadb/General.php index 173e9290f..455f1b4ca 100644 --- a/app/Http/Livewire/Project/Database/Mariadb/General.php +++ b/app/Http/Livewire/Project/Database/Mariadb/General.php @@ -28,6 +28,7 @@ class General extends Component 'database.ports_mappings' => 'nullable', 'database.is_public' => 'nullable|boolean', 'database.public_port' => 'nullable|integer', + 'database.is_log_drain_enabled' => 'nullable|boolean', ]; protected $validationAttributes = [ 'database.name' => 'Name', @@ -50,6 +51,20 @@ public function mount() $this->db_url_public = $this->database->getDbUrl(); } } + public function instantSaveAdvanced() { + try { + if (!$this->database->destination->server->isLogDrainEnabled()) { + $this->database->is_log_drain_enabled = false; + $this->emit('error', 'Log drain is not enabled on the server. Please enable it first.'); + return; + } + $this->database->save(); + $this->emit('success', 'Database updated successfully.'); + $this->emit('success', 'You need to restart the service for the changes to take effect.'); + } catch (Exception $e) { + return handleError($e, $this); + } + } public function submit() { try { diff --git a/app/Http/Livewire/Project/Database/Mongodb/General.php b/app/Http/Livewire/Project/Database/Mongodb/General.php index 189f2632e..84669a019 100644 --- a/app/Http/Livewire/Project/Database/Mongodb/General.php +++ b/app/Http/Livewire/Project/Database/Mongodb/General.php @@ -27,6 +27,7 @@ class General extends Component 'database.ports_mappings' => 'nullable', 'database.is_public' => 'nullable|boolean', 'database.public_port' => 'nullable|integer', + 'database.is_log_drain_enabled' => 'nullable|boolean', ]; protected $validationAttributes = [ 'database.name' => 'Name', @@ -48,7 +49,21 @@ public function mount() $this->db_url_public = $this->database->getDbUrl(); } } - + public function instantSaveAdvanced() + { + try { + if (!$this->database->destination->server->isLogDrainEnabled()) { + $this->database->is_log_drain_enabled = false; + $this->emit('error', 'Log drain is not enabled on the server. Please enable it first.'); + return; + } + $this->database->save(); + $this->emit('success', 'Database updated successfully.'); + $this->emit('success', 'You need to restart the service for the changes to take effect.'); + } catch (Exception $e) { + return handleError($e, $this); + } + } public function submit() { try { diff --git a/app/Http/Livewire/Project/Database/Mysql/General.php b/app/Http/Livewire/Project/Database/Mysql/General.php index cb1a063db..c63cea293 100644 --- a/app/Http/Livewire/Project/Database/Mysql/General.php +++ b/app/Http/Livewire/Project/Database/Mysql/General.php @@ -28,6 +28,7 @@ class General extends Component 'database.ports_mappings' => 'nullable', 'database.is_public' => 'nullable|boolean', 'database.public_port' => 'nullable|integer', + 'database.is_log_drain_enabled' => 'nullable|boolean', ]; protected $validationAttributes = [ 'database.name' => 'Name', @@ -50,6 +51,21 @@ public function mount() $this->db_url_public = $this->database->getDbUrl(); } } + public function instantSaveAdvanced() + { + try { + if (!$this->database->destination->server->isLogDrainEnabled()) { + $this->database->is_log_drain_enabled = false; + $this->emit('error', 'Log drain is not enabled on the server. Please enable it first.'); + return; + } + $this->database->save(); + $this->emit('success', 'Database updated successfully.'); + $this->emit('success', 'You need to restart the service for the changes to take effect.'); + } catch (Exception $e) { + return handleError($e, $this); + } + } public function submit() { try { diff --git a/app/Http/Livewire/Project/Database/Postgresql/General.php b/app/Http/Livewire/Project/Database/Postgresql/General.php index ebc69a1bc..1804953ee 100644 --- a/app/Http/Livewire/Project/Database/Postgresql/General.php +++ b/app/Http/Livewire/Project/Database/Postgresql/General.php @@ -34,6 +34,7 @@ class General extends Component 'database.ports_mappings' => 'nullable', 'database.is_public' => 'nullable|boolean', 'database.public_port' => 'nullable|integer', + 'database.is_log_drain_enabled' => 'nullable|boolean', ]; protected $validationAttributes = [ 'database.name' => 'Name', @@ -57,6 +58,20 @@ public function mount() $this->db_url_public = $this->database->getDbUrl(); } } + public function instantSaveAdvanced() { + try { + if (!$this->database->destination->server->isLogDrainEnabled()) { + $this->database->is_log_drain_enabled = false; + $this->emit('error', 'Log drain is not enabled on the server. Please enable it first.'); + return; + } + $this->database->save(); + $this->emit('success', 'Database updated successfully.'); + $this->emit('success', 'You need to restart the service for the changes to take effect.'); + } catch (Exception $e) { + return handleError($e, $this); + } + } public function instantSave() { try { diff --git a/app/Http/Livewire/Project/Database/Redis/General.php b/app/Http/Livewire/Project/Database/Redis/General.php index 834a9f381..c2a28eef8 100644 --- a/app/Http/Livewire/Project/Database/Redis/General.php +++ b/app/Http/Livewire/Project/Database/Redis/General.php @@ -25,6 +25,7 @@ class General extends Component 'database.ports_mappings' => 'nullable', 'database.is_public' => 'nullable|boolean', 'database.public_port' => 'nullable|integer', + 'database.is_log_drain_enabled' => 'nullable|boolean', ]; protected $validationAttributes = [ 'database.name' => 'Name', @@ -43,6 +44,20 @@ public function mount() $this->db_url_public = $this->database->getDbUrl(); } } + public function instantSaveAdvanced() { + try { + if (!$this->database->destination->server->isLogDrainEnabled()) { + $this->database->is_log_drain_enabled = false; + $this->emit('error', 'Log drain is not enabled on the server. Please enable it first.'); + return; + } + $this->database->save(); + $this->emit('success', 'Database updated successfully.'); + $this->emit('success', 'You need to restart the service for the changes to take effect.'); + } catch (Exception $e) { + return handleError($e, $this); + } + } public function submit() { try { diff --git a/app/Http/Livewire/Project/Service/Application.php b/app/Http/Livewire/Project/Service/Application.php index 701a90c19..8a785b9c6 100644 --- a/app/Http/Livewire/Project/Service/Application.php +++ b/app/Http/Livewire/Project/Service/Application.php @@ -16,6 +16,7 @@ class Application extends Component 'application.image' => 'required', 'application.exclude_from_status' => 'required|boolean', 'application.required_fqdn' => 'required|boolean', + 'application.is_log_drain_enabled' => 'nullable|boolean', ]; public function render() { @@ -25,7 +26,11 @@ public function instantSave() { $this->submit(); } - + public function instantSaveAdvanced() + { + $this->submit(); + $this->emit('success', 'You need to restart the service for the changes to take effect.'); + } public function delete() { try { @@ -44,6 +49,11 @@ public function submit() { try { $this->validate(); + if (!$this->application->service->destination->server->isLogDrainEnabled()) { + $this->application->is_log_drain_enabled = false; + $this->emit('error', 'Log drain is not enabled on the server. Please enable it first.'); + return; + } $this->application->save(); updateCompose($this->application); $this->emit('success', 'Application saved successfully.'); diff --git a/app/Http/Livewire/Project/Service/Database.php b/app/Http/Livewire/Project/Service/Database.php index dee2785ba..6bf6098ad 100644 --- a/app/Http/Livewire/Project/Service/Database.php +++ b/app/Http/Livewire/Project/Service/Database.php @@ -21,18 +21,31 @@ class Database extends Component 'database.exclude_from_status' => 'required|boolean', 'database.public_port' => 'nullable|integer', 'database.is_public' => 'required|boolean', + 'database.is_log_drain_enabled' => 'required|boolean', ]; public function render() { return view('livewire.project.service.database'); } - public function mount() { + public function mount() + { if ($this->database->is_public) { $this->db_url_public = $this->database->getServiceDatabaseUrl(); } $this->refreshFileStorages(); } - public function instantSave() { + public function instantSaveAdvanced() + { + if (!$this->database->service->destination->server->isLogDrainEnabled()) { + $this->database->is_log_drain_enabled = false; + $this->emit('error', 'Log drain is not enabled on the server. Please enable it first.'); + return; + } + $this->submit(); + $this->emit('success', 'You need to restart the service for the changes to take effect.'); + } + public function instantSave() + { if ($this->database->is_public && !$this->database->public_port) { $this->emit('error', 'Public port is required.'); $this->database->is_public = false; diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 4e4f66301..dacdbf89b 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -864,7 +864,7 @@ private function generate_compose_file() ] ] ]; - if ($this->server->isDrainLogActivated()) { + if ($this->server->isLogDrainEnabled() && $this->application->isLogDrainEnabled()) { $docker_compose['services'][$this->container_name]['logging'] = [ 'driver' => 'fluentd', 'options' => [ diff --git a/app/Models/Application.php b/app/Models/Application.php index 27f34df34..cb3d85f94 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -300,6 +300,9 @@ public function isHealthcheckDisabled(): bool } return false; } + public function isLogDrainEnabled() { + return data_get($this, 'settings.is_log_drain_enabled', false); + } public function isConfigurationChanged($save = false) { $newConfigHash = $this->fqdn . $this->git_repository . $this->git_branch . $this->git_commit_sha . $this->build_pack . $this->static_image . $this->install_command . $this->build_command . $this->start_command . $this->port_exposes . $this->port_mappings . $this->base_directory . $this->publish_directory . $this->health_check_path . $this->health_check_port . $this->health_check_host . $this->health_check_method . $this->health_check_return_code . $this->health_check_scheme . $this->health_check_response_text . $this->health_check_interval . $this->health_check_timeout . $this->health_check_retries . $this->health_check_start_period . $this->health_check_enabled . $this->limits_memory . $this->limits_swap . $this->limits_swappiness . $this->limits_reservation . $this->limits_cpus . $this->limits_cpuset . $this->limits_cpu_shares . $this->dockerfile . $this->dockerfile_location . $this->custom_labels; diff --git a/app/Models/Server.php b/app/Models/Server.php index f00f772a8..9d91ea123 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -304,7 +304,7 @@ public function isFunctional() { return $this->settings->is_reachable && $this->settings->is_usable; } - public function isDrainLogActivated() + public function isLogDrainEnabled() { return $this->settings->is_logdrain_newrelic_enabled || $this->settings->is_logdrain_highlight_enabled || $this->settings->is_logdrain_axiom_enabled; } diff --git a/app/Models/Service.php b/app/Models/Service.php index 76c88eb85..cf78e8260 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -797,7 +797,7 @@ public function parse(bool $isNew = false): Collection $serviceLabels = $serviceLabels->merge(fqdnLabelsForTraefik($this->uuid, $fqdns, true)); } } - if ($this->server->isDrainLogActivated()) { + if ($this->server->isLogDrainEnabled() && $savedService->isLogDrainEnabled()) { data_set($service, 'logging', [ 'driver' => 'fluentd', 'options' => [ diff --git a/app/Models/ServiceApplication.php b/app/Models/ServiceApplication.php index b1db1c581..b8e3f1a41 100644 --- a/app/Models/ServiceApplication.php +++ b/app/Models/ServiceApplication.php @@ -18,6 +18,10 @@ protected static function booted() $service->fileStorages()->delete(); }); } + public function isLogDrainEnabled() + { + return data_get($this, 'is_log_drain_enabled', false); + } public function type() { return 'service'; diff --git a/app/Models/ServiceDatabase.php b/app/Models/ServiceDatabase.php index 2feaeb947..79c1dd176 100644 --- a/app/Models/ServiceDatabase.php +++ b/app/Models/ServiceDatabase.php @@ -16,6 +16,10 @@ protected static function booted() $service->fileStorages()->delete(); }); } + public function isLogDrainEnabled() + { + return data_get($this, 'is_log_drain_enabled', false); + } public function type() { return 'service'; diff --git a/app/Models/StandaloneMariadb.php b/app/Models/StandaloneMariadb.php index f9f3ad1ae..cb9fa9aa2 100644 --- a/app/Models/StandaloneMariadb.php +++ b/app/Models/StandaloneMariadb.php @@ -41,6 +41,10 @@ protected static function booted() $database->environment_variables()->delete(); }); } + public function isLogDrainEnabled() + { + return data_get($this, 'is_log_drain_enabled', false); + } public function type(): string { return 'standalone-mariadb'; diff --git a/app/Models/StandaloneMongodb.php b/app/Models/StandaloneMongodb.php index 628cb6942..3a5b7a52a 100644 --- a/app/Models/StandaloneMongodb.php +++ b/app/Models/StandaloneMongodb.php @@ -44,7 +44,10 @@ protected static function booted() $database->environment_variables()->delete(); }); } - + public function isLogDrainEnabled() + { + return data_get($this, 'is_log_drain_enabled', false); + } public function mongoInitdbRootPassword(): Attribute { return Attribute::make( diff --git a/app/Models/StandaloneMysql.php b/app/Models/StandaloneMysql.php index d7314f59b..6de57cb73 100644 --- a/app/Models/StandaloneMysql.php +++ b/app/Models/StandaloneMysql.php @@ -46,6 +46,11 @@ public function type(): string return 'standalone-mysql'; } + public function isLogDrainEnabled() + { + return data_get($this, 'is_log_drain_enabled', false); + } + public function portsMappings(): Attribute { return Attribute::make( diff --git a/app/Models/StandalonePostgresql.php b/app/Models/StandalonePostgresql.php index ca19e7a87..1bef3b6c9 100644 --- a/app/Models/StandalonePostgresql.php +++ b/app/Models/StandalonePostgresql.php @@ -42,6 +42,11 @@ protected static function booted() }); } + public function isLogDrainEnabled() + { + return data_get($this, 'is_log_drain_enabled', false); + } + public function portsMappings(): Attribute { return Attribute::make( diff --git a/app/Models/StandaloneRedis.php b/app/Models/StandaloneRedis.php index a0de53a3e..fe1281c22 100644 --- a/app/Models/StandaloneRedis.php +++ b/app/Models/StandaloneRedis.php @@ -37,6 +37,11 @@ protected static function booted() }); } + public function isLogDrainEnabled() + { + return data_get($this, 'is_log_drain_enabled', false); + } + public function portsMappings(): Attribute { return Attribute::make( diff --git a/config/sentry.php b/config/sentry.php index d1111bbd4..0c8ab1b30 100644 --- a/config/sentry.php +++ b/config/sentry.php @@ -7,7 +7,7 @@ // The release version of your application // Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')) - 'release' => '4.0.0-beta.143', + 'release' => '4.0.0-beta.144', // When left empty or `null` the Laravel environment will be used 'environment' => config('app.env'), diff --git a/config/version.php b/config/version.php index 318484b79..a4a00caab 100644 --- a/config/version.php +++ b/config/version.php @@ -1,3 +1,3 @@ boolean('is_log_drain_enabled')->default(false); + }); + Schema::table('standalone_redis', function (Blueprint $table) { + $table->boolean('is_log_drain_enabled')->default(false); + }); + Schema::table('standalone_mysqls', function (Blueprint $table) { + $table->boolean('is_log_drain_enabled')->default(false); + }); + Schema::table('standalone_mariadbs', function (Blueprint $table) { + $table->boolean('is_log_drain_enabled')->default(false); + }); + Schema::table('standalone_postgresqls', function (Blueprint $table) { + $table->boolean('is_log_drain_enabled')->default(false); + }); + Schema::table('standalone_mongodbs', function (Blueprint $table) { + $table->boolean('is_log_drain_enabled')->default(false); + }); + Schema::table('service_applications', function (Blueprint $table) { + $table->boolean('is_log_drain_enabled')->default(false); + }); + Schema::table('service_databases', function (Blueprint $table) { + $table->boolean('is_log_drain_enabled')->default(false); + }); + + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('application_settings', function (Blueprint $table) { + $table->dropColumn('is_log_drain_enabled'); + }); + Schema::table('standalone_redis', function (Blueprint $table) { + $table->dropColumn('is_log_drain_enabled'); + }); + Schema::table('standalone_mysqls', function (Blueprint $table) { + $table->dropColumn('is_log_drain_enabled'); + }); + Schema::table('standalone_mariadbs', function (Blueprint $table) { + $table->dropColumn('is_log_drain_enabled'); + }); + Schema::table('standalone_postgresqls', function (Blueprint $table) { + $table->dropColumn('is_log_drain_enabled'); + }); + Schema::table('standalone_mongodbs', function (Blueprint $table) { + $table->dropColumn('is_log_drain_enabled'); + }); + Schema::table('service_applications', function (Blueprint $table) { + $table->dropColumn('is_log_drain_enabled'); + }); + Schema::table('service_databases', function (Blueprint $table) { + $table->dropColumn('is_log_drain_enabled'); + }); + + } +}; diff --git a/resources/views/livewire/project/application/general.blade.php b/resources/views/livewire/project/application/general.blade.php index 2753b4bf7..7d7b9c999 100644 --- a/resources/views/livewire/project/application/general.blade.php +++ b/resources/views/livewire/project/application/general.blade.php @@ -114,6 +114,8 @@