From 7138a6d203feb62bec1ae9170899f3914bfcb63c Mon Sep 17 00:00:00 2001 From: Peter Elmered Date: Thu, 18 Jul 2024 19:16:00 +0200 Subject: [PATCH 1/5] Add summary for detailed Health checks --- .../StoredCheckResults/StoredCheckResults.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/ResultStores/StoredCheckResults/StoredCheckResults.php b/src/ResultStores/StoredCheckResults/StoredCheckResults.php index 8a74322d..2d0b1972 100644 --- a/src/ResultStores/StoredCheckResults/StoredCheckResults.php +++ b/src/ResultStores/StoredCheckResults/StoredCheckResults.php @@ -81,10 +81,19 @@ public function containsCheckWithStatus(array|Status $statuses): bool ); } + public function getFailing() + { + return $this->storedCheckResults->filter( + fn (StoredCheckResult $line) => $line->status !== Status::ok()->value + ); + } + public function toJson(): string { return (string) json_encode([ 'finishedAt' => $this->finishedAt->getTimestamp(), + 'status' => $this->allChecksOk() ? 'ok' : 'failing', + 'failingChecks' => $this->getFailing()->map->name->implode(', ') ?: '', 'checkResults' => $this->storedCheckResults->map(fn (StoredCheckResult $line) => $line->toArray()), ]); } From f60b4cb8389d9c743cf5e629340e0814381db612 Mon Sep 17 00:00:00 2001 From: Peter Elmered Date: Thu, 18 Jul 2024 19:31:51 +0200 Subject: [PATCH 2/5] Add test case for getFailing() --- tests/ResultStores/StoredCheckResultsTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/ResultStores/StoredCheckResultsTest.php b/tests/ResultStores/StoredCheckResultsTest.php index 5e2256a2..70f0fb88 100644 --- a/tests/ResultStores/StoredCheckResultsTest.php +++ b/tests/ResultStores/StoredCheckResultsTest.php @@ -28,6 +28,17 @@ expect($storedCheckResults->containsFailingCheck())->toBeTrue(); }); +it('returns a list of failed checks', function () { + $storedCheckResults = new StoredCheckResults(new DateTime(), collect([ + makeStoredCheckResultWithStatus(Status::warning()), + makeStoredCheckResultWithStatus(Status::ok()), + ])); + $failing = $storedCheckResults->getFailing(); + expect($failing->first()->status)->toBe('warning'); + expect($failing->first()->name)->toBe('test'); + expect($failing->count())->toBe(1); +}); + it('has a method to check if all checks are good', function () { $storedCheckResults = new StoredCheckResults(new DateTime(), collect([ makeStoredCheckResultWithStatus(Status::ok()), From 023cbe37b66bd3758ed2ca9270ef39efddd85bc5 Mon Sep 17 00:00:00 2001 From: Peter Elmered Date: Sat, 20 Jul 2024 17:39:36 +0200 Subject: [PATCH 3/5] Update test snapshots --- ...cheHealthResultStoreTest__it_can_cache_check_results__1.json | 2 ++ ...eTest__it_can_retrieve_the_latest_results_from_cache__1.json | 2 ++ ...reTest__it_can_retrieve_the_latest_results_from_json__1.json | 2 ++ ...lay_the_results_as_json_when_the_request_accepts_json__1.yml | 2 ++ ...reTest__it_can_retrieve_the_latest_results_from_json__1.json | 2 ++ ...StoreTest__it_can_write_check_results_to_a_json_file__1.json | 2 ++ ...hen_the_endpoint_is_enabled_and_the_secret_is_correct__1.yml | 2 ++ ...endpoint_if_the_relevant_config_option_is_set_to_true__1.yml | 2 ++ .../ReportTest__it_can_create_create_report__1.txt | 2 +- 9 files changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/__snapshots__/CacheHealthResultStoreTest__it_can_cache_check_results__1.json b/tests/__snapshots__/CacheHealthResultStoreTest__it_can_cache_check_results__1.json index 9bf0fe4d..c246a469 100644 --- a/tests/__snapshots__/CacheHealthResultStoreTest__it_can_cache_check_results__1.json +++ b/tests/__snapshots__/CacheHealthResultStoreTest__it_can_cache_check_results__1.json @@ -1,5 +1,7 @@ { "finishedAt": 1609459200, + "status": "ok", + "failingChecks": "", "checkResults": [ { "name": "FakeUsedDiskSpace", diff --git a/tests/__snapshots__/CacheHealthResultStoreTest__it_can_retrieve_the_latest_results_from_cache__1.json b/tests/__snapshots__/CacheHealthResultStoreTest__it_can_retrieve_the_latest_results_from_cache__1.json index 9bf0fe4d..c246a469 100644 --- a/tests/__snapshots__/CacheHealthResultStoreTest__it_can_retrieve_the_latest_results_from_cache__1.json +++ b/tests/__snapshots__/CacheHealthResultStoreTest__it_can_retrieve_the_latest_results_from_cache__1.json @@ -1,5 +1,7 @@ { "finishedAt": 1609459200, + "status": "ok", + "failingChecks": "", "checkResults": [ { "name": "FakeUsedDiskSpace", diff --git a/tests/__snapshots__/EloquentHealthResultStoreTest__it_can_retrieve_the_latest_results_from_json__1.json b/tests/__snapshots__/EloquentHealthResultStoreTest__it_can_retrieve_the_latest_results_from_json__1.json index 9bf0fe4d..c246a469 100644 --- a/tests/__snapshots__/EloquentHealthResultStoreTest__it_can_retrieve_the_latest_results_from_json__1.json +++ b/tests/__snapshots__/EloquentHealthResultStoreTest__it_can_retrieve_the_latest_results_from_json__1.json @@ -1,5 +1,7 @@ { "finishedAt": 1609459200, + "status": "ok", + "failingChecks": "", "checkResults": [ { "name": "FakeUsedDiskSpace", diff --git a/tests/__snapshots__/HealthCheckJsonResultsControllerTest__it_will_display_the_results_as_json_when_the_request_accepts_json__1.yml b/tests/__snapshots__/HealthCheckJsonResultsControllerTest__it_will_display_the_results_as_json_when_the_request_accepts_json__1.yml index 830d33f5..4c98b450 100644 --- a/tests/__snapshots__/HealthCheckJsonResultsControllerTest__it_will_display_the_results_as_json_when_the_request_accepts_json__1.yml +++ b/tests/__snapshots__/HealthCheckJsonResultsControllerTest__it_will_display_the_results_as_json_when_the_request_accepts_json__1.yml @@ -1,3 +1,5 @@ finishedAt: 1609459200 +status: failing +failingChecks: FakeUsedDiskSpace checkResults: - { name: FakeUsedDiskSpace, label: 'Fake Used Disk Space', notificationMessage: 'The disk is almost full (100% used).', shortSummary: 100%, status: failed, meta: { disk_space_used_percentage: 100 } } diff --git a/tests/__snapshots__/JsonFileHealthResultStoreTest__it_can_retrieve_the_latest_results_from_json__1.json b/tests/__snapshots__/JsonFileHealthResultStoreTest__it_can_retrieve_the_latest_results_from_json__1.json index 9bf0fe4d..c246a469 100644 --- a/tests/__snapshots__/JsonFileHealthResultStoreTest__it_can_retrieve_the_latest_results_from_json__1.json +++ b/tests/__snapshots__/JsonFileHealthResultStoreTest__it_can_retrieve_the_latest_results_from_json__1.json @@ -1,5 +1,7 @@ { "finishedAt": 1609459200, + "status": "ok", + "failingChecks": "", "checkResults": [ { "name": "FakeUsedDiskSpace", diff --git a/tests/__snapshots__/JsonFileHealthResultStoreTest__it_can_write_check_results_to_a_json_file__1.json b/tests/__snapshots__/JsonFileHealthResultStoreTest__it_can_write_check_results_to_a_json_file__1.json index 9bf0fe4d..c246a469 100644 --- a/tests/__snapshots__/JsonFileHealthResultStoreTest__it_can_write_check_results_to_a_json_file__1.json +++ b/tests/__snapshots__/JsonFileHealthResultStoreTest__it_can_write_check_results_to_a_json_file__1.json @@ -1,5 +1,7 @@ { "finishedAt": 1609459200, + "status": "ok", + "failingChecks": "", "checkResults": [ { "name": "FakeUsedDiskSpace", diff --git a/tests/__snapshots__/OhDearCheckResultsTest__it_will_display_the_results_as_json_when_the_endpoint_is_enabled_and_the_secret_is_correct__1.yml b/tests/__snapshots__/OhDearCheckResultsTest__it_will_display_the_results_as_json_when_the_endpoint_is_enabled_and_the_secret_is_correct__1.yml index 830d33f5..4c98b450 100644 --- a/tests/__snapshots__/OhDearCheckResultsTest__it_will_display_the_results_as_json_when_the_endpoint_is_enabled_and_the_secret_is_correct__1.yml +++ b/tests/__snapshots__/OhDearCheckResultsTest__it_will_display_the_results_as_json_when_the_endpoint_is_enabled_and_the_secret_is_correct__1.yml @@ -1,3 +1,5 @@ finishedAt: 1609459200 +status: failing +failingChecks: FakeUsedDiskSpace checkResults: - { name: FakeUsedDiskSpace, label: 'Fake Used Disk Space', notificationMessage: 'The disk is almost full (100% used).', shortSummary: 100%, status: failed, meta: { disk_space_used_percentage: 100 } } diff --git a/tests/__snapshots__/OhDearCheckResultsTest__it_will_run_the_checks_when_visiting_the_endpoint_if_the_relevant_config_option_is_set_to_true__1.yml b/tests/__snapshots__/OhDearCheckResultsTest__it_will_run_the_checks_when_visiting_the_endpoint_if_the_relevant_config_option_is_set_to_true__1.yml index 830d33f5..4c98b450 100644 --- a/tests/__snapshots__/OhDearCheckResultsTest__it_will_run_the_checks_when_visiting_the_endpoint_if_the_relevant_config_option_is_set_to_true__1.yml +++ b/tests/__snapshots__/OhDearCheckResultsTest__it_will_run_the_checks_when_visiting_the_endpoint_if_the_relevant_config_option_is_set_to_true__1.yml @@ -1,3 +1,5 @@ finishedAt: 1609459200 +status: failing +failingChecks: FakeUsedDiskSpace checkResults: - { name: FakeUsedDiskSpace, label: 'Fake Used Disk Space', notificationMessage: 'The disk is almost full (100% used).', shortSummary: 100%, status: failed, meta: { disk_space_used_percentage: 100 } } diff --git a/tests/__snapshots__/ReportTest__it_can_create_create_report__1.txt b/tests/__snapshots__/ReportTest__it_can_create_create_report__1.txt index 38734ae2..96e56ca4 100644 --- a/tests/__snapshots__/ReportTest__it_can_create_create_report__1.txt +++ b/tests/__snapshots__/ReportTest__it_can_create_create_report__1.txt @@ -1 +1 @@ -{"finishedAt":978307200,"checkResults":[{"name":"name","label":"label","notificationMessage":"message","shortSummary":"summary","status":"ok","meta":{"name":"value"}}]} \ No newline at end of file +{"finishedAt":978307200,"status":"ok","failingChecks":"","checkResults":[{"name":"name","label":"label","notificationMessage":"message","shortSummary":"summary","status":"ok","meta":{"name":"value"}}]} \ No newline at end of file From 9601894ebcee13128e1f4482ba15bc1c62dcdb48 Mon Sep 17 00:00:00 2001 From: Peter Elmered Date: Fri, 26 Jul 2024 14:23:07 +0200 Subject: [PATCH 4/5] Update snapshot for recently added test --- ...ll_return_the_configured_status_for_a_unhealthy_check__1.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/__snapshots__/HealthCheckJsonResultsControllerTest__it_will_return_the_configured_status_for_a_unhealthy_check__1.yml b/tests/__snapshots__/HealthCheckJsonResultsControllerTest__it_will_return_the_configured_status_for_a_unhealthy_check__1.yml index 830d33f5..4c98b450 100644 --- a/tests/__snapshots__/HealthCheckJsonResultsControllerTest__it_will_return_the_configured_status_for_a_unhealthy_check__1.yml +++ b/tests/__snapshots__/HealthCheckJsonResultsControllerTest__it_will_return_the_configured_status_for_a_unhealthy_check__1.yml @@ -1,3 +1,5 @@ finishedAt: 1609459200 +status: failing +failingChecks: FakeUsedDiskSpace checkResults: - { name: FakeUsedDiskSpace, label: 'Fake Used Disk Space', notificationMessage: 'The disk is almost full (100% used).', shortSummary: 100%, status: failed, meta: { disk_space_used_percentage: 100 } } From 826f802e011d3fd55119ea6def336fde6f4ee28a Mon Sep 17 00:00:00 2001 From: Peter Elmered Date: Mon, 29 Jul 2024 16:29:52 +0200 Subject: [PATCH 5/5] Use array instead of comma separated string as failed checks list --- src/ResultStores/StoredCheckResults/StoredCheckResults.php | 2 +- ...heHealthResultStoreTest__it_can_cache_check_results__1.json | 2 +- ...Test__it_can_retrieve_the_latest_results_from_cache__1.json | 2 +- ...eTest__it_can_retrieve_the_latest_results_from_json__1.json | 2 +- ...ay_the_results_as_json_when_the_request_accepts_json__1.yml | 3 ++- ...l_return_the_configured_status_for_a_unhealthy_check__1.yml | 3 ++- ...eTest__it_can_retrieve_the_latest_results_from_json__1.json | 2 +- ...toreTest__it_can_write_check_results_to_a_json_file__1.json | 2 +- ...en_the_endpoint_is_enabled_and_the_secret_is_correct__1.yml | 3 ++- ...ndpoint_if_the_relevant_config_option_is_set_to_true__1.yml | 3 ++- .../ReportTest__it_can_create_create_report__1.txt | 2 +- 11 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/ResultStores/StoredCheckResults/StoredCheckResults.php b/src/ResultStores/StoredCheckResults/StoredCheckResults.php index e0b2a9d9..01007909 100644 --- a/src/ResultStores/StoredCheckResults/StoredCheckResults.php +++ b/src/ResultStores/StoredCheckResults/StoredCheckResults.php @@ -93,7 +93,7 @@ public function toJson(): string return (string) json_encode([ 'finishedAt' => $this->finishedAt->getTimestamp(), 'status' => $this->allChecksOk() ? 'ok' : 'failing', - 'failingChecks' => $this->getFailing()->map->name->implode(', ') ?: '', + 'failingChecks' => $this->getFailing()->map->name ?: [], 'checkResults' => $this->storedCheckResults->map(fn (StoredCheckResult $line) => $line->toArray()), ]); } diff --git a/tests/__snapshots__/CacheHealthResultStoreTest__it_can_cache_check_results__1.json b/tests/__snapshots__/CacheHealthResultStoreTest__it_can_cache_check_results__1.json index c246a469..5fc0157f 100644 --- a/tests/__snapshots__/CacheHealthResultStoreTest__it_can_cache_check_results__1.json +++ b/tests/__snapshots__/CacheHealthResultStoreTest__it_can_cache_check_results__1.json @@ -1,7 +1,7 @@ { "finishedAt": 1609459200, "status": "ok", - "failingChecks": "", + "failingChecks": [], "checkResults": [ { "name": "FakeUsedDiskSpace", diff --git a/tests/__snapshots__/CacheHealthResultStoreTest__it_can_retrieve_the_latest_results_from_cache__1.json b/tests/__snapshots__/CacheHealthResultStoreTest__it_can_retrieve_the_latest_results_from_cache__1.json index c246a469..5fc0157f 100644 --- a/tests/__snapshots__/CacheHealthResultStoreTest__it_can_retrieve_the_latest_results_from_cache__1.json +++ b/tests/__snapshots__/CacheHealthResultStoreTest__it_can_retrieve_the_latest_results_from_cache__1.json @@ -1,7 +1,7 @@ { "finishedAt": 1609459200, "status": "ok", - "failingChecks": "", + "failingChecks": [], "checkResults": [ { "name": "FakeUsedDiskSpace", diff --git a/tests/__snapshots__/EloquentHealthResultStoreTest__it_can_retrieve_the_latest_results_from_json__1.json b/tests/__snapshots__/EloquentHealthResultStoreTest__it_can_retrieve_the_latest_results_from_json__1.json index c246a469..5fc0157f 100644 --- a/tests/__snapshots__/EloquentHealthResultStoreTest__it_can_retrieve_the_latest_results_from_json__1.json +++ b/tests/__snapshots__/EloquentHealthResultStoreTest__it_can_retrieve_the_latest_results_from_json__1.json @@ -1,7 +1,7 @@ { "finishedAt": 1609459200, "status": "ok", - "failingChecks": "", + "failingChecks": [], "checkResults": [ { "name": "FakeUsedDiskSpace", diff --git a/tests/__snapshots__/HealthCheckJsonResultsControllerTest__it_will_display_the_results_as_json_when_the_request_accepts_json__1.yml b/tests/__snapshots__/HealthCheckJsonResultsControllerTest__it_will_display_the_results_as_json_when_the_request_accepts_json__1.yml index 4c98b450..5738e064 100644 --- a/tests/__snapshots__/HealthCheckJsonResultsControllerTest__it_will_display_the_results_as_json_when_the_request_accepts_json__1.yml +++ b/tests/__snapshots__/HealthCheckJsonResultsControllerTest__it_will_display_the_results_as_json_when_the_request_accepts_json__1.yml @@ -1,5 +1,6 @@ finishedAt: 1609459200 status: failing -failingChecks: FakeUsedDiskSpace +failingChecks: + - FakeUsedDiskSpace checkResults: - { name: FakeUsedDiskSpace, label: 'Fake Used Disk Space', notificationMessage: 'The disk is almost full (100% used).', shortSummary: 100%, status: failed, meta: { disk_space_used_percentage: 100 } } diff --git a/tests/__snapshots__/HealthCheckJsonResultsControllerTest__it_will_return_the_configured_status_for_a_unhealthy_check__1.yml b/tests/__snapshots__/HealthCheckJsonResultsControllerTest__it_will_return_the_configured_status_for_a_unhealthy_check__1.yml index 4c98b450..5738e064 100644 --- a/tests/__snapshots__/HealthCheckJsonResultsControllerTest__it_will_return_the_configured_status_for_a_unhealthy_check__1.yml +++ b/tests/__snapshots__/HealthCheckJsonResultsControllerTest__it_will_return_the_configured_status_for_a_unhealthy_check__1.yml @@ -1,5 +1,6 @@ finishedAt: 1609459200 status: failing -failingChecks: FakeUsedDiskSpace +failingChecks: + - FakeUsedDiskSpace checkResults: - { name: FakeUsedDiskSpace, label: 'Fake Used Disk Space', notificationMessage: 'The disk is almost full (100% used).', shortSummary: 100%, status: failed, meta: { disk_space_used_percentage: 100 } } diff --git a/tests/__snapshots__/JsonFileHealthResultStoreTest__it_can_retrieve_the_latest_results_from_json__1.json b/tests/__snapshots__/JsonFileHealthResultStoreTest__it_can_retrieve_the_latest_results_from_json__1.json index c246a469..5fc0157f 100644 --- a/tests/__snapshots__/JsonFileHealthResultStoreTest__it_can_retrieve_the_latest_results_from_json__1.json +++ b/tests/__snapshots__/JsonFileHealthResultStoreTest__it_can_retrieve_the_latest_results_from_json__1.json @@ -1,7 +1,7 @@ { "finishedAt": 1609459200, "status": "ok", - "failingChecks": "", + "failingChecks": [], "checkResults": [ { "name": "FakeUsedDiskSpace", diff --git a/tests/__snapshots__/JsonFileHealthResultStoreTest__it_can_write_check_results_to_a_json_file__1.json b/tests/__snapshots__/JsonFileHealthResultStoreTest__it_can_write_check_results_to_a_json_file__1.json index c246a469..5fc0157f 100644 --- a/tests/__snapshots__/JsonFileHealthResultStoreTest__it_can_write_check_results_to_a_json_file__1.json +++ b/tests/__snapshots__/JsonFileHealthResultStoreTest__it_can_write_check_results_to_a_json_file__1.json @@ -1,7 +1,7 @@ { "finishedAt": 1609459200, "status": "ok", - "failingChecks": "", + "failingChecks": [], "checkResults": [ { "name": "FakeUsedDiskSpace", diff --git a/tests/__snapshots__/OhDearCheckResultsTest__it_will_display_the_results_as_json_when_the_endpoint_is_enabled_and_the_secret_is_correct__1.yml b/tests/__snapshots__/OhDearCheckResultsTest__it_will_display_the_results_as_json_when_the_endpoint_is_enabled_and_the_secret_is_correct__1.yml index 4c98b450..5738e064 100644 --- a/tests/__snapshots__/OhDearCheckResultsTest__it_will_display_the_results_as_json_when_the_endpoint_is_enabled_and_the_secret_is_correct__1.yml +++ b/tests/__snapshots__/OhDearCheckResultsTest__it_will_display_the_results_as_json_when_the_endpoint_is_enabled_and_the_secret_is_correct__1.yml @@ -1,5 +1,6 @@ finishedAt: 1609459200 status: failing -failingChecks: FakeUsedDiskSpace +failingChecks: + - FakeUsedDiskSpace checkResults: - { name: FakeUsedDiskSpace, label: 'Fake Used Disk Space', notificationMessage: 'The disk is almost full (100% used).', shortSummary: 100%, status: failed, meta: { disk_space_used_percentage: 100 } } diff --git a/tests/__snapshots__/OhDearCheckResultsTest__it_will_run_the_checks_when_visiting_the_endpoint_if_the_relevant_config_option_is_set_to_true__1.yml b/tests/__snapshots__/OhDearCheckResultsTest__it_will_run_the_checks_when_visiting_the_endpoint_if_the_relevant_config_option_is_set_to_true__1.yml index 4c98b450..5738e064 100644 --- a/tests/__snapshots__/OhDearCheckResultsTest__it_will_run_the_checks_when_visiting_the_endpoint_if_the_relevant_config_option_is_set_to_true__1.yml +++ b/tests/__snapshots__/OhDearCheckResultsTest__it_will_run_the_checks_when_visiting_the_endpoint_if_the_relevant_config_option_is_set_to_true__1.yml @@ -1,5 +1,6 @@ finishedAt: 1609459200 status: failing -failingChecks: FakeUsedDiskSpace +failingChecks: + - FakeUsedDiskSpace checkResults: - { name: FakeUsedDiskSpace, label: 'Fake Used Disk Space', notificationMessage: 'The disk is almost full (100% used).', shortSummary: 100%, status: failed, meta: { disk_space_used_percentage: 100 } } diff --git a/tests/__snapshots__/ReportTest__it_can_create_create_report__1.txt b/tests/__snapshots__/ReportTest__it_can_create_create_report__1.txt index 96e56ca4..542df2df 100644 --- a/tests/__snapshots__/ReportTest__it_can_create_create_report__1.txt +++ b/tests/__snapshots__/ReportTest__it_can_create_create_report__1.txt @@ -1 +1 @@ -{"finishedAt":978307200,"status":"ok","failingChecks":"","checkResults":[{"name":"name","label":"label","notificationMessage":"message","shortSummary":"summary","status":"ok","meta":{"name":"value"}}]} \ No newline at end of file +{"finishedAt":978307200,"status":"ok","failingChecks":[],"checkResults":[{"name":"name","label":"label","notificationMessage":"message","shortSummary":"summary","status":"ok","meta":{"name":"value"}}]} \ No newline at end of file