From 0e5019987a0145904fd377ea063f7dbd720bd84f Mon Sep 17 00:00:00 2001 From: Bartek Tofel Date: Fri, 19 Jan 2024 11:37:14 -0300 Subject: [PATCH] Log stream improvements (#11791) * use default docker hooks from CTF, pass logstream as functional option when creating a new container * bump ctf * use tagged ctf version * use tagged CTF version * use log stream from env component, not cl node --- integration-tests/docker/test_env/cl_node.go | 25 +------------------ integration-tests/docker/test_env/test_env.go | 17 ++----------- .../docker/test_env/test_env_builder.go | 2 +- 3 files changed, 4 insertions(+), 40 deletions(-) diff --git a/integration-tests/docker/test_env/cl_node.go b/integration-tests/docker/test_env/cl_node.go index 1466d03c6f1..fefc9ca8838 100644 --- a/integration-tests/docker/test_env/cl_node.go +++ b/integration-tests/docker/test_env/cl_node.go @@ -52,12 +52,8 @@ type ClNode struct { UserEmail string `json:"userEmail"` UserPassword string `json:"userPassword"` AlwaysPullImage bool `json:"-"` - PostStartsHooks []tc.ContainerHook `json:"-"` - PostStopsHooks []tc.ContainerHook `json:"-"` - PreTerminatesHooks []tc.ContainerHook `json:"-"` t *testing.T l zerolog.Logger - ls *logstream.LogStream } type ClNodeOption = func(c *ClNode) @@ -97,7 +93,7 @@ func WithDbContainerName(name string) ClNodeOption { func WithLogStream(ls *logstream.LogStream) ClNodeOption { return func(c *ClNode) { - c.ls = ls + c.LogStream = ls } } @@ -150,25 +146,6 @@ func NewClNode(networks []string, imageName, imageVersion string, nodeConfig *ch return n, nil } -func (n *ClNode) SetDefaultHooks() { - n.PostStartsHooks = []tc.ContainerHook{ - func(ctx context.Context, c tc.Container) error { - if n.ls != nil { - return n.ls.ConnectContainer(ctx, c, "cl-node") - } - return nil - }, - } - n.PostStopsHooks = []tc.ContainerHook{ - func(ctx context.Context, c tc.Container) error { - if n.ls != nil { - return n.ls.DisconnectContainer(c) - } - return nil - }, - } -} - func (n *ClNode) SetTestLogger(t *testing.T) { n.l = logging.GetTestLogger(t) n.t = t diff --git a/integration-tests/docker/test_env/test_env.go b/integration-tests/docker/test_env/test_env.go index c27078dc16f..4ffa8cb3a88 100644 --- a/integration-tests/docker/test_env/test_env.go +++ b/integration-tests/docker/test_env/test_env.go @@ -1,7 +1,6 @@ package test_env import ( - "context" "encoding/json" "fmt" "math/big" @@ -66,7 +65,7 @@ func (te *CLClusterTestEnv) WithTestEnvConfig(cfg *TestEnvConfig) *CLClusterTest te.Cfg = cfg if cfg.MockAdapter.ContainerName != "" { n := []string{te.Network.Name} - te.MockAdapter = test_env.NewKillgrave(n, te.Cfg.MockAdapter.ImpostersPath, test_env.WithContainerName(te.Cfg.MockAdapter.ContainerName)) + te.MockAdapter = test_env.NewKillgrave(n, te.Cfg.MockAdapter.ImpostersPath, test_env.WithContainerName(te.Cfg.MockAdapter.ContainerName), test_env.WithLogStream(te.LogStream)) } return te } @@ -154,7 +153,7 @@ func (te *CLClusterTestEnv) StartClCluster(nodeConfig *chainlink.Config, count i if te.Cfg != nil && te.Cfg.ClCluster != nil { te.ClCluster = te.Cfg.ClCluster } else { - opts = append(opts, WithSecrets(secretsConfig)) + opts = append(opts, WithSecrets(secretsConfig), WithLogStream(te.LogStream)) te.ClCluster = &ClCluster{} for i := 0; i < count; i++ { ocrNode, err := NewClNode([]string{te.Network.Name}, os.Getenv("CHAINLINK_IMAGE"), os.Getenv("CHAINLINK_VERSION"), nodeConfig, opts...) @@ -172,18 +171,6 @@ func (te *CLClusterTestEnv) StartClCluster(nodeConfig *chainlink.Config, count i } } - if te.LogStream != nil { - for _, node := range te.ClCluster.Nodes { - node.ls = te.LogStream - } - if te.MockAdapter != nil { - err := te.LogStream.ConnectContainer(context.Background(), te.MockAdapter.Container, "mock-adapter") - if err != nil { - return err - } - } - } - // Start/attach node containers return te.ClCluster.Start() } diff --git a/integration-tests/docker/test_env/test_env_builder.go b/integration-tests/docker/test_env/test_env_builder.go index dd5e2643bcd..336a70ded2b 100644 --- a/integration-tests/docker/test_env/test_env_builder.go +++ b/integration-tests/docker/test_env/test_env_builder.go @@ -238,7 +238,7 @@ func (b *CLTestEnvBuilder) Build() (*CLClusterTestEnv, error) { return nil, fmt.Errorf("test environment builder failed: %w", fmt.Errorf("cannot start mock adapter without a network")) } - b.te.MockAdapter = test_env.NewKillgrave([]string{b.te.Network.Name}, "") + b.te.MockAdapter = test_env.NewKillgrave([]string{b.te.Network.Name}, "", test_env.WithLogStream(b.te.LogStream)) err = b.te.StartMockAdapter() if err != nil {