From 9b93c00301417904e859c4dd255f1072a6bb2132 Mon Sep 17 00:00:00 2001 From: Steffen Jost Date: Mon, 10 Jul 2023 15:28:20 +0000 Subject: [PATCH] refactor(health): show all health checks that may lead to failure (WIP) --- .../categories/health/de-de-formal.msg | 13 +++-- messages/uniworx/categories/health/en-eu.msg | 13 +++-- src/Foundation/I18n.hs | 1 + src/Handler/Health.hs | 57 ++++++++++++------- src/Model/Types/Health.hs | 2 + 5 files changed, 52 insertions(+), 34 deletions(-) diff --git a/messages/uniworx/categories/health/de-de-formal.msg b/messages/uniworx/categories/health/de-de-formal.msg index 34566d000..429a37e47 100644 --- a/messages/uniworx/categories/health/de-de-formal.msg +++ b/messages/uniworx/categories/health/de-de-formal.msg @@ -3,12 +3,13 @@ # SPDX-License-Identifier: AGPL-3.0-or-later HealthReport: Instanz-Zustand -HealthMatchingClusterConfig: Cluster-geteilte Konfiguration ist aktuell -HealthHTTPReachable: Cluster kann an der erwarteten URL über HTTP erreicht werden -HealthLDAPAdmins: Anteil der Administrator:innen mit LDAP Authentifizierung, welche tatsächlich im LDAP-Verzeichnis gefunden werden können -HealthSMTPConnect: SMTP-Server kann erreicht werden -HealthWidgetMemcached: Memcached-Server liefert Widgets korrekt aus -HealthActiveJobExecutors: Anteil der job-workers, die neue Befehle annehmen +HealthCheckMatchingClusterConfig: Cluster-geteilte Konfiguration ist aktuell +HealthCheckHTTPReachable: Cluster kann an der erwarteten URL über HTTP erreicht werden +HealthCheckLDAPAdmins: Anteil der Administrator:innen mit LDAP Authentifizierung, welche tatsächlich im LDAP-Verzeichnis gefunden werden können +HealthCheckSMTPConnect: SMTP-Server kann erreicht werden +HealthCheckWidgetMemcached: Memcached-Server liefert Widgets korrekt aus +HealthCheckActiveJobExecutors: Anteil der job-workers, die neue Befehle annehmen +HealthCheckDoesFlush: Zustandspüfung läuft durch InstanceIdentification: Instanz-Identifikation InstanceId: Instanz-Nummer ClusterId: Cluster-Nummer \ No newline at end of file diff --git a/messages/uniworx/categories/health/en-eu.msg b/messages/uniworx/categories/health/en-eu.msg index 1bf279300..948a7c4cc 100644 --- a/messages/uniworx/categories/health/en-eu.msg +++ b/messages/uniworx/categories/health/en-eu.msg @@ -3,12 +3,13 @@ # SPDX-License-Identifier: AGPL-3.0-or-later HealthReport: Health report -HealthMatchingClusterConfig: Cluster config matches -HealthHTTPReachable: Cluster can be reached under the expected URL via HTTP -HealthLDAPAdmins: Proportion of administrators with LDAP authentication that were actually found in the LDAP directory -HealthSMTPConnect: SMTP server is reachable -HealthWidgetMemcached: Memcached server is serving widgets correctly -HealthActiveJobExecutors: Proportion of job workers accepting new jobs +HealthCheckMatchingClusterConfig: Cluster config matches +HealthCheckHTTPReachable: Cluster can be reached under the expected URL via HTTP +HealthCheckLDAPAdmins: Proportion of administrators with LDAP authentication that were actually found in the LDAP directory +HealthCheckSMTPConnect: SMTP server is reachable +HealthCheckWidgetMemcached: Memcached server is serving widgets correctly +HealthCheckActiveJobExecutors: Proportion of job workers accepting new jobs +HealthCheckDoesFlush: Health reports flushes InstanceIdentification: Instance identification InstanceId: Instance id ClusterId: Cluster id diff --git a/src/Foundation/I18n.hs b/src/Foundation/I18n.hs index c82adf9d4..9f093d135 100644 --- a/src/Foundation/I18n.hs +++ b/src/Foundation/I18n.hs @@ -247,6 +247,7 @@ mkMessageVariant ''UniWorX ''PWHashMessage "messages/auth/pw-hash" "de" mkMessageVariant ''UniWorX ''ButtonMessage "messages/button" "de" mkMessageVariant ''UniWorX ''FrontendMessage "messages/frontend" "de-de-formal" +embedRenderMessage ''UniWorX ''HealthCheck id -- not possible here embedRenderMessage ''UniWorX ''AvsLicence id -- required by UniWorXAvsMessages mkMessageAddition ''UniWorX "Qualification" "messages/uniworx/categories/qualification" "de-de-formal" mkMessageAddition ''UniWorX "Avs" "messages/uniworx/categories/avs" "de-de-formal" diff --git a/src/Handler/Health.hs b/src/Handler/Health.hs index aad83d566..3fd4a1c99 100644 --- a/src/Handler/Health.hs +++ b/src/Handler/Health.hs @@ -34,7 +34,7 @@ getHealthR = do waitResult <- atomically $ maybe (pure $ Left False) (fmap (const $ Left True) . waitDelay) delay <|> (fmap Right . assertM (not. Set.null) $ readTVar reportStore) case waitResult of Left False -> sendResponseStatus noContent204 () - Left True -> sendResponseStatus internalServerError500 ("System is not generating HealthReports" :: Text) + Left True -> sendResponseStatus internalServerError500 ("System is not generating HealthReports" :: Text) -- can this ever happen after it was non-null? Right _ -> redirect HealthR Just healthReports -> do let (Max lastUpdated, Min status) = ofoldMap1 (Max *** Min . healthReportStatus) healthReports @@ -57,28 +57,41 @@ getHealthR = do setTitleI MsgHealthReport [whamlet| $newline never +

