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

Implement GetExperimentInDB #558

Merged
merged 6 commits into from
May 22, 2019
Merged

Implement GetExperimentInDB #558

merged 6 commits into from
May 22, 2019

Conversation

hougangliu
Copy link
Member

@hougangliu hougangliu commented May 20, 2019

This change is Reviewable

@hougangliu
Copy link
Member Author

/hold

@hougangliu
Copy link
Member Author

/hold cancel

@@ -140,8 +141,13 @@ func (g *DefaultValidator) validateSupportedJob(job *unstructured.Unstructured)
}

func (g *DefaultValidator) validateForCreate(inst *experimentsv1alpha2.Experiment) error {
isErrNoRows := func (e error) bool {
Copy link
Member

Choose a reason for hiding this comment

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

Why should we use such a func instead of sql.ErrNoRows, is there any problem that we want to avoid?

Copy link
Member Author

Choose a reason for hiding this comment

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

sql.ErrNoRows is raised by db interface in grpc server, in grpc client side, we cannot get sql.ErrNoRows, which has been wrapped.

Copy link
Member

Choose a reason for hiding this comment

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

It looks hacky. Just wondering if there is a better way to handle this

Copy link
Member

Choose a reason for hiding this comment

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

I feel that DB errors should not be exposed to controller

Copy link
Member

Choose a reason for hiding this comment

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

Could we catch the error in GetExperimentFromDB? If the error is sql.ErrNoRows we return nil, or we return error to the controller.

Copy link
Member

Choose a reason for hiding this comment

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

how will you handle similar errors for other api calls? eg: Alreadyexists for RegisterExperiment etc

Copy link
Member Author

Choose a reason for hiding this comment

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

For others APIs, our use cases don't need care what the error type is now when error is not nil.

Copy link
Member

Choose a reason for hiding this comment

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

Can we update managerclient.go as follows:

func (d *DefaultClient) GetExperimentFromDB(instance *experimentsv1alpha2.Experiment) (*api_pb.GetExperimentReply, error) {
	request := &api_pb.GetExperimentRequest{
		ExperimentName: instance.Name,
	}
	if exp, err := commonv1alpha2.GetExperiment(request); err != nil {
		if !isErrNoRows(err) {
			return nil, fmt.Errorf("Fail to check record for the experiment in DB: %v", err)
		}
	}
	return exp, nil
}

Then the error will be handled in manager client and not be exposed to the controller.

Copy link
Member Author

@hougangliu hougangliu May 22, 2019

Choose a reason for hiding this comment

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

I had used "PreCheckRegisterExperiment" to replace "GetExperimentFromDB" in latest commit.
I think we should avoid to parse Error message string to judge what its original error in grpc server side is, especially when we support more DB backends, we must refactor isErrNoRows to parse the error message string to match other backends ErrNoRows counterparts.

Copy link
Member

Choose a reason for hiding this comment

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

SGTM

@hougangliu
Copy link
Member Author

/test coverage/coveralls

@hougangliu
Copy link
Member Author

/retest

@gaocegege
Copy link
Member

@richardsliu Could we allow the decrease of coveralls? We can set a floor for it. Maybe 50%

@richardsliu
Copy link
Contributor

@gaocegege We can set a failure threshold at 50%, and a coverage decrease threshold at maybe 5%. Does that sound ok?

@gaocegege
Copy link
Member

SGTM, thanks.

@richardsliu
Copy link
Contributor

@gaocegege Done.

@gaocegege
Copy link
Member

gaocegege commented May 21, 2019

@hougangliu Please rebase

@hougangliu
Copy link
Member Author

/test Travis CI

@hougangliu
Copy link
Member Author

PTAL @gaocegege @johnugeorge @richardsliu

Copy link
Member

@gaocegege gaocegege left a comment

Choose a reason for hiding this comment

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

/lgtm
WDYT @johnugeorge

@johnugeorge
Copy link
Member

LGTM

In general, i feel that the right solution is to have a translation layer between DB and GRPC to translate the DB errors to common set of errors defined for GRPC that can be used by any caller(eg: controller, api user, UI etc). I am sure that there will be more errors to be differentiated at the caller level( controller here) and this solution might not scale.
Also, returning DB error directly to the caller is also not good IMO as we are exposing backend details to the user.

@hougangliu
Copy link
Member Author

hougangliu commented May 22, 2019

LGTM

In general, i feel that the right solution is to have a translation layer between DB and GRPC to translate the DB errors to common set of errors defined for GRPC that can be used by any caller(eg: controller, api user, UI etc). I am sure that there will be more errors to be differentiated at the caller level( controller here) and this solution might not scale.
Also, returning DB error directly to the caller is also not good IMO as we are exposing backend details to the user.

For now, the reason why we didn't do the translation is that so far we don't care what the error exactly is except this validation case. So I don't think it's worth spending much time to add a translation layer just for hiding backend details, at least, its priority is not high. Anyway, we can create a issue to trace discuss for it so that we may do it in coming release

@hougangliu
Copy link
Member Author

/approve

@k8s-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hougangliu

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit 17dbca3 into kubeflow:master May 22, 2019
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants