From 04e82085d8c81b8022c10f14289ed8f8db2ec22f Mon Sep 17 00:00:00 2001 From: VidhuSarwal <61115425+VidhuSarwal@users.noreply.github.com> Date: Fri, 20 Dec 2024 13:53:41 +0000 Subject: [PATCH 1/6] validate: refactor linearization handling in operations.go Refactored validateLinearizableOperationsAndVisualize to remove the anonymous visualization function. Made a Results struct to store LinearizationInfo, Model, and the logger, simplifying the code. Signed-off-by: VidhuSarwal <61115425+VidhuSarwal@users.noreply.github.com> --- tests/robustness/validate/operations.go | 39 +++++++++++++++++++------ tests/robustness/validate/validate.go | 7 +++-- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/tests/robustness/validate/operations.go b/tests/robustness/validate/operations.go index 9f39407ad81..9fd371e5e4f 100644 --- a/tests/robustness/validate/operations.go +++ b/tests/robustness/validate/operations.go @@ -32,10 +32,38 @@ var ( errFutureRevRespRequested = errors.New("request about a future rev with response") ) -func validateLinearizableOperationsAndVisualize(lg *zap.Logger, operations []porcupine.Operation, timeout time.Duration) (result porcupine.CheckResult, visualize func(basepath string) error) { +type Results struct { + Info porcupine.LinearizationInfo + Model porcupine.Model + Lg *zap.Logger // Include logger in the Results struct +} + +// Change the Visualize method to match the signature func(path string) error +func (r Results) Visualize(path string) error { + // Directly use the logger from the Results struct + r.Lg.Info("Saving visualization", zap.String("path", path)) + err := porcupine.VisualizePath(r.Model, r.Info, path) + if err != nil { + return fmt.Errorf("failed to visualize, err: %w", err) + } + return nil +} + +func validateLinearizableOperationsAndVisualize( + lg *zap.Logger, + operations []porcupine.Operation, + timeout time.Duration, +) (result porcupine.CheckResult, results Results) { lg.Info("Validating linearizable operations", zap.Duration("timeout", timeout)) start := time.Now() result, info := porcupine.CheckOperationsVerbose(model.NonDeterministicModel, operations, timeout) + + results = Results{ + Info: info, + Model: model.NonDeterministicModel, + Lg: lg, + } + switch result { case porcupine.Illegal: lg.Error("Linearization failed", zap.Duration("duration", time.Since(start))) @@ -46,14 +74,7 @@ func validateLinearizableOperationsAndVisualize(lg *zap.Logger, operations []por default: panic(fmt.Sprintf("Unknown Linearization result %s", result)) } - return result, func(path string) error { - lg.Info("Saving visualization", zap.String("path", path)) - err := porcupine.VisualizePath(model.NonDeterministicModel, info, path) - if err != nil { - return fmt.Errorf("failed to visualize, err: %w", err) - } - return nil - } + return result, results } func validateSerializableOperations(lg *zap.Logger, operations []porcupine.Operation, replay *model.EtcdReplay) (lastErr error) { diff --git a/tests/robustness/validate/validate.go b/tests/robustness/validate/validate.go index 5918ec0df83..0c52ca6267a 100644 --- a/tests/robustness/validate/validate.go +++ b/tests/robustness/validate/validate.go @@ -35,11 +35,12 @@ func ValidateAndReturnVisualize(t *testing.T, lg *zap.Logger, cfg Config, report linearizableOperations := patchLinearizableOperations(reports, persistedRequests) serializableOperations := filterSerializableOperations(reports) - linearizable, visualize := validateLinearizableOperationsAndVisualize(lg, linearizableOperations, timeout) + linearizable, results := validateLinearizableOperationsAndVisualize(lg, linearizableOperations, timeout) if linearizable != porcupine.Ok { t.Error("Failed linearization, skipping further validation") - return visualize + return results.Visualize } + // TODO: Use requests from linearization for replay. replay := model.NewReplay(persistedRequests) @@ -51,7 +52,7 @@ func ValidateAndReturnVisualize(t *testing.T, lg *zap.Logger, cfg Config, report if err != nil { t.Errorf("Failed validating serializable operations, err: %s", err) } - return visualize + return results.Visualize } type Config struct { From 3a1dc18806deb02579ecce4df4c7c378a0c21177 Mon Sep 17 00:00:00 2001 From: VidhuSarwal Date: Sat, 21 Dec 2024 15:04:48 +0530 Subject: [PATCH 2/6] Upgraded github.com/anishathalye/porcupine to v1.0.0 --- go.sum | 2 ++ tests/go.mod | 2 +- tests/robustness/validate/operations.go | 1 - 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/go.sum b/go.sum index ef78d8c5048..82268e574b9 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow= github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4= +github.com/anishathalye/porcupine v1.0.0 h1:93eF6d26IMDky+G4h8FcLuYp1oO+no8a//I7asq/oKI= +github.com/anishathalye/porcupine v1.0.0/go.mod h1:WM0SsFjWNl2Y4BqHr/E/ll2yY1GY1jqn+W7Z/84Zoog= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bgentry/speakeasy v0.2.0 h1:tgObeVOf8WAvtuAX6DhJ4xks4CFNwPDZiqzGqIHE51E= diff --git a/tests/go.mod b/tests/go.mod index 04e44721008..308a6a0eaea 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -16,7 +16,7 @@ replace ( ) require ( - github.com/anishathalye/porcupine v0.1.4 + github.com/anishathalye/porcupine v1.0.0 github.com/coreos/go-semver v0.3.1 github.com/golang/protobuf v1.5.4 github.com/google/go-cmp v0.6.0 diff --git a/tests/robustness/validate/operations.go b/tests/robustness/validate/operations.go index 9fd371e5e4f..b6054f9ef0e 100644 --- a/tests/robustness/validate/operations.go +++ b/tests/robustness/validate/operations.go @@ -38,7 +38,6 @@ type Results struct { Lg *zap.Logger // Include logger in the Results struct } -// Change the Visualize method to match the signature func(path string) error func (r Results) Visualize(path string) error { // Directly use the logger from the Results struct r.Lg.Info("Saving visualization", zap.String("path", path)) From bc166dd9c028f679f932021ae9b0ed110db2bd9c Mon Sep 17 00:00:00 2001 From: VidhuSarwal Date: Sat, 21 Dec 2024 15:34:10 +0530 Subject: [PATCH 3/6] Added TODO and fxed PR Comment. --- tests/robustness/validate/operations.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/robustness/validate/operations.go b/tests/robustness/validate/operations.go index b6054f9ef0e..a0770701bce 100644 --- a/tests/robustness/validate/operations.go +++ b/tests/robustness/validate/operations.go @@ -35,11 +35,11 @@ var ( type Results struct { Info porcupine.LinearizationInfo Model porcupine.Model - Lg *zap.Logger // Include logger in the Results struct + Lg *zap.Logger // // TODO: Remove logger from struct and instead of making it an argument for Visualize } func (r Results) Visualize(path string) error { - // Directly use the logger from the Results struct + r.Lg.Info("Saving visualization", zap.String("path", path)) err := porcupine.VisualizePath(r.Model, r.Info, path) if err != nil { From 65f9421ab57f9a9096b909f5ee4679becfed594a Mon Sep 17 00:00:00 2001 From: VidhuSarwal Date: Sat, 21 Dec 2024 15:36:53 +0530 Subject: [PATCH 4/6] Changed return type of ValidateAndReturnVisualize to return the entire results struct --- tests/robustness/validate/validate.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/robustness/validate/validate.go b/tests/robustness/validate/validate.go index 0c52ca6267a..a17fc2f467b 100644 --- a/tests/robustness/validate/validate.go +++ b/tests/robustness/validate/validate.go @@ -28,8 +28,7 @@ import ( "go.etcd.io/etcd/tests/v3/robustness/report" ) -// ValidateAndReturnVisualize returns visualize as porcupine.linearizationInfo used to generate visualization is private. -func ValidateAndReturnVisualize(t *testing.T, lg *zap.Logger, cfg Config, reports []report.ClientReport, persistedRequests []model.EtcdRequest, timeout time.Duration) (visualize func(basepath string) error) { +func ValidateAndReturnVisualize(t *testing.T, lg *zap.Logger, cfg Config, reports []report.ClientReport, persistedRequests []model.EtcdRequest, timeout time.Duration) Results { err := checkValidationAssumptions(reports, persistedRequests) require.NoErrorf(t, err, "Broken validation assumptions") linearizableOperations := patchLinearizableOperations(reports, persistedRequests) @@ -38,7 +37,7 @@ func ValidateAndReturnVisualize(t *testing.T, lg *zap.Logger, cfg Config, report linearizable, results := validateLinearizableOperationsAndVisualize(lg, linearizableOperations, timeout) if linearizable != porcupine.Ok { t.Error("Failed linearization, skipping further validation") - return results.Visualize + return results } // TODO: Use requests from linearization for replay. @@ -52,7 +51,7 @@ func ValidateAndReturnVisualize(t *testing.T, lg *zap.Logger, cfg Config, report if err != nil { t.Errorf("Failed validating serializable operations, err: %s", err) } - return results.Visualize + return results } type Config struct { From 105bb8812216a7bcb9277669417f867da1ee7c6a Mon Sep 17 00:00:00 2001 From: VidhuSarwal Date: Sat, 21 Dec 2024 15:51:42 +0530 Subject: [PATCH 5/6] upgraded github.com/anishathalye/porcupine to v1.0.0 --- go.mod | 1 + tests/robustness/validate/operations.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 67ddfea9290..3dbdde727f4 100644 --- a/go.mod +++ b/go.mod @@ -42,6 +42,7 @@ require ( require ( github.com/VividCortex/ewma v1.2.0 // indirect + github.com/anishathalye/porcupine v1.0.0 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/cenkalti/backoff/v4 v4.3.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect diff --git a/tests/robustness/validate/operations.go b/tests/robustness/validate/operations.go index a0770701bce..7f241a310e3 100644 --- a/tests/robustness/validate/operations.go +++ b/tests/robustness/validate/operations.go @@ -35,7 +35,7 @@ var ( type Results struct { Info porcupine.LinearizationInfo Model porcupine.Model - Lg *zap.Logger // // TODO: Remove logger from struct and instead of making it an argument for Visualize + Lg *zap.Logger // TODO: Remove logger from struct and instead of making it an argument for Visualize } func (r Results) Visualize(path string) error { From e451f4feb48395cac1a6d2b168e0dff0e659d77e Mon Sep 17 00:00:00 2001 From: VidhuSarwal <61115425+vidhusarwal@users.noreply.github.com> Date: Sat, 21 Dec 2024 16:08:24 +0530 Subject: [PATCH 6/6] made changes to go.sum file Signed-off-by: VidhuSarwal --- go.mod | 3 ++- go.sum | 2 ++ tests/go.sum | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 3dbdde727f4..39d5ffda8d0 100644 --- a/go.mod +++ b/go.mod @@ -32,7 +32,7 @@ require ( go.etcd.io/etcd/etcdutl/v3 v3.6.0-alpha.0 go.etcd.io/etcd/pkg/v3 v3.6.0-alpha.0 go.etcd.io/etcd/server/v3 v3.6.0-alpha.0 - go.etcd.io/etcd/tests/v3 v3.0.0-00010101000000-000000000000 + go.etcd.io/etcd/tests/v3 v3.5.17 go.etcd.io/raft/v3 v3.6.0-beta.0 go.uber.org/zap v1.27.0 golang.org/x/time v0.8.0 @@ -47,6 +47,7 @@ require ( github.com/cenkalti/backoff/v4 v4.3.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/coreos/go-systemd/v22 v22.5.0 // indirect + github.com/creack/pty v1.1.18 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/fatih/color v1.18.0 // indirect github.com/go-logr/logr v1.4.2 // indirect diff --git a/go.sum b/go.sum index 82268e574b9..1fa4538f8fa 100644 --- a/go.sum +++ b/go.sum @@ -24,6 +24,8 @@ github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03V github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY= +github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/tests/go.sum b/tests/go.sum index 64a0dfe72c3..1fa4538f8fa 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -2,8 +2,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow= github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4= -github.com/anishathalye/porcupine v0.1.4 h1:rRekB2jH1mbtLPEzuqyMHp4scU52Bcc1jgkPi1kWFQA= -github.com/anishathalye/porcupine v0.1.4/go.mod h1:/X9OQYnVb7DzfKCQVO4tI1Aq+o56UJW+RvN/5U4EuZA= +github.com/anishathalye/porcupine v1.0.0 h1:93eF6d26IMDky+G4h8FcLuYp1oO+no8a//I7asq/oKI= +github.com/anishathalye/porcupine v1.0.0/go.mod h1:WM0SsFjWNl2Y4BqHr/E/ll2yY1GY1jqn+W7Z/84Zoog= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bgentry/speakeasy v0.2.0 h1:tgObeVOf8WAvtuAX6DhJ4xks4CFNwPDZiqzGqIHE51E=