+ $case status + $of HealthSuccess + _{MsgMessageSuccess} + $of _ + _{MsgMessageError} +
$forall (_, report) <- healthReports' - $case report - $of HealthMatchingClusterConfig passed -
_{MsgHealthMatchingClusterConfig} -
#{boolSymbol passed} - $of HealthHTTPReachable (Just passed) -
_{MsgHealthHTTPReachable} -
#{boolSymbol passed} - $of HealthLDAPAdmins (Just found) -
_{MsgHealthLDAPAdmins} -
#{textPercent found 1} - $of HealthSMTPConnect (Just passed) -
_{MsgHealthSMTPConnect} -
#{boolSymbol passed} - $of HealthWidgetMemcached (Just passed) -
_{MsgHealthWidgetMemcached} -
#{boolSymbol passed} - $of HealthActiveJobExecutors (Just active) -
_{MsgHealthActiveJobExecutors} -
#{textPercent active 1} - $of _ + $with hcclass = classifyHealthReport report + $with hcstatus = HealthSuccess == healthReportStatus report + $case report + $of HealthMatchingClusterConfig passed +
_{MsgHealthCheckMatchingClusterConfig} +
#{boolSymbol passed} + $of HealthHTTPReachable (Just passed) +
_{MsgHealthCheckHTTPReachable} +
#{boolSymbol passed} + $of HealthLDAPAdmins (Just found) +
_{MsgHealthCheckLDAPAdmins} +
#{textPercent found 1} + $of HealthSMTPConnect (Just passed) +
_{MsgHealthCheckSMTPConnect} +
#{boolSymbol passed} + $of HealthWidgetMemcached (Just passed) +
_{MsgHealthCheckWidgetMemcached} +
#{boolSymbol passed} + $of HealthActiveJobExecutors (Just active) +
_{MsgHealthCheckActiveJobExecutors} +
#{textPercent active 1} + $of HealthDoesFlush mProp +
_{hcclass} +
#{boolSymbol hcstatus} + $of _ + |] provideJson healthReports provideRep . return . Builder.toLazyText $ Aeson.encodePrettyToTextBuilder healthReports @@ -105,7 +118,7 @@ getInstanceR = do provideRep . return $ tshow instanceInfo --- Most simple page for simple liveness checks +-- Most simple page for simple liveness checks, but it always delivers 200 getStatusR :: Handler Html getStatusR = do starttime <- getsYesod appStartTime diff --git a/src/Model/Types/Health.hs b/src/Model/Types/Health.hs index a1f49fad2..6528232bc 100644 --- a/src/Model/Types/Health.hs +++ b/src/Model/Types/Health.hs @@ -27,6 +27,8 @@ instance Finite HealthCheck instance Hashable HealthCheck instance NFData HealthCheck +-- embedRenderMessage ''UniWorX ''HealthCheck id -- not possible here + deriveJSON defaultOptions { constructorTagModifier = camelToPathPiece' 2 } ''HealthCheck