Skip to content

fix(operator): close idle DCGM scrape connections - #16099

Closed
git-jxj wants to merge 2 commits into
ai-dynamo:mainfrom
git-jxj:fix/operator-close-dcgm-scrape-connections
Closed

git-jxj wants to merge 2 commits into
ai-dynamo:mainfrom
git-jxj:fix/operator-close-dcgm-scrape-connections

Conversation

@git-jxj

@git-jxj git-jxj commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Each DCGM scrape creates its own HTTP transport. After a response is read to EOF, its TCP connection remains idle in that unused transport with no idle timeout. Repeated discovery rounds can accumulate sockets and transport goroutines while exporters keep connections alive.

Close the client's idle connections when the scrape returns. The defer runs after the response body is closed and preserves the existing request timeouts.

Details

Add a real HTTP keep-alive regression that repeats scrapes and checks server-side TCP connection closure for successful responses, invalid Prometheus exposition, and missing GPU metrics. Successful scrapes and both metric parsing error paths fail before the fix.

Where should the reviewer start?

deploy/operator/internal/gpu/discovery.go and discovery_connection_test.go.

Validation

  • go test ./internal/gpu -count=1 -v
  • go test -race ./internal/gpu -count=1
  • go test -p 4 ./... with Kubernetes 1.30.0 envtest assets.
  • golangci-lint run (v1.64.8)
  • make check
  • Pre-commit checks on the changed files with Python 3.12.

Related Issues

Closes #16097

Summary by CodeRabbit

  • Bug Fixes
    • Idle HTTP connections are now released when GPU metrics collection finishes, helping prevent unused connections from lingering.
    • GPU metrics scraping continues to report successful results and surface errors for unavailable endpoints, invalid metrics, or missing GPU data.

@git-jxj
git-jxj requested a review from a team as a code owner October 10, 2026 07:44
@copy-pr-bot

copy-pr-bot Bot commented Oct 10, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@git-jxj
git-jxj temporarily deployed to external_collaborator October 10, 2026 07:44 — with GitHub Actions Inactive
@git-jxj
git-jxj temporarily deployed to external_collaborator October 10, 2026 07:44 — with GitHub Actions Inactive
@github-actions

Copy link
Copy Markdown
Contributor

👋 Hi git-jxj! Thank you for contributing to ai-dynamo/dynamo.

Just a reminder: The NVIDIA Test Github Validation CI runs an essential subset of the testing framework to quickly catch errors.Your PR reviewers may elect to test the changes comprehensively before approving your changes.

🚀

@github-actions github-actions Bot added external-contribution Pull request is from an external contributor fix deployment::k8s Relates to dynamo deployment in kubernetes labels Oct 10, 2026
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: ai-dynamo/dynamo/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: cdbd6e7b-05d5-4db2-b307-7e1d005e4017


📥 Commits

Reviewing files that changed from the base of the PR and between 0f01da1 and 0c8d39a.



📒 Files selected for processing (2)
  • deploy/operator/internal/gpu/discovery.go
  • deploy/operator/internal/gpu/discovery_connection_test.go


Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 9 remain after this review.




Walkthrough

ScrapeMetricsEndpoint now closes idle HTTP connections when it returns. A regression test covers successful scrapes and error responses, and verifies that server connections close.

Changes

GPU scrape connection cleanup

Layer / File(s) Summary
Scrape cleanup and regression test
deploy/operator/internal/gpu/discovery.go, deploy/operator/internal/gpu/discovery_connection_test.go
ScrapeMetricsEndpoint defers closing idle connections. The test checks successful and failing scrapes, confirms three connections were accepted, and verifies that active connections eventually reach zero.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 0c8d3

This change closes idle connections left over after each DCGM metrics scrape, with no change to scrape behavior or timeouts. A regression test covers the connection cleanup. No merge-blocking risk was found.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check Passed The changes satisfy the coding requirements in [#16097]. ScrapeMetricsEndpoint defers client.CloseIdleConnections() for its single-use transport. The defer runs after the existing response-body cl…
Out of Scope Changes check Passed The pull request changes only the DCGM scrape connection lifecycle and adds a focused regression test for that behavior. The test directly supports [#16097]. No unrelated scraper or unrelated product …
Title check Passed The title clearly describes the main change: closing idle DCGM scrape connections in the operator.
Description check Passed The description explains the connection leak, the implementation, regression coverage, reviewer starting points, validation, and related issue. The Summary heading serves the required overview conte…

  • Fix all pre-merge checks with AI
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

errContains string
}{
{name: "success", status: http.StatusOK, body: metrics},
{name: "HTTP error", status: http.StatusServiceUnavailable, body: metrics, errContains: "returned status 503"},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The HTTP error row does not exercise the idle-connection leak this regression targets: ScrapeMetricsEndpoint returns before consuming the response body, so the existing deferred body close closes the non-reusable connection even without CloseIdleConnections. Status-error handling is already protected by TestScrapeMetricsEndpoint/404_response, while the close-idle behavior remains covered by rows that consume the body before returning.

🤖 AI Fix

Remove the HTTP error table row from TestScrapeMetricsEndpointClosesConnections.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Confirmed by temporarily removing CloseIdleConnections: the HTTP-error row still passed, while success, invalid exposition, and missing GPU metrics each failed with open connections. Removed the HTTP-error row and its now-constant status field in cf637e0. All three retained cases fail without the fix and pass with it, including the GPU package race run. Status errors remain covered by the existing 404 test.

@git-jxj
git-jxj temporarily deployed to external_collaborator October 11, 2026 01:45 — with GitHub Actions Inactive
@git-jxj

git-jxj commented Oct 15, 2026

Copy link
Copy Markdown
Contributor Author

Current head cf637e09f2 is still missing the full CI status checks. Could a code owner authorize this revision with /ok to test cf637e09f2 when appropriate? The separate lychee failure is in untouched documentation links (404/503); could a maintainer triage or rerun that job?

This branch was previously deployed

1 inactive deployment
external_collaborator — cf637e09 Deployed Oct 11, 2026 by git-jxj via ok-to-test #30077
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deployment::k8s Relates to dynamo deployment in kubernetes external-contribution Pull request is from an external contributor fix size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: DCGM metrics scraping retains idle connections after each discovery

1 participant