Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

Commit 59b38cd

Browse files
committed
Get output files when they have a suffix
1 parent 7df1dd7 commit 59b38cd

4 files changed

Lines changed: 35 additions & 3 deletions

File tree

e2e/_suites/kubernetes-autodiscover/autodiscover_test.go

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,19 +366,45 @@ func (m *podsManager) waitForEventsCondition(podName string, conditionFn func(ct
366366
localPath := filepath.Join(tmpDir, "events")
367367
exp := backoff.WithContext(backoff.NewConstantBackOff(1*time.Second), ctx)
368368
return backoff.Retry(func() error {
369-
_, err := m.kubectl.Run(ctx, "cp", "--no-preserve", containerPath, localPath)
369+
err := m.copyEvents(ctx, containerPath, localPath)
370370
if err != nil {
371-
log.Debugf("Failed to copy events from %s to %s: %s", containerPath, localPath, err)
372-
return err
371+
return fmt.Errorf("failed to copy events from %s: %w", containerPath, err)
373372
}
374373
ok, err := conditionFn(ctx, localPath)
374+
if err != nil {
375+
return fmt.Errorf("events condition failed: %w", err)
376+
}
375377
if !ok {
376378
return fmt.Errorf("events do not satisfy condition")
377379
}
378380
return nil
379381
}, exp)
380382
}
381383

384+
func (m *podsManager) copyEvents(ctx context.Context, containerPath string, localPath string) error {
385+
today := time.Now().Format("20060102")
386+
paths := []string{
387+
containerPath,
388+
389+
// Format used since 8.0.
390+
containerPath + "-" + today + ".ndjson",
391+
}
392+
393+
var err error
394+
var output string
395+
for _, containerPath := range paths {
396+
// This command always succeeds, so check if the local path has been created.
397+
os.Remove(localPath)
398+
output, _ = m.kubectl.Run(ctx, "cp", "--no-preserve", containerPath, localPath)
399+
if _, err = os.Stat(localPath); os.IsNotExist(err) {
400+
continue
401+
}
402+
return nil
403+
}
404+
log.Debugf("Failed to copy events from %s to %s: %s", containerPath, localPath, output)
405+
return err
406+
}
407+
382408
func (m *podsManager) getPodInstances(ctx context.Context, podName string) (instances []string, err error) {
383409
span, _ := apm.StartSpanOptions(m.ctx, "Getting pod instances", "pod.instances.get", apm.SpanOptions{
384410
Parent: apm.SpanFromContext(m.ctx).TraceContext(),

e2e/_suites/kubernetes-autodiscover/testdata/templates/filebeat.yml.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ data:
4444
output.file:
4545
path: /tmp
4646
filename: beats-events
47+
rotate_every_kb: 100000
48+
rotate_on_startup: false
4749
---
4850
apiVersion: apps/v1
4951
kind: DaemonSet

e2e/_suites/kubernetes-autodiscover/testdata/templates/heartbeat.yml.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ data:
4141
output.file:
4242
path: /tmp
4343
filename: beats-events
44+
rotate_every_kb: 100000
45+
rotate_on_startup: false
4446
---
4547
# Deploy singleton instance in the whole cluster for some unique data sources, like kube-state-metrics
4648
apiVersion: apps/v1

e2e/_suites/kubernetes-autodiscover/testdata/templates/metricbeat.yml.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ data:
1818
output.file:
1919
path: /tmp
2020
filename: beats-events
21+
rotate_every_kb: 100000
22+
rotate_on_startup: false
2123
---
2224
apiVersion: apps/v1
2325
kind: DaemonSet

0 commit comments

Comments
 (0)