Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Non default registry #20

Merged
merged 2 commits into from
Jun 16, 2017
Merged

Conversation

brancz
Copy link
Collaborator

@brancz brancz commented Jun 12, 2017

This PR allows instrumenting the gRPC metrics with a custom metrics registry instead of the default Prometheus registry. This is useful if you don't want random init functions to register metrics on your registry, but have control over it.

Additionally it allow the histogram buckets to be chosen on a per server/service basis, rather than globally.

I have yet to actually plug this into an application to try it out, but the tests are passing so I'm confident that it works properly. I was careful to keep the existing interface, to not break existing users, but it would be good to validate this. Also if the current usage can be broken I have other ideas on how to potentially change it.

Let me know what you want me to do in terms of the license header. I'm working out of Germany and a copyright transfer is not possible by law.

@mwitkow

@codecov-io
Copy link

codecov-io commented Jun 12, 2017

Codecov Report

Merging #20 into master will decrease coverage by 3.7%.
The diff coverage is 81.81%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #20      +/-   ##
==========================================
- Coverage   86.36%   82.66%   -3.71%     
==========================================
  Files           5        7       +2     
  Lines         154      248      +94     
==========================================
+ Hits          133      205      +72     
- Misses         13       35      +22     
  Partials        8        8
Impacted Files Coverage Δ
server.go 100% <100%> (+11.76%) ⬆️
client_reporter.go 100% <100%> (+6.66%) ⬆️
server_reporter.go 100% <100%> (+14%) ⬆️
client.go 100% <100%> (+20%) ⬆️
util.go 69.23% <62.5%> (-10.77%) ⬇️
server_metrics.go 72.22% <72.22%> (ø)
client_metrics.go 88% <88%> (ø)

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 2500245...42b3df7. Read the comment docs.

@brancz
Copy link
Collaborator Author

brancz commented Jun 12, 2017

I have now plugged this into an application and can confirm that this indeed works.

@mwitkow
Copy link
Member

mwitkow commented Jun 13, 2017

Wow, that's a massive PR. But it looks good overall. Please add a comments to ClientMetrics and ServerMetrics (or on their New* functions) as to when you may choose to use use them manually instead of relying on Default*Metrics.

server.go Outdated
}
return err
// EnableHandlingTimeHistogram turns on recording of handling time of RPCs for server-side interceptors.
// Histogram metrics can be very expensive for Prometheus to retain and query.
Copy link
Member

Choose a reason for hiding this comment

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

Please add a note that this only works for the DefaultServerMetrics.

server.go Outdated
return err
// PreregisterServices takes a gRPC server and pre-initializes all counters to 0.
// This allows for easier monitoring in Prometheus (no missing metrics), and should be called *after* all services have
// been registered with the server.
Copy link
Member

Choose a reason for hiding this comment

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

Please add a note that this only works for DefaultServerMetrics.

server.go Outdated
// Histogram metrics can be very expensive for Prometheus to retain and query.
func EnableHandlingTimeHistogram(opts ...HistogramOption) {
DefaultServerMetrics.EnableHandlingTimeHistogram(opts...)
prom.Register(DefaultServerMetrics.serverHandledHistogram)
Copy link
Member

Choose a reason for hiding this comment

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

how about we move this to EnableHandlingTimeHistogram istelf?

Copy link
Member

Choose a reason for hiding this comment

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

Or will that die hard because of double registration?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's unclear that the method actually instruments a metric, so I wanted to keep it out of the underlying method, but keep the existing interface.

Aside from that, yes registration is expected to be unique:

// Register registers a new Collector to be included in metrics
// collection. It returns an error if the descriptors provided by the
// Collector are invalid or if they — in combination with descriptors of
// already registered Collectors — do not fulfill the consistency and
// uniqueness criteria described in the documentation of metric.Desc.

"google.golang.org/grpc/codes"
)

type ClientMetrics struct {
Copy link
Member

Choose a reason for hiding this comment

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

please add comments here and how it relates to `Default

@brancz
Copy link
Collaborator Author

brancz commented Jun 13, 2017

Added documentation everywhere, let me know what you think.

@brancz
Copy link
Collaborator Author

brancz commented Jun 16, 2017

@mwitkow ping?

@mwitkow
Copy link
Member

mwitkow commented Jun 16, 2017

Looks good, thank you! :)

@mwitkow mwitkow merged commit 0c1b191 into grpc-ecosystem:master Jun 16, 2017
@brancz brancz deleted the non-default-registry branch June 16, 2017 11:05
@brancz brancz mentioned this pull request Apr 17, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants