Skip to content

Conversation

@AlekSi
Copy link
Contributor

@AlekSi AlekSi commented Jan 4, 2018

No description provided.

timvaillancourt and others added 13 commits January 4, 2018 14:57
* 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
Copy link

codecov bot commented Jan 4, 2018

Codecov Report

Merging #85 into develop will decrease coverage by 1%.
The diff coverage is 11.88%.

Impacted file tree graph

@@             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
Impacted Files Coverage Δ
collector/mongod/replset_status.go 0% <ø> (ø) ⬆️
collector/mongod/global_lock.go 77.27% <ø> (ø) ⬆️
collector/mongos/sharding_status.go 0% <0%> (ø) ⬆️
shared/utils.go 0% <0%> (ø) ⬆️
collector/mongod/collections_status.go 0% <0%> (ø)
collector/mongos/database_status.go 0% <0%> (ø)
mongodb_exporter.go 1.53% <0%> (-0.05%) ⬇️
collector/mongod/oplog_status.go 0% <0%> (ø) ⬆️
collector/mongos/collections_status.go 0% <0%> (ø)
collector/mongos/sharding_topology.go 0% <0%> (ø) ⬆️
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a65811a...f58598a. Read the comment docs.

* `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).
Copy link

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?

Copy link
Contributor Author

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()
}
Copy link

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.

return nil
}
for _, db := range database_names {
if db == "admin" || db == "test" || db == "local" {
Copy link

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 {
Copy link

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)
}

Copy link
Contributor Author

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
```

Copy link

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?

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's wasn't required.

}

func AddCodeCommentToQuery(query *mgo.Query) *mgo.Query {
_, fileName, lineNum, ok := runtime.Caller(1)
Copy link

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)
Copy link

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?

Copy link
Contributor Author

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
Copy link

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)

Copy link
Contributor Author

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)
Copy link

Choose a reason for hiding this comment

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

@timvaillancourt

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
Copy link

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's #84.

@AlekSi AlekSi merged commit c1c7cff into develop Jan 17, 2018
@AlekSi AlekSi deleted the PMM-1764-small-improvements branch January 17, 2018 09:09
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.

6 participants