From b0a1aacde279adeb0b387590303af0e33ccbdccc Mon Sep 17 00:00:00 2001 From: briskt <3172830+briskt@users.noreply.github.com> Date: Tue, 5 Mar 2024 07:13:40 -0700 Subject: [PATCH 1/4] set version string to develop --- 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 28961f2..a354aec 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.1.2', + 'release' => 'idp-id-sync@develop', 'before_send' => function (Event $event) use ($idpName): ?Event { $event->setExtra(['idp' => $idpName]); return $event; From fed114aefcc09e3524761a71d8cde14c456a0dc0 Mon Sep 17 00:00:00 2001 From: briskt <3172830+briskt@users.noreply.github.com> Date: Thu, 7 Mar 2024 08:14:08 -0700 Subject: [PATCH 2/4] new Monitor component to issue "heartbeat" calls to a monitoring service --- application/common/components/Monitor.php | 38 +++++++++++++ application/common/config/main.php | 6 ++ .../console/controllers/BatchController.php | 55 +++++++++++++------ 3 files changed, 81 insertions(+), 18 deletions(-) create mode 100644 application/common/components/Monitor.php diff --git a/application/common/components/Monitor.php b/application/common/components/Monitor.php new file mode 100644 index 0000000..b513820 --- /dev/null +++ b/application/common/components/Monitor.php @@ -0,0 +1,38 @@ +heartbeatUrl)) { + return; + } + + $client = new Client(); + + $method = 'POST'; + if ($this->heartbeatMethod !== '') { + $method = $this->heartbeatMethod; + } + + try { + $client->request($method, $this->heartbeatUrl); + } catch (\Throwable) { + } + } +} diff --git a/application/common/config/main.php b/application/common/config/main.php index a354aec..063be76 100644 --- a/application/common/config/main.php +++ b/application/common/config/main.php @@ -4,6 +4,7 @@ use Sentry\Event; use Sil\Idp\IdSync\common\components\IdBrokerBase; use Sil\Idp\IdSync\common\components\IdStoreBase; +use Sil\Idp\IdSync\common\components\Monitor; use Sil\Idp\IdSync\common\components\notify\EmailServiceNotifier; use Sil\JsonLog\target\EmailServiceTarget; use Sil\JsonLog\target\JsonStreamTarget; @@ -142,6 +143,11 @@ ], 'notifier' => $notifierConfig, + 'monitor' => [ + 'class' => Monitor::class, + 'heartbeatUrl' => Env::get('HEARTBEAT_URL'), + 'heartbeatMethod' => Env::get('HEARTBEAT_METHOD'), + ] ], 'params' => [ 'syncSafetyCutoff' => Env::get('SYNC_SAFETY_CUTOFF'), diff --git a/application/console/controllers/BatchController.php b/application/console/controllers/BatchController.php index 018df84..cfc9160 100644 --- a/application/console/controllers/BatchController.php +++ b/application/console/controllers/BatchController.php @@ -3,6 +3,7 @@ namespace Sil\Idp\IdSync\console\controllers; use Sentry\CheckInStatus; +use Sil\Idp\IdSync\common\components\Monitor; use Sil\Idp\IdSync\common\traits\SyncProvider; use Yii; use yii\console\Controller; @@ -15,19 +16,28 @@ class BatchController extends Controller public function actionFull() { - $checkInId = captureCheckIn( - slug: Yii::$app->params['sentryMonitorSlug'], - status: CheckInStatus::inProgress() - ); + $sentryMonitorSlug = Yii::$app->params['sentryMonitorSlug']; + if ($sentryMonitorSlug !== "") { + $checkInId = captureCheckIn( + slug: $sentryMonitorSlug, + status: CheckInStatus::inProgress() + ); + } $synchronizer = $this->getSynchronizer(); $synchronizer->syncAllNotifyException(); - captureCheckIn( - slug: Yii::$app->params['sentryMonitorSlug'], - status: CheckInStatus::ok(), - checkInId: $checkInId, - ); + if ($sentryMonitorSlug != "") { + captureCheckIn( + slug: $sentryMonitorSlug, + status: CheckInStatus::ok(), + checkInId: $checkInId, + ); + } + + /* @var $monitor Monitor */ + $monitor = Yii::$app->monitor; + $monitor->Heartbeat(); } /** @@ -36,10 +46,13 @@ public function actionFull() */ public function actionIncremental() { - $checkInId = captureCheckIn( - slug: Yii::$app->params['sentryMonitorSlug'], - status: CheckInStatus::inProgress() - ); + $sentryMonitorSlug = Yii::$app->params['sentryMonitorSlug']; + if ($sentryMonitorSlug !== "") { + $checkInId = captureCheckIn( + slug: $sentryMonitorSlug, + status: CheckInStatus::inProgress() + ); + } $synchronizer = $this->getSynchronizer(); $synchronizer->syncUsersChangedSince(strtotime('-11 minutes')); @@ -47,10 +60,16 @@ public function actionIncremental() $synchronizer = $this->getSynchronizer(); $synchronizer->syncAllNotifyException(); - captureCheckIn( - slug: Yii::$app->params['sentryMonitorSlug'], - status: CheckInStatus::ok(), - checkInId: $checkInId, - ); + if ($sentryMonitorSlug != "") { + captureCheckIn( + slug: $sentryMonitorSlug, + status: CheckInStatus::ok(), + checkInId: $checkInId, + ); + } + + /* @var $monitor Monitor */ + $monitor = Yii::$app->monitor; + $monitor->Heartbeat(); } } From 02f2a54fa27233cfc993233089ca2fb4ae7eacf1 Mon Sep 17 00:00:00 2001 From: briskt <3172830+briskt@users.noreply.github.com> Date: Thu, 7 Mar 2024 09:26:14 -0700 Subject: [PATCH 3/4] fix the heartbeatMethod setup --- application/common/components/Monitor.php | 5 +++-- application/common/config/main.php | 1 + local.env.dist | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/application/common/components/Monitor.php b/application/common/components/Monitor.php index b513820..aad8665 100644 --- a/application/common/components/Monitor.php +++ b/application/common/components/Monitor.php @@ -26,13 +26,14 @@ public function Heartbeat() $client = new Client(); $method = 'POST'; - if ($this->heartbeatMethod !== '') { + if (!empty($this->heartbeatMethod)) { $method = $this->heartbeatMethod; } try { $client->request($method, $this->heartbeatUrl); - } catch (\Throwable) { + } catch (\Throwable $e) { + \Yii::error('heartbeat error: ' . $e->getMessage()); } } } diff --git a/application/common/config/main.php b/application/common/config/main.php index 063be76..6fa967b 100644 --- a/application/common/config/main.php +++ b/application/common/config/main.php @@ -143,6 +143,7 @@ ], 'notifier' => $notifierConfig, + 'monitor' => [ 'class' => Monitor::class, 'heartbeatUrl' => Env::get('HEARTBEAT_URL'), diff --git a/local.env.dist b/local.env.dist index f44e20a..b53810c 100644 --- a/local.env.dist +++ b/local.env.dist @@ -120,3 +120,7 @@ SENTRY_MONITOR_SLUG= #TEST_SECURE_USER_CONFIG_apiKey=abc123 #TEST_SECURE_USER_CONFIG_apiSecret=abc123 #TEST_SECURE_USER_EMPLOYEE_ID=123456 + +# Optional: configure the URL and http method of a monitoring service to call after every successful sync +HEARTBEAT_URL=https://push.nodeping.com/v1?id=MY_CHECK_ID_HERE&checktoken=LONG_CHECK_TOKEN_HERE' +#HEARTBEAT_METHOD=POST From a4cbd5d5b30d31a8822622b4773e29a270c8f19d Mon Sep 17 00:00:00 2001 From: briskt <3172830+briskt@users.noreply.github.com> Date: Thu, 7 Mar 2024 09:29:10 -0700 Subject: [PATCH 4/4] set version to 5.2.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 6fa967b..a9b3a22 100644 --- a/application/common/config/main.php +++ b/application/common/config/main.php @@ -132,7 +132,7 @@ 'clientOptions' => [ 'attach_stacktrace' => false, // stack trace identifies the logger call stack, not helpful 'environment' => YII_ENV, - 'release' => 'idp-id-sync@develop', + 'release' => 'idp-id-sync@5.2.0', 'before_send' => function (Event $event) use ($idpName): ?Event { $event->setExtra(['idp' => $idpName]); return $event;