Skip to content

Commit

Permalink
functional: use strings for LogOutput
Browse files Browse the repository at this point in the history
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
  • Loading branch information
gyuho committed Apr 17, 2018
1 parent 671e4a5 commit 8ee8778
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 188 deletions.
6 changes: 3 additions & 3 deletions functional.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ agent-configs:
pre-vote: true
initial-corrupt-check: true
logger: zap
log-output: /tmp/etcd-functional-1/etcd.log
log-output: [/tmp/etcd-functional-1/etcd.log]
debug: true
client-cert-data: ""
client-cert-path: ""
Expand Down Expand Up @@ -85,7 +85,7 @@ agent-configs:
pre-vote: true
initial-corrupt-check: true
logger: zap
log-output: /tmp/etcd-functional-2/etcd.log
log-output: [/tmp/etcd-functional-2/etcd.log]
debug: true
client-cert-data: ""
client-cert-path: ""
Expand Down Expand Up @@ -136,7 +136,7 @@ agent-configs:
pre-vote: true
initial-corrupt-check: true
logger: zap
log-output: /tmp/etcd-functional-3/etcd.log
log-output: [/tmp/etcd-functional-3/etcd.log]
debug: true
client-cert-data: ""
client-cert-path: ""
Expand Down
7 changes: 4 additions & 3 deletions functional/agent/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,14 @@ func (srv *Server) handleTesterRequest(req *rpcpb.Request) (resp *rpcpb.Response
}
}

// just archive the first file
func (srv *Server) createEtcdLogFile() error {
var err error
srv.etcdLogFile, err = os.Create(srv.Member.Etcd.LogOutput)
srv.etcdLogFile, err = os.Create(srv.Member.Etcd.LogOutput[0])
if err != nil {
return err
}
srv.lg.Info("created etcd log file", zap.String("path", srv.Member.Etcd.LogOutput))
srv.lg.Info("created etcd log file", zap.String("path", srv.Member.Etcd.LogOutput[0]))
return nil
}

Expand Down Expand Up @@ -664,7 +665,7 @@ func (srv *Server) handle_SIGQUIT_ETCD_AND_ARCHIVE_DATA() (*rpcpb.Response, erro
// TODO: support separate WAL directory
if err = archive(
srv.Member.BaseDir,
srv.Member.Etcd.LogOutput,
srv.Member.Etcd.LogOutput[0],
srv.Member.Etcd.DataDir,
); err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions functional/rpcpb/etcd_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestEtcd(t *testing.T) {
InitialCorruptCheck: true,

Logger: "zap",
LogOutput: "/tmp/etcd-functional-1/etcd.log",
LogOutput: []string{"/tmp/etcd-functional-1/etcd.log"},
Debug: true,
}

Expand Down Expand Up @@ -133,7 +133,7 @@ func TestEtcd(t *testing.T) {
expc.PreVote = true
expc.ExperimentalInitialCorruptCheck = true
expc.Logger = "zap"
expc.LogOutput = "/tmp/etcd-functional-1/etcd.log"
expc.LogOutput = []string{"/tmp/etcd-functional-1/etcd.log"}
expc.Debug = true
cfg, err := e.EmbedConfig()
if err != nil {
Expand Down
357 changes: 184 additions & 173 deletions functional/rpcpb/rpc.pb.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion functional/rpcpb/rpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ message Etcd {

string Logger = 71 [(gogoproto.moretags) = "yaml:\"logger\""];
// LogOutput is the log file to store current etcd server logs.
string LogOutput = 72 [(gogoproto.moretags) = "yaml:\"log-output\""];
repeated string LogOutput = 72 [(gogoproto.moretags) = "yaml:\"log-output\""];
bool Debug = 73 [(gogoproto.moretags) = "yaml:\"debug\""];
}

Expand Down
12 changes: 9 additions & 3 deletions functional/tester/cluster_read_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,17 @@ func read(lg *zap.Logger, fpath string) (*Cluster, error) {
clus.Members[i].ClientCertData = string(data)
}

if mem.Etcd.LogOutput == "" {
if len(mem.Etcd.LogOutput) == 0 {
return nil, fmt.Errorf("mem.Etcd.LogOutput cannot be empty")
}
if !strings.HasPrefix(mem.Etcd.LogOutput, mem.BaseDir) {
return nil, fmt.Errorf("LogOutput %q must be prefixed with BaseDir %q", mem.Etcd.LogOutput, mem.BaseDir)
for _, v := range mem.Etcd.LogOutput {
switch v {
case "stderr", "stdout", "/dev/null", "default":
default:
if !strings.HasPrefix(v, mem.BaseDir) {
return nil, fmt.Errorf("LogOutput %q must be prefixed with BaseDir %q", v, mem.BaseDir)
}
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions functional/tester/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func Test_read(t *testing.T) {
PreVote: true,
InitialCorruptCheck: true,
Logger: "zap",
LogOutput: "/tmp/etcd-functional-1/etcd.log",
LogOutput: []string{"/tmp/etcd-functional-1/etcd.log"},
Debug: true,
},
ClientCertData: "",
Expand Down Expand Up @@ -116,7 +116,7 @@ func Test_read(t *testing.T) {
PreVote: true,
InitialCorruptCheck: true,
Logger: "zap",
LogOutput: "/tmp/etcd-functional-2/etcd.log",
LogOutput: []string{"/tmp/etcd-functional-2/etcd.log"},
Debug: true,
},
ClientCertData: "",
Expand Down Expand Up @@ -169,7 +169,7 @@ func Test_read(t *testing.T) {
PreVote: true,
InitialCorruptCheck: true,
Logger: "zap",
LogOutput: "/tmp/etcd-functional-3/etcd.log",
LogOutput: []string{"/tmp/etcd-functional-3/etcd.log"},
Debug: true,
},
ClientCertData: "",
Expand Down

0 comments on commit 8ee8778

Please sign in to comment.