2023-07-21 23:12:18 +02:00
|
|
|
package kubeprobes
|
|
|
|
|
|
|
|
import "sync"
|
|
|
|
|
|
|
|
type statusQuery struct {
|
2024-03-02 23:55:28 +01:00
|
|
|
ok bool
|
|
|
|
passed []statusEntry
|
|
|
|
failed []statusEntry
|
|
|
|
|
|
|
|
mux sync.Mutex
|
|
|
|
wg sync.WaitGroup
|
|
|
|
}
|
|
|
|
|
|
|
|
type statusEntry struct {
|
|
|
|
Probe string `json:"probe"`
|
|
|
|
Status error `json:"status,omitempty"`
|
2023-07-21 23:12:18 +02:00
|
|
|
}
|
|
|
|
|
2024-03-02 23:55:28 +01:00
|
|
|
func (sq *statusQuery) wait() {
|
2023-07-21 23:12:18 +02:00
|
|
|
sq.wg.Wait()
|
|
|
|
}
|
|
|
|
|
2024-03-03 23:24:42 +01:00
|
|
|
func newStatusQuery(probes []Probe) *statusQuery {
|
2023-07-21 23:12:18 +02:00
|
|
|
sq := &statusQuery{
|
2024-03-02 23:55:28 +01:00
|
|
|
ok: true,
|
|
|
|
passed: make([]statusEntry, 0, len(probes)),
|
|
|
|
failed: make([]statusEntry, 0, len(probes)),
|
|
|
|
mux: sync.Mutex{},
|
|
|
|
wg: sync.WaitGroup{},
|
2023-07-21 23:12:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sq.wg.Add(len(probes))
|
|
|
|
for _, probe := range probes {
|
|
|
|
probe := probe
|
|
|
|
go func() {
|
|
|
|
defer sq.wg.Done()
|
2024-03-02 23:55:28 +01:00
|
|
|
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(),
|
|
|
|
})
|
2023-07-21 23:12:18 +02:00
|
|
|
}
|
2024-03-02 23:55:28 +01:00
|
|
|
sq.mux.Unlock()
|
2023-07-21 23:12:18 +02:00
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
return sq
|
|
|
|
}
|