From 29d998113037b8eb3165c2bd2565cb1455779c59 Mon Sep 17 00:00:00 2001 From: Dan Nita Date: Fri, 8 Nov 2024 10:43:28 +0000 Subject: [PATCH 1/6] send error log to gcp logging --- .github/workflows/dev_deployment.yaml | 5 +++-- app/Exceptions/Handler.php | 7 +++++++ app/Http/Controllers/Api/V1/TestController.php | 8 ++++++++ config/routes.php | 15 +++++++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dev_deployment.yaml b/.github/workflows/dev_deployment.yaml index 7c540a578..4ac892ccd 100644 --- a/.github/workflows/dev_deployment.yaml +++ b/.github/workflows/dev_deployment.yaml @@ -5,6 +5,7 @@ on: push: branches: - 'dev' + - 'send_error_log_to_gcp_logging' env: PROJECT_ID: '${{ secrets.PROJECT_ID }}' @@ -26,7 +27,7 @@ jobs: id: checkout uses: actions/checkout@v4 with: - ref: dev + ref: send_error_log_to_gcp_logging - name: Read VERSION file id: getversion @@ -76,7 +77,7 @@ jobs: id: checkout uses: actions/checkout@v4 with: - ref: dev + ref: send_error_log_to_gcp_logging - name: Google Auth id: auth diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 3913de4de..042704280 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -2,6 +2,7 @@ namespace App\Exceptions; +use CloudLogger; use Config; use Throwable; use Illuminate\Http\Request; @@ -77,6 +78,12 @@ public function render($request, Throwable $e): mixed ]; } + CloudLogger::write([ + 'action_type' => 'EXCEPTION', + 'action_message' => $response['message'], + 'details' => $response['details'], + ]); + return response()->json($response, $statusCode); } } diff --git a/app/Http/Controllers/Api/V1/TestController.php b/app/Http/Controllers/Api/V1/TestController.php index 3e09612a4..cf605bcdc 100644 --- a/app/Http/Controllers/Api/V1/TestController.php +++ b/app/Http/Controllers/Api/V1/TestController.php @@ -64,4 +64,12 @@ public function testGCPLogger(Request $request): JsonResponse return response()->json(['status' => 'success']); } + + public function testSendException(Request $request): JsonResponse + { + throw new \Exception('test exception'); + + return response()->json(['status' => 'success']); + } + } diff --git a/config/routes.php b/config/routes.php index 2d1164d6c..760fedb4f 100644 --- a/config/routes.php +++ b/config/routes.php @@ -3619,4 +3619,19 @@ ], 'constraint' => [], ], + + // test + [ + 'name' => 'test exception' , + 'method' => 'get', + 'path' => '/test-send-exception', + 'methodController' => 'TestController@testSendException', + 'namespaceController' => 'App\Http\Controllers\Api\V1', + 'middleware' => [ + 'sanitize.input', + ], + 'constraint' => [], + ], + + ]; From 38040bf79586240e83d85ab7ad9e34afe5eb4a5f Mon Sep 17 00:00:00 2001 From: Dan Nita Date: Fri, 8 Nov 2024 11:00:46 +0000 Subject: [PATCH 2/6] update --- .github/workflows/dev_deployment.yaml | 5 ++-- .../Controllers/Api/V1/TestController.php | 7 ------ config/routes.php | 14 ----------- docker/start.sh | 23 +++++++++++-------- 4 files changed, 15 insertions(+), 34 deletions(-) diff --git a/.github/workflows/dev_deployment.yaml b/.github/workflows/dev_deployment.yaml index 4ac892ccd..7c540a578 100644 --- a/.github/workflows/dev_deployment.yaml +++ b/.github/workflows/dev_deployment.yaml @@ -5,7 +5,6 @@ on: push: branches: - 'dev' - - 'send_error_log_to_gcp_logging' env: PROJECT_ID: '${{ secrets.PROJECT_ID }}' @@ -27,7 +26,7 @@ jobs: id: checkout uses: actions/checkout@v4 with: - ref: send_error_log_to_gcp_logging + ref: dev - name: Read VERSION file id: getversion @@ -77,7 +76,7 @@ jobs: id: checkout uses: actions/checkout@v4 with: - ref: send_error_log_to_gcp_logging + ref: dev - name: Google Auth id: auth diff --git a/app/Http/Controllers/Api/V1/TestController.php b/app/Http/Controllers/Api/V1/TestController.php index cf605bcdc..812257b02 100644 --- a/app/Http/Controllers/Api/V1/TestController.php +++ b/app/Http/Controllers/Api/V1/TestController.php @@ -65,11 +65,4 @@ public function testGCPLogger(Request $request): JsonResponse return response()->json(['status' => 'success']); } - public function testSendException(Request $request): JsonResponse - { - throw new \Exception('test exception'); - - return response()->json(['status' => 'success']); - } - } diff --git a/config/routes.php b/config/routes.php index 760fedb4f..13b572c48 100644 --- a/config/routes.php +++ b/config/routes.php @@ -3620,18 +3620,4 @@ 'constraint' => [], ], - // test - [ - 'name' => 'test exception' , - 'method' => 'get', - 'path' => '/test-send-exception', - 'methodController' => 'TestController@testSendException', - 'namespaceController' => 'App\Http\Controllers\Api\V1', - 'middleware' => [ - 'sanitize.input', - ], - 'constraint' => [], - ], - - ]; diff --git a/docker/start.sh b/docker/start.sh index a33cd6f21..c843995a4 100755 --- a/docker/start.sh +++ b/docker/start.sh @@ -23,16 +23,19 @@ fi # Start the Octane server in the background $base_command & -# Separate the command from the cron timings, so as to first check for -# duplicates, thus being immune to multiple insertions -cronCommand="/usr/local/bin/php /var/www/artisan schedule:run >> /dev/null 2>&1" -cronJob="* * * * * $cronCommand" - -# To add the above to local crontab -( crontab -l | grep -v -F "$cronCommand" ; echo "$cronJob" ) | crontab - - -## To remove the above from local crontab -# ( crontab -l | grep -v -F "$cronCommand" ) | crontab - +# for the dev, preprod and prod environment the scheduler was moved based on google scheduler. +if [ "$APP_ENV" = 'local' ]; then + # Separate the command from the cron timings, so as to first check for + # duplicates, thus being immune to multiple insertions + cronCommand="/usr/local/bin/php /var/www/artisan schedule:run >> /dev/null 2>&1" + cronJob="* * * * * $cronCommand" + + # To add the above to local crontab + ( crontab -l | grep -v -F "$cronCommand" ; echo "$cronJob" ) | crontab - + + ## To remove the above from local crontab + # ( crontab -l | grep -v -F "$cronCommand" ) | crontab - +fi # To activate cron service service cron start From ef82b3fdd05045a7803155260c9c4536dca7ba3b Mon Sep 17 00:00:00 2001 From: Dan Nita Date: Fri, 8 Nov 2024 11:15:01 +0000 Subject: [PATCH 3/6] update --- app/Exceptions/Handler.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 042704280..a6f7734c3 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -78,11 +78,13 @@ public function render($request, Throwable $e): mixed ]; } - CloudLogger::write([ - 'action_type' => 'EXCEPTION', - 'action_message' => $response['message'], - 'details' => $response['details'], - ]); + if (env('GOOGLE_CLOUD_LOGGING_ENABLED')) { + CloudLogger::write([ + 'action_type' => 'EXCEPTION', + 'action_message' => $response['message'], + 'details' => $response['details'], + ]); + } return response()->json($response, $statusCode); } From d256ee4547e9d7d933423e8fc0ea1b72b3712839 Mon Sep 17 00:00:00 2001 From: Dan Nita Date: Fri, 8 Nov 2024 11:24:44 +0000 Subject: [PATCH 4/6] update --- docker/start.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker/start.sh b/docker/start.sh index c843995a4..ca076af94 100755 --- a/docker/start.sh +++ b/docker/start.sh @@ -35,10 +35,10 @@ if [ "$APP_ENV" = 'local' ]; then ## To remove the above from local crontab # ( crontab -l | grep -v -F "$cronCommand" ) | crontab - -fi -# To activate cron service -service cron start + # To activate cron service + service cron start +fi php artisan horizon From fee328e447cd1ca454bd1e9d3476b0e6aa0c082a Mon Sep 17 00:00:00 2001 From: Dan Nita Date: Fri, 8 Nov 2024 11:51:53 +0000 Subject: [PATCH 5/6] update --- app/Http/Controllers/Api/V1/TestController.php | 1 - docker/start.sh | 2 -- 2 files changed, 3 deletions(-) diff --git a/app/Http/Controllers/Api/V1/TestController.php b/app/Http/Controllers/Api/V1/TestController.php index 812257b02..3e09612a4 100644 --- a/app/Http/Controllers/Api/V1/TestController.php +++ b/app/Http/Controllers/Api/V1/TestController.php @@ -64,5 +64,4 @@ public function testGCPLogger(Request $request): JsonResponse return response()->json(['status' => 'success']); } - } diff --git a/docker/start.sh b/docker/start.sh index ca076af94..c36681e2a 100755 --- a/docker/start.sh +++ b/docker/start.sh @@ -41,5 +41,3 @@ if [ "$APP_ENV" = 'local' ]; then fi php artisan horizon - - From 322c340851d1a10fa6a7f9e6981a77fdcb21706d Mon Sep 17 00:00:00 2001 From: Dan Nita Date: Fri, 8 Nov 2024 11:56:59 +0000 Subject: [PATCH 6/6] update --- config/routes.php | 1 - 1 file changed, 1 deletion(-) diff --git a/config/routes.php b/config/routes.php index 13b572c48..2d1164d6c 100644 --- a/config/routes.php +++ b/config/routes.php @@ -3619,5 +3619,4 @@ ], 'constraint' => [], ], - ];