func (c Controller) runChecksFor(categories []string) ([]fthealth.CheckResult, map[string][]fthealth.CheckResult) { var checks []fthealth.Check categorisedChecks := make(map[string][]*fthealth.Check) categorisedResults := make(map[string][]fthealth.CheckResult) for _, c := range categories { categorisedChecks[c] = []*fthealth.Check{} categorisedResults[c] = []fthealth.CheckResult{} } var acks map[string]string = make(map[string]string) for _, mService := range c.registry.measuredServices() { if !containsAtLeastOneFrom(categories, mService.service.Categories) { continue } check := NewServiceHealthCheck(*mService.service, c.registry.checker()) checks = append(checks, check) for _, category := range mService.service.Categories { if categoryChecks, exists := categorisedChecks[category]; exists { categorisedChecks[category] = append(categoryChecks, &check) } } ack := c.registry.getAck(mService.service.ServiceKey) if ack != "" { acks[mService.service.Name] = ack } } healthChecks := fthealth.RunCheck("Forced check run", "", true, checks...).Checks var result []fthealth.CheckResult for _, ch := range healthChecks { if ack, found := acks[ch.Name]; found { ch.Ack = ack } result = append(result, ch) for category, checks := range categorisedChecks { for _, check := range checks { if check.Name == ch.Name { categorisedResults[category] = append(categorisedResults[category], ch) } } } } updateCachedAndBufferedHealth(c.registry, healthChecks) return result, categorisedResults }
func (r *EtcdServiceRegistry) scheduleCheck(mService *MeasuredService, timer *time.Timer) { // wait select { case <-mService.cachedHealth.terminate: return case <-timer.C: } // run check healthResult := fthealth.RunCheck(mService.service.Name, fmt.Sprintf("Checks the health of %v", mService.service.Name), true, NewServiceHealthCheck(*mService.service, r._checker)) healthResult.Checks[0].Ack = mService.service.Ack r.updateCachedAndBufferedHealth(mService, &healthResult) waitDuration := r.findShortestPeriod(*mService.service) go r.scheduleCheck(mService, time.NewTimer(waitDuration)) }