Skip to content

Commit

Permalink
feat(webserver): add UnaryClientInterceptors and StreamClientIntercep…
Browse files Browse the repository at this point in the history
…tors for grpc DialOptions
  • Loading branch information
searKing committed Sep 2, 2024
1 parent ed47ff6 commit 842152e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
24 changes: 24 additions & 0 deletions pkg/webserver/webserver.interceptors.grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,27 @@ func (f *Factory) StreamServerInterceptors(interceptors ...grpc.StreamServerInte
}
return interceptors
}

func (f *Factory) UnaryClientInterceptors(interceptors ...grpc.UnaryClientInterceptor) []grpc.UnaryClientInterceptor {
// handle request timeout
interceptors = append(interceptors, timeoutlimit.UnaryClientInterceptor(f.fc.HandledTimeoutUnary))
// burst limit
interceptors = append(interceptors, burstlimit.UnaryClientInterceptor(f.fc.MaxConcurrencyUnary, f.fc.BurstLimitTimeoutUnary))
// request id
if f.fc.FillRequestId {
interceptors = append(interceptors, requestid.UnaryClientInterceptor())
}
return interceptors
}

func (f *Factory) StreamClientInterceptors(interceptors ...grpc.StreamClientInterceptor) []grpc.StreamClientInterceptor {
// handle request timeout
interceptors = append(interceptors, timeoutlimit.StreamClientInterceptor(f.fc.HandledTimeoutUnary))
// burst limit
interceptors = append(interceptors, burstlimit.StreamClientInterceptor(f.fc.MaxConcurrencyUnary, f.fc.BurstLimitTimeoutUnary))
// request id
if f.fc.FillRequestId {
interceptors = append(interceptors, requestid.StreamClientInterceptor())
}
return interceptors
}
2 changes: 2 additions & 0 deletions pkg/webserver/webserver.options.grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@ func (f *Factory) DialOptions(opts ...grpc.DialOption) []grpc.DialOption {
if f.fc.EnableOpenTelemetry {
opts = append(opts, otel.DialOptions()...)
}
opts = append(opts, grpc.WithChainUnaryInterceptor(f.UnaryClientInterceptors()...))
opts = append(opts, grpc.WithChainStreamInterceptor(f.StreamClientInterceptors()...))
return opts
}

0 comments on commit 842152e

Please sign in to comment.