github.com/uber/kraken@v0.1.4/lib/healthcheck/testing.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 "github.com/uber/kraken/utils/stringset"
    17  
    18  // IdentityFilter is a Filter which never filters out any addresses.
    19  type IdentityFilter struct{}
    20  
    21  // Run runs the filter.
    22  func (f IdentityFilter) Run(addrs stringset.Set) stringset.Set {
    23  	return addrs.Copy()
    24  }
    25  
    26  // Failed is a no-op.
    27  func (f IdentityFilter) Failed(addr string) {}
    28  
    29  // ManualFilter is a Filter whose unhealthy hosts can be manually changed.
    30  type ManualFilter struct {
    31  	Unhealthy stringset.Set
    32  }
    33  
    34  // NewManualFilter returns a new ManualFilter.
    35  func NewManualFilter() *ManualFilter {
    36  	return &ManualFilter{stringset.New()}
    37  }
    38  
    39  // Run removes any unhealthy addrs.
    40  func (f *ManualFilter) Run(addrs stringset.Set) stringset.Set {
    41  	return addrs.Sub(f.Unhealthy)
    42  }
    43  
    44  // BinaryFilter is a filter which can be switched to all-healthy vs. all-unhealthy.
    45  type BinaryFilter struct {
    46  	Healthy bool
    47  }
    48  
    49  // NewBinaryFilter returns a new BinaryFilter that defaults to all-healthy.
    50  func NewBinaryFilter() *BinaryFilter {
    51  	return &BinaryFilter{true}
    52  }
    53  
    54  // Run runs the filter.
    55  func (f BinaryFilter) Run(addrs stringset.Set) stringset.Set {
    56  	if f.Healthy {
    57  		return addrs.Copy()
    58  	}
    59  	return stringset.New()
    60  }