diff --git a/seaweed-block/cmd/sw-block/shell_check.go b/seaweed-block/cmd/sw-block/shell_check.go index 8e880d566c..5e4215c4e4 100644 --- a/seaweed-block/cmd/sw-block/shell_check.go +++ b/seaweed-block/cmd/sw-block/shell_check.go @@ -133,6 +133,7 @@ func (s inspectionShell) check(volume, format string, stdout, stderr io.Writer) f = checkElsewhere("master did not answer; prerequisite unavailable") } r := inspectionResult{ID: c.ID, Title: c.Title, Reach: c.Reach, Status: f.Status, Finding: f.Finding} + r.Finding = strings.Join(strings.Fields(r.Finding), " ") if f.Status == "FAIL" { code = 1 r.Cure = c.Cure @@ -405,9 +406,12 @@ func (o *inspectionObservation) clock() checkFinding { if diff < 0 { diff = -diff } - bound := diff + rtt/2 - finding := fmt.Sprintf("local clock difference plus RTT uncertainty %s; configured max skew %s", bound, o.shell.maxClockSkew) - if bound >= o.shell.maxClockSkew/2 { + if diff < 0 { + return checkFail("clock difference exceeds the duration range") + } + finding := fmt.Sprintf("local clock difference %s plus RTT uncertainty %s; configured max skew %s", diff, rtt/2, o.shell.maxClockSkew) + limit := o.shell.maxClockSkew / 2 + if diff >= limit || rtt/2 >= limit-diff { return checkFail(finding) } return checkOK(finding) diff --git a/seaweed-block/cmd/sw-block/shell_test.go b/seaweed-block/cmd/sw-block/shell_test.go index 1e16577866..df8e04876f 100644 --- a/seaweed-block/cmd/sw-block/shell_test.go +++ b/seaweed-block/cmd/sw-block/shell_test.go @@ -2,7 +2,9 @@ package main import ( "bytes" + "context" "encoding/json" + "net" "net/http" "net/http/httptest" "os" @@ -10,6 +12,11 @@ import ( "strings" "sync/atomic" "testing" + "time" + + "github.com/seaweedfs/seaweed-block/core/rpc/control" + "google.golang.org/grpc" + "google.golang.org/protobuf/types/known/timestamppb" ) func TestShellClusterStatusReadsTheMasterWithoutKubernetes(t *testing.T) { @@ -29,6 +36,36 @@ func TestShellClusterStatusReadsTheMasterWithoutKubernetes(t *testing.T) { } } +type futureInspectionMaster struct{ cmdFakeClusterEvidenceServer } + +func (futureInspectionMaster) GetClusterStatus(ctx context.Context, q *control.GetClusterStatusRequest) (*control.ClusterStatusResponse, error) { + r, err := (cmdFakeClusterEvidenceServer{}).GetClusterStatus(ctx, q) + r.CapturedAt = timestamppb.New(time.Date(3000, 1, 1, 0, 0, 0, 0, time.UTC)) + return r, err +} +func TestShellClockCannotCallAnOverflowingDifferenceOK(t *testing.T) { + ln, err := net.Listen("tcp", "127.0.0.1:0") + if err != nil { + t.Fatal(err) + } + srv := grpc.NewServer() + control.RegisterClusterEvidenceServiceServer(srv, futureInspectionMaster{}) + go func() { _ = srv.Serve(ln) }() + defer srv.Stop() + defer ln.Close() + var out, errout bytes.Buffer + run([]string{"shell", "-master", ln.Addr().String(), "-server-id", "m02", "-c", "cluster.check -o json"}, &out, &errout) + var rows []inspectionResult + if err := json.Unmarshal(out.Bytes(), &rows); err != nil { + t.Fatal(err) + } + for _, r := range rows { + if r.ID == "clock.skew" && r.Status != "FAIL" { + t.Fatalf("impossible clock accepted: %+v", r) + } + } +} + func TestShellCheckNeverCallsOffHostChecksOK(t *testing.T) { addr, closeMaster := startCmdFakeMaster(t) defer closeMaster()