Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/types/load_traffic.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ type RequestGet struct {
Namespace string `json:"namespace" yaml:"namespace"`
// Name is object's name.
Name string `json:"name" yaml:"name"`
// KeySpaceSize is used to generate random number as name's suffix.
KeySpaceSize int `json:"keySpaceSize" yaml:"keySpaceSize"`
}

// RequestList defines LIST request for target objects.
Expand Down
10 changes: 9 additions & 1 deletion request/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ type requestGetBuilder struct {
namespace string
name string
resourceVersion string
keySpaceSize int
maxRetries int
}

Expand All @@ -162,6 +163,7 @@ func newRequestGetBuilder(src *types.RequestGet, resourceVersion string, maxRetr
namespace: src.Namespace,
name: src.Name,
resourceVersion: resourceVersion,
keySpaceSize: src.KeySpaceSize,
maxRetries: maxRetries,
}
}
Expand All @@ -178,7 +180,13 @@ func (b *requestGetBuilder) Build(cli rest.Interface) Requester {
if b.namespace != "" {
comps = append(comps, "namespaces", b.namespace)
}
comps = append(comps, b.resource, b.name)

finalName := b.name
if b.keySpaceSize > 0 {
randomInt, _ := rand.Int(rand.Reader, big.NewInt(int64(b.keySpaceSize)))
finalName = fmt.Sprintf("%s-%d", b.name, randomInt.Int64())
}
comps = append(comps, b.resource, finalName)

return &DiscardRequester{
BaseRequester: BaseRequester{
Expand Down
6 changes: 3 additions & 3 deletions request/requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ func (reqr *BaseRequester) URL() *url.URL {
func (reqr *BaseRequester) MaskedURL() *url.URL {
originalURL := reqr.req.URL()

// Aggregates for DELETE and PATCH methods, replaces the last path segment
// for DELETE and PATCH requests so they can be aggregated (e.g. in metrics)
if reqr.method == http.MethodDelete || reqr.method == http.MethodPatch {
// Aggregates for DELETE, PATCH, and GET methods, replaces the last path segment
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove the comment in either line 42 or line 46 and only keep one?

// for DELETE, PATCH, and GET requests so they can be aggregated (e.g. in metrics)
if reqr.method == http.MethodDelete || reqr.method == http.MethodPatch || reqr.method == http.MethodGet {
if u, err := url.Parse(originalURL.String()); err == nil {
u.Path = path.Join(path.Dir(u.Path), ":name")
return u // String() will keep ":name" as-is
Expand Down
Loading