Resiliency patterns for golang

Overview

go-resiliency

Build Status GoDoc Code of Conduct

Resiliency patterns for golang. Based in part on Hystrix, Semian, and others.

Currently implemented patterns include:

  • circuit-breaker (in the breaker directory)
  • semaphore (in the semaphore directory)
  • deadline/timeout (in the deadline directory)
  • batching (in the batcher directory)
  • retriable (in the retrier directory)

Follows semantic versioning using https://gopkg.in/ - import from gopkg.in/eapache/go-resiliency.v1 for guaranteed API stability.

Issues
  • Protect PRNG against simultaneous access. (Was: Add setter for Retrier random number generator)

    Protect PRNG against simultaneous access. (Was: Add setter for Retrier random number generator)

    Thank you for this project.

    This pull request adds SetRand(Float64er) in order to provides ones own random number generator.

    Uses cases include the following:

    • providing an alternate RNG.
    • providing a thread safe RNG.
    opened by gglachant 5
  • Add RunCtx to retrier

    Add RunCtx to retrier

    Thank you very much for this project. I often use retrier package.

    There are three changes

    • Add retrier.RunCtx(ctx context.Context work func(ctx context.Context) error) error.
    • Add test for retrier.RunCtx
    • Modify travis.yml for supporting only 1.7 and 1.10

    fixes #16

    opened by tukeJonny 4
  • Please release again

    Please release again

    The sole current release is missing years of fixes

    opened by nim-nim 4
  • added leaky bucket rate limiter

    added leaky bucket rate limiter

    First off thanks for the awesome project. Really love your clean style.

    I needed a leaky bucket rate limiter to add to a client i was building and thought that this might be useful to this repo.

    This isn't the final commit as we need to add README to package, just wanting to see if this is something you are interested in?

    opened by kidtronnix 3
  • retrier: support context.Context

    retrier: support context.Context

    Greetings, I'm a user of the retry package, mostly because it's a dependency of the shopify/sarama package - so it's already available in my vendor directory.

    I'm interested to know if you'd be in favor of supporting the context package for retrier -- I imagine the interface to be

    (r *Retrier) RunCtx(context.Context, func() error) error
    

    This would allow the retrier to exit early if the provided context is cancelled prior to the retry wait period. If the context is cancelled, it could return the error of the last failure, or ctx.Err() - I'm unsure which would be preferred.

    I would imagine the retier struct would need to be extended to include a time.Timer that would be reset upon each call to Run/RunCtx, and each iteration of attempts.

    Exiting early would me a simple matter of having a function such as

    // sleep will return true if the time channel has a message
    // sent on it before the context expires
    //
    // accepts a <-chan time.Time for more deterministic testing
    // no need to rely on the runtime to fire the timer
    func sleep(ctx context.Context, t <-chan time.Time) bool {
        select {
        case <-t:
            return true
        case <-ctx.Done():
            return false
        }
    }
    

    the call to time.Sleep() could then be replaced with

    if !sleep(ctx, r.timer.C) {
        // return previous error?
        return ctx.Err()
    }
    

    The implementation of Run could then become

    (r *Retrier) Run(fn func() error) error {
        return r.RunCtx(context.Background(), fn)
    }
    

    This approach is seen in the standard library, and is a nice way to maintain backwards compatibility.

    Please let me know your thoughts - if this is something you'd approve of, I could likely find the time to do the implementation.

    opened by chrisguiney 3
  • add log for breaker error

    add log for breaker error

    I feel that you should add log when some occur in function func (b *Breaker) doWork(state uint32, work func() error) error, it convenient for us to find error

    opened by Stephan14 2
  • Retry / Backoff

    Retry / Backoff

    As the title says, it might be handy to have a package for retriable actions with different back-off strategies etc.

    enhancement 
    opened by eapache 2
  • goroutine leak in Deadline.Run

    goroutine leak in Deadline.Run

    if Run() returns ErrTimeOut, the work function would block on sending to channel result.

    opened by evolsnow 2
  • Please release again!

    Please release again!

    Missing a number of new fixes, including RunCtx :)

    opened by wtachau 2
  • clarify deadline example

    clarify deadline example

    The deadline example says: // check stopper function and give up if timed out What is the stopper function? Stopper is a channel. Perhaps the example can be expanded to show how to do this?

    opened by predmond 2
  • Implements error unwrapping for error checking

    Implements error unwrapping for error checking

    Issue related to #28

    Note: this might need further consideration, since errors.Is was added on Go 1.13, which might be a breaking change for clients.

    I have considered other alternative like using optional parameters & build constraints so this will only be compiled for the correct Go version, but that requires much bigger changes.

    opened by taufik-rama 0
  • Error unwrapping for `retrier/`

    Error unwrapping for `retrier/`

    Hello, I've some feature request regarding the title

    Basically, I propose we use errors.Is() from standard library to check for the blacklisted/whitelisted error types (the err == pass bit)

    https://github.com/eapache/go-resiliency/blob/b98ce2825f7276cc41027348986a241ef5d62fd8/retrier/classifier.go#L40-L44

    The reason is that currently we need to specify exacly what the error kind is, without checking if an error actually contains ("wraps") another error which are actually listed

    Say we've implements a custom type to better handle specific error usecase

    type HTTPError struct {
        error
        host string
        path string
    }
    
    func (h HTTPError) Error() string { // implements Go's `error` type
        return "failed on HTTP request to " + h.host + h.path + " reason: " + h.error.Error()
    }
    
    func (h HTTPError) Unwrap() error { // will be called from standard library error unwrapping
        return h.error
    }
    

    And that the error type wraps context.Canceled, which is defined as a blacklist

    
    backoff := // ...
    class := retrier.BlacklistClassifier{
    	context.Canceled,
    }
    retry := retrier.New(backoff, class)
    
    // ...
    
    retry.Run(func() {
        // ...
        return HTTPError{error: context.Cancelled, host: "...", path: "..."}
    })
    

    The blacklist check would fail, because err == pass won't know what the "internal" value of the error actually is

    opened by taufik-rama 0
  • avoid goroutine leak

    avoid goroutine leak

    opened by 1046102779 1
