| 82 | } |
| 83 | |
| 84 | func (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 | |
| 124 | func (p *Probe) IsHealthy() bool { |
| 125 | p.RLock() |