-
Notifications
You must be signed in to change notification settings - Fork 2.4k
fix(redisotel): fix buggy append in reportPoolStats #3122
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
base: master
Are you sure you want to change the base?
Conversation
4ff1439
to
fc5be74
Compare
Hello @wzy9607, thank you for the contribution. Can you please add a test for that change with the idleAttrs. Interesting bug and nice catch! |
3426c02
to
b9ac847
Compare
done. |
Yes, it does indeed have flaws and potential risks. |
@monkey92t should we merge? |
The current append twice to `conf.attrs` approach in `reportPoolStats` may result in unexpected idleAttrs, due to `append` [can mutate](golang/go#29115 (comment)) the underlying array of the original slice, as demonstrated at <https://go.dev/play/p/jwRMofH91eQ?v=goprev>. Also, I replaced `metric.WithAttributes` in `reportPoolStats` with `metric.WithAttributeSet`, since `WithAttributes` is just `WithAttributeSet` with some extra works that are not needed here, see <https://pkg.go.dev/go.opentelemetry.io/otel/metric@v1.22.0#WithAttributes>.
I have solved the merge conflicts, can you take a look again? @monkey92t @ndyakov |
The current append twice to
conf.attrs
approach inreportPoolStats
may result in unexpected idleAttrs, due toappend
can mutate the underlying array of the original slice, as demonstrated at https://go.dev/play/p/jwRMofH91eQ?v=goprev and below.Also, I replaced
metric.WithAttributes
inreportPoolStats
withmetric.WithAttributeSet
, sinceWithAttributes
is justWithAttributeSet
with some extra works that are not needed here, see https://pkg.go.dev/go.opentelemetry.io/otel/metric@v1.22.0#WithAttributes.demonstration of the bug
outputs
while the intended result in
reportPoolStats
usecase isidle: [{a {4 0 a <nil>}} {b {4 0 b <nil>}} {c {4 0 c <nil>}} {state {4 0 idle <nil>}}]
.