-
Notifications
You must be signed in to change notification settings - Fork 18
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
Mongo #5
Conversation
@bill828 could you help to review? |
pkg/store/mongodb/mongodbStore.go
Outdated
} | ||
var services []pms.Service | ||
if err = cur.All(ctx, &services); err != nil { | ||
panic(err) |
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.
Why panic here? panic may terminate the process. Is that possible to return the 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.
will fix it.
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 { |
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 believe the segment should be:
if result.Err() != nil {
if result.Err() == mongo.ErrNoDocuments {
return errors.Errorf(xxxxx)
}
return result.Err()
}
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.
It seems no need to check if result.Err() != nil here.
pkg/store/mongodb/mongodbStore.go
Outdated
} | ||
var services []pms.Service | ||
if err = cur.All(ctx, &services); err != nil { | ||
panic(err) |
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.
Why panic 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.
will fix it.
(counts["service1"].RolePolicyCount != int64(len(rolePolicies))) { | ||
t.Fatal("incorrect role policy number") | ||
} | ||
fmt.Println(counts) |
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.
uses t.Log
.
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.
will fix it
pkg/store/mongodb/storeBuiler.go
Outdated
import ( | ||
"context" | ||
|
||
"github.com/prometheus/common/log" |
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.
We are using logrus, not prometheus log.
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.
will fix it.
pkg/store/mongodb/storeBuiler.go
Outdated
client, err := mongo.Connect(context.TODO(), clientOptions) | ||
|
||
if err != nil { | ||
log.Fatal(err) |
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 log.Fatal
terminate the process?
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.
yes, will fix it.
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.
Looks good to me.
No description provided.