Merge pull request #15851 from serathius/robustness-generic
tests/robustness: Make weighted pick random genericdependabot/go_modules/github.com/prometheus/procfs-0.11.0
commit
f6161673af
|
@ -45,14 +45,14 @@ var (
|
||||||
keyCount: 10,
|
keyCount: 10,
|
||||||
leaseTTL: DefaultLeaseTTL,
|
leaseTTL: DefaultLeaseTTL,
|
||||||
largePutSize: 32769,
|
largePutSize: 32769,
|
||||||
writeChoices: []choiceWeight{
|
writeChoices: []choiceWeight[etcdRequestType]{
|
||||||
{choice: string(Put), weight: 45},
|
{choice: Put, weight: 45},
|
||||||
{choice: string(LargePut), weight: 5},
|
{choice: LargePut, weight: 5},
|
||||||
{choice: string(Delete), weight: 10},
|
{choice: Delete, weight: 10},
|
||||||
{choice: string(MultiOpTxn), weight: 10},
|
{choice: MultiOpTxn, weight: 10},
|
||||||
{choice: string(PutWithLease), weight: 10},
|
{choice: PutWithLease, weight: 10},
|
||||||
{choice: string(LeaseRevoke), weight: 10},
|
{choice: LeaseRevoke, weight: 10},
|
||||||
{choice: string(CompareAndSet), weight: 10},
|
{choice: CompareAndSet, weight: 10},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -66,10 +66,10 @@ var (
|
||||||
keyCount: 10,
|
keyCount: 10,
|
||||||
largePutSize: 32769,
|
largePutSize: 32769,
|
||||||
leaseTTL: DefaultLeaseTTL,
|
leaseTTL: DefaultLeaseTTL,
|
||||||
writeChoices: []choiceWeight{
|
writeChoices: []choiceWeight[etcdRequestType]{
|
||||||
{choice: string(Put), weight: 85},
|
{choice: Put, weight: 85},
|
||||||
{choice: string(MultiOpTxn), weight: 10},
|
{choice: MultiOpTxn, weight: 10},
|
||||||
{choice: string(LargePut), weight: 5},
|
{choice: LargePut, weight: 5},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -82,10 +82,10 @@ var (
|
||||||
averageKeyCount: 5,
|
averageKeyCount: 5,
|
||||||
resource: "pods",
|
resource: "pods",
|
||||||
namespace: "default",
|
namespace: "default",
|
||||||
writeChoices: []choiceWeight{
|
writeChoices: []choiceWeight[KubernetesRequestType]{
|
||||||
{choice: string(KubernetesUpdate), weight: 75},
|
{choice: KubernetesUpdate, weight: 75},
|
||||||
{choice: string(KubernetesDelete), weight: 15},
|
{choice: KubernetesDelete, weight: 15},
|
||||||
{choice: string(KubernetesCreate), weight: 10},
|
{choice: KubernetesCreate, weight: 10},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -99,9 +99,9 @@ var (
|
||||||
keyCount: 10,
|
keyCount: 10,
|
||||||
largePutSize: 8196,
|
largePutSize: 8196,
|
||||||
leaseTTL: DefaultLeaseTTL,
|
leaseTTL: DefaultLeaseTTL,
|
||||||
writeChoices: []choiceWeight{
|
writeChoices: []choiceWeight[etcdRequestType]{
|
||||||
{choice: string(Put), weight: 95},
|
{choice: Put, weight: 95},
|
||||||
{choice: string(LargePut), weight: 5},
|
{choice: LargePut, weight: 5},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@ type Traffic interface {
|
||||||
|
|
||||||
type etcdTraffic struct {
|
type etcdTraffic struct {
|
||||||
keyCount int
|
keyCount int
|
||||||
writeChoices []choiceWeight
|
writeChoices []choiceWeight[etcdRequestType]
|
||||||
leaseTTL int64
|
leaseTTL int64
|
||||||
largePutSize int
|
largePutSize int
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ type kubernetesTraffic struct {
|
||||||
averageKeyCount int
|
averageKeyCount int
|
||||||
resource string
|
resource string
|
||||||
namespace string
|
namespace string
|
||||||
writeChoices []choiceWeight
|
writeChoices []choiceWeight[KubernetesRequestType]
|
||||||
}
|
}
|
||||||
|
|
||||||
type KubernetesRequestType string
|
type KubernetesRequestType string
|
||||||
|
@ -174,7 +174,7 @@ func (t kubernetesTraffic) Write(ctx context.Context, c *recordingClient, ids id
|
||||||
if len(objects) > t.averageKeyCount*3/2 {
|
if len(objects) > t.averageKeyCount*3/2 {
|
||||||
err = t.Delete(writeCtx, c, string(randomPod.Key), randomPod.ModRevision)
|
err = t.Delete(writeCtx, c, string(randomPod.Key), randomPod.ModRevision)
|
||||||
} else {
|
} else {
|
||||||
op := KubernetesRequestType(pickRandom(t.writeChoices))
|
op := pickRandom(t.writeChoices)
|
||||||
switch op {
|
switch op {
|
||||||
case KubernetesDelete:
|
case KubernetesDelete:
|
||||||
err = t.Delete(writeCtx, c, string(randomPod.Key), randomPod.ModRevision)
|
err = t.Delete(writeCtx, c, string(randomPod.Key), randomPod.ModRevision)
|
||||||
|
@ -256,7 +256,7 @@ func (t etcdTraffic) Write(ctx context.Context, c *recordingClient, limiter *rat
|
||||||
writeCtx, cancel := context.WithTimeout(ctx, RequestTimeout)
|
writeCtx, cancel := context.WithTimeout(ctx, RequestTimeout)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
switch etcdRequestType(pickRandom(t.writeChoices)) {
|
switch pickRandom(t.writeChoices) {
|
||||||
case Put:
|
case Put:
|
||||||
err = c.Put(writeCtx, key, fmt.Sprintf("%d", id.RequestId()))
|
err = c.Put(writeCtx, key, fmt.Sprintf("%d", id.RequestId()))
|
||||||
case LargePut:
|
case LargePut:
|
||||||
|
@ -356,12 +356,12 @@ func randString(size int) string {
|
||||||
return data.String()
|
return data.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
type choiceWeight struct {
|
type choiceWeight[T any] struct {
|
||||||
choice string
|
choice T
|
||||||
weight int
|
weight int
|
||||||
}
|
}
|
||||||
|
|
||||||
func pickRandom(choices []choiceWeight) string {
|
func pickRandom[T any](choices []choiceWeight[T]) T {
|
||||||
sum := 0
|
sum := 0
|
||||||
for _, op := range choices {
|
for _, op := range choices {
|
||||||
sum += op.weight
|
sum += op.weight
|
||||||
|
|
Loading…
Reference in New Issue