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
monitoring: metrics enhancements and proposal for dropping expvar #351
Conversation
78e4d4e
to
64dd452
Compare
|
Some more healthy separation of concerns. |
|
@shipperizer It looks lime at CI time, we have a failure because mockgen was not run. |
|
Also, it looks like we should be moving to Uber's fork of the Mock framework. |
32e2757
to
459d136
Compare
reason is due to the following happening in the GetStats method of the ldap.Stats struct ``` internal/monitoring/mock_interfaces.go:92:13: assignment copies lock value to ret0: (github.com/nmcclain/ldap.Stats, bool) contains github.com/nmcclain/ldap.Stats contains sync.Mutex internal/monitoring/mock_interfaces.go:93:9: return copies lock value: github.com/nmcclain/ldap.Stats contains sync.Mutex internal/monitoring/ldap_test.go:23:56: call of mockLDAPServer.EXPECT().GetStats().MinTimes(1).Return copies lock value: github.com/nmcclain/ldap.Stats contains sync.Mutex ```
459d136
to
a7539fa
Compare
managed to fix that, i forgot to hook the
happy to move to any mock, main pro of the built-in is the I noticed that there is a |
|
Actually, I was referring to Uber's fork of mockgen as it appears that the original, which you have been using, was EOL'd in July of this year and they recommend switching to that maintained fork. |
|
SonarCloud Quality Gate failed.
|
|
Hmm, this metric setup is a bit odd and doesn't really follow best practices. For Go applications, it's discouraged to create metrics in a separate package. Rather you define metrics to be package local. This makes it easier to understand the use and avoids leaking data between packages. |
|
Hi @SuperQ thanks for sharing your knowledge. Could you point us to a bit of literature on this topic? |
|
"Instantiate the metric classes in the same file you use them" This exactly for Go as well as other languages. You can see a good example in Prometheus itself. Note how the package vars are not exported. This avoids package level metric leaking. It's much easier for both users and developers to know by default the scope of a metric is within a specific section of the code. I also noticed that there's a 15 second loop, this is also against the implementation practices. If you use a gauge metric where it's used you can avoid having the goroutine updating the data internally. |
@SuperQ agreed, unfortunately i tried to reuse the original struct where those "metrics" are created https://github.com/nmcclain/ldap/blob/master/server.go#L66 being in another package meant that to expose those i can only go this way, or otherwise stick with the previous approach of owning internal counters anuyway point taken, will try to improve on that |











The aim of this PR is to introduce new metrics for the tcp response time but also to propose a new way of pulling metrics from the LDAP server struct, without using expvar
ldap_metricis fetched on a schedule from theldap.Server.Statsstruct which is how the underlying library instrument its calls, time window is 15stcp_response_time_secondsinstead is achieved by exploiting the named return parameters and running a defer function in each LDAP operation handlerExample of new metrics added below