Skip to content

Commit 9d3e97d

Browse files
authored
Collect restart logs separately (#1437)
* read all logs even with restarts * subdirs * add test private keys to the lib, updated besu default image * changeset
1 parent e34941d commit 9d3e97d

File tree

10 files changed

+75
-13
lines changed

10 files changed

+75
-13
lines changed

book/src/framework/components/blockchains/evm.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,17 @@ Public: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
7272
Private: ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
7373
```
7474

75-
Test keys for `Besu` can be found [here](https://besu.hyperledger.org/23.4.1/private-networks/reference/accounts-for-testing)
75+
For `Besu` keys are
76+
```
77+
Public: 0xfe3b557e8fb62b89f4916b721be55ceb828dbd73
78+
Private: 0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63
79+
80+
Public: 0x627306090abaB3A6e1400e9345bC60c78a8BEf57
81+
Private: 0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3
82+
83+
Public: 0xf17f52151EbEF6C7334FAD080c5704D77216b732
84+
Private: 0xae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f
85+
```
86+
87+
More docs for `Besu` can be found [here](https://besu.hyperledger.org/private-networks/reference/accounts-for-testing)
7688

book/src/framework/configuration.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
| CTF_CONFIGS | Path(s) to test config files. <br/>Can be more than one, ex.: smoke.toml,smoke_1.toml,smoke_2.toml.<br/>First filepath will hold all the merged values | Any valid TOML file path | - ||
88
| CTF_LOG_LEVEL | Harness log level | `info`, `debug`, `trace` | `info` | 🚫 |
99
| CTF_PROMTAIL_DEBUG | Set `true` if you are integrating with remote `Loki` push API to debug Promtail | `true`, `false` | `false` | 🚫 |
10+
| CTF_IGNORE_CRITICAL_LOGS | Ignore all logs that has CRIT,FATAL or PANIC levels (Chainlink nodes only!) | `true`, `false` | `false` | 🚫 |
11+
| CTF_CHAINLINK_IMAGE | Flag to override Chainlink Docker image in format $repository:$tag | $repository:$tag | - | 🚫 |
12+
| CTF_JD_IMAGE | Job distributor service image in format $repository:$tag | $repository:$tag | - | 🚫 |
1013
| LOKI_URL | URL to `Loki` push api, should be like`${host}/loki/api/v1/push` | URL | `http://host.docker.internal:3030/loki/api/v1/push` | 🚫 |
1114
| LOKI_TENANT_ID | Streams all components logs to `Loki`, see params below | `string` | `promtail` | 🚫 |
1215
| LOKI_BASIC_AUTH | Basic auth in format $user:$password | `$user:$password` | - | 🚫 |
1316
| 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` | 🚫 |
15-
| CTF_CHAINLINK_IMAGE | Flag to override Chainlink Docker image in format $repository:$tag | $repository:$tag | - | 🚫 |

framework/.changeset/v0.3.3.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- Upgrade Besu to 24.9.1
2+
- Expose default test private keys as framework constants
3+
- Collect all the logs even between restarts

framework/components/blockchain/besu.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,15 @@ import (
1212
"github.com/testcontainers/testcontainers-go/wait"
1313
)
1414

15+
const (
16+
DefaultBesuPrivateKey1 = "8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63"
17+
DefaultBesuPrivateKey2 = "c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3"
18+
DefaultBesuPrivateKey3 = "ae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f"
19+
)
20+
1521
func defaultBesu(in *Input) {
1622
if in.Image == "" {
17-
in.Image = "hyperledger/besu:22.1.0"
23+
in.Image = "hyperledger/besu:24.9.1"
1824
}
1925
if in.ChainID == "" {
2026
in.ChainID = "1337"

framework/components/blockchain/geth.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const (
5151
}
5252
}
5353
`
54+
DefaultGethPrivateKey = `ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80`
5455
)
5556

5657
var initScript = `

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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
)
2222

2323
const (
24-
DefaultCTFLogsDir = "logs"
24+
DefaultCTFLogsDir = "logs/docker"
2525
)
2626

2727
func IsDockerRunning() bool {
@@ -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/examples/myproject/smoke.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[blockchain_a]
33
# choose "anvil", "geth" or "besu"
44
# uncomment the second line for "anvil"
5-
type = "geth"
5+
type = "besu"
66
# docker_cmd_params = ["-b", "1"]
77

88
[data_provider]

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)