Skip to content

Commit

Permalink
*: add MaxRetries to loadprofile spec
Browse files Browse the repository at this point in the history
By default, we should set MaxRetries to zero. NoRetry can help us verify
the flowcontrol settings.

Signed-off-by: Wei Fu <[email protected]>
  • Loading branch information
fuweid committed Jan 31, 2024
1 parent 9c17a2a commit 23b9720
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
4 changes: 4 additions & 0 deletions api/types/load_traffic.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ type LoadProfileSpec struct {
ContentType ContentType `json:"contentType" yaml:"contentType"`
// DisableHTTP2 means client will use HTTP/1.1 protocol if it's true.
DisableHTTP2 bool `json:"disableHTTP2" yaml:"disableHTTP2"`
// MaxRetries makes the request use the given integer as a ceiling of
// retrying upon receiving "Retry-After" headers and 429 status-code
// in the response (<= 0 means no retry).
MaxRetries int `json:"maxRetries" yaml:"maxRetries"`
// Requests defines the different kinds of requests with weights.
// The executor should randomly pick by weight.
Requests []*WeightedRequest
Expand Down
8 changes: 8 additions & 0 deletions cmd/kperf/commands/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ var runCommand = cli.Command{
Name: "disable-http2",
Usage: "Disable HTTP2 protocol",
},
cli.IntFlag{
Name: "max-retries",
Usage: "Retry request after receiving 429 http code (<=0 means no retry)",
Value: 0,
},
cli.StringFlag{
Name: "result",
Usage: "Path to the file which stores results",
Expand Down Expand Up @@ -170,6 +175,9 @@ func loadConfig(cliCtx *cli.Context) (*types.LoadProfile, error) {
if v := "disable-http2"; cliCtx.IsSet(v) {
profileCfg.Spec.DisableHTTP2 = cliCtx.Bool(v)
}
if v := "max-retries"; cliCtx.IsSet(v) {
profileCfg.Spec.MaxRetries = cliCtx.Int(v)
}

if err := profileCfg.Validate(); err != nil {
return nil, err
Expand Down
20 changes: 12 additions & 8 deletions request/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ func NewWeightedRandomRequests(spec *types.LoadProfileSpec) (*WeightedRandomRequ
var builder RESTRequestBuilder
switch {
case r.StaleList != nil:
builder = newRequestListBuilder(r.StaleList, "0")
builder = newRequestListBuilder(r.StaleList, "0", spec.MaxRetries)
case r.QuorumList != nil:
builder = newRequestListBuilder(r.QuorumList, "")
builder = newRequestListBuilder(r.QuorumList, "", spec.MaxRetries)
case r.StaleGet != nil:
builder = newRequestGetBuilder(r.StaleGet, "0")
builder = newRequestGetBuilder(r.StaleGet, "0", spec.MaxRetries)
case r.QuorumGet != nil:
builder = newRequestGetBuilder(r.QuorumGet, "")
builder = newRequestGetBuilder(r.QuorumGet, "", spec.MaxRetries)
default:
return nil, fmt.Errorf("not implement for PUT yet")
}
Expand Down Expand Up @@ -130,9 +130,10 @@ type requestGetBuilder struct {
namespace string
name string
resourceVersion string
maxRetries int
}

func newRequestGetBuilder(src *types.RequestGet, resourceVersion string) *requestGetBuilder {
func newRequestGetBuilder(src *types.RequestGet, resourceVersion string, maxRetries int) *requestGetBuilder {
return &requestGetBuilder{
version: schema.GroupVersion{
Group: src.Group,
Expand All @@ -142,6 +143,7 @@ func newRequestGetBuilder(src *types.RequestGet, resourceVersion string) *reques
namespace: src.Namespace,
name: src.Name,
resourceVersion: resourceVersion,
maxRetries: maxRetries,
}
}

Expand All @@ -165,7 +167,7 @@ func (b *requestGetBuilder) Build(cli rest.Interface) (string, *rest.Request) {
&metav1.GetOptions{ResourceVersion: b.resourceVersion},
scheme.ParameterCodec,
schema.GroupVersion{Version: "v1"},
)
).MaxRetries(b.maxRetries)
}

type requestListBuilder struct {
Expand All @@ -175,9 +177,10 @@ type requestListBuilder struct {
limit int64
labelSelector string
resourceVersion string
maxRetries int
}

func newRequestListBuilder(src *types.RequestList, resourceVersion string) *requestListBuilder {
func newRequestListBuilder(src *types.RequestList, resourceVersion string, maxRetries int) *requestListBuilder {
return &requestListBuilder{
version: schema.GroupVersion{
Group: src.Group,
Expand All @@ -188,6 +191,7 @@ func newRequestListBuilder(src *types.RequestList, resourceVersion string) *requ
limit: int64(src.Limit),
labelSelector: src.Selector,
resourceVersion: resourceVersion,
maxRetries: maxRetries,
}
}

Expand Down Expand Up @@ -215,5 +219,5 @@ func (b *requestListBuilder) Build(cli rest.Interface) (string, *rest.Request) {
},
scheme.ParameterCodec,
schema.GroupVersion{Version: "v1"},
)
).MaxRetries(b.maxRetries)
}

0 comments on commit 23b9720

Please sign in to comment.