Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misleading error when generating a report with no deployment #846

Merged

Conversation

kczpl
Copy link
Contributor

@kczpl kczpl commented Nov 11, 2024

Summary

The problem is that when running local tests, the report generator errors out with a misleading message instead of explicitly stating that there is no deployment and therefore cannot generate a report. The error message should be clearer.

This pull request changes the error message when there is no ongoing deployment while generating a report. It improves error handling by checking whether the current Terraform state includes the metrics instance and errors out when it doesn't. To implement this, the ExternalDBSettings.DriverName configuration was changed to use PostgreSQL by default.

Ticket Link

--> https://mattermost.atlassian.net/browse/MM-56949
Github issue: mattermost/mattermost#29148

@agarciamontoro
Copy link
Member

Thank you for the PR, @kczpl! Will take a look as soon as I can :)

@agarciamontoro agarciamontoro added the 2: Dev Review Requires review by a core committer label Nov 11, 2024
@kczpl
Copy link
Contributor Author

kczpl commented Nov 11, 2024

Thank you! I've also responded in the contributors channel thread.

If my understanding of the issue or approach is incorrect, I'm ready to continue working on this, as I'm still unsure about my solution. :))

Copy link
Member

@agarciamontoro agarciamontoro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @kczpl! The code looks good, just a couple of comments:

  1. If no deployer.json is configured at all, there is another error that is returned earlier. I'm thinking that we can fix this by setting the default of TerraformStateDir as ./ltstatus (I don't really know why I didn't do that when I added it, to be honest). The error is the following:
> go run ./cmd/ltctl report generate --output=base.out --label=base "2022-10-20 08:43:39" "2022-10-20 08:44:53"
Flag --prometheus-url is not set. Defaulting to the deployment's Prometheus server...Error: failed to create terraform engine: not enough permissions to create Terraform state directory "/var/lib/mattermost-load-test-ng".
Here's some alternatives you can try:
	1. Change the TerraformStateDir setting in config/deployer.json to a directory you have permissions over (recommended).
	2. Manually create the currently configured directory "/var/lib/mattermost-load-test-ng" and change its owner to your current user.
	3. Run this and all next commands as root (not recommended).
exit status 1
  1. It seems we're missing a newline when we return the Flag --prometheus-url is not set. Defaulting to the deployment's Prometheus server... error, so the new error is a bit buried. Can you add it? Here's what I see:
> go run ./cmd/ltctl report generate --output=base.out --label=base "2022-10-20 08:43:39" "2022-10-20 08:44:53"
Flag --prometheus-url is not set. Defaulting to the deployment's Prometheus server...Error: the output has no metrics, no active deployment found
exit status 1

@@ -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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we can return something slightly more useful to the user, in the lines of:

Suggested change
return fmt.Errorf("the output has no metrics, no active deployment found")
return fmt.Errorf("no active deployment found, use the --prometheus-url flag if you have a local or manually deployed Prometheus server running")

Copy link
Contributor Author

@kczpl kczpl Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure thing! Added that with an extra \n for better readability.

Flag --prometheus-url is not set. Defaulting to the deployment's Prometheus server...
Error: no active deployment found, use the `--prometheus-url` flag.
If you have a local or manually deployed Prometheus server running
exit status 1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If no deployer.json is configured at all, there is another error that is returned earlier. I'm thinking that we can fix this by setting the default of TerraformStateDir as ./ltstatus (I don't really know why I didn't do that when I added it, to be honest). The error is the following:

I get now - I thought it was intentional and that the error occurred because I had no state provided. I have changed the default as suggested and added a small test.

It seems we're missing a newline when we return the Flag --prometheus-url is not set. Defaulting to the deployment's Prometheus server... error, so the new error is a bit buried. Can you add it?

Not a problem! I agree it's not user-friendly, and I've fixed that

@kczpl kczpl requested a review from agarciamontoro November 13, 2024 09:10
@@ -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("no active deployment found, use the `--prometheus-url` flag.\nIf you have a local or manually deployed Prometheus server running")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to break the line. It's a single error message. Let the user's console break the line for us :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense :)) I've just pushed the removal

@@ -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"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine with the change, but is this somehow related to the PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @agnivade ! :D
I did this so we can reach !output.HasMetrics() in report.go.
As far as I understand, we want to change the default directory, because when deployer.json is not configured it takes default path and we get a 'no permission' error instead no deployment

This is what @agarciamontoro mentioned in this comment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@agnivade: Not the original goal, but to get to the correct state we wanted, we need it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, understood!

Copy link
Member

@agarciamontoro agarciamontoro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of nits in the comments, but other than that it looks good!

cmd/ltctl/report.go Outdated Show resolved Hide resolved
deployment/config.go Outdated Show resolved Hide resolved
kczpl and others added 2 commits November 15, 2024 12:02
Co-authored-by: Alejandro García Montoro <[email protected]>
Copy link
Member

@agnivade agnivade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done @kczpl !

@agarciamontoro agarciamontoro self-requested a review November 18, 2024 15:53
Copy link
Member

@agarciamontoro agarciamontoro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @kczpl, this is great! I've already tested it, so we can get this merged :)

@agarciamontoro agarciamontoro added 4: Reviews Complete All reviewers have approved the pull request and removed 2: Dev Review Requires review by a core committer labels Nov 18, 2024
@agarciamontoro agarciamontoro merged commit 286a3f7 into mattermost:master Nov 18, 2024
1 check passed
@kczpl
Copy link
Contributor Author

kczpl commented Nov 18, 2024

@agarciamontoro @agnivade
thanks guys! I'm looking forward to more open issues in this repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4: Reviews Complete All reviewers have approved the pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants