Repository navigation
Reduce lock scope in Kafka metrics reporter - #20535
Conversation
Pull request dashboard statusMerged · refreshed 2026-10-15 12:26 UTC Status above doesn't look right?
|
Co-authored-by: trask <218610+trask@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
The cleanup refactor consistently preserves ordering and close-failure semantics without holding the bookkeeping lock during external calls.
0 open findings
What changed in this PR
Reduces Kafka metrics reporter lock contention while preserving ordered observable cleanup.
Changes:
- Snapshots registrations under lock, then logs and closes them outside it.
- Removes registrations only after successful closure across replacement, removal, and shutdown.
| File | Description |
|---|---|
OpenTelemetryMetricsReporter.java |
Narrows lock scope for observable lifecycle operations. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| private void closeInstrumentAndRemove(RegisteredObservable registeredObservable) { | ||
| closeInstrument(registeredObservable.getObservable()); | ||
| synchronized (lock) { | ||
| for (Iterator<RegisteredObservable> it = registeredObservables.iterator(); it.hasNext(); ) { |
There was a problem hiding this comment.
could this be replaced with registeredObservables.remove(registeredObservable)?
| } | ||
|
|
||
| for (RegisteredObservable registeredObservable : observablesToClose) { | ||
| closeInstrumentAndRemove(registeredObservable); |
There was a problem hiding this comment.
Feels inefficient. It needs to loop over registeredObservables list to remove each element while previously it looped only once.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: ee62c0a6-39b4-4534-92d6-83f191bb8a8c
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: ee62c0a6-39b4-4534-92d6-83f191bb8a8c
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0c244542-4785-4886-a331-68c25ca59fa2

Move observable cleanup and replacement logging outside the reporter’s bookkeeping lock while preserving callback order and close-failure behavior.