Skip to content

Commit 4734042

Browse files
authored
Merge branch 'main' into TT-1858-Add-test-code-owner-in-test-results-metadata
2 parents b2b077e + ef81a77 commit 4734042

File tree

10 files changed

+112
-0
lines changed

10 files changed

+112
-0
lines changed

.github/workflows/framework-golden-tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ jobs:
1010
env:
1111
LOKI_TENANT_ID: promtail
1212
LOKI_URL: http://localhost:3030/loki/api/v1/push
13+
# this is not the best practice, and it must be fixed, run your tests WITHOUT IT!
14+
# however, on current latest image we must use this flag
15+
CTF_IGNORE_CRITICAL_LOGS: true
1316
runs-on: ubuntu-latest
1417
permissions:
1518
id-token: write

book/src/framework/configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
| LOKI_TENANT_ID | Streams all components logs to `Loki`, see params below | `string` | `promtail` | 🚫 |
1212
| LOKI_BASIC_AUTH | Basic auth in format $user:$password | `$user:$password` | - | 🚫 |
1313
| RESTY_DEBUG | Log all Resty client HTTP calls | `true`, `false` | `false` | 🚫 |
14+
| CTF_IGNORE_CRITICAL_LOGS | Ignore all logs that has CRIT,FATAL or PANIC levels (Chainlink nodes only!) | `true`, `false` | `false` | 🚫 |

framework/.changeset/v0.3.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
- Add Geth node variant
22
- Add Besu node variant
33
- Remove unnecessary blockchain params from docs, set defaults
4+
- Fail any test if there are "CRIT|FATAL|PANIC" log levels (Chainlink nodes only!)
45
- Add "ctf c c" command to clean up all cache files

framework/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ func Load[X any](t *testing.T) (*X, error) {
132132
require.NoError(t, err)
133133
err = WriteAllContainersLogs()
134134
require.NoError(t, err)
135+
err = checkNodeLogErrors(DefaultCTFLogsDir)
136+
require.NoError(t, err)
135137
})
136138
// TODO: not all the people have AWS access, sadly enough, uncomment when granted
137139
//if os.Getenv(EnvVarAWSSecretsManager) == "true" {

framework/logs.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package framework
2+
3+
import (
4+
"bufio"
5+
"fmt"
6+
"os"
7+
"path/filepath"
8+
"regexp"
9+
)
10+
11+
const (
12+
EnvVarIgnoreCriticalLogs = "CTF_IGNORE_CRITICAL_LOGS"
13+
)
14+
15+
// checkNodeLogsErrors check Chainlink nodes logs for error levels
16+
func checkNodeLogErrors(dir string) error {
17+
if os.Getenv(EnvVarIgnoreCriticalLogs) == "true" {
18+
L.Warn().Msg(`CTF_IGNORE_CRITICAL_LOGS is set to true, we ignore all CRIT|FATAL|PANIC errors in node logs!`)
19+
return nil
20+
}
21+
fileRegex := regexp.MustCompile(`^node.*\.log$`)
22+
logLevelRegex := regexp.MustCompile(`(CRIT|PANIC|FATAL)`)
23+
24+
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
25+
if err != nil {
26+
return err
27+
}
28+
if !info.IsDir() && fileRegex.MatchString(info.Name()) {
29+
file, err := os.Open(path)
30+
if err != nil {
31+
return fmt.Errorf("failed to open file %s: %w", path, err)
32+
}
33+
defer file.Close()
34+
35+
scanner := bufio.NewScanner(file)
36+
lineNumber := 1
37+
for scanner.Scan() {
38+
line := scanner.Text()
39+
if logLevelRegex.MatchString(line) {
40+
return fmt.Errorf("file %s contains a matching log level at line %d: %s", path, lineNumber, line)
41+
}
42+
lineNumber++
43+
}
44+
if err := scanner.Err(); err != nil {
45+
return fmt.Errorf("error reading file %s: %w", path, err)
46+
}
47+
}
48+
return nil
49+
})
50+
return err
51+
}

framework/logs_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package framework
2+
3+
import (
4+
"path/filepath"
5+
"testing"
6+
)
7+
8+
// Table test for checkLogFilesForLevels
9+
func TestCheckLogFilesForLevels(t *testing.T) {
10+
tests := []struct {
11+
name string
12+
dir string
13+
content string
14+
expectError bool
15+
}{
16+
{
17+
name: "Clean",
18+
dir: "clean",
19+
expectError: false,
20+
},
21+
{
22+
name: "Contains CRIT",
23+
dir: "crit",
24+
expectError: true,
25+
},
26+
{
27+
name: "Contains PANIC",
28+
dir: "panic",
29+
expectError: true,
30+
},
31+
{
32+
name: "Contains FATAL",
33+
dir: "fatal",
34+
expectError: true,
35+
},
36+
}
37+
38+
for _, tt := range tests {
39+
t.Run(tt.name, func(t *testing.T) {
40+
err := checkNodeLogErrors(filepath.Join("testdata", tt.dir))
41+
if tt.expectError && err == nil {
42+
t.Errorf("expected error but got none")
43+
} else if !tt.expectError && err != nil {
44+
t.Errorf("did not expect error but got: %v", err)
45+
}
46+
})
47+
}
48+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2024-11-29T09:09:31.901Z [INFO] StartUpHealthReport shutdown complete services/health.go:47 version=2.17.0@5ebb632
2+
2024-11-29T09:09:31.901Z [DEBUG] StartUpHealthReport shutdown complete services/health.go:47 version=2.17.0@5ebb632
3+
2024-11-29T09:09:31.901Z [WARN] StartUpHealthReport shutdown complete services/health.go:47 version=2.17.0@5ebb632
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2024-11-29T09:09:31.901Z [CRIT] StartUpHealthReport shutdown complete services/health.go:47 version=2.17.0@5ebb632
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2024-11-29T09:09:31.901Z [FATAL] StartUpHealthReport shutdown complete services/health.go:47 version=2.17.0@5ebb632
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2024-11-29T09:09:31.901Z [PANIC] StartUpHealthReport shutdown complete services/health.go:47 version=2.17.0@5ebb632

0 commit comments

Comments
 (0)