Merge pull request #755 from gavin-ts/simpler-chaos

testing chaos with more readable/simpler ids and labels
This commit is contained in:
gavin-ts 2023-02-10 18:54:40 -08:00 committed by GitHub
commit f86862f3ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -15,6 +15,8 @@ import (
"oss.terrastruct.com/d2/d2target" "oss.terrastruct.com/d2/d2target"
) )
const complexIDs = false
func GenDSL(maxi int) (_ string, err error) { func GenDSL(maxi int) (_ string, err error) {
gs := &dslGenState{ gs := &dslGenState{
rand: mathrand.New(mathrand.NewSource(time.Now().UnixNano())), rand: mathrand.New(mathrand.NewSource(time.Now().UnixNano())),
@ -62,7 +64,11 @@ func (gs *dslGenState) gen(maxi int) error {
} }
func (gs *dslGenState) genNode(containerID string) (string, error) { func (gs *dslGenState) genNode(containerID string) (string, error) {
nodeID := gs.randStr(32, true) maxLen := 8
if complexIDs {
maxLen = 32
}
nodeID := gs.randStr(maxLen, true)
if containerID != "" { if containerID != "" {
nodeID = containerID + "." + nodeID nodeID = containerID + "." + nodeID
} }
@ -95,7 +101,11 @@ func (gs *dslGenState) node() error {
if gs.roll(25, 75) == 0 { if gs.roll(25, 75) == 0 {
// 25% chance of adding a label. // 25% chance of adding a label.
gs.g, err = d2oracle.Set(gs.g, nodeID, nil, go2.Pointer(gs.randStr(256, false))) maxLen := 8
if complexIDs {
maxLen = 256
}
gs.g, err = d2oracle.Set(gs.g, nodeID, nil, go2.Pointer(gs.randStr(maxLen, false)))
if err != nil { if err != nil {
return err return err
} }
@ -154,7 +164,11 @@ func (gs *dslGenState) edge() error {
return err return err
} }
if gs.randBool() { if gs.randBool() {
gs.g, err = d2oracle.Set(gs.g, key, nil, go2.Pointer(gs.randStr(128, false))) maxLen := 8
if complexIDs {
maxLen = 128
}
gs.g, err = d2oracle.Set(gs.g, key, nil, go2.Pointer(gs.randStr(maxLen, false)))
if err != nil { if err != nil {
return err return err
} }
@ -191,11 +205,15 @@ func (gs *dslGenState) randBool() bool {
// TODO go back to using xrand.String, currently some incompatibility with // TODO go back to using xrand.String, currently some incompatibility with
// stuffing these strings into a script for dagre // stuffing these strings into a script for dagre
func randRune() rune { func randRune() rune {
if complexIDs {
if mathrand.Int31n(100) == 0 { if mathrand.Int31n(100) == 0 {
// Generate newline 1% of the time. // Generate newline 1% of the time.
return '\n' return '\n'
} }
return mathrand.Int31n(128) + 1 return mathrand.Int31n(128) + 1
} else {
return mathrand.Int31n(26) + 97
}
} }
func (gs *dslGenState) findOuterSequenceDiagram(nodeID string) string { func (gs *dslGenState) findOuterSequenceDiagram(nodeID string) string {