go-grpc-prometheus icon indicating copy to clipboard operation
go-grpc-prometheus copied to clipboard

Use stats handler instead of interceptor and add message size histograms

Open tonywang opened this issue 5 years ago • 8 comments

Hi guys,

Working on #85

I add stats_handlers on server-side and client side, there is some question need discuss with you:

  1. In the stats.Handler, I can't distinguish between unary and stream, so how do our metrics want labels to be named?
  • Is it to reuse existing metrics, default grpc_type to unary or create some new metrics without grpc_type label.

  • Or use some dynamic large methods, provide grpc_type when users use interceptors, and no grpc_type when users use stats.handler

  1. default bucket, current I set the default bucket like []float64{42, 2097, 52429, 1048576, 2097152, 3355443}, according to the ratio of the message size to the default maximum value, the specific ratio is 0.00001, 0.0005, 0.0125, 0.025, 0.5, 0.8, do this make sense?

tonywang avatar Apr 17 '20 00:04 tonywang

Strange, when the test is performed hard on 1.11 versions, some results are not as expected, I need to test again.

    --- FAIL: TestClientStatsHandlerSuite/TestStreamingIncrementsMetrics (0.01s)
        server_test.go:316: expected 1 grpc_client_handling_seconds value; got 3; 
        server_test.go:316: expected 2 grpc_client_handling_seconds value; got 4; 

tonywang avatar Apr 17 '20 01:04 tonywang

Codecov Report

Merging #88 into master will increase coverage by 4.22%. The diff coverage is 84.39%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #88      +/-   ##
==========================================
+ Coverage   72.45%   76.67%   +4.22%     
==========================================
  Files          11       13       +2     
  Lines         363      566     +203     
==========================================
+ Hits          263      434     +171     
- Misses         89      115      +26     
- Partials       11       17       +6     
Impacted Files Coverage Δ
client_metrics.go 65.55% <72.72%> (+2.05%) :arrow_up:
server_metrics.go 78.66% <76.00%> (-1.54%) :arrow_down:
client_stats_handler.go 85.71% <85.71%> (ø)
server_stats_handler.go 85.71% <85.71%> (ø)
client.go 70.00% <100.00%> (+12.85%) :arrow_up:
client_reporter.go 87.75% <100.00%> (+8.44%) :arrow_up:
server.go 100.00% <100.00%> (ø)
server_reporter.go 100.00% <100.00%> (ø)
util.go 76.47% <100.00%> (+7.23%) :arrow_up:
... and 1 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 8a6536e...36752fb. Read the comment docs.

codecov-io avatar May 04 '20 09:05 codecov-io

@brancz @bwplotka I try to move all metrics to stats.Handler, please help me review this.

tonywang avatar May 04 '20 09:05 tonywang

Any chance this PR could be looked at?

cmeury avatar Dec 16 '20 13:12 cmeury

Hi 👋🏽

Sorry for the massive, lag. We consolidating projects and moving to single repo where we have more control and awareness. We are moving this code base longer to https://github.com/grpc-ecosystem/go-grpc-middleware/tree/v2 and we moved existing state of Prometheus middleware to https://github.com/grpc-ecosystem/go-grpc-middleware/tree/v2/providers/openmetrics

This means that before we release v2 this is the best opportunity to shape new https://github.com/grpc-ecosystem/go-grpc-middleware/tree/v2/providers/openmetrics with whatever we want to change in API 🤗 If you want to change something effectively long term, I would suggest switching your PR and rebasing it on https://github.com/grpc-ecosystem/go-grpc-middleware/tree/v2/providers/openmetrics instead (notice v2 branch, not master!).

Sorry for the confusion, but it's needed for the project sustainability. Cheers!

bwplotka avatar Mar 15 '21 15:03 bwplotka

Can we avoid name "stats", it's not explicit, I am afraid. It sounds like we should have just size in name that's it, no? 🤗

bwplotka avatar Mar 15 '21 15:03 bwplotka

Hi @bwplotka and thanks for restarting the conversation here!

This means that before we release v2 this is the best opportunity to shape new https://github.com/grpc-ecosystem/go-grpc-middleware/tree/v2/providers/openmetrics with whatever we want to change in API If you want to change something effectively long term, I would suggest switching your PR and rebasing it on https://github.com/grpc-ecosystem/go-grpc-middleware/tree/v2/providers/openmetrics instead (notice v2 branch, not master!).

I see that https://github.com/grpc-ecosystem/go-grpc-middleware/tree/v2/providers/openmetrics already has additional metrics compared to this branch, but does this also mean it is intended as a replacement for this package? If so, can we expect that to be a drop-in replacement for prometheus metrics as used here?

inge4pres avatar Mar 16 '21 09:03 inge4pres

Did this PR get moved to the new repo? I would love to have an easy way to monitor request size, sometimes the server goes under heavy load without the count of requests changing much and I hypothesize it may be because of bad actors submitting overly large payloads.

CyborgMaster avatar Apr 03 '21 21:04 CyborgMaster