Check performs the health checks. An error is only returned in the case of a misconfiguration or if any one of the Checkers returns an error.
()
| 49 | // returned in the case of a misconfiguration or if |
| 50 | // any one of the Checkers returns an error. |
| 51 | func (c Checkup) Check() ([]types.Result, error) { |
| 52 | if c.ConcurrentChecks == 0 { |
| 53 | c.ConcurrentChecks = DefaultConcurrentChecks |
| 54 | } |
| 55 | if c.ConcurrentChecks < 0 { |
| 56 | return nil, fmt.Errorf("invalid value for ConcurrentChecks: %d (must be set > 0)", |
| 57 | c.ConcurrentChecks) |
| 58 | } |
| 59 | |
| 60 | results := make([]types.Result, len(c.Checkers)) |
| 61 | errs := make(types.Errors, len(c.Checkers)) |
| 62 | throttle := make(chan struct{}, c.ConcurrentChecks) |
| 63 | wg := sync.WaitGroup{} |
| 64 | |
| 65 | for i, checker := range c.Checkers { |
| 66 | throttle <- struct{}{} |
| 67 | wg.Add(1) |
| 68 | go func(i int, checker Checker) { |
| 69 | results[i], errs[i] = checker.Check() |
| 70 | <-throttle |
| 71 | wg.Done() |
| 72 | }(i, checker) |
| 73 | } |
| 74 | wg.Wait() |
| 75 | |
| 76 | if !c.Timestamp.IsZero() { |
| 77 | for i := range results { |
| 78 | results[i].Timestamp = c.Timestamp.UTC().UnixNano() |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | if !errs.Empty() { |
| 83 | return results, errs |
| 84 | } |
| 85 | |
| 86 | for _, service := range c.Notifiers { |
| 87 | err := service.Notify(results) |
| 88 | if err != nil { |
| 89 | log.Printf("ERROR sending notifications for %s: %s", service.Type(), err) |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | return results, nil |
| 94 | } |
| 95 | |
| 96 | // CheckAndStore performs health checks and immediately |
| 97 | // stores the results to the configured storage if there |