Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add error and latency-based routing control (part 2) #128

Closed
Closed
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
1d84eed
fix: added command for test coverage
polsar88 Aug 13, 2024
22c7514
feat: upgraded Go version
polsar88 Aug 14, 2024
36447a3
fix: typos
polsar88 Aug 14, 2024
339e1c9
fix: comment
polsar88 Aug 15, 2024
0cf2b4c
fix: TODO
polsar88 Aug 15, 2024
888ac69
feat: add instructions on generating HTML coverage report
polsar88 Aug 17, 2024
90b15e0
feat: add HealthCheck method for Ethereum client
polsar88 Aug 17, 2024
3bc2508
fix: rename method
polsar88 Aug 17, 2024
0fcaa79
feat: initial implementation of latency checker
polsar88 Aug 17, 2024
62455a3
fix: add a TODO
polsar88 Aug 17, 2024
510bf97
fix: access to failure counts map is now thread-safe
polsar88 Aug 17, 2024
6b8fbc1
fix: refactor anonymous function into `runCheckForMethod` method
polsar88 Aug 18, 2024
6c02c16
fix: further refactoring
polsar88 Aug 18, 2024
c40eb46
fix: refactoring
polsar88 Aug 18, 2024
6b8ee86
fix: formatting
polsar88 Aug 18, 2024
54c7455
feat: wire routing configs into HealthCheckManager
polsar88 Aug 18, 2024
c5d84e0
fix: refactoring & additional validation
polsar88 Aug 18, 2024
faeec65
fix: add a test
polsar88 Aug 18, 2024
e2cc632
fix: refactoring
polsar88 Aug 18, 2024
9601d2e
feat: add latency override logic
polsar88 Aug 18, 2024
cc33e27
fix: add latency config tests
polsar88 Aug 18, 2024
af55fcf
feat: wire RoutingConfig into LatencyChecker
polsar88 Aug 18, 2024
e204d9f
fix: un-export LatencyConfig methods
polsar88 Aug 18, 2024
67003be
fix: LatencyCheck's ShouldRun filed is now initialized based on the r…
polsar88 Aug 18, 2024
51445ca
feat: latency checks for all configured methods are now run in parallel
polsar88 Aug 18, 2024
4a2174f
fix: lint
polsar88 Aug 18, 2024
ac32a35
fix: add comment
polsar88 Aug 19, 2024
a93a55d
feat: initial implementation of `LatencyCheck.IsPassing` method
polsar88 Aug 25, 2024
ae69578
feat: add tests for LatencyCheck
polsar88 Aug 25, 2024
13adab3
fix: lint
polsar88 Aug 25, 2024
c78b389
fix: add a TODO
polsar88 Aug 25, 2024
0ff2006
feat: wire active method calls into HealthCheckManager
polsar88 Aug 25, 2024
995d7bc
feat: add flag to indicate whether to use active or passive latency c…
polsar88 Aug 25, 2024
a252f50
fix: refactoring
polsar88 Aug 25, 2024
48e3251
feat: implement record request logic
polsar88 Aug 25, 2024
17231d3
feat: add tests
polsar88 Aug 25, 2024
60e6a92
feat: add tests
polsar88 Aug 25, 2024
9659e29
fix: `eth_chainId` method is now allowed in the config
polsar88 Aug 25, 2024
672a7f7
feat: complete routing config parsing and initialization
polsar88 Aug 26, 2024
3c6076e
feat: add tests
polsar88 Aug 26, 2024
11ac885
feat: create error and latency circuit breaker interfaces
polsar88 Aug 26, 2024
689fd35
feat: wire routing config to circuit breakers
polsar88 Aug 27, 2024
4b77e05
feat: add initial implementation of SlidingWindow interface
polsar88 Aug 27, 2024
62a64b8
fix: rename methods
polsar88 Aug 27, 2024
029372a
fix: The RecordRequest method now records every request
polsar88 Aug 27, 2024
ca43269
fix: circuit breaker design improvements
polsar88 Aug 27, 2024
66694b0
fix: circuit breakers are now thread-safe
polsar88 Aug 27, 2024
3dbbbde
fix: errors and latencies are now properly recorded
polsar88 Aug 27, 2024
57837ba
feat: add Prometheus instrumentation to RecordRequest method
polsar88 Aug 27, 2024
91dc2a0
fix: formatting
polsar88 Aug 27, 2024
1026517
fix: TODOs
polsar88 Aug 27, 2024
7c15233
fix: errors circuit breaker IsOpen method now works correctly
polsar88 Aug 27, 2024
a53a9a8
fix: TODOs
polsar88 Aug 27, 2024
b13e997
fix: rename methods for indicate they are only used for passive healt…
polsar88 Aug 27, 2024
49d13d8
fix: TODOs
polsar88 Aug 27, 2024
0055b31
feat: each JSON RPC subrequest now counts toward the error rate
polsar88 Aug 27, 2024
3fe3258
fix: rename Latency method to RecordLatency
polsar88 Aug 27, 2024
08b0341
fix: update a TODO
polsar88 Aug 28, 2024
8b97890
feat: add `failsafe-go` package
polsar88 Aug 29, 2024
2d297af
fix: an upstream can now be marked unhealthy only for the RPC methods…
polsar88 Aug 29, 2024
3f9684f
feat: high latency rate is now used to determine whether latency circ…
polsar88 Aug 29, 2024
3f318d2
feat: wired `alwaysRoute` routing config setting to PriorityRoundRobi…
polsar88 Aug 29, 2024
d4d421d
feat: add support for indicating the reason why an upstream is unhealthy
polsar88 Aug 30, 2024
d399d59
feat: routing algorithm to route to an unhealthy upstream
polsar88 Aug 30, 2024
b7ae0b3
feat: `failsafe-go` is now used for latency circuit breaking
polsar88 Aug 30, 2024
fd726d7
feat: `failsafe-go` is now used for error circuit breaking
polsar88 Aug 30, 2024
73edd03
fix: change generic type for circuit breaker
polsar88 Aug 30, 2024
0e66d3a
fix: remove sliding window
polsar88 Aug 30, 2024
f3a07e7
fix: update comments
polsar88 Aug 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.21
go-version: 1.22
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.21
go-version: 1.22
- uses: actions/checkout@v3
- name: Cache Go modules
uses: actions/cache@v2
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ linters:
- wsl

