Skip to content

Commit

Permalink
[FAB-12725] defensive treatment of info.FullMethod
Browse files Browse the repository at this point in the history
grpc interceptors are provided the target method as part of the
grpc.StreamServerInfo. The documented format of the method is
'/package.service/method/'.

In order to prevent panics if that changes, modify the code to ensure
the method split produces the expected number of substrings.

Change-Id: I7de64c7cd2d8c61e5e517c2db4db5115c6961707
Signed-off-by: Matthew Sykes <[email protected]>
  • Loading branch information
sykesm authored and mastersingh24 committed Nov 8, 2018
1 parent cbcac8c commit bac3310
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions common/grpcmetrics/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@ func StreamServerInterceptor(sm *StreamMetrics) grpc.StreamServerInterceptor {

func serviceMethod(fullMethod string) (service, method string) {
normalizedMethod := strings.Replace(fullMethod, ".", "_", -1)
parts := strings.SplitN(normalizedMethod[1:], "/", 2)
return parts[0], parts[1]
parts := strings.SplitN(normalizedMethod, "/", -1)
if len(parts) != 3 {
return "unknown", "unknown"
}
return parts[1], parts[2]
}

type serverStream struct {
Expand Down

0 comments on commit bac3310

Please sign in to comment.