@@ -436,15 +436,7 @@ func (c *client) trySend(rpc hrpc.Call) (err error) {
436436 c .fail (err )
437437 }
438438 if r := c .unregisterRPC (id ); r != nil {
439- if m , ok := r .(* multi ); ok {
440- for _ , call := range m .calls {
441- if call != nil {
442- rpcResultCount .WithLabelValues (c .Addr (), call .Name (), "failure" ).Inc ()
443- }
444- }
445- } else {
446- rpcResultCount .WithLabelValues (c .Addr (), r .Name (), "failure" ).Inc ()
447- }
439+ c .trackRPCResult (r , "error" )
448440 // we are the ones to unregister the rpc,
449441 // return err to notify client of it
450442 return err
@@ -473,6 +465,20 @@ func (c *client) receiveRPCs() {
473465 }
474466}
475467
468+ func (c * client ) trackRPCResult (rpc hrpc.Call , status string ) {
469+ if m , ok := rpc .(* multi ); ok {
470+ for _ , call := range m .calls {
471+ if call != nil {
472+ rpcResultCount .WithLabelValues (
473+ c .Addr (), call .Name (), status , "batch" ).Inc ()
474+ }
475+ }
476+ } else {
477+ rpcResultCount .WithLabelValues (
478+ c .Addr (), rpc .Name (), status , "unary" ).Inc ()
479+ }
480+ }
481+
476482func (c * client ) receive (r io.Reader ) (err error ) {
477483 var (
478484 sz [4 ]byte
@@ -527,19 +533,11 @@ func (c *client) receive(r io.Reader) (err error) {
527533 // It's our responsibility to deliver the response or error to the
528534 // caller as we unregistered the rpc.
529535 defer func () {
530- status := "success "
536+ status := "ok "
531537 if err != nil {
532- status = "failure"
533- }
534- if m , ok := rpc .(* multi ); ok {
535- for _ , call := range m .calls {
536- if call != nil {
537- rpcResultCount .WithLabelValues (c .Addr (), call .Name (), status ).Inc ()
538- }
539- }
540- } else {
541- rpcResultCount .WithLabelValues (c .Addr (), rpc .Name (), status ).Inc ()
538+ status = "error"
542539 }
540+ c .trackRPCResult (rpc , status )
543541 returnResult (rpc , response , err )
544542 }()
545543
0 commit comments