Releases(v1.2.0)
  • v1.2.0(Jun 14, 2019)

    Note: This release requires Golang at least 1.7, which is higher than the previous release. All the versions being dropped are multiple years old and no longer supported upstream, so I'm not counting this as a breaking change.

    • Add RunCtx method on Retrier to support running with a context.
    • Ensure the Retrier's use of random numbers is concurrency-safe.
    • Bump CI to ensure we support newer Golang versions.
    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Mar 26, 2018)

Owner
Evan Huus
Amateur musician and actor. Trying to end up with the right regrets.
Evan Huus
Standard Go Project Layout

This is a basic layout for Go application projects. It's not an official standard defined by the core Go dev team; however, it is a set of common historical and emerging project layout patterns in the Go ecosystem. Some of these patterns are more popular than others. It also has a number of small enhancements along with several supporting directories common to any large enough real world application.

null 25.1k Jul 17, 2021
The gofinder program is an acme user interface to search through Go projects.

The gofinder program is an acme user interface to search through Go projects.

null 22 Jun 13, 2021
CRAQ (Chain Replication with Apportioned Queries) in Go

CRAQ is a replication protocol that allows reads from any replica while still maintaining strong consistency. CRAQ should provide better read throughput than Raft and Paxos. Read performance grows linearly with the number of nodes added to the system. Network chatter is significantly lower compared to Raft and Paxos.

Des Preston 83 Jul 4, 2021
🌍 📋 A web dashboard to inspect Terraform States

?? ?? A web dashboard to inspect Terraform States

Camptocamp 1.3k Jul 24, 2021
[TOOL, CLI] - Filter and examine Go type structures, interfaces and their transitive dependencies and relationships. Export structural types as TypeScript value object or bare type representations.

typex Examine Go types and their transitive dependencies. Export results as TypeScript value objects (or types) declaration. Installation go get -u gi

Daniel T. Gorski 132 May 23, 2021
Enforce git message commit consistency

Gommit Gommit analyze commits messages to ensure they follow defined pattern. Summary Setup Usage Practical Usage Third Part Libraries Setup Download

Anthony HAMON 94 Jul 23, 2021
ghw - Golang HardWare discovery/inspection library

ghw - Golang HardWare discovery/inspection library ghw is a small Golang library providing hardware inspection and discovery for Linux and Windows.

Jay Pipes 1k Jul 17, 2021
Minimalistic, pluggable Golang evloop/timer handler with dependency-injection

Anagent Minimalistic, pluggable Golang evloop/timer handler with dependency-injection - based on codegangsta/inject - go-macaron/inject and chuckpresl

Ettore Di Giacinto 13 Jun 22, 2021
A Go project template

Powered by Cookiecutter, Cookiecutter Golang is a framework for jumpstarting production-ready go projects quickly.

Luis Morales 463 Jul 16, 2021
Support CI generation of SBOMs via golang tooling.

Software Package Data Exchange (SPDX) is an open standard for communicating software bill of materials (SBOM) information that supports accurate identification of software components, explicit mapping of relationships between components, and the association of security and licensing information with each component.

SPDX 45 Jul 21, 2021
James is your butler and helps you to create, build, debug, test and run your Go projects

go-james James is your butler and helps you to create, build, debug, test and run your Go projects. When you often create new apps using Go, it quickl

Pieter Claerhout 43 Jun 15, 2021
dockerized (postgres + nginx + golang + react)

PNGR Stack Dockerized (postgres + nginx + golang + react) starter kit Only implements basic user signup, session management, and a toy post type to de

Karl Keefer 584 Jul 1, 2021
Record CS knowlegement with XMind, version 2.0. 使用 XMind 记录 Linux 操作系统,网络,C++,Golang 以及数据库的一些设计

Psyduck 另一个用 XMind 记录 CS 基础问题的地方,同样提供了 .xmind 源文件以及导出的 .pdf 文件,XMind 版本为「XMind 2020」。 在 2020 年时,曾花了约 2 个月的时间整理了第一份 XMind 知识库: ZeroMind。 之所以额外创建一个 Repo

SmartKeyerror 3.5k Jul 24, 2021
Auto-evaluate your Golang code.

Ginker Ginker is a GUI application for auto-evaluating your Golang code. It allows you to write and run Golang code on the fly and it will help you to

nkoporec 8 Jun 23, 2021