Repository: etcd-io/etcd
File: tests/antithesis/test-template/robustness/finally/main.go (Go)

Code before:
	"slices"
	"time"

	"github.com/antithesishq/antithesis-sdk-go/assert"
	"go.uber.org/zap"

	"go.etcd.io/etcd/tests/v3/antithesis/test-template/robustness/common"
	"go.etcd.io/etcd/tests/v3/robustness/report"
	"go.etcd.io/etcd/tests/v3/robustness/validate"
)

const (
	reportFileName = "history.html"
)

var NodeCount = "3"

func main() {
	local := flag.Bool("local", false, "run finally locally and connect to etcd instances via localhost")
	flag.Parse()

	cfg := common.MakeConfig(NodeCount)

	_, reportPath, dirs := common.DefaultPaths(cfg)
	if *local {
		_, reportPath, dirs = common.LocalPaths(cfg)
	}

	lg, err := zap.NewProduction()
	if err != nil {
		panic(err)
	}
	reports, err := report.LoadClientReports(reportPath)
	assert.Always(err == nil, "Loaded client reports", map[string]any{"error": err})
	tf, err := report.LoadTrafficDetail(reportPath)
	if err != nil && !os.IsNotExist(err) {
		panic(err)
	}

	result := validateReports(lg, dirs, reports, tf)
	if err := result.Linearization.Visualize(lg, filepath.Join(reportPath, reportFileName)); err != nil {
		panic(err)
	}
}

func validateReports(lg *zap.Logger, serversDataPath map[string]string, reports []report.ClientReport, tf report.TrafficDetail) validate.RobustnessResult {
	persistedRequests, err := report.PersistedRequests(lg, slices.Collect(maps.Values(serversDataPath)))
	assertResult(validate.ResultFromError(err), "Loaded persisted requests")

	validateConfig := validate.Config{ExpectRevisionUnique: tf.ExpectUniqueRevision}
	result := validate.ValidateAndReturnVisualize(lg, validateConfig, reports, persistedRequests, 5*time.Minute)

Review comment (suggestion):
For the future, would also good to move `LocalPaths` into `GetPaths`

Code after:
	"slices"
	"time"

	"github.com/antithesishq/antithesis-sdk-go/assert"
	"go.uber.org/zap"

	"go.etcd.io/etcd/tests/v3/antithesis/test-template/robustness/common"
	"go.etcd.io/etcd/tests/v3/robustness/report"
	"go.etcd.io/etcd/tests/v3/robustness/validate"
)

const (
	reportFileName = "history.html"
)

var NodeCount = "3"

func main() {
	local := flag.Bool("local", false, "run finally locally and connect to etcd instances via localhost")
	flag.Parse()

	cfg := common.MakeConfig(NodeCount)

	_, reportPath, dirs := common.GetPaths(cfg)
	if *local {
		_, reportPath, dirs = common.LocalPaths(cfg)
	}

	lg, err := zap.NewProduction()
	if err != nil {
		panic(err)
	}
	reports, err := report.LoadClientReports(reportPath)
	assert.Always(err == nil, "Loaded client reports", map[string]any{"error": err})
	tf, err := report.LoadTrafficDetail(reportPath)
	if err != nil && !os.IsNotExist(err) {
		panic(err)
	}

	result := validateReports(lg, dirs, reports, tf)
	if err := result.Linearization.Visualize(lg, filepath.Join(reportPath, reportFileName)); err != nil {
		panic(err)
	}
}

func validateReports(lg *zap.Logger, serversDataPath map[string]string, reports []report.ClientReport, tf report.TrafficDetail) validate.RobustnessResult {
	persistedRequests, err := report.PersistedRequests(lg, slices.Collect(maps.Values(serversDataPath)))
	assertResult(validate.ResultFromError(err), "Loaded persisted requests")

	validateConfig := validate.Config{ExpectRevisionUnique: tf.ExpectUniqueRevision}
	result := validate.ValidateAndReturnVisualize(lg, validateConfig, reports, persistedRequests, 5*time.Minute)