github.com/gravitational/teleport/api@v0.0.0-20240507183017-3110591cbafc/breaker/doc.go (about)

     1  // Copyright 2022 Gravitational, 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  
    15  // Package breaker implements a circuit breaker.
    16  //
    17  // Circuit breaker watches the error from executed functions and according to the configured TripFn will
    18  // allow requests for a period of time before slowly allowing a few.
    19  //
    20  // Circuit breakers start in StateStandby first, observing errors and watching Metrics.
    21  //
    22  // Once the Circuit breaker TripFn returns true, it enters the StateTripped, where it blocks all traffic and returns
    23  // ErrStateTripped for the configured Config.TrippedPeriod.
    24  //
    25  // After the Config.TrippedPeriod passes, Circuit breaker enters StateRecovering, during that state it will
    26  // either transition to StateStandby after the Config.RecoveryLimit is met or StateTripped if the Config.Recover TripFn
    27  // is satisfied.
    28  //
    29  // It is possible to define actions on transitions between states:
    30  //
    31  // * Config.OnTripped is called on transition (StateStandby -> StateTripped)
    32  // * Config.OnStandBy is called on transition (StateRecovering -> StateStandby)
    33  package breaker