healthcheck

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Copyright (c) 2016-2019 Uber Technologies, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) 2016-2019 Uber Technologies, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) 2016-2019 Uber Technologies, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) 2016-2019 Uber Technologies, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) 2016-2019 Uber Technologies, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) 2016-2019 Uber Technologies, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) 2016-2019 Uber Technologies, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) 2016-2019 Uber Technologies, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) 2016-2019 Uber Technologies, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BinaryFilter

type BinaryFilter struct {
	Healthy bool
}

BinaryFilter is a filter which can be switched to all-healthy vs. all-unhealthy.

func NewBinaryFilter

func NewBinaryFilter() *BinaryFilter

NewBinaryFilter returns a new BinaryFilter that defaults to all-healthy.

func (BinaryFilter) Run

func (f BinaryFilter) Run(addrs stringset.Set) stringset.Set

Run runs the filter.

type Checker

type Checker interface {
	Check(ctx context.Context, addr string) error
}

Checker runs a health check against an address.

func Default

func Default(tls *tls.Config) Checker

Default returns a Checker which makes a GET request against /health.

type Filter

type Filter interface {
	Run(addrs stringset.Set) stringset.Set
}

Filter filters out unhealthy hosts from a host list.

func NewFilter

func NewFilter(config FilterConfig, checker Checker) Filter

NewFilter creates a new Filter. Filter is stateful -- consecutive runs are required to detect healthy / unhealthy hosts.

type FilterConfig

type FilterConfig struct {
	// Fails is the number of consecutive failed health checks for a host to be
	// considered unhealthy.
	Fails int `yaml:"fails"`

	// Passes is the number of consecutive passed health checks for a host to be
	// considered healthy.
	Passes int `yaml:"passes"`

	// Timeout of each individual health check.
	Timeout time.Duration `yaml:"timeout"`
}

FilterConfig defines configuration for Filter.

type IdentityFilter

type IdentityFilter struct{}

IdentityFilter is a Filter which never filters out any addresses.

func (IdentityFilter) Failed

func (f IdentityFilter) Failed(addr string)

Failed is a no-op.

func (IdentityFilter) Run

func (f IdentityFilter) Run(addrs stringset.Set) stringset.Set

Run runs the filter.

type List

type List interface {
	hostlist.List
	Failed(addr string)
}

List is a hostlist.List which can be passively health checked.

func NoopFailed

func NoopFailed(list hostlist.List) List

NoopFailed converts a hostlist.List to a List by making the Failed method a no-op. Useful for using a Monitor in place of a Passive.

type ManualFilter

type ManualFilter struct {
	Unhealthy stringset.Set
}

ManualFilter is a Filter whose unhealthy hosts can be manually changed.

func NewManualFilter

func NewManualFilter() *ManualFilter

NewManualFilter returns a new ManualFilter.

func (*ManualFilter) Run

func (f *ManualFilter) Run(addrs stringset.Set) stringset.Set

Run removes any unhealthy addrs.

type Monitor

type Monitor struct {
	// contains filtered or unexported fields
}

Monitor performs active health checks asynchronously. Can be used in as a hostlist.List.

func NewMonitor

func NewMonitor(config MonitorConfig, hosts hostlist.List, filter Filter) *Monitor

NewMonitor monitors the health of hosts using filter.

func (*Monitor) Resolve

func (m *Monitor) Resolve() stringset.Set

Resolve returns the latest healthy hosts.

func (*Monitor) Stop

func (m *Monitor) Stop()

Stop stops the monitor.

type MonitorConfig

type MonitorConfig struct {
	Interval time.Duration `yaml:"interval"`
}

MonitorConfig defines configuration for Monitor.

type Passive

type Passive struct {
	// contains filtered or unexported fields
}

Passive wraps a passive health check and can be used as a hostlist.List. See PassiveFilter for passive health check documenation.

func NewPassive

func NewPassive(hosts hostlist.List, filter PassiveFilter) *Passive

NewPassive returns a new Passive.

func (*Passive) Failed

func (p *Passive) Failed(addr string)

Failed marks a request to addr as failed.

func (*Passive) Resolve

func (p *Passive) Resolve() stringset.Set

Resolve returns the latest healthy hosts. If all hosts are unhealthy, returns all hosts.

type PassiveFilter

type PassiveFilter interface {
	Filter
	Failed(addr string)
}

PassiveFilter filters unhealthy hosts passively by tracking failed requests to hosts. Clients are responsible for marking failures from individual hosts, and PassiveFilter updates which hosts are unhealthy. It is recommended that clients only mark failures for network errors, not HTTP errors.

func NewPassiveFilter

func NewPassiveFilter(config PassiveFilterConfig, clk clock.Clock) PassiveFilter

NewPassiveFilter creates a new PassiveFilter.

type PassiveFilterConfig

type PassiveFilterConfig struct {
	// Fails is the number of failed requests that must occur during the FailTimeout
	// period for a host to be marked as unhealthy.
	Fails int `yaml:"fails"`

	// FailTimeout is the window of time during which Fails must occur for a host
	// to be marked as unhealthy.
	//
	// FailTimeout is also the time for which a server is marked unhealthy.
	FailTimeout time.Duration `yaml:"fail_timeout"`
}

PassiveFilterConfig defines configuration for PassiveFilter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL