github.com/uber/kraken@v0.1.4/lib/healthcheck/config.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 "time" 18 ) 19 20 // FilterConfig defines configuration for Filter. 21 type FilterConfig struct { 22 // Fails is the number of consecutive failed health checks for a host to be 23 // considered unhealthy. 24 Fails int `yaml:"fails"` 25 26 // Passes is the number of consecutive passed health checks for a host to be 27 // considered healthy. 28 Passes int `yaml:"passes"` 29 30 // Timeout of each individual health check. 31 Timeout time.Duration `yaml:"timeout"` 32 } 33 34 func (c *FilterConfig) applyDefaults() { 35 if c.Fails == 0 { 36 c.Fails = 3 37 } 38 if c.Passes == 0 { 39 c.Passes = 2 40 } 41 if c.Timeout == 0 { 42 c.Timeout = 3 * time.Second 43 } 44 } 45 46 // MonitorConfig defines configuration for Monitor. 47 type MonitorConfig struct { 48 Interval time.Duration `yaml:"interval"` 49 } 50 51 func (c *MonitorConfig) applyDefaults() { 52 if c.Interval == 0 { 53 c.Interval = 10 * time.Second 54 } 55 } 56 57 // PassiveFilterConfig defines configuration for PassiveFilter. 58 type PassiveFilterConfig struct { 59 // Fails is the number of failed requests that must occur during the FailTimeout 60 // period for a host to be marked as unhealthy. 61 Fails int `yaml:"fails"` 62 63 // FailTimeout is the window of time during which Fails must occur for a host 64 // to be marked as unhealthy. 65 // 66 // FailTimeout is also the time for which a server is marked unhealthy. 67 FailTimeout time.Duration `yaml:"fail_timeout"` 68 } 69 70 func (c *PassiveFilterConfig) applyDefaults() { 71 if c.Fails == 0 { 72 c.Fails = 3 73 } 74 if c.FailTimeout == 0 { 75 c.FailTimeout = 5 * time.Minute 76 } 77 }