github.com/uber/kraken@v0.1.4/lib/healthcheck/passive.go (about) 1 // Copyright (c) 2016-2019 Uber Technologies, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 package healthcheck 15 16 import ( 17 "github.com/uber/kraken/lib/hostlist" 18 "github.com/uber/kraken/utils/stringset" 19 ) 20 21 // Passive wraps a passive health check and can be used as a hostlist.List. See 22 // PassiveFilter for passive health check documenation. 23 type Passive struct { 24 hosts hostlist.List 25 filter PassiveFilter 26 } 27 28 // NewPassive returns a new Passive. 29 func NewPassive(hosts hostlist.List, filter PassiveFilter) *Passive { 30 return &Passive{hosts, filter} 31 } 32 33 // Resolve returns the latest healthy hosts. If all hosts are unhealthy, returns 34 // all hosts. 35 func (p *Passive) Resolve() stringset.Set { 36 all := p.hosts.Resolve() 37 healthy := p.filter.Run(all) 38 if len(healthy) == 0 { 39 return all 40 } 41 return healthy 42 } 43 44 // Failed marks a request to addr as failed. 45 func (p *Passive) Failed(addr string) { 46 p.filter.Failed(addr) 47 }