MCPcopy
hub / github.com/cortexlabs/cortex / StartProbing

Method StartProbing

pkg/probe/probe.go:84–122  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

82}
83
84func (p *Probe) StartProbing() chan struct{} {
85 stop := make(chan struct{})
86
87 time.AfterFunc(time.Duration(p.InitialDelaySeconds)*time.Second, func() {
88 ticker := time.NewTicker(time.Duration(p.PeriodSeconds) * time.Second)
89
90 successCount := int32(0)
91 failureCount := int32(0)
92
93 for {
94 select {
95 case <-stop:
96 return
97 case <-ticker.C:
98 healthy := p.probeContainer()
99 if healthy {
100 successCount++
101 failureCount = 0
102 } else {
103 failureCount++
104 successCount = 0
105 }
106
107 p.Lock()
108
109 if successCount >= p.SuccessThreshold {
110 p.healthy = true
111 } else if failureCount >= p.FailureThreshold {
112 p.healthy = false
113 }
114 p.hasRunOnce = true
115
116 p.Unlock()
117 }
118 }
119 })
120
121 return stop
122}
123
124func (p *Probe) IsHealthy() bool {
125 p.RLock()

Callers 7

TestHandlerSuccessHTTPFunction · 0.95
TestProbeHTTPFailureFunction · 0.95
TestProbeHTTPSuccessFunction · 0.95
TestHandlerSuccessTCPFunction · 0.80
TestDefaultProbeSuccessFunction · 0.80
TestDefaultProbeFailureFunction · 0.80
mainFunction · 0.80

Calls 1

probeContainerMethod · 0.95

Tested by 6

TestHandlerSuccessHTTPFunction · 0.76
TestProbeHTTPFailureFunction · 0.76
TestProbeHTTPSuccessFunction · 0.76
TestHandlerSuccessTCPFunction · 0.64
TestDefaultProbeSuccessFunction · 0.64
TestDefaultProbeFailureFunction · 0.64