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

prometheus: Add ip labels to server metrics

Open diabloneo opened this issue 11 months ago • 0 comments

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 for ServerMetrics
  • 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"}

diabloneo avatar Nov 06 '24 07:11 diabloneo