go-grpc-middleware
go-grpc-middleware copied to clipboard
prometheus: Add ip labels to server metrics
Add two labels grpc_server_ip and grpc_client_ip to the server metrics when option WithServerIPLabelsEnabled() is set. These labels are not added by default for compatibility.
This pr proposes an implementation for issue #644
Changes
- Add
WithServerIPLabelsEnabled()option forServerMetrics - Add labels grpc_server_ip and grpc_client_ip to server metrics when the option is turned on. The IPs are extracted from peer context.
Verification
The metric scraped into Prometheus likes:
grpc_server_handled_total{component="controller",grpc_client_ip="10.16.18.58",grpc_code="OK",grpc_method="StreamResourceGroup",grpc_server_ip="10.16.18.58",grpc_service="controller.Controller",grpc_type="server_stream",instance="10.16.18.58:6013",job="app-internal-metrics"}