github.com/globocom/reliable-request
go get github.com/globocom/reliable-request

github.com/globocom/reliable-request

A golang opinionated library to provide reliable request using hystrix-go, go-cache, and go-resiliency.

by globocom

v0.0.2 (see all)License:BSD-3-Clause
go get github.com/globocom/reliable-request
Readme

Reliablereq

Build Status Go Report Card

A golang opinionated library to provide reliable request using hystrix-go, go-cache, and go-resiliency.

When you do a Get, it provides:

Usage

req := reliablereq.NewReliableRequest()
req.TTLCache = 1 * time.Second
req.EnableStaleCache = false
body, err := req.Get("http://example.com/list")

// passing authentication/authorization bearer token
req := reliablereq.NewReliableRequest()
req.Headers = map[string]string{"Authorization": "Bearer foobar"}
body, err := req.Get("http://example.com/list")

// creating a different hystrix command
req := reliablereq.NewReliableRequest()
req.UpdateHystrixConfig("api2command", hystrix.CommandConfig{
        Timeout:                800 + 100,
        MaxConcurrentRequests:  100,
        ErrorPercentThreshold:  50,
        RequestVolumeThreshold: 20,
        SleepWindow:            5000,
    })
 body, err := req.Get("http://example.com/list")

WARNING

Make sure you use different Hystrix commands for other endpoint APIs or separated Circuit Breaker contexts, otherwise, an endpoint may open the circuit breaker and all other requests will fail.

Opinionated defaults

// reliable request defaults
rr := ReliableRequest{
  EnableCache:        true,
  TTLCache:           1 * time.Minute,
  EnableStaleCache:   true,
  TTLStaleCache:      24 * time.Hour,
}
// hystrix
var defaultHystrixConfiguration = hystrix.CommandConfig{
  Timeout:                800 + 100, // the defaultTimeout http client + a small gap
  MaxConcurrentRequests:  100,
  ErrorPercentThreshold:  50,
  RequestVolumeThreshold: 3,
  SleepWindow:            5000,
}
// http client
client := &http.Client{
  Transport: &http.Transport{
    DialContext: (&net.Dialer{
      Timeout:   800 * time.Millisecond,
      KeepAlive: 30 * time.Second,
    }).DialContext,
    MaxIdleConns:        100,
    MaxIdleConnsPerHost: 100,
    TLSHandshakeTimeout: 800 * time.Millisecond,
  },
  Timeout: 800 * time.Millisecond,
}

Future

  • provide a proxy to setup hystrix
  • add retry logic (by go-resiliency)
  • add more examples, like token header requests and more
  • discuss the adopted defaults
  • discuss whether async hystrix is better (Go instead of Do)
  • understand and test the simultaneous client req hystrix config to see its implications
  • add go api documentation
  • add hooks (callbacks) to provides means for metrics gathering
  • add more HTTP verbs?
  • add load stress

GitHub Stars

12

LAST COMMIT

2yrs ago

MAINTAINERS

0

CONTRIBUTORS

5

OPEN ISSUES

1

OPEN PRs

1
VersionTagPublished
v0.0.2
2yrs ago
v0.0.1
3yrs ago
No alternatives found
No tutorials found
Add a tutorial