Skip to content

Reduce lock scope in Kafka metrics reporter - #20535

Merged
laurit merged 5 commits into
mainfrom
copilot/reduce-lock-scope-kafka-metrics-reporter
Oct 15, 2026
Merged

laurit merged 5 commits into
mainfrom
copilot/reduce-lock-scope-kafka-metrics-reporter

Conversation

Copilot AI commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Replacement and removal: Close selected observables in order; remove each registration only after its close succeeds.
  • Shutdown: Apply the same ordered cleanup behavior when closing all instruments.

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Merged · refreshed 2026-10-15 12:26 UTC

Status above doesn't look right?
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

Co-authored-by: trask <218610+trask@users.noreply.github.com>
Copilot AI changed the title [WIP] Reduce lock scope in Kafka metrics reporter Reduce lock scope in Kafka metrics reporter Oct 12, 2026
Copilot AI requested a review from trask October 12, 2026 15:09
@trask
trask requested a balanced review from Copilot October 12, 2026 15:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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.

@trask
trask marked this pull request as ready for review October 12, 2026 16:45
@trask
trask requested a review from a team as a code owner October 12, 2026 16:45
private void closeInstrumentAndRemove(RegisteredObservable registeredObservable) {
closeInstrument(registeredObservable.getObservable());
synchronized (lock) {
for (Iterator<RegisteredObservable> it = registeredObservables.iterator(); it.hasNext(); ) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this be replaced with registeredObservables.remove(registeredObservable)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

for (RegisteredObservable registeredObservable : observablesToClose) {
closeInstrumentAndRemove(registeredObservable);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels inefficient. It needs to loop over registeredObservables list to remove each element while previously it looped only once.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trask added 2 commits October 13, 2026 08:36
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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Lifecycle operations can interleave, causing observables to survive shutdown or be closed multiple times.

1 open finding

🧠 Review effort: Balanced

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 0c244542-4785-4886-a331-68c25ca59fa2

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The cleanup refactor preserves ordering and failure behavior without introducing a supported lifecycle race.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

@laurit
laurit merged commit 8df8b77 into main Oct 15, 2026
70 checks passed
@laurit
laurit deleted the copilot/reduce-lock-scope-kafka-metrics-reporter branch October 15, 2026 12:25
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.

4 participants