Skip to content

Disable peer discovery for direct IP gravity URLs#244

Merged
jhaynie merged 1 commit intomainfrom
disable-peer-discovery-for-direct-ips
May 2, 2026
Merged

Disable peer discovery for direct IP gravity URLs#244
jhaynie merged 1 commit intomainfrom
disable-peer-discovery-for-direct-ips

Conversation

@jhaynie
Copy link
Copy Markdown
Member

@jhaynie jhaynie commented May 2, 2026

Summary

  • Detect when Gravity is configured entirely with literal IP URLs
  • Skip starting the peer discovery loop for those static direct-IP configurations
  • Add coverage for IPv4, IPv6, mixed hostname/IP, and disabled discovery startup

Tests

  • go test ./gravity

Summary by CodeRabbit

Release Notes

  • New Features

    • Peer discovery is now automatically optimized and disabled when all configured Gravity service endpoints are direct IP addresses.
  • Tests

    • Added comprehensive test coverage for endpoint IP detection and peer discovery behavior.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9ecff273-59dc-4d14-812b-be8910d1e426

📥 Commits

Reviewing files that changed from the base of the PR and between 1ffef6b and 5e6c952.

📒 Files selected for processing (2)
  • gravity/grpc_client.go
  • gravity/peer_discovery_test.go
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build
  • GitHub Check: Analyze (go)
🔇 Additional comments (4)
gravity/grpc_client.go (2)

839-840: Direct-IP detection + disable flag wiring is solid.

The allGravityURLsAreDirectIPs/isDirectIPGravityURL helpers are coherent and the assignment in startMultiEndpoint cleanly maps config shape to runtime behavior.

Also applies to: 1195-1237


5095-5098: Peer discovery short-circuit is correctly scoped.

Early-returning in startPeerDiscovery when peerDiscoveryDisabled is set cleanly prevents starting the loop for direct-IP-only configs.

gravity/peer_discovery_test.go (2)

201-251: Good table coverage for direct-IP classification.

This test set exercises the important parsing branches and expected enable/disable outcomes well.


874-895: Disabled peer discovery behavior is validated clearly.

The test correctly asserts that the loop state remains uninitialized and resolver execution is blocked in direct-IP mode.


📝 Walkthrough

Walkthrough

The PR adds a peerDiscoveryDisabled flag to GravityClient that is set when all configured Gravity URLs resolve to direct IPs. When this flag is true, the peer discovery loop skips initialization. Helper functions detect whether each URL is a direct IP, and tests validate the detection logic and disabled behavior.

Changes

Peer Discovery Disablement for Direct IP Gravity URLs

Layer / File(s) Summary
Data Structure
gravity/grpc_client.go
GravityClient struct gains a peerDiscoveryDisabled boolean field to track whether peer discovery should be disabled.
Helper Functions
gravity/grpc_client.go
Implements allGravityURLsAreDirectIPs() and isDirectIPGravityURL() to parse Gravity URLs and use net.ParseIP to determine if they are direct IP addresses (IPv4, bracketed IPv6) rather than hostnames.
Behavior Integration
gravity/grpc_client.go
During startMultiEndpoint() setup, peerDiscoveryDisabled is set based on whether all Gravity URLs are direct IPs. In startPeerDiscovery(), an early return prevents the peer discovery goroutine from starting when the flag is set.
Tests
gravity/peer_discovery_test.go
Adds table-driven test TestAllGravityURLsAreDirectIPs validating IP detection logic for IPv4, IPv6, hostnames, and edge cases. Adds TestStartPeerDiscovery_DisabledForDirectIPGravityURLs to verify the peer discovery loop remains inactive when all URLs are direct IPs.
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Review rate limit: 0/5 reviews remaining, refill in 53 minutes and 54 seconds.

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

@jhaynie jhaynie merged commit 32ce707 into main May 2, 2026
5 checks passed
@jhaynie jhaynie deleted the disable-peer-discovery-for-direct-ips branch May 2, 2026 17:21
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.

1 participant