-
Notifications
You must be signed in to change notification settings - Fork 82
Rebalance missing validation and code refactor #986
base: master
Are you sure you want to change the base?
Conversation
Remaining :
Will update the PR with the remaining sections. |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
}
plugins/rebalance/rest.go
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you missing error handling here?
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 I want the error to be not nil
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: in what scenario createRebalanceInfo
will return nil?
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 this scenario won't happen, but I have kept the error handling in case of future use.
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 this is for future use, this check will become redundant now. then we need to comment the code or remove it
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same question about logging as above.
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.
Already answered in your PR
@@ -162,14 +171,14 @@ func rebalanceStopHandler(w http.ResponseWriter, r *http.Request) { | |||
return | |||
} | |||
|
|||
rebalinfo, err := GetRebalanceInfo(volname) | |||
rebalInfo, err := GetRebalanceInfo(volname) |
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.
question:
do we need to return ErrRebalanceNotStarted
error if get from store fails?
plugins/rebalance/rest.go
Outdated
@@ -162,14 +171,14 @@ func rebalanceStopHandler(w http.ResponseWriter, r *http.Request) { | |||
return | |||
} | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as ctx is already defined as ctx := r.Context()
,send ctx
instead of r.Context()
to restutils.SendHTTPError
@@ -188,34 +197,33 @@ func rebalanceStopHandler(w http.ResponseWriter, r *http.Request) { | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same WithField
question for logging in this 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.
Answered
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where ever its required place add Long
command to give more information about this CLI command to users
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.
ok
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question:
do we need to convert err.Error()
error to string before logging?
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.
err.Error() itself is a string.
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.
log.WithError
does not expect input as string, you need to pass error to it
plugins/rebalance/rest.go
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -118,25 +127,16 @@ func rebalanceStartHandler(w http.ResponseWriter, r *http.Request) { | |||
* rebalance process is one per node per volume. | |||
* Need to handle scenarios where process is started in | |||
* 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use WithField
if you have only one field to log
plugins/rebalance/rest.go
Outdated
restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err.Error()) | ||
return | ||
} | ||
|
||
err = txn.Do() | ||
if err != nil { | ||
logger.WithFields(log.Fields{ | ||
"error": err.Error(), | ||
logger.WithError(err).WithFields(log.Fields{ |
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.
use WithField
to log if you have only one field to log
plugins/rebalance/rest.go
Outdated
return | ||
} | ||
|
||
err = txn.Do() | ||
if err != nil { | ||
logger.WithFields(log.Fields{ | ||
"error": err.Error(), | ||
logger.WithError(err).WithFields(log.Fields{ |
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.
same here log with WithField
req := rebalanceapi.StartReq{ | ||
Option: option, | ||
} | ||
url := fmt.Sprintf("/v1/volumes/%s/rebalance/start", volname) |
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.
missing import fmt package
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.
Done
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, where are you importing HTTP package?
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.
Done
d6308da
to
109d636
Compare
func init() { | ||
|
||
// Rebalance Start | ||
rebalanceStartCmd.Flags().BoolVar(&flagRebalanceStartCmdForce, "force", false, "Force") |
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.
The description of the flags can be a little bit more elaborate.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: typo (seesion)
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.
Please use rebalance operation instead of rebalance session.
@@ -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") |
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.
Does this require to log the volume name as well?
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
@@ -81,14 +79,16 @@ WebhookTest | POST | /events/webhook/test | [Webhook](https://godoc.org/github.c | |||
WebhookDelete | DELETE | /events/webhook | [WebhookDel](https://godoc.org/github.com/gluster/glusterd2/pkg/api#WebhookDel) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | |||
WebhookList | GET | /events/webhook | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [WebhookList](https://godoc.org/github.com/gluster/glusterd2/pkg/api#WebhookList) | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has to be regenerated
Issue: #428