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

Fix: fix AssembleMsg bad use, pass []any as any in variadic function #1964

Merged
merged 4 commits into from
Jul 15, 2022

Conversation

alingse
Copy link
Contributor

@alingse alingse commented Jul 10, 2022

What this PR does:

i am write a linter to lint bad use pass []any as any in variadic function and check the top go repo.

the AssembleMsg func code is here https://github.com/alibaba/sentinel-golang/blob/2af86608857884da543eabe7941b61d60edc51a4/logging/logging.go#L152-L208

func AssembleMsg(depth int, logLevel, msg string, err error, keysAndValues ...interface{}) string {
        ....
	kvLen := len(keysAndValues)
	if kvLen&1 != 0 {
		sb.WriteByte(',')
		sb.WriteByte('"')
		sb.WriteString("kvs")
		sb.WriteByte('"')
		sb.WriteByte(':')
		s := fmt.Sprintf("%+v", keysAndValues)
		data := toSafeJSONString(s)
		sb.Write(data)
	} else if kvLen != 0 {
		for i := 0; i < kvLen; {
			k := keysAndValues[i]
			v := keysAndValues[i+1]
        ....

if someone call DubboLoggerWrapper.Info with Info("msg", "name", "hello", "address", "world") for log,

it will pass whole []any as any into func AssembleMsg,

and got kvs: ["name", "hello", "adress", "world"] instead of "name":"hello", "address":"world"

Which issue(s) this PR fixes:
Fixes #

You should pay attention to items below to ensure your pr passes our ci test
We do not merge pr with ci tests failed

  • All ut passed (run 'go test ./...' in project root)
  • After go-fmt ed , run 'go fmt project' using goland.
  • Golangci-lint passed, run 'sudo golangci-lint run' in project root.
  • After import formatted, (using imports-formatter to run 'imports-formatter .' in project root, to format your import blocks, mentioned in CONTRIBUTING.md above)
  • Your new-created file needs to have apache license at the top, like other existed file does.
  • All integration test passed. You can run integration test locally (with docker env). Clone our dubbo-go-samples project and replace the go.mod to your dubbo-go, and run 'sudo sh start_integration_test.sh' at root of samples project root. (M1 Slice is not Support)

dependabot bot and others added 4 commits June 10, 2022 13:07
….0 (apache#1929)

Bumps [github.com/emicklei/go-restful/v3](https://github.com/emicklei/go-restful) from 3.7.4 to 3.8.0.
- [Release notes](https://github.com/emicklei/go-restful/releases)
- [Changelog](https://github.com/emicklei/go-restful/blob/v3/CHANGES.md)
- [Commits](emicklei/go-restful@v3.7.4...v3.8.0)

---
updated-dependencies:
- dependency-name: github.com/emicklei/go-restful/v3
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@AlexStocks AlexStocks changed the base branch from master to 3.0 July 11, 2022 05:56
@AlexStocks
Copy link
Contributor

@alingse thx for your contributions to dubbogo. the main branch of dubbogo is 3.0. So I have changed your pr's target branch from master to 3.0.

@codecov-commenter
Copy link

Codecov Report

Merging #1964 (9fb49fd) into 3.0 (026711b) will decrease coverage by 0.61%.
The diff coverage is 25.71%.

@@            Coverage Diff             @@
##              3.0    #1964      +/-   ##
==========================================
- Coverage   44.96%   44.34%   -0.62%     
==========================================
  Files         287      283       -4     
  Lines       17135    17023     -112     
==========================================
- Hits         7704     7549     -155     
- Misses       8618     8670      +52     
+ Partials      813      804       -9     
Impacted Files Coverage Δ
cluster/cluster/base/cluster_invoker.go 24.44% <ø> (ø)
cluster/cluster/broadcast/cluster_invoker.go 80.00% <ø> (ø)
cluster/cluster/failback/cluster_invoker.go 75.82% <ø> (ø)
cluster/cluster/failover/cluster_invoker.go 66.66% <ø> (ø)
cluster/cluster/failsafe/cluster_invoker.go 81.81% <ø> (ø)
cluster/cluster/forking/cluster_invoker.go 58.33% <ø> (ø)
cluster/loadbalance/p2c/loadbalance.go 76.36% <ø> (ø)
cluster/loadbalance/ringhash/ringhash.go 63.33% <ø> (ø)
cluster/router/tag/match.go 90.69% <ø> (ø)
cluster/router/tag/router.go 59.64% <ø> (ø)
... and 130 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1abbc2e...9fb49fd. Read the comment docs.

@AlexStocks AlexStocks merged commit 5b0a87e into apache:3.0 Jul 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants