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

Mongo #5

Merged
merged 6 commits into from
Jul 1, 2020
Merged

Mongo #5

merged 6 commits into from
Jul 1, 2020

Conversation

dingwenfang
Copy link
Contributor

No description provided.

@caiwl caiwl requested a review from bill828 June 30, 2020 14:12
@caiwl
Copy link
Contributor

caiwl commented Jun 30, 2020

@bill828 could you help to review?

@bill828
Copy link
Contributor

bill828 commented Jul 1, 2020

@bill828 could you help to review?

@bill828 could you help to review?

sure, I'll review this PR today.

}
var services []pms.Service
if err = cur.All(ctx, &services); err != nil {
panic(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why panic here? panic may terminate the process. Is that possible to return the error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will fix it.

pkg/store/mongodb/mongodbStore.go Show resolved Hide resolved
filter := bson.D{{"_id", serviceName}}
update := bson.D{{"$pull", bson.D{{"policies", bson.D{{"$exists", true}}}}}}
result := serviceCollection.FindOneAndUpdate(ctx, filter, update)
if result.Err() == mongo.ErrNoDocuments {
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe the segment should be:

if result.Err() != nil {
    if result.Err() == mongo.ErrNoDocuments {
         return errors.Errorf(xxxxx)
    }
    return result.Err()
}
return nil

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems no need to check if result.Err() != nil here.

}
var services []pms.Service
if err = cur.All(ctx, &services); err != nil {
panic(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why panic here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will fix it.

(counts["service1"].RolePolicyCount != int64(len(rolePolicies))) {
t.Fatal("incorrect role policy number")
}
fmt.Println(counts)
Copy link
Contributor

Choose a reason for hiding this comment

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

uses t.Log.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will fix it

import (
"context"

"github.com/prometheus/common/log"
Copy link
Contributor

Choose a reason for hiding this comment

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

We are using logrus, not prometheus log.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will fix it.

client, err := mongo.Connect(context.TODO(), clientOptions)

if err != nil {
log.Fatal(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does log.Fatal terminate the process?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, will fix it.

Copy link
Contributor

@bill828 bill828 left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@dingwenfang dingwenfang merged commit b00ce42 into teramoby:master Jul 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants