diff options
author | Stan Hu <stanhu@gmail.com> | 2022-10-06 23:27:19 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2022-10-07 00:09:45 +0300 |
commit | ecde3d72c3aeeb20547fc5b2186c14a93f0b28db (patch) | |
tree | af34477d837c03f38a4886cf1c05346de33b3607 | |
parent | 99b5528b66b23c1a8399027ecdef306267e668ae (diff) |
Improve NTP connectivity error message
On hosts where pool.ntp.org is not reachable, it's not obvious which
NTP server the clock synchronization check attempted to use and that
`NTP_HOST` can be set. This commit improves the error message.
For example, with `NTP_HOST` set to `example.com`, we can see:
Before:
```
FAIL: clock synchronization: praefect: query ntp: read udp 192.168.1.109:56948->93.184.216.34:123: i/o timeout
```
After:
```
FAIL: clock synchronization: praefect: query ntp host example.com: read udp 192.168.1.109:56948->93.184.216.34:123: i/o timeout
```
Or if `NTP_HOST` is not set:
Before:
```
FAIL: clock synchronization: praefect: query ntp host: read udp 192.168.1.109:56948->51.255.142.175:123: i/o timeout
```
After:
```
FAIL: clock synchronization: praefect: query ntp host pool.ntp.org: read udp 192.168.1.109:56948->51.255.142.175:123: i/o timeout (NTP_HOST was not set)
```
Changelog: changed
-rw-r--r-- | internal/helper/clock.go | 2 | ||||
-rw-r--r-- | internal/praefect/service/checks.go | 6 | ||||
-rw-r--r-- | internal/praefect/service/checks_test.go | 10 |
3 files changed, 15 insertions, 3 deletions
diff --git a/internal/helper/clock.go b/internal/helper/clock.go index bc47aa401..a2f8209b2 100644 --- a/internal/helper/clock.go +++ b/internal/helper/clock.go @@ -17,7 +17,7 @@ func CheckClockSync(ntpHost string, driftThreshold time.Duration) (bool, error) resp, err := ntp.Query(ntpHost) if err != nil { - return false, fmt.Errorf("query ntp: %w", err) + return false, fmt.Errorf("query ntp host %s: %w", ntpHost, err) } if err := resp.Validate(); err != nil { return false, fmt.Errorf("validate ntp response: %w", err) diff --git a/internal/praefect/service/checks.go b/internal/praefect/service/checks.go index 41fd44de1..52411f318 100644 --- a/internal/praefect/service/checks.go +++ b/internal/praefect/service/checks.go @@ -234,7 +234,11 @@ func NewClockSyncCheck(clockDriftCheck func(ntpHost string, driftThreshold time. g.Go(func() error { synced, err := clockDriftCheck(ntpHost, driftThreshold) if err != nil { - return fmt.Errorf("praefect: %w", err) + message := "" + if ntpHost == "" { + message = " (NTP_HOST was not set)" + } + return fmt.Errorf("praefect: %w%s", err, message) } if !synced { return errors.New("praefect: clock is not synced") diff --git a/internal/praefect/service/checks_test.go b/internal/praefect/service/checks_test.go index 851d21692..14aaa9ee5 100644 --- a/internal/praefect/service/checks_test.go +++ b/internal/praefect/service/checks_test.go @@ -526,7 +526,15 @@ func TestNewClockSyncCheck(t *testing.T) { { desc: "failure", offsetCheck: func(_ string, _ time.Duration) (bool, error) { return false, assert.AnError }, - expErr: fmt.Errorf("praefect: %w", assert.AnError), + expErr: fmt.Errorf("praefect: %w (NTP_HOST was not set)", assert.AnError), + }, + { + desc: "failure with NTP_HOST set", + offsetCheck: func(_ string, _ time.Duration) (bool, error) { return false, assert.AnError }, + setup: func(t *testing.T) { + t.Setenv("NTP_HOST", "custom") + }, + expErr: fmt.Errorf("praefect: %w", assert.AnError), }, { desc: "custom url", |