Skip to content

Commit

Permalink
xds: optimize fault injection filter with empty config (#4367)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfawley committed May 4, 2021
1 parent 79e55d6 commit 4f3aa7c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
7 changes: 6 additions & 1 deletion xds/internal/httpfilter/fault/fault.go
Expand Up @@ -125,7 +125,12 @@ func (builder) BuildClientInterceptor(cfg, override httpfilter.FilterConfig) (ir
}
}

return &interceptor{config: c.config}, nil
icfg := c.config
if (icfg.GetMaxActiveFaults() != nil && icfg.GetMaxActiveFaults().GetValue() == 0) ||
(icfg.GetDelay() == nil && icfg.GetAbort() == nil) {
return nil, nil
}
return &interceptor{config: icfg}, nil
}

type interceptor struct {
Expand Down
22 changes: 22 additions & 0 deletions xds/internal/httpfilter/fault/fault_test.go
Expand Up @@ -161,6 +161,28 @@ func (s) TestFaultInjection_Unary(t *testing.T) {
randOutInc int
want []subcase
}{{
name: "max faults zero",
cfgs: []*fpb.HTTPFault{{
MaxActiveFaults: wrapperspb.UInt32(0),
Abort: &fpb.FaultAbort{
Percentage: &tpb.FractionalPercent{Numerator: 100, Denominator: tpb.FractionalPercent_HUNDRED},
ErrorType: &fpb.FaultAbort_GrpcStatus{GrpcStatus: uint32(codes.Aborted)},
},
}},
randOutInc: 5,
want: []subcase{{
code: codes.OK,
repeat: 25,
}},
}, {
name: "no abort or delay",
cfgs: []*fpb.HTTPFault{{}},
randOutInc: 5,
want: []subcase{{
code: codes.OK,
repeat: 25,
}},
}, {
name: "abort always",
cfgs: []*fpb.HTTPFault{{
Abort: &fpb.FaultAbort{
Expand Down

0 comments on commit 4f3aa7c

Please sign in to comment.