Documentation ¶
Overview ¶
Copyright (C) 2019-2024 vdaas.org vald team <vald@vdaas.org>
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
https://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) 2019-2024 vdaas.org vald team <vald@vdaas.org>
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
https://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) 2019-2024 vdaas.org vald team <vald@vdaas.org>
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
https://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) 2019-2024 vdaas.org vald team <vald@vdaas.org>
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
https://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) 2019-2024 vdaas.org vald team <vald@vdaas.org>
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
https://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) 2019-2024 vdaas.org vald team <vald@vdaas.org>
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
https://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 ¶
- func Metrics(context.Context) (ms map[string]map[State]int64)
- type BreakerOption
- func WithClosedErrorRate(f float32) BreakerOption
- func WithClosedErrorTripper(tp Tripper) BreakerOption
- func WithClosedRefreshTimeout(timeout string) BreakerOption
- func WithHalfOpenErrorRate(f float32) BreakerOption
- func WithHalfOpenErrorTripper(tp Tripper) BreakerOption
- func WithMinSamples(min int64) BreakerOption
- func WithOpenTimeout(timeout string) BreakerOption
- type CircuitBreaker
- type Counter
- type Option
- type State
- type Tripper
- type TripperFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BreakerOption ¶
type BreakerOption func(*breaker) error
func WithClosedErrorRate ¶
func WithClosedErrorRate(f float32) BreakerOption
WithClosedErrorRate returns an option that sets error rate when breaker state is "Closed". The rate is expected to be between 0 and 1.0. When the rate is exceeded, the breaker state will be changed from "Closed" to "Open".
func WithClosedErrorTripper ¶
func WithClosedErrorTripper(tp Tripper) BreakerOption
WithClosedErrorTripper returns an option that sets whether it should trip when in "Closed" state.
func WithClosedRefreshTimeout ¶
func WithClosedRefreshTimeout(timeout string) BreakerOption
WithClosedRefreshTimeout returns an option that sets the timeout of "Closed" state. After this period, the counter will be refreshed.
func WithHalfOpenErrorRate ¶
func WithHalfOpenErrorRate(f float32) BreakerOption
WithHalfOpenErrorRate returns an option that sets error rate when breaker state is "HalfOpen". The rate is expected to be between 0 and 1.0. When the rate is exceeded, the breaker state will be changed from "HalfOpen" to "Open".
func WithHalfOpenErrorTripper ¶
func WithHalfOpenErrorTripper(tp Tripper) BreakerOption
WithHalfOpenErrorTripper returns an option that sets whether it should trip when in "Half-Open" state.
func WithMinSamples ¶
func WithMinSamples(min int64) BreakerOption
WithMinSamples returns an option that sets minimum sample count.
func WithOpenTimeout ¶
func WithOpenTimeout(timeout string) BreakerOption
WithOpenTimeout returns an option that sets the timeout of "Open" state. After this period, the state will be changed from "Open" to "HalfOpen".
type CircuitBreaker ¶
type CircuitBreaker interface {
Do(ctx context.Context, key string, fn func(ctx context.Context) (any, error)) (val any, err error)
}
CircuitBreaker is a state machine to prevent doing processes that are likely to fail.
func NewCircuitBreaker ¶
func NewCircuitBreaker(opts ...Option) (CircuitBreaker, error)
NewCircuitBreaker returns CircuitBreaker object if no error occurs.
type Option ¶
type Option func(*breakerManager) error
func WithBreakerOpts ¶
func WithBreakerOpts(opts ...BreakerOption) Option
type Tripper ¶
Tripper is a function type to determine if the CircuitBreaker should trip.
func NewRateTripper ¶
type TripperFunc ¶
func (TripperFunc) ShouldTrip ¶
func (f TripperFunc) ShouldTrip(c Counter) bool