-
Notifications
You must be signed in to change notification settings - Fork 9.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Retain process logs on robustness tests #16077
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,8 +40,14 @@ var ( | |
EtcdServerReadyLines = []string{"ready to serve client requests"} | ||
) | ||
|
||
type LogLines interface { | ||
Lines() []string | ||
LineCount() int | ||
} | ||
|
||
// EtcdProcess is a process that serves etcd requests. | ||
type EtcdProcess interface { | ||
LogLines | ||
EndpointsGRPC() []string | ||
EndpointsHTTP() []string | ||
EndpointsMetrics() []string | ||
|
@@ -61,9 +67,8 @@ type EtcdProcess interface { | |
} | ||
|
||
type LogsExpect interface { | ||
LogLines | ||
ExpectWithContext(context.Context, string) (string, error) | ||
Lines() []string | ||
LineCount() int | ||
} | ||
|
||
type EtcdServerProcess struct { | ||
|
@@ -72,6 +77,7 @@ type EtcdServerProcess struct { | |
proxy proxy.Server | ||
failpoints *BinaryFailpoints | ||
donec chan struct{} // closed when Interact() terminates | ||
logs *procLogs | ||
} | ||
|
||
type EtcdServerProcessConfig struct { | ||
|
@@ -108,7 +114,7 @@ func NewEtcdServerProcess(cfg *EtcdServerProcessConfig) (*EtcdServerProcess, err | |
return nil, err | ||
} | ||
} | ||
ep := &EtcdServerProcess{cfg: cfg, donec: make(chan struct{})} | ||
ep := &EtcdServerProcess{cfg: cfg, donec: make(chan struct{}), logs: &procLogs{}} | ||
if cfg.GoFailPort != 0 { | ||
ep.failpoints = &BinaryFailpoints{member: ep} | ||
} | ||
|
@@ -124,8 +130,8 @@ func (ep *EtcdServerProcess) EndpointsHTTP() []string { | |
} | ||
func (ep *EtcdServerProcess) EndpointsMetrics() []string { return []string{ep.cfg.MetricsURL} } | ||
|
||
func (epc *EtcdServerProcess) Etcdctl(opts ...config.ClientOption) *EtcdctlV3 { | ||
etcdctl, err := NewEtcdctl(epc.Config().Client, epc.EndpointsGRPC(), opts...) | ||
func (ep *EtcdServerProcess) Etcdctl(opts ...config.ClientOption) *EtcdctlV3 { | ||
etcdctl, err := NewEtcdctl(ep.Config().Client, ep.EndpointsGRPC(), opts...) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
@@ -177,6 +183,7 @@ func (ep *EtcdServerProcess) Stop() (err error) { | |
return nil | ||
} | ||
defer func() { | ||
ep.logs.append(ep.proc.Lines()) | ||
ep.proc = nil | ||
}() | ||
|
||
|
@@ -235,6 +242,14 @@ func (ep *EtcdServerProcess) Logs() LogsExpect { | |
return ep.proc | ||
} | ||
|
||
func (ep *EtcdServerProcess) Lines() []string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Proposed interface
|
||
return ep.logs.Lines() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find it pretty unnatural that calling |
||
} | ||
|
||
func (ep *EtcdServerProcess) LineCount() int { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't looks like it's used by anyone. Remove? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just two places ultimately: https://github.com/search?q=repo%3Aetcd-io%2Fetcd%20LineCount&type=code but looks like it could be removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean it's not needed for EtcdServerProcess. |
||
return ep.logs.LineCount() | ||
} | ||
|
||
func (ep *EtcdServerProcess) Kill() error { | ||
ep.cfg.lg.Info("killing server...", zap.String("name", ep.cfg.Name)) | ||
return ep.proc.Signal(syscall.SIGKILL) | ||
|
@@ -378,3 +393,20 @@ func GetVersionFromBinary(binaryPath string) (*semver.Version, error) { | |
|
||
return nil, fmt.Errorf("could not find version in binary output of %s, lines outputted were %v", binaryPath, lines) | ||
} | ||
|
||
type procLogs struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't think the name makes sense. Does "proc" refer to process or something else? As this merges log lines from multiple process lines it's definitely not processLogs. |
||
procLogs []string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You know you don't need to create struct just have |
||
} | ||
|
||
func (m *procLogs) append(lines []string) { | ||
m.procLogs = append(m.procLogs, strings.Repeat("=", 50)+"\n") | ||
m.procLogs = append(m.procLogs, lines...) | ||
} | ||
|
||
func (m *procLogs) Lines() []string { | ||
return m.procLogs | ||
} | ||
|
||
func (m *procLogs) LineCount() int { | ||
return len(m.procLogs) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't need to be a pointer.