From fb1137f6945c2c70e7775918bca30feb9ea4f607 Mon Sep 17 00:00:00 2001 From: zyy17 Date: Mon, 11 Nov 2024 15:41:20 +0800 Subject: [PATCH] fix: specify empty logDir when only log to stdout (#210) * fix: specify empty logDir when only log to stdout * fix: e2e failed --- pkg/dbconfig/common.go | 13 ++++++++++--- .../test_cluster_enable_monitoring.go | 5 ++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pkg/dbconfig/common.go b/pkg/dbconfig/common.go index d2045cc..60952f6 100644 --- a/pkg/dbconfig/common.go +++ b/pkg/dbconfig/common.go @@ -172,12 +172,19 @@ func (c *LoggingConfig) ConfigureLogging(spec *v1alpha1.LoggingSpec) { return } - if spec.IsOnlyLogToStdout() { - c.Dir = nil - } else if spec.LogsDir != "" { + // Default to empty string. + c.Dir = pointer.String("") + + // If logsDir is set, use it as the log directory. + if len(spec.LogsDir) > 0 { c.Dir = pointer.String(spec.LogsDir) } + // If only log to stdout, disable log to file even if logsDir is set. + if spec.IsOnlyLogToStdout() { + c.Dir = pointer.String("") + } + c.Level = pointer.String(c.levelWithFilters(string(spec.Level), spec.Filters)) c.LogFormat = pointer.String(string(spec.Format)) diff --git a/tests/e2e/greptimedbcluster/test_cluster_enable_monitoring.go b/tests/e2e/greptimedbcluster/test_cluster_enable_monitoring.go index af9bb3f..e49384d 100644 --- a/tests/e2e/greptimedbcluster/test_cluster_enable_monitoring.go +++ b/tests/e2e/greptimedbcluster/test_cluster_enable_monitoring.go @@ -100,10 +100,9 @@ func TestClusterEnableMonitoring(ctx context.Context, h *helper.Helper) { // Disable monitoring. By("Disable monitoring") + originalCluster := testCluster.DeepCopy() testCluster.Spec.Monitoring.Enabled = false - Eventually(func() error { - return h.Update(ctx, testCluster) - }, helper.DefaultTimeout, time.Second).ShouldNot(HaveOccurred(), "failed to update cluster") + Expect(h.Patch(ctx, testCluster, client.MergeFrom(originalCluster))).NotTo(HaveOccurred(), "failed to patch cluster") By("Check the status of testCluster") Eventually(func() error {