Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/antithesis/config/docker-compose-1-node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ services:
container_name: client
entrypoint: ["/opt/antithesis/entrypoint/entrypoint"]
user: "${USER_ID:-root}:${GROUP_ID:-root}"
environment:
ETCD_ROBUSTNESS_ENDPOINTS: "etcd0:2379"
ETCD_ROBUSTNESS_DATA_PATHS: "/var/etcddata0"
ETCD_ROBUSTNESS_REPORT_PATH: "/var/report"
depends_on:
etcd0:
condition: service_started
Expand Down
4 changes: 4 additions & 0 deletions tests/antithesis/config/docker-compose-3-node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ services:
container_name: client
entrypoint: ["/opt/antithesis/entrypoint/entrypoint"]
user: "${USER_ID:-root}:${GROUP_ID:-root}"
environment:
ETCD_ROBUSTNESS_ENDPOINTS: "etcd0:2379,etcd1:2379,etcd2:2379"
ETCD_ROBUSTNESS_DATA_PATHS: "/var/etcddata0,/var/etcddata1,/var/etcddata2"
ETCD_ROBUSTNESS_REPORT_PATH: "/var/report"
depends_on:
etcd0:
condition: service_started
Expand Down
15 changes: 7 additions & 8 deletions tests/antithesis/test-template/entrypoint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,16 @@ var NodeCount = "3"
// CheckHealth checks health of all etcd nodes
func CheckHealth() bool {
cfg := common.MakeConfig(NodeCount)
hosts, _, _ := common.GetPaths(cfg)

nodeOptions := []string{"etcd0", "etcd1", "etcd2"}[:cfg.NodeCount]

// iterate over each node and check health
for _, node := range nodeOptions {
// iterate over each host and check health
for _, host := range hosts {
cli, err := clientv3.New(clientv3.Config{
Endpoints: []string{fmt.Sprintf("http://%s:2379", node)},
Endpoints: []string{fmt.Sprintf("http://%s", host)},
DialTimeout: 5 * time.Second,
})
if err != nil {
fmt.Printf("Client [entrypoint]: connection failed with %s\n", node)
fmt.Printf("Client [entrypoint]: connection failed with %s\n", host)
fmt.Printf("Client [entrypoint]: error: %v\n", err)
return false
}
Expand All @@ -60,12 +59,12 @@ func CheckHealth() bool {
// fetch the key setting-up to confirm that the node is available
_, err = cli.Get(context.Background(), "setting-up")
if err != nil {
fmt.Printf("Client [entrypoint]: connection failed with %s\n", node)
fmt.Printf("Client [entrypoint]: connection failed with %s\n", host)
fmt.Printf("Client [entrypoint]: error: %v\n", err)
return false
}

fmt.Printf("Client [entrypoint]: connection successful with %s\n", node)
fmt.Printf("Client [entrypoint]: connection successful with %s\n", host)
}

return true
Expand Down
43 changes: 42 additions & 1 deletion tests/antithesis/test-template/robustness/common/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package common
import (
"fmt"
"os"
"strings"
)

const (
Expand All @@ -36,9 +37,49 @@ const (
defaultetcdLocalDataPath = "/tmp/etcddata%d"
localetcdDataPathEnv = "ETCD_ROBUSTNESS_DATA_PATH_PREFIX"
localReportPath = "report"

endpointsEnv = "ETCD_ROBUSTNESS_ENDPOINTS"
dataPathsEnv = "ETCD_ROBUSTNESS_DATA_PATHS"
reportPathEnv = "ETCD_ROBUSTNESS_REPORT_PATH"
)

func DefaultPaths(cfg *Config) (hosts []string, reportPath string, dataPaths map[string]string) {
func GetPaths(cfg *Config) (hosts []string, reportPath string, dataPaths map[string]string) {
// Check for environment variable overrides first
envDataPathsStr := os.Getenv(dataPathsEnv)
envReportPath := os.Getenv(reportPathEnv)
envEndpointsStr := os.Getenv(endpointsEnv)

defaultHosts, defaultReportPath, defaultDataPaths := defaultPaths(cfg)

hosts = defaultHosts
if envEndpointsStr != "" {
hosts = strings.Split(envEndpointsStr, ",")
for i, host := range hosts {
hosts[i] = strings.TrimSpace(host)
}
}

reportPath = defaultReportPath
if envReportPath != "" {
reportPath = envReportPath
}

dataPaths = defaultDataPaths
if envDataPathsStr != "" {
envDataPaths := strings.Split(envDataPathsStr, ",")
if len(envDataPaths) != len(hosts) {
panic(fmt.Sprintf("Mismatched number of endpoints and data paths: %d endpoints, %d data paths", len(hosts), len(envDataPaths)))
}

dataPaths = make(map[string]string)
for i, endpoint := range hosts {
dataPaths[endpoint] = strings.TrimSpace(envDataPaths[i])
}
}
return hosts, reportPath, dataPaths
}

func defaultPaths(cfg *Config) (hosts []string, reportPath string, dataPaths map[string]string) {
hosts = []string{defaultetcd0, defaultetcd1, defaultetcd2}[:cfg.NodeCount]
reportPath = defaultReportPath
dataPaths = etcdDataPaths(defaultetcdDataPath, cfg.NodeCount)
Expand Down
2 changes: 1 addition & 1 deletion tests/antithesis/test-template/robustness/finally/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func main() {

cfg := common.MakeConfig(NodeCount)

_, reportPath, dirs := common.DefaultPaths(cfg)
_, reportPath, dirs := common.GetPaths(cfg)
if *local {
_, reportPath, dirs = common.LocalPaths(cfg)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the future, would also good to move LocalPaths into GetPaths

}
Expand Down
2 changes: 1 addition & 1 deletion tests/antithesis/test-template/robustness/traffic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func main() {

cfg := common.MakeConfig(NodeCount)

hosts, reportPath, etcdetcdDataPaths := common.DefaultPaths(cfg)
hosts, reportPath, etcdetcdDataPaths := common.GetPaths(cfg)
if *local {
hosts, reportPath, etcdetcdDataPaths = common.LocalPaths(cfg)
}
Expand Down