From 3573e1a0b2d3129b191e21047b7bbf0b754bc6e5 Mon Sep 17 00:00:00 2001 From: Bartek Tofel Date: Wed, 11 Dec 2024 18:14:55 +0100 Subject: [PATCH] [TT-1894] add logstream flushing to default ccip cleanup (#1570) ## Motivation No Docker container logs are ever dumped. ## Solution CCIP local cluster setup was missing crucial part of flushing the logs. --- .../ccip-tests/testsetups/ccip.go | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/integration-tests/ccip-tests/testsetups/ccip.go b/integration-tests/ccip-tests/testsetups/ccip.go index eee424d50d..74fdd3c35b 100644 --- a/integration-tests/ccip-tests/testsetups/ccip.go +++ b/integration-tests/ccip-tests/testsetups/ccip.go @@ -35,6 +35,7 @@ import ( "github.com/smartcontractkit/chainlink-testing-framework/lib/k8s/config" "github.com/smartcontractkit/chainlink-testing-framework/lib/k8s/environment" "github.com/smartcontractkit/chainlink-testing-framework/lib/networks" + "github.com/smartcontractkit/chainlink-testing-framework/lib/utils/osutil" "github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext" integrationactions "github.com/smartcontractkit/chainlink/integration-tests/actions" @@ -1386,6 +1387,10 @@ func (o *CCIPTestSetUpOutputs) CreateEnvironment( t.Cleanup(func() { if configureCLNode { if ccipEnv.LocalCluster != nil { + if t.Failed() || (ccipEnv.LocalCluster.TestConfig.GetLoggingConfig() != nil && ccipEnv.LocalCluster.TestConfig.GetLoggingConfig().TestLogCollect != nil && *ccipEnv.LocalCluster.TestConfig.GetLoggingConfig().TestLogCollect) { + flushClLogs(*lggr, ccipEnv.LocalCluster) + } + err := ccipEnv.LocalCluster.Terminate() require.NoError(t, err, "Local cluster termination shouldn't fail") require.NoError(t, o.Reporter.SendReport(t, namespace, false), "Aggregating and sending report shouldn't fail") @@ -1406,6 +1411,24 @@ func (o *CCIPTestSetUpOutputs) CreateEnvironment( return chainByChainID } +func flushClLogs(l zerolog.Logger, testEnv *test_env.CLClusterTestEnv) { + l.Info().Msg("Shutting down LogStream") + logPath, err := osutil.GetAbsoluteFolderPath("logs") + if err == nil { + l.Info().Str("Absolute path", logPath).Msg("LogStream logs folder location") + } + + l.Info().Msg("Flushing LogStream logs") + // we can't do much if this fails, so we just log the error in LogStream + if err := testEnv.LogStream.FlushAndShutdown(); err != nil { + l.Error().Err(err).Msg("Error flushing and shutting down LogStream") + } + testEnv.LogStream.PrintLogTargetsLocations() + testEnv.LogStream.SaveLogLocationInTestSummary() + + l.Info().Msg("Finished shutting down LogStream") +} + func createEnvironmentConfig(t *testing.T, envName string, testConfig *CCIPTestConfig, reportPath string) *environment.Config { envConfig := &environment.Config{ NamespacePrefix: envName,