-
Notifications
You must be signed in to change notification settings - Fork 438
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: return entry when request is blocked. #494
base: master
Are you sure you want to change the base?
Changes from all commits
5888fee
165ca74
b9b2a79
81af6f2
744fddb
0852527
07a5fdc
647d16d
45477fd
eb4bd7f
3f72de3
2908042
5489fe8
592fe60
8a7a883
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,73 +7,66 @@ on: | |
branches: "*" | ||
|
||
jobs: | ||
|
||
build: | ||
name: ${{ matrix.os }} - Go ${{ matrix.go_version }} | ||
runs-on: ubuntu-latest | ||
strategy: | ||
# If you want to matrix build , you can append the following list. | ||
# If you want to matrix build , you can append the following list. | ||
matrix: | ||
go_version: | ||
- 1.13 | ||
- 1.14 | ||
- 1.18 | ||
- 1.19 | ||
os: | ||
- ubuntu-latest | ||
|
||
steps: | ||
- name: Set up Go ${{ matrix.go_version }} | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ${{ matrix.go_version }} | ||
id: go | ||
|
||
- name: Set up Go ${{ matrix.go_version }} | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ${{ matrix.go_version }} | ||
id: go | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v2 | ||
|
||
- name: Cache build dependence | ||
uses: actions/cache@v2 | ||
with: | ||
# Cache | ||
path: ~/go/pkg/mod | ||
# Cache key | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
# An ordered list of keys to use for restoring the cache if no cache hit occurred for key | ||
restore-keys: ${{ runner.os }}-go- | ||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install goimports | ||
run: go get golang.org/x/tools/cmd/goimports | ||
- name: Cache build dependence | ||
uses: actions/cache@v2 | ||
with: | ||
# Cache | ||
path: ~/go/pkg/mod | ||
# Cache key | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
# An ordered list of keys to use for restoring the cache if no cache hit occurred for key | ||
restore-keys: ${{ runner.os }}-go- | ||
|
||
- name: Install go ci lint | ||
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.27.0 | ||
- name: Install go ci lint | ||
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.50.1 | ||
|
||
- name: Run Linter | ||
run: golangci-lint run --timeout=10m -v --disable-all --enable=govet --enable=staticcheck --enable=ineffassign --enable=misspell | ||
- name: Run Linter | ||
run: golangci-lint run --timeout=10m -v --disable-all --enable=govet --enable=staticcheck --enable=ineffassign --enable=misspell | ||
|
||
- name: Test | ||
run: | | ||
diff -u <(echo -n) <(gofmt -d -s .) | ||
diff -u <(echo -n) <(goimports -d .) | ||
Comment on lines
-55
to
-56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this two line will help to locate code which needs to be re-format |
||
go test -v -race ./... -coverprofile=coverage.txt -covermode=atomic | ||
cd ./pkg/datasource/consul | ||
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic | ||
cd ../etcdv3 | ||
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic | ||
cd ../k8s | ||
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic | ||
cd ../nacos | ||
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic | ||
cd ../apollo | ||
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic | ||
cd ../../adapters/echo | ||
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic | ||
cd ../gear | ||
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic | ||
cd ../gin | ||
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic | ||
cd ../grpc | ||
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic | ||
cd ../micro | ||
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic | ||
- name: Coverage | ||
run: bash <(curl -s https://codecov.io/bash) | ||
- name: Test | ||
run: | | ||
go test -v -race ./... -coverprofile=coverage.txt -covermode=atomic | ||
cd ./pkg/datasource/consul | ||
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic | ||
cd ../etcdv3 | ||
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic | ||
cd ../k8s | ||
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic | ||
cd ../nacos | ||
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic | ||
cd ../apollo | ||
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic | ||
cd ../../adapters/echo | ||
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic | ||
cd ../gear | ||
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic | ||
cd ../gin | ||
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic | ||
cd ../grpc | ||
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic | ||
cd ../micro | ||
go test -race -count=1 ./... -coverprofile=coverage.txt -covermode=atomic | ||
- name: Coverage | ||
run: bash <(curl -s https://codecov.io/bash) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,7 +176,7 @@ func entry(resource string, options *EntryOptions) (*base.SentinelEntry, *base.B | |
// must finish the lifecycle of r. | ||
blockErr := base.NewBlockErrorFromDeepCopy(r.BlockError()) | ||
e.Exit() | ||
return nil, blockErr | ||
return e, blockErr | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why return entry when blocked, and what do you need to do with it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leave the control to caller, and they can do any thing like log/metrics/fallback which needs entry info. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand. Do you want to get an EntryContext through entry? or you can give an example, how do you do things like log/metric/fallback There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is the use case. Right now, there is no way to fetch entry info like ResourceType/TrafficType... when error happens. |
||
} | ||
|
||
return e, nil | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,6 @@ | |
package hotspot | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"reflect" | ||
"strconv" | ||
|
@@ -101,13 +100,8 @@ type Rule struct { | |
} | ||
|
||
func (r *Rule) String() string { | ||
b, err := json.Marshal(r) | ||
if err != nil { | ||
// Return the fallback string | ||
return fmt.Sprintf("{Id:%s, Resource:%s, MetricType:%+v, ControlBehavior:%+v, ParamIndex:%d, ParamKey:%s, Threshold:%d, MaxQueueingTimeMs:%d, BurstCount:%d, DurationInSec:%d, ParamsMaxCapacity:%d, SpecificItems:%+v}", | ||
r.ID, r.Resource, r.MetricType, r.ControlBehavior, r.ParamIndex, r.ParamKey, r.Threshold, r.MaxQueueingTimeMs, r.BurstCount, r.DurationInSec, r.ParamsMaxCapacity, r.SpecificItems) | ||
} | ||
return string(b) | ||
return fmt.Sprintf("{Id:%s, Resource:%s, MetricType:%+v, ControlBehavior:%+v, ParamIndex:%d, ParamKey:%s, Threshold:%d, MaxQueueingTimeMs:%d, BurstCount:%d, DurationInSec:%d, ParamsMaxCapacity:%d, SpecificItems:%+v}", | ||
r.ID, r.Resource, r.MetricType, r.ControlBehavior, r.ParamIndex, r.ParamKey, r.Threshold, r.MaxQueueingTimeMs, r.BurstCount, r.DurationInSec, r.ParamsMaxCapacity, r.SpecificItems) | ||
Comment on lines
+103
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe it is more appropriate to keep the original There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. json marshal do not support map[interface{}]int64 like SpecificItems |
||
} | ||
func (r *Rule) ResourceName() string { | ||
return r.Resource | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
goimports check is necessary to format code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's recommend to use linters in golangci-lint.
https://golangci-lint.run/usage/linters/#goimports