Skip to content

Commit ee637be

Browse files
authored
Update circuit-breaker playground (#40)
1 parent 0b88246 commit ee637be

File tree

15 files changed

+253
-224
lines changed

15 files changed

+253
-224
lines changed

.github/workflows/bench.yml

Lines changed: 33 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -12,43 +12,27 @@ on:
1212
description: 'New Ref'
1313
required: true
1414

15-
# Cancel the workflow in progress in newer build is about to start.
16-
concurrency:
17-
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
18-
cancel-in-progress: true
19-
2015
env:
2116
GO111MODULE: "on"
2217
CACHE_BENCHMARK: "off" # Enables benchmark result reuse between runs, may skew latency results.
2318
RUN_BASE_BENCHMARK: "on" # Runs benchmark for PR base in case benchmark result is missing.
24-
GO_VERSION: 1.23.x
2519
jobs:
2620
bench:
21+
strategy:
22+
matrix:
23+
go-version: [ stable ]
2724
runs-on: ubuntu-latest
2825
steps:
29-
- name: Install Go stable
30-
if: env.GO_VERSION != 'tip'
31-
uses: actions/setup-go@v4
26+
- name: Install Go
27+
uses: actions/setup-go@v5
3228
with:
33-
go-version: ${{ env.GO_VERSION }}
34-
35-
- name: Install Go tip
36-
if: env.GO_VERSION == 'tip'
37-
run: |
38-
curl -sL https://storage.googleapis.com/go-build-snap/go/linux-amd64/$(git ls-remote https://github.com/golang/go.git HEAD | awk '{print $1;}').tar.gz -o gotip.tar.gz
39-
ls -lah gotip.tar.gz
40-
mkdir -p ~/sdk/gotip
41-
tar -C ~/sdk/gotip -xzf gotip.tar.gz
42-
~/sdk/gotip/bin/go version
43-
echo "PATH=$HOME/go/bin:$HOME/sdk/gotip/bin/:$PATH" >> $GITHUB_ENV
44-
29+
go-version: ${{ matrix.go-version }}
4530
- name: Checkout code
46-
uses: actions/checkout@v3
31+
uses: actions/checkout@v4
4732
with:
4833
ref: ${{ (github.event.inputs.new != '') && github.event.inputs.new || github.event.ref }}
49-
5034
- name: Go cache
51-
uses: actions/cache@v3
35+
uses: actions/cache@v4
5236
with:
5337
# In order:
5438
# * Module download cache
@@ -59,58 +43,49 @@ jobs:
5943
key: ${{ runner.os }}-go-cache-${{ hashFiles('**/go.sum') }}
6044
restore-keys: |
6145
${{ runner.os }}-go-cache
62-
6346
- name: Restore benchstat
64-
uses: actions/cache@v3
47+
uses: actions/cache@v4
6548
with:
6649
path: ~/go/bin/benchstat
67-
key: ${{ runner.os }}-benchstat-legacy
68-
50+
key: ${{ runner.os }}-benchstat
6951
- name: Restore base benchmark result
70-
id: base-benchmark
7152
if: env.CACHE_BENCHMARK == 'on'
72-
uses: actions/cache@v3
53+
id: benchmark-base
54+
uses: actions/cache@v4
7355
with:
7456
path: |
7557
bench-master.txt
7658
bench-main.txt
7759
# Use base sha for PR or new commit hash for master/main push in benchmark result key.
7860
key: ${{ runner.os }}-bench-${{ (github.event.pull_request.base.sha != github.event.after) && github.event.pull_request.base.sha || github.event.after }}
79-
80-
- name: Run benchmark
81-
run: |
82-
export REF_NAME=new
83-
make bench
84-
OUTPUT=$(make bench-stat-diff)
85-
echo "${OUTPUT}"
86-
echo "diff<<EOF" >> $GITHUB_OUTPUT && echo "$OUTPUT" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
87-
OUTPUT=$(make bench-stat)
88-
echo "${OUTPUT}"
89-
echo "result<<EOF" >> $GITHUB_OUTPUT && echo "$OUTPUT" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
90-
91-
- name: Run benchmark for base code
92-
if: env.RUN_BASE_BENCHMARK == 'on' && steps.base-benchmark.outputs.cache-hit != 'true' && (github.event.pull_request.base.sha != '' || github.event.inputs.old != '')
61+
- name: Checkout base code
62+
if: env.RUN_BASE_BENCHMARK == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && (github.event.pull_request.base.sha != '' || github.event.inputs.old != '')
63+
uses: actions/checkout@v4
64+
with:
65+
ref: ${{ (github.event.pull_request.base.sha != '' ) && github.event.pull_request.base.sha || github.event.inputs.old }}
66+
path: __base
67+
- name: Run base benchmark
68+
if: env.RUN_BASE_BENCHMARK == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && (github.event.pull_request.base.sha != '' || github.event.inputs.old != '')
9369
run: |
94-
git fetch origin master ${{ github.event.pull_request.base.sha }}
95-
HEAD=$(git rev-parse HEAD)
96-
git reset --hard ${{ github.event.pull_request.base.sha }}
9770
export REF_NAME=master
98-
make bench-run bench-stat
99-
git reset --hard $HEAD
100-
101-
- name: Benchmark stats
71+
cd __base
72+
make | grep bench-run && (BENCH_COUNT=5 make bench-run bench-stat && cp bench-master.txt ../bench-master.txt) || echo "No benchmarks in base"
73+
- name: Benchmark
10274
id: bench
10375
run: |
10476
export REF_NAME=new
77+
BENCH_COUNT=5 make bench
10578
OUTPUT=$(make bench-stat-diff)
106-
echo "${OUTPUT}"
107-
echo "diff<<EOF" >> $GITHUB_OUTPUT && echo "$OUTPUT" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
79+
OUTPUT="${OUTPUT//'%'/'%25'}"
80+
OUTPUT="${OUTPUT//$'\n'/'%0A'}"
81+
OUTPUT="${OUTPUT//$'\r'/'%0D'}"
82+
echo "::set-output name=diff::$OUTPUT"
10883
OUTPUT=$(make bench-stat)
109-
echo "${OUTPUT}"
110-
echo "result<<EOF" >> $GITHUB_OUTPUT && echo "$OUTPUT" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
111-
112-
- name: Comment benchmark result
113-
continue-on-error: true
84+
OUTPUT="${OUTPUT//'%'/'%25'}"
85+
OUTPUT="${OUTPUT//$'\n'/'%0A'}"
86+
OUTPUT="${OUTPUT//$'\r'/'%0D'}"
87+
echo "::set-output name=result::$OUTPUT"
88+
- name: Comment Benchmark Result
11489
uses: marocchino/sticky-pull-request-comment@v2
11590
with:
11691
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/cloc.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ jobs:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- name: Checkout code
16-
uses: actions/checkout@v3
16+
uses: actions/checkout@v4
1717
with:
1818
path: pr
1919
- name: Checkout base code
20-
uses: actions/checkout@v3
20+
uses: actions/checkout@v4
2121
with:
2222
ref: ${{ github.event.pull_request.base.sha }}
2323
path: base

.github/workflows/golangci-lint.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ jobs:
1919
name: golangci-lint
2020
runs-on: ubuntu-latest
2121
steps:
22-
- uses: actions/setup-go@v3
22+
- uses: actions/setup-go@v5
2323
with:
24-
go-version: 1.23.x
25-
- uses: actions/checkout@v2
24+
go-version: stable
25+
- uses: actions/checkout@v4
2626
- name: golangci-lint
27-
uses: golangci/golangci-lint-action@v6.1.0
27+
uses: golangci/golangci-lint-action@v6.5.0
2828
with:
2929
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
30-
version: v1.61.0
30+
version: v1.64.5
3131

3232
# Optional: working directory, useful for monorepos
3333
# working-directory: somedir

.github/workflows/gorelease.yml

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,19 @@ concurrency:
99
cancel-in-progress: true
1010

1111
env:
12-
GO_VERSION: 1.23.x
12+
GO_VERSION: stable
1313
jobs:
1414
gorelease:
1515
runs-on: ubuntu-latest
1616
steps:
17-
- name: Install Go stable
18-
if: env.GO_VERSION != 'tip'
19-
uses: actions/setup-go@v4
17+
- name: Install Go
18+
uses: actions/setup-go@v5
2019
with:
2120
go-version: ${{ env.GO_VERSION }}
22-
- name: Install Go tip
23-
if: env.GO_VERSION == 'tip'
24-
run: |
25-
curl -sL https://storage.googleapis.com/go-build-snap/go/linux-amd64/$(git ls-remote https://github.com/golang/go.git HEAD | awk '{print $1;}').tar.gz -o gotip.tar.gz
26-
ls -lah gotip.tar.gz
27-
mkdir -p ~/sdk/gotip
28-
tar -C ~/sdk/gotip -xzf gotip.tar.gz
29-
~/sdk/gotip/bin/go version
30-
echo "PATH=$HOME/go/bin:$HOME/sdk/gotip/bin/:$PATH" >> $GITHUB_ENV
3121
- name: Checkout code
32-
uses: actions/checkout@v3
22+
uses: actions/checkout@v4
3323
- name: Gorelease cache
34-
uses: actions/cache@v3
24+
uses: actions/cache@v4
3525
with:
3626
path: |
3727
~/go/bin/gorelease

.github/workflows/release-assets.yml

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,18 @@ on:
88
- created
99
env:
1010
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
11-
GO_VERSION: 1.23.x
11+
GO_VERSION: stable
1212
jobs:
1313
build:
1414
name: Upload Release Assets
1515
runs-on: ubuntu-latest
1616
steps:
17-
- name: Install Go stable
18-
if: env.GO_VERSION != 'tip'
19-
uses: actions/setup-go@v4
17+
- name: Install Go
18+
uses: actions/setup-go@v5
2019
with:
2120
go-version: ${{ env.GO_VERSION }}
22-
- name: Install Go tip
23-
if: env.GO_VERSION == 'tip'
24-
run: |
25-
curl -sL https://storage.googleapis.com/go-build-snap/go/linux-amd64/$(git ls-remote https://github.com/golang/go.git HEAD | awk '{print $1;}').tar.gz -o gotip.tar.gz
26-
ls -lah gotip.tar.gz
27-
mkdir -p ~/sdk/gotip
28-
tar -C ~/sdk/gotip -xzf gotip.tar.gz
29-
~/sdk/gotip/bin/go version
30-
echo "PATH=$HOME/go/bin:$HOME/sdk/gotip/bin/:$PATH" >> $GITHUB_ENV
3121
- name: Checkout code
32-
uses: actions/checkout@v3
22+
uses: actions/checkout@v4
3323
- name: Build artifacts
3424
run: |
3525
make release-assets
@@ -41,6 +31,14 @@ jobs:
4131
asset_path: ./linux_amd64.tar.gz
4232
asset_name: linux_amd64.tar.gz
4333
asset_content_type: application/tar+gzip
34+
- name: Upload linux_amd64_dbg.tar.gz
35+
if: hashFiles('linux_amd64_dbg.tar.gz') != ''
36+
uses: actions/upload-release-asset@v1
37+
with:
38+
upload_url: ${{ github.event.release.upload_url }}
39+
asset_path: ./linux_amd64_dbg.tar.gz
40+
asset_name: linux_amd64_dbg.tar.gz
41+
asset_content_type: application/tar+gzip
4442
- name: Upload linux_arm64.tar.gz
4543
if: hashFiles('linux_arm64.tar.gz') != ''
4644
uses: actions/upload-release-asset@v1

.github/workflows/test-unit.yml

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,25 @@ concurrency:
1515
env:
1616
GO111MODULE: "on"
1717
RUN_BASE_COVERAGE: "on" # Runs test for PR base in case base test coverage is missing.
18-
COV_GO_VERSION: 1.22.x # Version of Go to collect coverage
18+
COV_GO_VERSION: stable # Version of Go to collect coverage
1919
TARGET_DELTA_COV: 90 # Target coverage of changed lines, in percents
2020
jobs:
2121
test:
2222
strategy:
2323
matrix:
24-
go-version: [ 1.22.x, 1.23.x ]
24+
go-version: [ stable, oldstable ]
2525
runs-on: ubuntu-latest
2626
steps:
27-
- name: Install Go stable
28-
if: matrix.go-version != 'tip'
29-
uses: actions/setup-go@v4
27+
- name: Install Go
28+
uses: actions/setup-go@v5
3029
with:
3130
go-version: ${{ matrix.go-version }}
3231

33-
- name: Install Go tip
34-
if: matrix.go-version == 'tip'
35-
run: |
36-
curl -sL https://storage.googleapis.com/go-build-snap/go/linux-amd64/$(git ls-remote https://github.com/golang/go.git HEAD | awk '{print $1;}').tar.gz -o gotip.tar.gz
37-
ls -lah gotip.tar.gz
38-
mkdir -p ~/sdk/gotip
39-
tar -C ~/sdk/gotip -xzf gotip.tar.gz
40-
~/sdk/gotip/bin/go version
41-
echo "PATH=$HOME/go/bin:$HOME/sdk/gotip/bin/:$PATH" >> $GITHUB_ENV
42-
4332
- name: Checkout code
44-
uses: actions/checkout@v3
33+
uses: actions/checkout@v4
4534

4635
- name: Go cache
47-
uses: actions/cache@v3
36+
uses: actions/cache@v4
4837
with:
4938
# In order:
5039
# * Module download cache
@@ -59,7 +48,7 @@ jobs:
5948
- name: Restore base test coverage
6049
id: base-coverage
6150
if: matrix.go-version == env.COV_GO_VERSION && github.event.pull_request.base.sha != ''
62-
uses: actions/cache@v2
51+
uses: actions/cache@v4
6352
with:
6453
path: |
6554
unit-base.txt
@@ -130,7 +119,7 @@ jobs:
130119

131120
- name: Upload code coverage
132121
if: matrix.go-version == env.COV_GO_VERSION
133-
uses: codecov/codecov-action@v1
122+
uses: codecov/codecov-action@v5
134123
with:
135-
file: ./unit.coverprofile
124+
files: ./unit.coverprofile
136125
flags: unittests

.golangci.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ linters-settings:
1212
threshold: 100
1313
misspell:
1414
locale: US
15-
unused:
16-
check-exported: false
1715
unparam:
1816
check-exported: true
1917

@@ -29,9 +27,10 @@ linters:
2927
- gochecknoglobals
3028
- funlen
3129
- gocognit
30+
- intrange
31+
- copyloopvar
3232
- lll
3333
- gochecknoglobals
34-
- gomnd
3534
- wrapcheck
3635
- paralleltest
3736
- forbidigo
@@ -46,16 +45,14 @@ linters:
4645
- dupword
4746
- depguard
4847
- tagalign
49-
- execinquery
5048
- mnd
5149
- testifylint
52-
- intrange
50+
- recvcheck
5351

5452
issues:
5553
exclude-use-default: false
5654
exclude-rules:
5755
- linters:
58-
- gomnd
5956
- mnd
6057
- goconst
6158
- noctx
@@ -75,4 +72,3 @@ issues:
7572
- revive
7673
text: "unused-parameter: parameter"
7774

78-

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#GOLANGCI_LINT_VERSION := "v1.61.0" # Optional configuration to pinpoint golangci-lint version.
1+
#GOLANGCI_LINT_VERSION := "v1.64.5" # Optional configuration to pinpoint golangci-lint version.
22

33
# The head of Makefile determines location of dev-go to include standard targets.
44
GO ?= go

_examples/circuit-breaker-playground/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22

33
This application simulates circuit breaker reaction on an unhealthy application.
44

5-
You can control server latency with Up/Down buttons in real time.
5+
You can control server latency with Up/Down buttons in real time.
6+
7+
Quit with "Q".
8+
9+
Run in proper terminal with TTY.

0 commit comments

Comments
 (0)