gatus icon indicating copy to clipboard operation
gatus copied to clipboard

feat(client): Add client network configuration for ICMP endpoint clients

Open n-thumann opened this issue 1 year ago • 1 comments

Summary

This PR adds support to explicitly specify the network to use for ICMP endpoint clients, e.g. IPv6. In the future, this may be extended to also support HTTPS endpoints (requested https://github.com/TwiN/gatus/issues/185).

Details

I decided to use ping.NewPinger instead of ping.New, because the latter automatically resolves the address before we can set the desired network. I set ip as the default config value. This is technically not needed and could be an empty string, because SetNetwork takes care of it anyways, but I think it's a cleaner approach.

Background

I am running Gatus on an IPv6-only machine. Sadly, net.ResolveIPAddr still returns a single IPv4 address, when being asked to resolve a dual-stacked host (see https://github.com/golang/go/issues/28666). Pinging the returned IPv4 address from Gatus will obviously fail on an IPv6-only host. I confirmed this by:

  • Adding ipv6.google.com as an ICMP endpoint: This works by default on an IPv6-only host, because this target is IPv6-only anyways
  • Adding google.com as an ICMP endpoint: This doesn't work by default on an IPv6-only host, because this target is dual-stacked and Gatus tries to ping via IPv4. Adding network: "ip6" to the endpoints client config fixes this.

Checklist

  • [x] Tested and/or added tests to validate that the changes work as intended, if applicable.
  • [x] Updated documentation in README.md, if applicable.

n-thumann avatar Jan 20 '24 23:01 n-thumann

Could you add some tests?

Done :v:

n-thumann avatar Jan 24 '24 21:01 n-thumann

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (6cbc59b) 78.51% compared to head (4d2cb75) 78.57%.

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #661      +/-   ##
==========================================
+ Coverage   78.51%   78.57%   +0.05%     
==========================================
  Files          58       58              
  Lines        4748     4746       -2     
==========================================
+ Hits         3728     3729       +1     
+ Misses        833      831       -2     
+ Partials      187      186       -1     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar Feb 07 '24 01:02 codecov-commenter

Thank you for the contribution!

TwiN avatar Feb 07 '24 02:02 TwiN