diff options
author | Will Chandler <wchandler@gitlab.com> | 2022-10-10 17:28:22 +0300 |
---|---|---|
committer | Will Chandler <wchandler@gitlab.com> | 2022-10-10 17:28:22 +0300 |
commit | cc9fe2bf1bce969be9d9616a67c386f0a7fc9b25 (patch) | |
tree | cb2ba2eadcf9570fa903fcd02781d377e051ec51 | |
parent | 625ad956b9d046d984090c7137a535307bf54a87 (diff) | |
parent | ecde3d72c3aeeb20547fc5b2186c14a93f0b28db (diff) |
Merge branch 'sh-improve-ntp-host-debug-message' into 'master'
Improve NTP connectivity error message
See merge request https://gitlab.com/gitlab-org/gitaly/-/merge_requests/4916
Merged-by: Will Chandler <wchandler@gitlab.com>
Approved-by: Sami Hiltunen <shiltunen@gitlab.com>
Approved-by: karthik nayak <knayak@gitlab.com>
Approved-by: Will Chandler <wchandler@gitlab.com>
Co-authored-by: Stan Hu <stanhu@gmail.com>
-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", |