Skip to content

Commit b6d02a5

Browse files
ShivaShiva
authored andcommitted
add more logs
1 parent fa88aed commit b6d02a5

3 files changed

Lines changed: 56 additions & 17 deletions

File tree

systest/backup/nfs-backup/backup_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ func backupRestoreTest(t *testing.T, backupAlphaName string, backupZeroName stri
5252

5353
// Wait for containers to be healthy before proceeding
5454
t.Logf("Waiting for %s to be healthy...", backupAlphaName)
55+
fmt.Println("=================================================")
56+
fmt.Println("testutil.DockerPrefix ------>", testutil.DockerPrefix)
57+
fmt.Println("=================================================")
5558
backupAlpha := testutil.ContainerInstance{Name: backupAlphaName, Prefix: testutil.DockerPrefix}
5659
require.NoError(t, backupAlpha.BestEffortWaitForHealthy(8080))
5760

t/t.go

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -230,40 +230,55 @@ func detectRace(prefix string) bool {
230230
}
231231

232232
func outputLogs(prefix string) {
233+
fmt.Printf("Outputting logs for prefix: %s\n", prefix)
234+
fmt.Println("=================================================")
235+
fmt.Println("=================================================")
236+
fmt.Println("=================================================")
233237
f, err := os.CreateTemp(".", prefix+"*.log")
234238
x.Check(err)
235239
defer func() {
236240
if err := f.Close(); err != nil {
237241
fmt.Printf("error closing file: %v", err)
238242
}
239243
}()
240-
printLogs := func(container string) {
241-
in := testutil.GetContainerInstance(prefix, container)
242-
c := in.GetContainer()
243-
if c == nil {
244-
return
245-
}
244+
245+
// Get all containers with this prefix instead of hardcoding container names
246+
// This works for both default docker-compose.yml and custom compose files
247+
containers := testutil.AllContainers(prefix)
248+
249+
fmt.Println("-------------------------------------------------")
250+
fmt.Printf("Containers: %+v\n", containers)
251+
fmt.Println("-------------------------------------------------")
252+
253+
for _, c := range containers {
246254
logCmd := exec.Command("docker", "logs", c.ID)
247255
out, err := logCmd.CombinedOutput()
248-
x.Check(err)
256+
if err != nil {
257+
fmt.Printf("Error getting logs for container %s (ID: %s): %v\n", c.Names, c.ID, err)
258+
continue
259+
}
249260
if _, err := f.Write(out); err != nil {
250261
fmt.Printf("error writing container logs to file: %v", err)
251262
}
252-
fmt.Printf("Docker logs for %s is %s with error %+v ", c.ID, string(out), err)
253-
}
254-
for i := 0; i <= 3; i++ {
255-
printLogs("zero" + strconv.Itoa(i))
263+
// Include container name in the log output for easier debugging
264+
containerName := "unknown"
265+
if len(c.Names) > 0 {
266+
containerName = strings.TrimPrefix(c.Names[0], "/")
267+
}
268+
fmt.Printf("Docker logs for %s (ID: %s):\n%s\n", containerName, c.ID, string(out))
256269
}
257270

258-
for i := 0; i <= 6; i++ {
259-
printLogs("alpha" + strconv.Itoa(i))
260-
}
271+
fmt.Println("-------------------------------------------------")
272+
fmt.Printf("Logs written to file: %s\n", f.Name())
273+
fmt.Println("-------------------------------------------------")
274+
261275
s := fmt.Sprintf("---> LOGS for %s written to %s .\n", prefix, f.Name())
262276
_, err = oc.Write([]byte(s))
263277
x.Check(err)
264278
}
265279

266280
func stopCluster(composeFile, prefix string, wg *sync.WaitGroup, err error) {
281+
fmt.Println("in stop cluster function========================")
267282
go func() {
268283
if err != nil {
269284
outputLogs(prefix)
@@ -547,9 +562,15 @@ func runTests(taskCh chan task, closer *z.Closer) error {
547562
} else {
548563
// we are not using err variable here because we dont want to
549564
// print logs of default cluster in case of custom test fail.
550-
if cerr := runCustomClusterTest(ctx, task.pkg.ID, wg, xmlFile); cerr != nil {
551-
return cerr
565+
if err = runCustomClusterTest(ctx, task.pkg.ID, wg, xmlFile); err != nil {
566+
fmt.Printf("Ran custom cluster test for package: %s with error: %v\n", task.pkg.ID, err)
567+
fmt.Println("=================================================")
568+
fmt.Println("=================================================")
569+
return err
552570
}
571+
fmt.Printf("Ran custom cluster test for package: %s with error: %v\n", task.pkg.ID, err)
572+
fmt.Println("=================================================")
573+
fmt.Println("=================================================")
553574
}
554575
}
555576
return err

testutil/docker.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ func (in ContainerInstance) BestEffortWaitForHealthy(privatePort uint16) error {
5050
if len(port) == 0 {
5151
return nil
5252
}
53+
fmt.Println("--------------------------------")
54+
fmt.Println("best effort wait for healthy port ------>", port)
55+
fmt.Println("--------------------------------", port == "")
5356
checkACL := func(body []byte) error {
5457
// Zero returns OK as response
5558
if string(body) == "OK" {
@@ -70,6 +73,9 @@ func (in ContainerInstance) BestEffortWaitForHealthy(privatePort uint16) error {
7073
tryWith := func(host string) error {
7174
maxAttempts := 60
7275
for attempt := range maxAttempts {
76+
fmt.Println("--------------------------------")
77+
fmt.Println("best effort wait for healthy attempt ------>", attempt)
78+
fmt.Println("-------------url-------------------", "http://"+host+":"+port+"/health")
7379
resp, err := http.Get("http://" + host + ":" + port + "/health")
7480
var body []byte
7581
if resp != nil && resp.Body != nil {
@@ -207,9 +213,16 @@ func AllContainers(prefix string) []types.Container {
207213

208214
var out []types.Container
209215
for _, c := range containers {
216+
fmt.Println("--------------------------------")
217+
fmt.Println("overall containers", c.Names)
218+
fmt.Println("-------------prefix-------------------", prefix)
210219
for _, name := range c.Names {
211220
if strings.HasPrefix(name, "/"+prefix) {
212221
out = append(out, c)
222+
fmt.Println("found container", name)
223+
} else {
224+
fmt.Println("-------------dont have that prefix-------------------", name)
225+
213226
}
214227
}
215228
}
@@ -227,7 +240,7 @@ func ContainerAddrWithHost(name string, privatePort uint16, host string) string
227240
}
228241

229242
func ContainerAddrWithHostRetry(name string, privatePort uint16, host string) string {
230-
maxAttempts := 30
243+
maxAttempts := 60
231244
for attempt := range maxAttempts {
232245
fmt.Printf("Attempt %d to get container address for %s:%d with host %s\n", attempt, name, privatePort, host)
233246
c := getContainer(name)
@@ -243,6 +256,8 @@ func ContainerAddrWithHostRetry(name string, privatePort uint16, host string) st
243256
}
244257
}
245258

259+
fmt.Printf("\n\n\ndid not find container address for %s:%d with host %s\n\n\n", name, privatePort, host)
260+
246261
return host + ":" + strconv.Itoa(int(privatePort))
247262
}
248263

0 commit comments

Comments
 (0)