From 255ae1e3824b280751cbd73bddc367b0b151f029 Mon Sep 17 00:00:00 2001 From: briskt <3172830+briskt@users.noreply.github.com> Date: Thu, 9 Nov 2023 19:57:24 -0700 Subject: [PATCH 1/7] use Sentry to monitor sync --- application/common/config/main.php | 1 + application/composer.json | 3 ++- application/composer.lock | 2 +- .../console/controllers/BatchController.php | 22 +++++++++++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/application/common/config/main.php b/application/common/config/main.php index 58e9ee8..78797c1 100644 --- a/application/common/config/main.php +++ b/application/common/config/main.php @@ -147,5 +147,6 @@ 'syncSafetyCutoff' => Env::get('SYNC_SAFETY_CUTOFF'), 'allowEmptyEmail' => Env::get('ALLOW_EMPTY_EMAIL', false), 'enableNewUserNotification' => Env::get('ENABLE_NEW_USER_NOTIFICATION', false), + 'sentryMonitorSlug' => Env::get('SENTRY_MONITOR_SLUG', 'idp-id-sync'), ], ]; diff --git a/application/composer.json b/application/composer.json index 52c91b8..873b15e 100644 --- a/application/composer.json +++ b/application/composer.json @@ -23,7 +23,8 @@ "guzzlehttp/guzzle": "^6.2", "google/apiclient": "^2.0", "codemix/yii2-streamlog": "^1.3", - "notamedia/yii2-sentry": "^1.7" + "notamedia/yii2-sentry": "^1.7", + "sentry/sentry": "^3.22" }, "require-dev": { "behat/behat": "^3.3", diff --git a/application/composer.lock b/application/composer.lock index ebfd4a4..69f944f 100644 --- a/application/composer.lock +++ b/application/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4a4d1f014f4b7c66f5f411c34d118025", + "content-hash": "1894856972ae17381c9546f46f8c2659", "packages": [ { "name": "bower-asset/inputmask", diff --git a/application/console/controllers/BatchController.php b/application/console/controllers/BatchController.php index ac543f3..52972c6 100644 --- a/application/console/controllers/BatchController.php +++ b/application/console/controllers/BatchController.php @@ -2,8 +2,11 @@ namespace Sil\Idp\IdSync\console\controllers; +use Sentry\CheckInStatus; use Sil\Idp\IdSync\common\traits\SyncProvider; +use Yii; use yii\console\Controller; +use function Sentry\captureCheckIn; class BatchController extends Controller { @@ -11,8 +14,16 @@ class BatchController extends Controller public function actionFull() { + $start_time = microtime(true); + $synchronizer = $this->getSynchronizer(); $synchronizer->syncAllNotifyException(); + + captureCheckIn( + slug: Yii::$app->params['sentryMonitorSlug'], + status: CheckInStatus::ok(), + duration: microtime(true) - $start_time, + ); } /** @@ -21,7 +32,18 @@ public function actionFull() */ public function actionIncremental() { + $start_time = microtime(true); + $synchronizer = $this->getSynchronizer(); $synchronizer->syncUsersChangedSince(strtotime('-11 minutes')); + + $synchronizer = $this->getSynchronizer(); + $synchronizer->syncAllNotifyException(); + + captureCheckIn( + slug: Yii::$app->params['sentryMonitorSlug'], + status: CheckInStatus::ok(), + duration: microtime(true) - $start_time, + ); } } From ede021fcaf09f541537d59e34a6d0b4e70014dbb Mon Sep 17 00:00:00 2001 From: briskt <3172830+briskt@users.noreply.github.com> Date: Thu, 9 Nov 2023 20:04:19 -0700 Subject: [PATCH 2/7] make psr2 --- .gitignore | 1 + application/console/controllers/BatchController.php | 1 + 2 files changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index f11b56f..26974ff 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ google-auth.json # PHP-CS-Fixer cache file. .php_cs.cache +.php-cs-fixer.cache dockercfg diff --git a/application/console/controllers/BatchController.php b/application/console/controllers/BatchController.php index 52972c6..db624b2 100644 --- a/application/console/controllers/BatchController.php +++ b/application/console/controllers/BatchController.php @@ -6,6 +6,7 @@ use Sil\Idp\IdSync\common\traits\SyncProvider; use Yii; use yii\console\Controller; + use function Sentry\captureCheckIn; class BatchController extends Controller From eeadf0021a845591a30eef756a1957dbd3c7784b Mon Sep 17 00:00:00 2001 From: briskt <3172830+briskt@users.noreply.github.com> Date: Thu, 9 Nov 2023 21:08:18 -0700 Subject: [PATCH 3/7] use Sentry inProgress monitor check-in --- application/console/controllers/BatchController.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/application/console/controllers/BatchController.php b/application/console/controllers/BatchController.php index db624b2..6de0b01 100644 --- a/application/console/controllers/BatchController.php +++ b/application/console/controllers/BatchController.php @@ -15,7 +15,10 @@ class BatchController extends Controller public function actionFull() { - $start_time = microtime(true); + $checkInId = captureCheckIn( + slug: Yii::$app->params['sentryMonitorSlug'], + status: CheckInStatus::inProgress() + ); $synchronizer = $this->getSynchronizer(); $synchronizer->syncAllNotifyException(); @@ -23,7 +26,7 @@ public function actionFull() captureCheckIn( slug: Yii::$app->params['sentryMonitorSlug'], status: CheckInStatus::ok(), - duration: microtime(true) - $start_time, + checkInId: $checkInId, ); } From 10103b6188fbfb9edf9b3e8037c86d011676b51e Mon Sep 17 00:00:00 2001 From: briskt <3172830+briskt@users.noreply.github.com> Date: Thu, 9 Nov 2023 21:29:04 -0700 Subject: [PATCH 4/7] use InProgress check-in for the incremental sync also --- application/console/controllers/BatchController.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/application/console/controllers/BatchController.php b/application/console/controllers/BatchController.php index 6de0b01..018df84 100644 --- a/application/console/controllers/BatchController.php +++ b/application/console/controllers/BatchController.php @@ -36,7 +36,10 @@ public function actionFull() */ public function actionIncremental() { - $start_time = microtime(true); + $checkInId = captureCheckIn( + slug: Yii::$app->params['sentryMonitorSlug'], + status: CheckInStatus::inProgress() + ); $synchronizer = $this->getSynchronizer(); $synchronizer->syncUsersChangedSince(strtotime('-11 minutes')); @@ -47,7 +50,7 @@ public function actionIncremental() captureCheckIn( slug: Yii::$app->params['sentryMonitorSlug'], status: CheckInStatus::ok(), - duration: microtime(true) - $start_time, + checkInId: $checkInId, ); } } From fa48d9078e0297518e86cca8d8bb2157f773c04f Mon Sep 17 00:00:00 2001 From: briskt <3172830+briskt@users.noreply.github.com> Date: Mon, 20 Nov 2023 16:25:23 -0700 Subject: [PATCH 5/7] set version string to 5.0.1-pre --- application/common/config/main.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/common/config/main.php b/application/common/config/main.php index 1649dda..994a442 100644 --- a/application/common/config/main.php +++ b/application/common/config/main.php @@ -131,7 +131,7 @@ 'clientOptions' => [ 'attach_stacktrace' => false, // stack trace identifies the logger call stack, not helpful 'environment' => YII_ENV, - 'release' => 'idp-id-sync@5.0.0', + 'release' => 'idp-id-sync@5.0.1-pre', 'before_send' => function (Event $event) use ($idpName): ?Event { $event->setExtra(['idp' => $idpName]); return $event; From dbc72f8fce694deb1de6ec95cdb4c9ea70be8344 Mon Sep 17 00:00:00 2001 From: briskt <3172830+briskt@users.noreply.github.com> Date: Mon, 20 Nov 2023 16:26:49 -0700 Subject: [PATCH 6/7] set version to 5.1.0 --- application/common/config/main.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/common/config/main.php b/application/common/config/main.php index 994a442..259501e 100644 --- a/application/common/config/main.php +++ b/application/common/config/main.php @@ -131,7 +131,7 @@ 'clientOptions' => [ 'attach_stacktrace' => false, // stack trace identifies the logger call stack, not helpful 'environment' => YII_ENV, - 'release' => 'idp-id-sync@5.0.1-pre', + 'release' => 'idp-id-sync@5.1.0', 'before_send' => function (Event $event) use ($idpName): ?Event { $event->setExtra(['idp' => $idpName]); return $event; From 14adb6fadd9a9e7667d2c35f196ba62bce2cef23 Mon Sep 17 00:00:00 2001 From: briskt <3172830+briskt@users.noreply.github.com> Date: Mon, 20 Nov 2023 16:32:35 -0700 Subject: [PATCH 7/7] add SENTRY_MONITOR_SLUG to local.env.dist --skip-ci --- local.env.dist | 3 +++ 1 file changed, 3 insertions(+) diff --git a/local.env.dist b/local.env.dist index c5554d8..f44e20a 100644 --- a/local.env.dist +++ b/local.env.dist @@ -77,6 +77,9 @@ ID_STORE_ADAPTER= # To use Sentry for error alerting, obtain DSN from Sentry dashboard: Settings - Projects - (project) - Client Keys SENTRY_DSN= +# To use Sentry monitor service, create a monitor and enter the slug value here +SENTRY_MONITOR_SLUG= + ## [prod|dev|test], app defaults to prod #APP_ENV=