run:
go: '1.21'
go: '1.22'
timeout: 5m
issues-exit-code: 1
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# syntax=docker/dockerfile:1.4

FROM golang:1.21-alpine3.20 as builder
FROM golang:1.22.6-alpine3.20 as builder

RUN apk add --no-cache make libc6-compat build-base

Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,21 @@ go build -v ./...
go test -v ./...
```

Running all tests that match regexp `TestHealthCheckManager`:
```sh
go test -v -run TestHealthCheckManager ./...
```

To measure test code coverage, install the following tool and run the above `go test` command with the `-cover` flag:
```sh
go get golang.org/x/tools/cmd/cover
```

You can generate HTML coverage report and open it in your browser by running:
```sh
go test -v -coverprofile=cover.out ./... && go tool cover -html=cover.out
```

#### Linting

This project relies on [golangci-lint](https://github.com/golangci/golangci-lint) for linting. You can set up an [integration with your code editor](https://golangci-lint.run/usage/integrations/) to run lint checks locally.
Expand Down
40 changes: 8 additions & 32 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ toolchain go1.22.3
require (
github.com/ethereum/go-ethereum v1.12.0
github.com/go-redis/cache/v9 v9.0.0
github.com/go-redis/redismock/v9 v9.0.3
github.com/google/go-cmp v0.6.0
github.com/prometheus/client_golang v1.14.0
github.com/redis/go-redis/v9 v9.0.5
Expand All @@ -22,66 +23,41 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chigopher/pathlib v0.19.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-ole/go-ole v1.2.1 // indirect
github.com/go-redis/redismock/v9 v9.0.3 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/holiman/uint256 v1.2.2-0.20230321075855-87b91420868c // indirect
github.com/huandu/xstrings v1.5.0 // indirect
github.com/iancoleman/strcase v0.3.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jinzhu/copier v0.4.0 // indirect
github.com/klauspost/compress v1.17.2 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.39.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/rs/zerolog v1.33.0 // indirect
github.com/sagikazarmark/locafero v0.6.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/cobra v1.8.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.19.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tklauser/go-sysconf v0.3.5 // indirect
github.com/tklauser/numcpus v0.2.2 // indirect
github.com/vektra/mockery/v2 v2.43.2 // indirect
github.com/vmihailenco/go-tinylfu v0.2.2 // indirect
github.com/vmihailenco/msgpack/v5 v5.3.4 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/mod v0.19.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/term v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/tools v0.23.0 // indirect
golang.org/x/tools/cmd/cover v0.1.0-deprecated // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
Loading
Loading