-
Notifications
You must be signed in to change notification settings - Fork 42
fix(scale):dont call controller if there is no valid scale pattern #109
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
Conversation
|
@Joshua-Anderson and @helgi are potential reviewers of this pull request based on my analysis of |
cmd/ps.go
Outdated
| return err | ||
| } | ||
| } else { | ||
| fmt.Printf("'%s' does not match the pattern 'type=num', ex: web=2\n", target) |
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.
I think we should just make this return an error if there's a bad seed in the scale list. That would solve this problem quickly, cause ps:scale to return non-zero and we can test for it.
e.g.
return fmt.Errorf("'%s' does not match the pattern 'type=num', ex: web=2\n", target)
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.
i am ok with returning and error but i think we are not returning an error because user can try to scale multiple proc types at a time and only few can be bad.
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.
yeah but what I mean is that if there is a single bad scale type we should error and say "hey, this process type is poorly formed, so we're not going to accept this request. Please try again."
Same thing applies for config:set as well. For example there were issues like #61 that was unintended, so there is precedence.
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.
also the current implementation will cause ps:scale to return 0 (meaning success) when they call deis ps:scale web=-1. That's not really what we would want to do in this scenario
|
In the future we should probably clean this out so we don't have to have this ugly testing code to mock out the client settings, but this works for now. Thanks! |
cmd/ps_test.go
Outdated
| t.Fatalf("error creating temp directory (%s)", err) | ||
| } | ||
| os.Setenv("DEIS_PROFILE", "testing") | ||
| os.Setenv("HOME", tmpDir) |
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.
This will break on windows, cause $HOME is different. I wrote settings.SetHome to handle the cross platform differences transparently.
|
The way I've normally tested the stuff is by extracting the logic I want to test into its own function and then test that, which IMO is a bit cleaner. I also have some mock session code in |
|
that is indeed the better approach, but I am happy to merge this as-is and we can clean this up later. |
| } | ||
| } else { | ||
| fmt.Printf("'%s' does not match the pattern 'type=num', ex: web=2\n", target) | ||
| return fmt.Errorf("'%s' does not match the pattern 'type=num', ex: web=2\n", target) |
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.
can this become a struct that implements error?
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.
you mean like https://github.com/deis/controller-sdk-go/blob/master/errors.go? Those errors are for server-side, but that is a good suggestion.
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.
not a global var, a global type since this has variable data in it:
type errInvalidScalePattern struct {
target string
}
// Error implements the error interface
func (e errInvalidScalePattern) Error() string {
return fmt.Sprintf("'%s' does not match the pattern 'type=num', ex: web=2\n", e.target)
}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.
this is something which needs to be done on the whole repo....may be i can create an issue and do it later?
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.
@kmala an issue to do it later is fine, but why not start with this one now?
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.
i had created an issue #129
Output before:
after: