Skip to content
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

Add IPv4-only configuration option #12632

Merged
merged 2 commits into from
Aug 3, 2022
Merged

Add IPv4-only configuration option #12632

merged 2 commits into from
Aug 3, 2022

Conversation

fanny-jiang
Copy link
Contributor

@fanny-jiang fanny-jiang commented Jul 28, 2022

What does this PR do?

Adds option to only check IPv4 addresses.

Motivation

A hostname may resolve to both IPv4 and IPv6 addresses despite the host lacking IPv6 connectivity. Enabling this option will check only IPv4 addresses and prevent false alerts from IPv6 addresses returning CRITICAL status due to "Network is unreachable" error returned from the socket.

Additional Notes

Also fixes the has_ipv6_connectivity() helper function in the tests, which was silently failing in the CI due to an exception from socket.gethostname() not getting caught.

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • PR title must be written as a CHANGELOG entry (see why)
  • Files changes must correspond to the primary purpose of the PR as described in the title (small unrelated changes should have their own PR)
  • PR must have changelog/ and integration/ labels attached

@codecov
Copy link

codecov bot commented Jul 28, 2022

Codecov Report

Merging #12632 (ac54749) into master (9e5c606) will increase coverage by 0.00%.
The diff coverage is 90.00%.

Flag Coverage Δ
tcp_check 91.58% <90.00%> (+1.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

@fanny-jiang fanny-jiang marked this pull request as ready for review July 29, 2022 15:54
@fanny-jiang fanny-jiang requested review from a team as code owners July 29, 2022 15:54
Copy link
Contributor

@ofek ofek left a comment

Choose a reason for hiding this comment

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

🥇

@fanny-jiang fanny-jiang merged commit b616b8e into master Aug 3, 2022
@fanny-jiang fanny-jiang deleted the fanny/tcp-ipv4 branch August 3, 2022 20:09
Comment on lines +80 to +88
if self.ipv4_only:
_, _, ipv4_list = socket.gethostbyname_ex(self.host)
self._addrs = [AddrTuple(ipv4_addr, socket.AF_INET) for ipv4_addr in ipv4_list]
else:
self._addrs = [
AddrTuple(sockaddr[0], socket_type)
for (socket_type, _, _, _, sockaddr) in socket.getaddrinfo(
self.host, self.port, 0, 0, socket.IPPROTO_TCP
)
Copy link
Contributor

@hithwen hithwen Aug 9, 2022

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants