-
Notifications
You must be signed in to change notification settings - Fork 42
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
Misleading error when generating a report with no deployment #846
Conversation
Thank you for the PR, @kczpl! Will take a look as soon as I can :) |
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. :)) |
There was a problem hiding this 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:
- 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
- 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
cmd/ltctl/report.go
Outdated
@@ -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") |
There was a problem hiding this comment.
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:
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") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
TerraformStateDir default to ./ltstate
cmd/ltctl/report.go
Outdated
@@ -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") |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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"` |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, understood!
There was a problem hiding this 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!
Co-authored-by: Alejandro García Montoro <[email protected]>
Co-authored-by: Alejandro García Montoro <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicely done @kczpl !
There was a problem hiding this 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 @agnivade |
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