55 lines
969 B
Go
55 lines
969 B
Go
package kubeprobes
|
|
|
|
import "sync"
|
|
|
|
type statusQuery struct {
|
|
ok bool
|
|
passed []statusEntry
|
|
failed []statusEntry
|
|
|
|
mux sync.Mutex
|
|
wg sync.WaitGroup
|
|
}
|
|
|
|
type statusEntry struct {
|
|
Probe string `json:"probe"`
|
|
Status error `json:"status,omitempty"`
|
|
}
|
|
|
|
func (sq *statusQuery) wait() {
|
|
sq.wg.Wait()
|
|
}
|
|
|
|
func newStatusQuery(probes []Probe) *statusQuery {
|
|
sq := &statusQuery{
|
|
ok: true,
|
|
passed: make([]statusEntry, 0, len(probes)),
|
|
failed: make([]statusEntry, 0, len(probes)),
|
|
mux: sync.Mutex{},
|
|
wg: sync.WaitGroup{},
|
|
}
|
|
|
|
sq.wg.Add(len(probes))
|
|
for _, probe := range probes {
|
|
probe := probe
|
|
go func() {
|
|
defer sq.wg.Done()
|
|
sq.mux.Lock()
|
|
if err := probe.status(); err != nil {
|
|
sq.ok = false
|
|
sq.failed = append(sq.failed, statusEntry{
|
|
Probe: probe.name(),
|
|
Status: err,
|
|
})
|
|
} else {
|
|
sq.passed = append(sq.passed, statusEntry{
|
|
Probe: probe.name(),
|
|
})
|
|
}
|
|
sq.mux.Unlock()
|
|
}()
|
|
}
|
|
|
|
return sq
|
|
}
|