Repository: etcd-io/etcd
File: tests/robustness/traffic/etcd.go (Go)

Code before:
		LeaseTTL:     DefaultLeaseTTL,
		// Please keep the sum of weights equal 100.
		Requests: []random.ChoiceWeight[EtcdRequestType]{
			{Choice: Get, Weight: 15},
			{Choice: List, Weight: 15},
			{Choice: StaleGet, Weight: 10},
			{Choice: StaleList, Weight: 10},
			{Choice: MultiOpTxn, Weight: 5},
			{Choice: LargePut, Weight: 5},
			{Choice: Put, Weight: 40},
		},
	}
	EtcdDelete Traffic = EtcdTraffic{
		KeyCount:     10,
		LargePutSize: 32769,
		LeaseTTL:     DefaultLeaseTTL,
		// Please keep the sum of weights equal 100.
		Requests: []random.ChoiceWeight[EtcdRequestType]{
			{Choice: Put, Weight: 50},
			{Choice: Delete, Weight: 50},
		},
	}
)

type EtcdTraffic struct {
	KeyCount     int
	Requests     []random.ChoiceWeight[EtcdRequestType]
	LeaseTTL     int64
	LargePutSize int
}

func (t EtcdTraffic) ExpectUniqueRevision() bool {
	return false
}

type EtcdRequestType string

const (
	Get           EtcdRequestType = "get"
	StaleGet      EtcdRequestType = "staleGet"
	List          EtcdRequestType = "list"
	StaleList     EtcdRequestType = "staleList"
	Put           EtcdRequestType = "put"
	LargePut      EtcdRequestType = "largePut"
	Delete        EtcdRequestType = "delete"
	MultiOpTxn    EtcdRequestType = "multiOpTxn"
	PutWithLease  EtcdRequestType = "putWithLease"
	LeaseRevoke   EtcdRequestType = "leaseRevoke"
	CompareAndSet EtcdRequestType = "compareAndSet"
	Defragment    EtcdRequestType = "defragment"
)

Review comment (bug):
Making the struct public make sense, however we should consider if it's convenient and safe to be used by users outside this package. It's good to consider that users might not know some internal assumptions about the fields.

Instead of making all fields in struct public we could create a function working as a constructor. This is safer as it allows us to add some logic on construction like validation for fields that would prevent panics or incorrect behavior. Maybe in the future would be good to check keyCount, LargePutSize and leaseTTL are not negative etcd. 

Code after:
		leaseTTL:     DefaultLeaseTTL,
		// Please keep the sum of weights equal 100.
		requests: []random.ChoiceWeight[etcdRequestType]{
			{Choice: Get, Weight: 15},
			{Choice: List, Weight: 15},
			{Choice: StaleGet, Weight: 10},
			{Choice: StaleList, Weight: 10},
			{Choice: MultiOpTxn, Weight: 5},
			{Choice: LargePut, Weight: 5},
			{Choice: Put, Weight: 40},
		},
	}
	EtcdDelete Traffic = etcdTraffic{
		keyCount:     10,
		largePutSize: 32769,
		leaseTTL:     DefaultLeaseTTL,
		// Please keep the sum of weights equal 100.
		requests: []random.ChoiceWeight[etcdRequestType]{
			{Choice: Put, Weight: 50},
			{Choice: Delete, Weight: 50},
		},
	}
	EtcdAntithesis Traffic = etcdTraffic{
		keyCount:     10,
		largePutSize: 32769,
		leaseTTL:     DefaultLeaseTTL,
		// Please keep the sum of weights equal 100.
		requests: []random.ChoiceWeight[etcdRequestType]{
			{Choice: Get, Weight: 50},
			{Choice: Put, Weight: 50},
		},
	}
)

type etcdTraffic struct {
	keyCount     int
	requests     []random.ChoiceWeight[etcdRequestType]
	leaseTTL     int64
	largePutSize int
}

func (t etcdTraffic) ExpectUniqueRevision() bool {
	return false
}

type etcdRequestType string

const (
	Get           etcdRequestType = "get"
	StaleGet      etcdRequestType = "staleGet"
	List          etcdRequestType = "list"