@@ -61,28 +61,29 @@ func (h *handler) streamHandler(_ interface{}, serverStream grpc.ServerStream) e
6161 if ! ok {
6262 return status .Errorf (codes .Internal , "ServerTransportStream not exists in context" )
6363 }
64+
6465 // full method name has the form /service/method, we want the service
6566 serviceName := strings .Split (fullMethodName , "/" )[1 ]
66- excluded := contains (h .disruption .Excluded , serviceName )
67- if ! excluded {
68- if h .disruption .ErrorRate > 0 && rand .Float32 () <= h .disruption .ErrorRate {
69- h .metrics .Inc (protocol .MetricRequestsFaulted )
70- return h .injectError (serverStream )
71- }
67+ if contains (h .disruption .Excluded , serviceName ) {
68+ h .metrics .Inc (protocol .MetricRequestsExcluded )
69+ return h .transparentForward (serverStream )
70+ }
7271
73- // add delay
74- if h .disruption .AverageDelay > 0 {
75- h .metrics .Inc (protocol .MetricRequestsFaulted )
72+ if rand .Float32 () < h .disruption .ErrorRate {
73+ h .metrics .Inc (protocol .MetricRequestsFaulted )
74+ return h .injectError (serverStream )
75+ }
7676
77- delay := int64 (h .disruption .AverageDelay )
78- if h .disruption .DelayVariation > 0 {
79- variation := int64 (h .disruption .DelayVariation )
80- delay = delay + variation - 2 * rand .Int63n (variation )
81- }
82- time .Sleep (time .Duration (delay ))
77+ // add delay
78+ if h .disruption .AverageDelay > 0 {
79+ h .metrics .Inc (protocol .MetricRequestsFaulted )
80+
81+ delay := int64 (h .disruption .AverageDelay )
82+ if h .disruption .DelayVariation > 0 {
83+ variation := int64 (h .disruption .DelayVariation )
84+ delay = delay + variation - 2 * rand .Int63n (variation )
8385 }
84- } else {
85- h .metrics .Inc (protocol .MetricRequestsExcluded )
86+ time .Sleep (time .Duration (delay ))
8687 }
8788
8889 return h .transparentForward (serverStream )
0 commit comments