diff --git a/api/types/load_traffic.go b/api/types/load_traffic.go index d5d9a3b..6e8196e 100644 --- a/api/types/load_traffic.go +++ b/api/types/load_traffic.go @@ -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. diff --git a/request/random.go b/request/random.go index 32012e0..6949302 100644 --- a/request/random.go +++ b/request/random.go @@ -149,6 +149,7 @@ type requestGetBuilder struct { namespace string name string resourceVersion string + keySpaceSize int maxRetries int } @@ -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, } } @@ -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{ diff --git a/request/requester.go b/request/requester.go index 9737b42..e5cf353 100644 --- a/request/requester.go +++ b/request/requester.go @@ -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 + // 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