This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tracer | |
import ( | |
"io" | |
opentracing "github.com/opentracing/opentracing-go" | |
"github.com/prometheus/client_golang/prometheus" | |
jaegercfg "github.com/uber/jaeger-client-go/config" | |
"github.com/uber/jaeger-client-go/rpcmetrics" | |
jprom "github.com/uber/jaeger-lib/metrics/prometheus" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# www.fduran.com | |
# Linux check DNS cache snooping | |
# check if somedomain (try popular ones like google.com etc) is cached in a dns_server | |
# with nslookup | |
nslookup -norecurse somedomain dns_server | |
# with dig | |
dig @dns_server somedomain A +norecurse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
breaker := newCircuitBreaker() | |
transport := http.NewTransport(breaker) | |
req := http.NewRequest( | |
http.WithRoundTripper(transport), | |
) | |
client := http.NewClient(req) | |
_ = http.NewStoreService(client) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Store responsible for storing the user. | |
func (s *StoreService) Store(user *User) error { | |
userResourceV2 := fmt.Sprintf("%s/%s/%s", usersAPIV2, user.Email, user.Country) | |
res, err := s.client.Get(userResourceV2) | |
if err != nil { | |
if err == srv.ErrCircuitBreakerOpen { | |
// fallback to apiv1 | |
userResourceV1 := fmt.Sprintf("%s?%s&%s", usersAPIV1, user.Email, user.Country) | |
res, err = s.client.Get(userResourceV1) | |
if err != nil { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Do is a convenient method for executing http requests. | |
func (r *Request) Do(method, url, contentType string, body io.Reader) (*http.Response, error) { | |
req, err := http.NewRequest(method, url, body) | |
if err != nil { | |
return nil, fmt.Errorf("failed to create request %v: ", err) | |
} | |
req.Header.Set("Content-Type", contentType) | |
ctx, cancel := context.WithTimeout(req.Context(), reqTimeout) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ( | |
// RequestOption is the request options. | |
RequestOption func(*Request) | |
// Request is the application http request. | |
Request struct { | |
client *http.Client | |
} | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ( | |
// Breaker is the http circuit breaker. | |
Breaker interface { | |
// Execute runs the given request if the circuit breaker is closed or half-open states. | |
// An error is instantly returned when the circuit breaker is tripped. | |
Execute(fn func() (interface{}, error)) | |
} | |
// Transport is the application http transport. | |
Transport struct { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type RoundTripper interface { | |
RoundTrip(*Request) (*Response, error) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Store responsible for storing the user. | |
func (s *StoreService) Store(user *User) error { | |
userResourceV2 := fmt.Sprintf("%s/%s/%s", usersAPIV2, user.Email, user.Country) | |
res, err := s.client.Get(userResourceV2) | |
if err != nil { | |
return fmt.Errorf("failed to fetch user: %v", err) | |
} | |
// code omitted | |