@@ -170,6 +170,9 @@ func (c *consulInstance) updateServices() error {
170
170
func (c * consulInstance ) convertToServers (nodes []* serviceEntry ) []configuration.ServiceServer {
171
171
servers := make ([]configuration.ServiceServer , 0 )
172
172
for _ , node := range nodes {
173
+ if ! c .validateHealthChecks (node ) {
174
+ continue
175
+ }
173
176
if node .Service .Address != "" {
174
177
servers = append (servers , configuration.ServiceServer {
175
178
Address : node .Service .Address ,
@@ -185,6 +188,61 @@ func (c *consulInstance) convertToServers(nodes []*serviceEntry) []configuration
185
188
return servers
186
189
}
187
190
191
+ func (c * consulInstance ) validateHealthChecks (node * serviceEntry ) bool {
192
+ switch * c .params .HealthCheckPolicy {
193
+ case models .ConsulHealthCheckPolicyAny :
194
+ return c .validateHealthChecksAny (node )
195
+ case models .ConsulHealthCheckPolicyAll :
196
+ return c .validateHealthChecksAll (node )
197
+ case models .ConsulHealthCheckPolicyMin :
198
+ return c .validateHealthChecksMin (node )
199
+ case models .ConsulHealthCheckPolicyNone :
200
+ return true
201
+ default :
202
+ return true
203
+ }
204
+ }
205
+
206
+ func (c * consulInstance ) validateHealthChecksAny (node * serviceEntry ) bool {
207
+ if node .Checks == nil || len (node .Checks ) == 0 {
208
+ return false
209
+ }
210
+
211
+ for _ , check := range node .Checks {
212
+ if check .Status == "passing" {
213
+ return true
214
+ }
215
+ }
216
+ return false
217
+ }
218
+
219
+ func (c * consulInstance ) validateHealthChecksAll (node * serviceEntry ) bool {
220
+ if node .Checks == nil || len (node .Checks ) == 0 {
221
+ return false
222
+ }
223
+
224
+ for _ , check := range node .Checks {
225
+ if check .Status != "passing" {
226
+ return false
227
+ }
228
+ }
229
+ return true
230
+ }
231
+
232
+ func (c * consulInstance ) validateHealthChecksMin (node * serviceEntry ) bool {
233
+ if node .Checks == nil || len (node .Checks ) == 0 {
234
+ return false
235
+ }
236
+
237
+ passing := 0
238
+ for _ , check := range node .Checks {
239
+ if check .Status == "passing" {
240
+ passing ++
241
+ }
242
+ }
243
+ return passing >= int (c .params .HealthCheckPolicyMin )
244
+ }
245
+
188
246
func (c * consulInstance ) hasServiceChanged (service string , index uint64 ) bool {
189
247
prevIndex , ok := c .prevIndexes [service ]
190
248
if ! ok {
@@ -313,6 +371,9 @@ type serviceEntry struct {
313
371
Address string
314
372
Port int
315
373
}
374
+ Checks []* struct {
375
+ Status string
376
+ }
316
377
}
317
378
318
379
type queryParams struct {
0 commit comments