Rebalance missing validation and code refactor #986
Rebalance missing validation and code refactor #986rishubhjain wants to merge 7 commits intogluster:masterfrom
Conversation
|
Remaining :
Will update the PR with the remaining sections. |
Madhu-1
left a comment
There was a problem hiding this comment.
please update endpoints.md file
plugins/rebalance/init.go
Outdated
| Pattern: "/volumes/{volname}/rebalance/start", | ||
| Version: 1, | ||
| RequestType: utils.GetTypeString((*rebalanceapi.StartReq)(nil)), | ||
| ResponseType: utils.GetTypeString((*uuid.UUID)(nil)), |
There was a problem hiding this comment.
instead of giving an ID to the user, send it as a JSON struct or send RebalStatus or RebalInfo to user,
type RebalanceStartResp struct{
ID string
}
| rebalinfo := createRebalanceInfo(volname, &req) | ||
| if rebalinfo == nil { | ||
| logger.WithError(err).Error("failed to create Rebalance info") | ||
| rebalInfo, err := GetRebalanceInfo(volname) |
There was a problem hiding this comment.
are you missing error handling here?
There was a problem hiding this comment.
No I want the error to be not nil
There was a problem hiding this comment.
what happens when we get err !=nil don't we need to stop proceeding further
and return the error to the user
plugins/rebalance/rest.go
Outdated
| } | ||
|
|
||
| rebalInfo = createRebalanceInfo(volname, &req) | ||
| if rebalInfo == nil { |
There was a problem hiding this comment.
question: in what scenario createRebalanceInfo will return nil?
There was a problem hiding this comment.
I think this scenario won't happen, but I have kept the error handling in case of future use.
There was a problem hiding this comment.
if this is for future use, this check will become redundant now. then we need to comment the code or remove it
| err = txn.Ctx.Set("rinfo", rebalInfo) | ||
| if err != nil { | ||
| logger.WithError(err).Error("failed to set rebalance info in transaction context") | ||
| logger.WithError(err).WithField("key", "rinfo").Error("failed to set rebalance info in transaction context") |
There was a problem hiding this comment.
same question about logging as above.
There was a problem hiding this comment.
Already answered in your PR
| } | ||
|
|
||
| rebalinfo, err := GetRebalanceInfo(volname) | ||
| rebalInfo, err := GetRebalanceInfo(volname) |
There was a problem hiding this comment.
question:
do we need to return ErrRebalanceNotStarted error if get from store fails?
plugins/rebalance/rest.go
Outdated
| rebalinfo, err := GetRebalanceInfo(volname) | ||
| rebalInfo, err := GetRebalanceInfo(volname) | ||
| if err != nil { | ||
| restutils.SendHTTPError(r.Context(), w, http.StatusBadRequest, ErrRebalanceNotStarted) |
There was a problem hiding this comment.
as ctx is already defined as ctx := r.Context() ,send ctx instead of r.Context() to restutils.SendHTTPError
| err = txn.Ctx.Set("volname", volname) | ||
| if err != nil { | ||
| logger.WithError(err).Error("failed to set volname in transaction context") | ||
| logger.WithError(err).WithField("key", "volname").Error("failed to set volname in transaction context") |
There was a problem hiding this comment.
same WithField question for logging in this PR?
plugins/rebalance/rest.go
Outdated
| rebalinfo.Volname = volname | ||
| rebalinfo.State = rebalanceapi.Stopped | ||
| rebalinfo.Cmd = rebalanceapi.CmdStop | ||
| rebalInfo.Volname = volname |
There was a problem hiding this comment.
question:
do we need to assign rebalInfo.Volname = volname as Volname already assigned during rebalance start?
|
@rishubhjain please add a TODO for UNDO functions in |
| ) | ||
|
|
||
| var rebalanceCmd = &cobra.Command{ | ||
| Use: "volume rebalance", |
There was a problem hiding this comment.
where ever its required place add Long command to give more information about this CLI command to users
glustercli/cmd/rebalance.go
Outdated
| volname := cmd.Flags().Args()[0] | ||
| var err error | ||
| if flagRebalanceStartCmdForce && flagRebalanceStartCmdFixLayout { | ||
| err := errors.New("Conflicting options found") |
There was a problem hiding this comment.
use above declared err variable here, start error with small case
glustercli/cmd/rebalance.go
Outdated
| if err != nil { | ||
| if verbose { | ||
| log.WithError(err.Error()).WithFields(log.Fields{ | ||
| "volume": volname, |
There was a problem hiding this comment.
question:
do we need to convert err.Error() error to string before logging?
There was a problem hiding this comment.
err.Error() itself is a string.
There was a problem hiding this comment.
log.WithError does not expect input as string, you need to pass error to it
| rebalinfo := createRebalanceInfo(volname, &req) | ||
| if rebalinfo == nil { | ||
| logger.WithError(err).Error("failed to create Rebalance info") | ||
| rebalInfo, err := GetRebalanceInfo(volname) |
There was a problem hiding this comment.
what happens when we get err !=nil don't we need to stop proceeding further
and return the error to the user
plugins/rebalance/rest.go
Outdated
| } | ||
|
|
||
| rebalInfo = createRebalanceInfo(volname, &req) | ||
| if rebalInfo == nil { |
There was a problem hiding this comment.
if this is for future use, this check will become redundant now. then we need to comment the code or remove it
plugins/rebalance/rest.go
Outdated
| * few nodes and failed in few others */ | ||
| logger.WithFields(log.Fields{ | ||
| "error": err.Error(), | ||
| logger.WithError(err).WithFields(log.Fields{ |
There was a problem hiding this comment.
use WithField if you have only one field to log
plugins/rebalance/rest.go
Outdated
| if err != nil { | ||
| logger.WithFields(log.Fields{ | ||
| "error": err.Error(), | ||
| logger.WithError(err).WithFields(log.Fields{ |
There was a problem hiding this comment.
use WithField to log if you have only one field to log
plugins/rebalance/rest.go
Outdated
| if err != nil { | ||
| logger.WithFields(log.Fields{ | ||
| "error": err.Error(), | ||
| logger.WithError(err).WithFields(log.Fields{ |
| req := rebalanceapi.StartReq{ | ||
| Option: option, | ||
| } | ||
| url := fmt.Sprintf("/v1/volumes/%s/rebalance/start", volname) |
| Option: option, | ||
| } | ||
| url := fmt.Sprintf("/v1/volumes/%s/rebalance/start", volname) | ||
| return c.post(url, req, http.StatusOK, nil) |
There was a problem hiding this comment.
same here, where are you importing HTTP package?
d6308da to
109d636
Compare
| func init() { | ||
|
|
||
| // Rebalance Start | ||
| rebalanceStartCmd.Flags().BoolVar(&flagRebalanceStartCmdForce, "force", false, "Force") |
There was a problem hiding this comment.
The description of the flags can be a little bit more elaborate.
There was a problem hiding this comment.
For now I am following the trend set by volumestart, will update both of them with more description in the next PR
2e16cd9 to
1f9abf2
Compare
glustercli/cmd/rebalance.go
Outdated
| const ( | ||
| helpRebalanceCmd = "Gluster Rebalance" | ||
| helpRebalanceStartCmd = "Start rebalance session for gluster volume" | ||
| helpRebalanceStatusCmd = "Status of rebalance seesion" |
There was a problem hiding this comment.
Please use rebalance operation instead of rebalance session.
|
|
||
| rebalinfo := createRebalanceInfo(volname, &req) | ||
| if rebalinfo == nil { | ||
| logger.WithError(err).Error("failed to create Rebalance info") |
There was a problem hiding this comment.
Does this require to log the volume name as well?
There was a problem hiding this comment.
IMO : Its easier to debug if the resource name is provided with error/debug message
|
|
||
| err := ctx.Get("rinfo", &rebalinfo) | ||
| err := ctx.Get("rinfo", &rebalInfo) | ||
| if err != nil { |
There was a problem hiding this comment.
Rebalance info would be more consistent across err messages.
|
On Fri, 20 Jul 2018 at 19:32, Rishubh Jain ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In plugins/rebalance/rest.go
<#986 (comment)>:
> @@ -44,14 +44,18 @@ func rebalanceStartHandler(w http.ResponseWriter, r *http.Request) {
return
}
- rebalinfo := createRebalanceInfo(volname, &req)
- if rebalinfo == nil {
- logger.WithError(err).Error("failed to create Rebalance info")
IMO : Its easier to debug if the resource name is provided with
error/debug message
What’s the resource name represent here? Isn’t that supposed to be volume
name?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#986 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AGp7mEcHkbYQhWDT1HB4blpGsPr9hepRks5uIeLvgaJpZM4VJwat>
.
--
- Atin (atinm)
|
|
retest this please |
| EventsList | GET | /events | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [Event](https://godoc.org/github.com/gluster/glusterd2/pkg/api#Event) | ||
| SelfHealInfo | GET | /volumes/{name}/{opts}/heal-info | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [BrickHealInfo](https://godoc.org/github.com/gluster/glusterd2/pkg/api#BrickHealInfo) | ||
| SelfHealInfo2 | GET | /volumes/{name}/heal-info | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [BrickHealInfo](https://godoc.org/github.com/gluster/glusterd2/pkg/api#BrickHealInfo) | ||
| SelfHealInfo | GET | /volumes/{volname}/{opts}/heal-info | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [BrickHealInfo](https://godoc.org/github.com/gluster/glusterd2/pkg/api#BrickHealInfo) |
There was a problem hiding this comment.
This has to be regenerated
Issue: #428