Skip to content

Commit 48f68ac

Browse files
committed
read all logs even with restarts
1 parent e34941d commit 48f68ac

File tree

4 files changed

+46
-7
lines changed

4 files changed

+46
-7
lines changed

framework/components/simple_node_set/reload.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package simple_node_set
22

33
import (
4+
"fmt"
5+
"github.com/google/uuid"
6+
"github.com/smartcontractkit/chainlink-testing-framework/framework"
47
"github.com/smartcontractkit/chainlink-testing-framework/framework/chaos"
58
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain"
69
"time"
@@ -9,6 +12,10 @@ import (
912
// UpgradeNodeSet updates nodes configuration TOML files
1013
// this API is discouraged, however, you can use it if nodes require restart or configuration updates, temporarily!
1114
func UpgradeNodeSet(in *Input, bc *blockchain.Output, wait time.Duration) (*Output, error) {
15+
uniq := fmt.Sprintf("%s-%s", framework.DefaultCTFLogsDir, uuid.NewString()[0:4])
16+
if err := framework.WriteAllContainersLogs(uniq); err != nil {
17+
return nil, err
18+
}
1219
_, err := chaos.ExecPumba("rm --volumes=false re2:^node.*|ns-postgresql.*", wait)
1320
if err != nil {
1421
return nil, err

framework/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ func Load[X any](t *testing.T) (*X, error) {
130130
t.Cleanup(func() {
131131
err := Store[X](input)
132132
require.NoError(t, err)
133-
err = WriteAllContainersLogs()
133+
err = WriteAllContainersLogs(DefaultCTFLogsDir)
134134
require.NoError(t, err)
135-
err = checkNodeLogErrors(DefaultCTFLogsDir)
135+
err = checkAllNodeLogErrors()
136136
require.NoError(t, err)
137137
})
138138
// TODO: not all the people have AWS access, sadly enough, uncomment when granted

framework/docker.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,11 @@ func isLocalToolDockerContainer(containerName string) bool {
189189
}
190190

191191
// WriteAllContainersLogs writes all Docker container logs to the default logs directory
192-
func WriteAllContainersLogs() error {
192+
func WriteAllContainersLogs(dir string) error {
193193
L.Info().Msg("Writing Docker containers logs")
194-
if _, err := os.Stat(DefaultCTFLogsDir); os.IsNotExist(err) {
195-
if err := os.MkdirAll(DefaultCTFLogsDir, 0755); err != nil {
196-
return fmt.Errorf("failed to create directory %s: %w", DefaultCTFLogsDir, err)
194+
if _, err := os.Stat(dir); os.IsNotExist(err) {
195+
if err := os.MkdirAll(dir, 0755); err != nil {
196+
return fmt.Errorf("failed to create directory %s: %w", dir, err)
197197
}
198198
}
199199
provider, err := tc.NewDockerProvider()
@@ -220,7 +220,7 @@ func WriteAllContainersLogs() error {
220220
L.Error().Err(err).Str("Container", containerName).Msg("failed to fetch logs for container")
221221
return err
222222
}
223-
logFilePath := filepath.Join(DefaultCTFLogsDir, fmt.Sprintf("%s.log", containerName))
223+
logFilePath := filepath.Join(dir, fmt.Sprintf("%s.log", containerName))
224224
logFile, err := os.Create(logFilePath)
225225
if err != nil {
226226
L.Error().Err(err).Str("Container", containerName).Msg("failed to create container log file")

framework/logs.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,44 @@ import (
66
"os"
77
"path/filepath"
88
"regexp"
9+
"strings"
910
)
1011

1112
const (
1213
EnvVarIgnoreCriticalLogs = "CTF_IGNORE_CRITICAL_LOGS"
1314
)
1415

16+
func getLogDirectories() ([]string, error) {
17+
logDirs := make([]string, 0)
18+
currentDir, err := os.Getwd()
19+
if err != nil {
20+
return nil, fmt.Errorf("failed to get current directory: %w", err)
21+
}
22+
entries, err := os.ReadDir(currentDir)
23+
if err != nil {
24+
return nil, fmt.Errorf("failed to read directory: %w", err)
25+
}
26+
for _, entry := range entries {
27+
if entry.IsDir() && strings.HasPrefix(entry.Name(), "logs-") {
28+
logDirs = append(logDirs, filepath.Join(currentDir, entry.Name()))
29+
}
30+
}
31+
return logDirs, nil
32+
}
33+
34+
func checkAllNodeLogErrors() error {
35+
dirs, err := getLogDirectories()
36+
if err != nil {
37+
return err
38+
}
39+
for _, dd := range dirs {
40+
if err := checkNodeLogErrors(dd); err != nil {
41+
return err
42+
}
43+
}
44+
return nil
45+
}
46+
1547
// checkNodeLogsErrors check Chainlink nodes logs for error levels
1648
func checkNodeLogErrors(dir string) error {
1749
if os.Getenv(EnvVarIgnoreCriticalLogs) == "true" {

0 commit comments

Comments
 (0)