Skip to content

Commit 1f33f39

Browse files
authored
[DX-3791] devenv tests Docker logs panics scan (#22021)
* use Docker logs fanout instead of reading logs in each function call * add scaning for panics to automation test * for all devenv tests scan logs for panics or errors + save them (in case of soak tests save only on failure) * remove redundant wrapper * add allowed error messages * fix compile * optimise clean up for subtests * fix lints * CR changes * gomodtidy * CR changes
1 parent df2100a commit 1f33f39

39 files changed

Lines changed: 234 additions & 414 deletions

core/scripts/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ require (
5454
github.com/smartcontractkit/chainlink-evm/gethwrappers v0.0.0-20260119171452-39c98c3b33cd
5555
github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20260409211238-5b99921cbc7c
5656
github.com/smartcontractkit/chainlink-protos/job-distributor v0.18.0
57-
github.com/smartcontractkit/chainlink-testing-framework/framework v0.15.16
57+
github.com/smartcontractkit/chainlink-testing-framework/framework v0.15.17
5858
github.com/smartcontractkit/chainlink-testing-framework/framework/components/chiprouter v1.0.2
5959
github.com/smartcontractkit/chainlink-testing-framework/framework/components/dockercompose v0.1.20
6060
github.com/smartcontractkit/chainlink-testing-framework/lib v1.54.5

core/scripts/go.sum

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

devenv/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ require (
2727
github.com/smartcontractkit/chainlink-evm v0.3.4-0.20260318010722-59d4165024f1
2828
github.com/smartcontractkit/chainlink-evm/gethwrappers v0.0.0-20251211123524-f0c4fe7cfc0a
2929
github.com/smartcontractkit/chainlink-protos/job-distributor v0.12.0
30-
github.com/smartcontractkit/chainlink-testing-framework/framework v0.15.16
30+
github.com/smartcontractkit/chainlink-testing-framework/framework v0.15.17
3131
github.com/smartcontractkit/chainlink-testing-framework/framework/components/fake v0.14.9
3232
github.com/smartcontractkit/chainlink-testing-framework/seth v1.51.5
3333
github.com/smartcontractkit/chainlink-testing-framework/wasp v1.51.2

devenv/go.sum

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

devenv/products/logs.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"io"
88
"strings"
9+
"time"
910

1011
"github.com/docker/docker/api/types/container"
1112
dfilter "github.com/docker/docker/api/types/filters"
@@ -71,6 +72,15 @@ func ScanLogs(l zerolog.Logger, settings ChainlinkNodeLogScannerSettings) error
7172
return lErr
7273
}
7374

75+
return ScanLogsFromStreams(l, settings, logStream)
76+
}
77+
78+
func ScanLogsFromStreams(l zerolog.Logger, settings ChainlinkNodeLogScannerSettings, logStream map[string]io.ReadCloser) error {
79+
if len(logStream) == 0 {
80+
l.Info().Msg("No container logs found to scan")
81+
return nil
82+
}
83+
7484
verifyLogsGroup := &errgroup.Group{}
7585
for _, stream := range logStream {
7686
verifyLogsGroup.Go(func() error {
@@ -240,3 +250,30 @@ func DefaultSettings(extraAllowedMessages ...AllowedLogMessage) ChainlinkNodeLog
240250
AllowedMessages: allowedMessages,
241251
}
242252
}
253+
254+
func CleanupContainerLogs(settings ChainlinkNodeLogScannerSettings) error {
255+
logDir := fmt.Sprintf("%s-%d", framework.DefaultCTFLogsDir, time.Now().UnixNano())
256+
257+
return framework.StreamCTFContainerLogsFanout(
258+
framework.LogStreamConsumer{
259+
Name: "scan-logs",
260+
Consume: func(logStreams map[string]io.ReadCloser) error {
261+
return ScanLogsFromStreams(framework.L, settings, logStreams)
262+
},
263+
},
264+
framework.LogStreamConsumer{
265+
Name: "save-container-logs",
266+
Consume: func(logStreams map[string]io.ReadCloser) error {
267+
_, saveErr := framework.SaveContainerLogsFromStreams(logDir, logStreams)
268+
return saveErr
269+
},
270+
},
271+
framework.LogStreamConsumer{
272+
Name: "print-panic-logs",
273+
Consume: func(logStreams map[string]io.ReadCloser) error {
274+
_ = framework.CheckContainersForPanicsFromStreams(logStreams, 100)
275+
return nil
276+
},
277+
},
278+
)
279+
}

devenv/tests/automation/load_test.go

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/hex"
66
"errors"
77
"fmt"
8+
"io"
89
"math"
910
"math/big"
1011
"strconv"
@@ -61,8 +62,39 @@ func TestLoad(t *testing.T) {
6162
}
6263

6364
t.Cleanup(func() {
64-
_, cErr := framework.SaveContainerLogs(fmt.Sprintf("%s-%s", framework.DefaultCTFLogsDir, t.Name()))
65-
require.NoError(t, cErr)
65+
scanErr := framework.StreamCTFContainerLogsFanout(
66+
framework.LogStreamConsumer{
67+
Name: "scan-logs",
68+
Consume: func(logStreams map[string]io.ReadCloser) error {
69+
return products.ScanLogsFromStreams(framework.L, products.DefaultSettings(), logStreams)
70+
},
71+
},
72+
framework.LogStreamConsumer{
73+
Name: "print-panic-logs",
74+
Consume: func(logStreams map[string]io.ReadCloser) error {
75+
_ = framework.CheckContainersForPanicsFromStreams(logStreams, 100)
76+
return nil
77+
},
78+
},
79+
)
80+
t.Error("failed to scan Docker container logs:", scanErr)
81+
82+
if t.Failed() {
83+
saveErr := framework.StreamCTFContainerLogsFanout(
84+
framework.LogStreamConsumer{
85+
Name: "save-container-logs",
86+
Consume: func(logStreams map[string]io.ReadCloser) error {
87+
_, saveErr := framework.SaveContainerLogsFromStreams(fmt.Sprintf("%s-%d", framework.DefaultCTFLogsDir, time.Now().UnixNano()), logStreams)
88+
return saveErr
89+
},
90+
},
91+
)
92+
if saveErr != nil {
93+
framework.L.Error().Err(saveErr).Msg("failed to save Docker container logs")
94+
}
95+
}
96+
// check scanErr only after saving logs to ensure we don't miss any errors
97+
require.NoError(t, scanErr, "failed to save Docker container logs")
6698
})
6799

68100
for _, tc := range testCases {
@@ -78,15 +110,6 @@ func TestLoad(t *testing.T) {
78110
fmt.Print(string(tcStr))
79111
fmt.Println("--------------------------------")
80112

81-
// dangerous: takes a lot of time, if test runs for a long time
82-
// t.Cleanup(func() {
83-
// err := products.ScanLogs(l, products.DefaultSettings())
84-
// require.NoError(t, err, "Found concerning logs in Chainlink Node logs")
85-
86-
// _, cErr := framework.SaveContainerLogs(fmt.Sprintf("%s-%s", framework.DefaultCTFLogsDir, t.Name()))
87-
// require.NoError(t, cErr)
88-
// })
89-
90113
outputFile := "../../env-out.toml"
91114
in, err := de.LoadOutput[de.Cfg](outputFile)
92115
require.NoError(t, err)

devenv/tests/automation/smoke_test.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package automation
22

33
import (
44
"encoding/json"
5-
"fmt"
65
"math/big"
76
"os"
87
"strconv"
@@ -43,8 +42,7 @@ func TestRegistry_2_0(t *testing.T) {
4342
}
4443

4544
func TestRegistry_2_1(t *testing.T) {
46-
// testNames := []string{"registry_2_1_conditional", "registry_2_1_logtrigger", "registry_2_1_with_mercury_v02", "registry_2_1_with_mercury_v03"}
47-
testNames := []string{"registry_2_1_logtrigger"}
45+
testNames := []string{"registry_2_1_conditional", "registry_2_1_logtrigger", "registry_2_1_with_mercury_v02", "registry_2_1_with_mercury_v03"}
4846
for _, tc := range testNames {
4947
basicAutomationTest(t, Testcase{
5048
RegistryVersion: contracts.RegistryVersion_2_1,
@@ -96,11 +94,8 @@ func basicAutomationTest(t *testing.T, testcase Testcase) {
9694
l.Info().Msg("Running test " + testcase.Name + " with registry version " + testcase.RegistryVersion.String())
9795

9896
t.Cleanup(func() {
99-
err := products.ScanLogs(l, products.DefaultSettings())
100-
require.NoError(t, err, "Found concerning logs in Chainlink Node logs")
101-
102-
_, cErr := framework.SaveContainerLogs(fmt.Sprintf("%s-%s", framework.DefaultCTFLogsDir, t.Name()))
103-
require.NoError(t, cErr)
97+
cleanupErr := products.CleanupContainerLogs(products.DefaultSettings())
98+
require.NoError(t, cleanupErr, "failed to process cleanup container logs")
10499
})
105100

106101
outputFile := "../../env-out.toml"

devenv/tests/cron/smoke_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package cron
22

33
import (
4-
"fmt"
54
"testing"
65
"time"
76

87
"github.com/stretchr/testify/assert"
98
"github.com/stretchr/testify/require"
109

11-
"github.com/smartcontractkit/chainlink-testing-framework/framework"
1210
"github.com/smartcontractkit/chainlink-testing-framework/framework/clclient"
1311
de "github.com/smartcontractkit/chainlink/devenv"
1412
"github.com/smartcontractkit/chainlink/devenv/products"
@@ -22,8 +20,8 @@ func TestSmoke(t *testing.T) {
2220
pdConfig, err := products.LoadOutput[cron.Configurator](outputFile)
2321
require.NoError(t, err)
2422
t.Cleanup(func() {
25-
_, cErr := framework.SaveContainerLogs(fmt.Sprintf("%s-%s", framework.DefaultCTFLogsDir, t.Name()))
26-
require.NoError(t, cErr)
23+
cleanupErr := products.CleanupContainerLogs(products.DefaultSettings())
24+
require.NoError(t, cleanupErr, "failed to process cleanup container logs")
2725
})
2826

2927
cls, err := clclient.New(in.NodeSets[0].Out.CLNodes)

devenv/tests/directrequest/smoke_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package directrequest
22

33
import (
4-
"fmt"
54
"math/big"
65
"testing"
76
"time"
@@ -10,7 +9,6 @@ import (
109
"github.com/ethereum/go-ethereum/common"
1110

1211
"github.com/smartcontractkit/chainlink-evm/gethwrappers/generated/test_api_consumer_wrapper"
13-
"github.com/smartcontractkit/chainlink-testing-framework/framework"
1412
de "github.com/smartcontractkit/chainlink/devenv"
1513
"github.com/smartcontractkit/chainlink/devenv/products"
1614
"github.com/smartcontractkit/chainlink/devenv/products/directrequest"
@@ -27,8 +25,8 @@ func TestSmoke(t *testing.T) {
2725
productCfg, err := products.LoadOutput[directrequest.Configurator](outputFile)
2826
require.NoError(t, err)
2927
t.Cleanup(func() {
30-
_, cErr := framework.SaveContainerLogs(fmt.Sprintf("%s-%s", framework.DefaultCTFLogsDir, t.Name()))
31-
require.NoError(t, cErr)
28+
cleanupErr := products.CleanupContainerLogs(products.DefaultSettings())
29+
require.NoError(t, cleanupErr, "failed to process cleanup container logs")
3230
})
3331

3432
c, auth, _, err := products.ETHClient(

devenv/tests/features/jd_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package features
22

33
import (
4-
"fmt"
54
"testing"
65

76
"github.com/stretchr/testify/require"
87

9-
"github.com/smartcontractkit/chainlink-testing-framework/framework"
108
"github.com/smartcontractkit/chainlink-testing-framework/framework/clclient/gql/client"
119
de "github.com/smartcontractkit/chainlink/devenv"
10+
"github.com/smartcontractkit/chainlink/devenv/products"
1211
)
1312

1413
func TestMultipleJobDistributors(t *testing.T) {
@@ -18,8 +17,8 @@ func TestMultipleJobDistributors(t *testing.T) {
1817
node := in.NodeSets[0].Out.CLNodes[0].Node
1918

2019
t.Cleanup(func() {
21-
_, cErr := framework.SaveContainerLogs(fmt.Sprintf("%s-%s", framework.DefaultCTFLogsDir, t.Name()))
22-
require.NoError(t, cErr)
20+
cleanupErr := products.CleanupContainerLogs(products.DefaultSettings())
21+
require.NoError(t, cleanupErr, "failed to process cleanup container logs")
2322
})
2423

2524
c, err := client.NewWithContext(t.Context(), node.ExternalURL, client.Credentials{

0 commit comments

Comments
 (0)