kubeprobes/query.go
Piotr Icikowski d33e9f19ea
refactor(kubeprobes): refactor code
- refactored types, interfaces, options etc.
- added new options dedicated for `StatefulProbe`s
2024-03-01 23:32:11 +01:00

40 lines
635 B
Go

package kubeprobes
import "sync"
type statusQuery struct {
allGreen bool
mux sync.Mutex
wg sync.WaitGroup
}
func (sq *statusQuery) isAllGreen() bool {
sq.wg.Wait()
sq.mux.Lock()
defer sq.mux.Unlock()
return sq.allGreen
}
func newStatusQuery(probes []ProbeFunction) *statusQuery {
sq := &statusQuery{
allGreen: true,
mux: sync.Mutex{},
wg: sync.WaitGroup{},
}
sq.wg.Add(len(probes))
for _, probe := range probes {
probe := probe
go func() {
defer sq.wg.Done()
if err := probe(); err != nil {
sq.mux.Lock()
sq.allGreen = false
sq.mux.Unlock()
}
}()
}
return sq
}