From 690ac4a92869b0ac7505e27784fbc1af0837c531 Mon Sep 17 00:00:00 2001 From: kczpl <89129941+kczpl@users.noreply.github.com> Date: Sun, 10 Nov 2024 17:05:35 +0100 Subject: [PATCH 1/5] Fix inconsistent error while generating report with no deployment --- cmd/ltctl/report.go | 5 +++++ deployment/config.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/ltctl/report.go b/cmd/ltctl/report.go index 0f7290990..1e26b109b 100644 --- a/cmd/ltctl/report.go +++ b/cmd/ltctl/report.go @@ -90,6 +90,11 @@ func RunGenerateReportCmdF(cmd *cobra.Command, args []string) error { if err != nil { return fmt.Errorf("could not parse output: %w", err) } + + if !output.HasMetrics() { + return fmt.Errorf("the output has no metrics, no active deployment found") + } + promURL = "http://" + output.MetricsServer.PublicIP + ":9090" } diff --git a/deployment/config.go b/deployment/config.go index 44c20c19a..af907e032 100644 --- a/deployment/config.go +++ b/deployment/config.go @@ -246,7 +246,7 @@ type TerraformDBSettings struct { // and provisioned. type ExternalDBSettings struct { // Mattermost database driver - DriverName string `default:"" validate:"oneof:{mysql, postgres, cockroach}"` + DriverName string `default:"postgres" validate:"oneof:{mysql, postgres, cockroach}"` // DSN to connect to the database DataSource string `default:""` // DSN to connect to the database replicas From a4a3c29e82ebc342e982d44968aac1b9c1a0eec8 Mon Sep 17 00:00:00 2001 From: kczpl <89129941+kczpl@users.noreply.github.com> Date: Tue, 12 Nov 2024 13:21:23 +0100 Subject: [PATCH 2/5] Improve error message while no active deployment found and change TerraformStateDir default to ./ltstate --- cmd/ltctl/report.go | 4 ++-- deployment/config.go | 3 ++- deployment/config_test.go | 3 +++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cmd/ltctl/report.go b/cmd/ltctl/report.go index 1e26b109b..56ab1241d 100644 --- a/cmd/ltctl/report.go +++ b/cmd/ltctl/report.go @@ -76,7 +76,7 @@ func RunGenerateReportCmdF(cmd *cobra.Command, args []string) error { } if promURL == "" { - fmt.Printf("Flag --prometheus-url is not set. Defaulting to the deployment's Prometheus server...") + fmt.Println("Flag --prometheus-url is not set. Defaulting to the deployment's Prometheus server...") config, err := getConfig(cmd) if err != nil { return err @@ -92,7 +92,7 @@ func RunGenerateReportCmdF(cmd *cobra.Command, args []string) error { } if !output.HasMetrics() { - return fmt.Errorf("the output has no metrics, no active deployment found") + return fmt.Errorf("no active deployment found, use the `--prometheus-url` flag.\nIf you have a local or manually deployed Prometheus server running") } promURL = "http://" + output.MetricsServer.PublicIP + ":9090" diff --git a/deployment/config.go b/deployment/config.go index af907e032..a83d99ec6 100644 --- a/deployment/config.go +++ b/deployment/config.go @@ -93,7 +93,8 @@ type Config struct { Report report.Config // Directory under which the .terraform directory and state files are managed. // It will be created if it does not exist - TerraformStateDir string `default:"/var/lib/mattermost-load-test-ng" validate:"notempty"` + // ./ltstate is the default value used when `deployer.json`` is configured at all + TerraformStateDir string `default:"./ltstate" validate:"notempty"` // URI of an S3 bucket whose contents are copied to the bucket created in the deployment S3BucketDumpURI string `default:"" validate:"s3uri"` // An optional URI to a MM server database dump file diff --git a/deployment/config_test.go b/deployment/config_test.go index 432bfbc2f..e9989c970 100644 --- a/deployment/config_test.go +++ b/deployment/config_test.go @@ -238,6 +238,9 @@ func TestClusterSubnetIDs(t *testing.T) { require.NotNil(t, cfg.ClusterSubnetIDs.Redis) require.Len(t, cfg.ClusterSubnetIDs.Redis, 0) + + require.NotNil(t, cfg.TerraformStateDir) + require.Equal(t, "./ltstate", cfg.TerraformStateDir) }) t.Run("String() of default values", func(t *testing.T) { From 513551cbf08f715629c8f71981636888f8e68bde Mon Sep 17 00:00:00 2001 From: kczpl <89129941+kczpl@users.noreply.github.com> Date: Fri, 15 Nov 2024 10:35:34 +0100 Subject: [PATCH 3/5] Remove unnecessary new line on no metrics error in report generation --- cmd/ltctl/report.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/ltctl/report.go b/cmd/ltctl/report.go index 56ab1241d..e8e9c4e17 100644 --- a/cmd/ltctl/report.go +++ b/cmd/ltctl/report.go @@ -92,7 +92,7 @@ func RunGenerateReportCmdF(cmd *cobra.Command, args []string) error { } if !output.HasMetrics() { - return fmt.Errorf("no active deployment found, use the `--prometheus-url` flag.\nIf you have a local or manually deployed Prometheus server running") + return fmt.Errorf("no active deployment found, use the `--prometheus-url` flag. If you have a local or manually deployed Prometheus server running") } promURL = "http://" + output.MetricsServer.PublicIP + ":9090" From 8bec6191696d560ee087272e71f0ff57874e19c5 Mon Sep 17 00:00:00 2001 From: Kuba <89129941+kczpl@users.noreply.github.com> Date: Fri, 15 Nov 2024 12:02:50 +0100 Subject: [PATCH 4/5] Remove comment in config.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Alejandro García Montoro --- deployment/config.go | 1 - 1 file changed, 1 deletion(-) diff --git a/deployment/config.go b/deployment/config.go index a83d99ec6..3995ab8be 100644 --- a/deployment/config.go +++ b/deployment/config.go @@ -93,7 +93,6 @@ type Config struct { Report report.Config // Directory under which the .terraform directory and state files are managed. // It will be created if it does not exist - // ./ltstate is the default value used when `deployer.json`` is configured at all TerraformStateDir string `default:"./ltstate" validate:"notempty"` // URI of an S3 bucket whose contents are copied to the bucket created in the deployment S3BucketDumpURI string `default:"" validate:"s3uri"` From cc5a7f66e48145069afe508aed2939031625c646 Mon Sep 17 00:00:00 2001 From: Kuba <89129941+kczpl@users.noreply.github.com> Date: Fri, 15 Nov 2024 12:07:36 +0100 Subject: [PATCH 5/5] Update no deployment message in report generation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Alejandro García Montoro --- cmd/ltctl/report.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/ltctl/report.go b/cmd/ltctl/report.go index e8e9c4e17..7395c7f9b 100644 --- a/cmd/ltctl/report.go +++ b/cmd/ltctl/report.go @@ -92,7 +92,7 @@ func RunGenerateReportCmdF(cmd *cobra.Command, args []string) error { } if !output.HasMetrics() { - return fmt.Errorf("no active deployment found, use the `--prometheus-url` flag. If you have a local or manually deployed Prometheus server running") + return fmt.Errorf("no active deployment found, use the `--prometheus-url` flag if you have a local or manually deployed Prometheus server running") } promURL = "http://" + output.MetricsServer.PublicIP + ":9090"