From 3547d3e0c11bc9f24ce6cffc915a3cae7e8c1746 Mon Sep 17 00:00:00 2001 From: Norwin Roosen Date: Sun, 10 Feb 2019 13:46:30 +0100 Subject: [PATCH] log result summary of all checks --- core/checkrunner.go | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/core/checkrunner.go b/core/checkrunner.go index 9f78d90..d03200d 100644 --- a/core/checkrunner.go +++ b/core/checkrunner.go @@ -23,6 +23,16 @@ func (results BoxCheckResults) Size(statusToCheck []string) int { } func (results BoxCheckResults) Log() { + // collect statistics for summary print + boxesSkipped := 0 + boxesWithIssues := 0 + boxesWithoutIssues := 0 + failedChecks := 0 + errorsByEvent := map[string]int{} + for event, _ := range checkers { + errorsByEvent[event] = 0 + } + for box, boxResults := range results { boxLog := log.WithFields(log.Fields{ "boxId": box.Id, @@ -40,14 +50,40 @@ func (results BoxCheckResults) Log() { } else { resultLog.Warnf("%s: %s", box.Name, r) countErr++ + errorsByEvent[r.Event]++ } } + if len(boxResults) == 0 { boxLog.Infof("%s: no checks defined", box.Name) + boxesSkipped++ } else if countErr == 0 { boxLog.Infof("%s: all is fine!", box.Name) + boxesWithoutIssues++ + } else { + // we logged the error(s) already + boxesWithIssues++ + failedChecks += countErr } } + + // print summary + boxesChecked := boxesWithIssues + boxesWithoutIssues + if boxesChecked > 1 { + summaryLog := log.WithFields(log.Fields{ + "boxesChecked": boxesChecked, + "boxesSkipped": boxesSkipped, // boxes are also skipped when they never submitted any measurements before! + "boxesOk": boxesWithoutIssues, + "boxesErr": boxesWithIssues, + "failedChecks": failedChecks, + "errorsByEvent": errorsByEvent, + }) + summaryLog.Infof( + "check summary: %v of %v checked boxes are fine (%v had no checks)!", + boxesWithoutIssues, + boxesChecked, + boxesSkipped) + } } func CheckBoxes(boxLocalConfs map[string]*NotifyConfig) (BoxCheckResults, error) { @@ -56,7 +92,7 @@ func CheckBoxes(boxLocalConfs map[string]*NotifyConfig) (BoxCheckResults, error) results := BoxCheckResults{} errs := []string{} - // TODO: check boxes in parallel, capped at 5 at once + // @TODO: check boxes in parallel, capped at 5 at once. and/or rate limit? for boxId, localConf := range boxLocalConfs { boxLogger := log.WithField("boxId", boxId) boxLogger.Info("checking box for events") @@ -77,6 +113,7 @@ func CheckBoxes(boxLocalConfs map[string]*NotifyConfig) (BoxCheckResults, error) } func checkBox(boxId string, defaultConf *NotifyConfig) (*Box, []CheckResult, error) { + // @FIXME: core package should be independent of viper! osem := NewOsemClient(viper.GetString("api")) // get box data