-
Notifications
You must be signed in to change notification settings - Fork 450
PMM-1764 Various small improvements #85
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
Conversation
* Disable pre-fetching (not needed on exporter queries), limit conn pool size and re-use database connection to MongoDB * Remove .Ping() on exporter.mongoSess, mgo.Session will recreate the conn for us * avoid race condition with sync.Mutex * Use lock on close of mgo session also * Use lock on close of mgo session also #2 * make pool limit a flag instead of hard-code * default to 1 connection, it seems to work fine even at high volume * Must return .Copy() of mgo.Session to avoid mgo deadlocking under concurrent calls. Moved session SocketTimeout to no longer be forever * Must defer .Close() on copied mgo.Session from .getSession * must check if != nil a 2nd time in getSession()
* Use mutex hat. * Protect Close() with lock too. * Count getSession() errors.
* Added query comments to .Find() queries in oplog_status.go, created shared/utils.go function to add comments, cleaned up duplicated code I made long ago * shorten comment
Codecov Report
@@ Coverage Diff @@
## develop #85 +/- ##
===========================================
- Coverage 24.59% 23.58% -1.01%
===========================================
Files 35 39 +4
Lines 1960 2226 +266
===========================================
+ Hits 482 525 +43
- Misses 1455 1678 +223
Partials 23 23
Continue to review full report at Codecov.
|
| * `mongodb_up` | ||
| * Some queries now contain [cursor comments](https://www.percona.com/blog/2017/06/21/tracing-mongodb-queries-to-code-with-cursor-comments/) | ||
| with source code locations. | ||
| * Go vendoring switched to [dep](https://github.com/golang/dep). |
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 know this is not the part of this PR but when and why we switched to dep for this repo? Upstream still uses glide, this means harder merges from upstream, for what benefits?
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 on our own now. :)
| return nil | ||
| } | ||
| return exporter.mongoSess.Copy() | ||
| } |
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.
Sharing one MongoSession 👍
Wouldn't be easier though to create MongoSession once, when exporter starts? This way you will also avoid that Mutex and you can even produce one time warning/error if connection details are incorrect.
collector/mongos/database_status.go
Outdated
| return nil | ||
| } | ||
| for _, db := range database_names { | ||
| if db == "admin" || db == "test" || db == "local" { |
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 we skip those? Especially test?
|
|
||
| mongoSess := shared.MongoSession(exporter.Opts.toSessionOps()) | ||
| mongoSess := exporter.getSession() | ||
| if mongoSess == 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 works, error is logged in other place, however more clean way would be to bubble up the error instead of hiding it?
mongoSess, err := exporter.getSession()
if err != nil {
log.Error(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.
I agree, but let's do it later.
| ``` | ||
| mongodb://CN=myName,OU=myOrgUnit,O=myOrg,L=myLocality,ST=myState,C=myCountry@localhost:27017/?authMechanism=MONGODB-X509 | ||
| ``` | ||
|
|
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.
Did we test that? I know it's mongodb_exporter repo, but did we put that also to our documentation for PMM? Link?
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's wasn't required.
| } | ||
|
|
||
| func AddCodeCommentToQuery(query *mgo.Query) *mgo.Query { | ||
| _, fileName, lineNum, ok := runtime.Caller(1) |
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 returns lineNum where AddCodeCommentToQuery was called? Could you add comment explaining that?
| session.SetPrefetch(0.00) | ||
| session.SetSyncTimeout(syncMongodbTimeout) | ||
| session.SetSocketTimeout(0) | ||
| session.SetSocketTimeout(dialMongodbTimeout) |
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 increases timeout to 3s?
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.
0 meant "no timeout".
| // connect directly, fail faster, do not retry - for faster responses and accurate metrics, including mongoUp | ||
| dialInfo.Direct = true | ||
| dialInfo.Timeout = dialMongodbTimeout | ||
| dialInfo.FailFast = true |
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.
Makes sense, but why we then in other parts of the code retry on failed queries for tries < 2 {? (yeah, I know it's not a part of this PR, just a note)
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.
Good point. We should remove them.
| return nil | ||
| } | ||
| session.SetMode(mgo.Eventual, true) | ||
| session.SetPoolLimit(opts.PoolLimit) |
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.
Just a side note: https://github.com/go-mgo/mgo/issues/246#issuecomment-199907660
Also you could set pool limit in DSN with maxPoolSize:
https://github.com/go-mgo/mgo/blob/v2/session.go#L292-L296
While this certainly makes some sense, I'm not sure about performance gain? @AlekSi was this somehow verified? Would be nice to understand what was the real issue here, if it was not sharing session or lack of this pool limit (which seems weird, because the code is really linear so one request should use one socket).
|
|
||
| ## v0.4.0 (not released yet) | ||
|
|
||
| * New flags `-collect.database` and `-collect.collection` can be used to enable collection of database and collection |
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.
Was this somewhere requested? Jira issue?
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.
That's #84.
No description provided.