Skip to content

Commit bcbe64d

Browse files
committed
dump log when start dp failed.
Signed-off-by: doujiang24 <doujiang24@gmail.com>
1 parent 50ef7bb commit bcbe64d

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

api/plugins/tests/integration/dataplane/data_plane.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,9 @@ func StartDataPlane(t *testing.T, opt *Option) (*DataPlane, error) {
266266
if _, ok := validationCache[digest]; !ok {
267267
// Workaround for https://github.com/envoyproxy/envoy/issues/35961
268268
// TODO: drop this once we upgrade to Envoy 1.30+
269-
cfgFile, _ := os.Create(cfgFile.Name())
270-
opt.Bootstrap.WriteToForValidation(cfgFile)
269+
validationFile, _ := os.Create(cfgFile.Name())
270+
opt.Bootstrap.WriteToForValidation(validationFile)
271+
validationFile.Close()
271272

272273
validateCmd := cmdline + " " + envoyValidateCmd
273274
cmds := strings.Fields(validateCmd)
@@ -286,8 +287,9 @@ func StartDataPlane(t *testing.T, opt *Option) (*DataPlane, error) {
286287

287288
validationCache[digest] = struct{}{}
288289

289-
cfgFile, _ = os.Create(cfgFile.Name())
290-
cfgFile.Write(content)
290+
restoreFile, _ := os.Create(cfgFile.Name())
291+
restoreFile.Write(content)
292+
restoreFile.Close()
291293
}
292294

293295
if opt.LogLevel != "" {
@@ -366,6 +368,7 @@ func StartDataPlane(t *testing.T, opt *Option) (*DataPlane, error) {
366368
select {
367369
case err := <-done:
368370
ticker.Stop()
371+
dumpEnvoyLog(dir)
369372
return nil, err
370373
case <-deadline:
371374
break loop
@@ -379,6 +382,7 @@ func StartDataPlane(t *testing.T, opt *Option) (*DataPlane, error) {
379382

380383
select {
381384
case err := <-done:
385+
dumpEnvoyLog(dir)
382386
return nil, err
383387
default:
384388
}
@@ -388,6 +392,20 @@ func StartDataPlane(t *testing.T, opt *Option) (*DataPlane, error) {
388392
return dp, nil
389393
}
390394

395+
func dumpEnvoyLog(dir string) {
396+
stdoutPath := filepath.Join(dir, "stdout")
397+
content, err := os.ReadFile(stdoutPath)
398+
if err != nil {
399+
logger.Info("failed to read envoy stdout for diagnostics", "err", err)
400+
return
401+
}
402+
if len(content) > 0 {
403+
logger.Info("envoy stdout on startup failure", "output", string(content))
404+
} else {
405+
logger.Info("envoy stdout is empty on startup failure")
406+
}
407+
}
408+
391409
func (dp *DataPlane) root() string {
392410
pwd, _ := os.Getwd()
393411
name := dp.t.Name()

0 commit comments

Comments
 (0)