Netflix/chaosmonkey · error

invalid attributes.chaosMonkey.meanTimeBetweenKillsInWorkDay

Error message

invalid attributes.chaosMonkey.meanTimeBetweenKillsInWorkDays: %d

What it means

After presence checks, fromJSON validates that meanTimeBetweenKillsInWorkDays is strictly positive when chaos monkey is enabled. A zero or negative value fails this check and produces this fmt.Errorf with the value interpolated.

Source

Thrown at spinnaker/fromjson.go:126

	cm := parsed.Attributes.ChaosMonkey

	if cm.Enabled == nil {
		return nil, errors.New("'attributes.chaosMonkey.enabled' field missing")
	}

	// Check if mean time between kills is missing.
	// If not enabled, it's ok if it's missing
	if *cm.Enabled && cm.MeanTimeBetweenKillsInWorkDays == nil {
		return nil, errors.New("attributes.chaosMonkey.meanTimeBetweenKillsInWorkDays missing")
	}

	if *cm.Enabled && cm.MinTimeBetweenKillsInWorkDays == nil {
		return nil, errors.New("attributes.chaosMonkey.minTimeBetweenKillsInWorkDays missing")
	}

	if *cm.Enabled && (*cm.MeanTimeBetweenKillsInWorkDays <= 0) {
		return nil, fmt.Errorf("invalid attributes.chaosMonkey.meanTimeBetweenKillsInWorkDays: %d", cm.MeanTimeBetweenKillsInWorkDays)
	}

	grouping := chaosmonkey.Cluster

	switch cm.Grouping {
	case "app":
		grouping = chaosmonkey.App
	case "stack":
		grouping = chaosmonkey.Stack
	case "cluster":
		grouping = chaosmonkey.Cluster
	default:
		// If not enabled, the user may not have specified a grouping at all,
		// in which case we stick with the default
		if *cm.Enabled {
			return nil, errors.Errorf("Unknown grouping: %s", cm.Grouping)
		}
	}

View on GitHub (pinned to eaa28fb761)

Solutions

  1. Set meanTimeBetweenKillsInWorkDays to a positive integer (e.g. 5) in attributes.chaosMonkey
  2. Add upstream validation that rejects intervals <= 0 before persisting the config
  3. Note the message contains a pre-existing bug: it formats the pointer cm.MeanTimeBetweenKillsInWorkDays, not *cm.MeanTimeBetweenKillsInWorkDays, so the printed value is a pointer — check the raw config for the actual number

Example fix

// before
"chaosMonkey": {"enabled": true, "meanTimeBetweenKillsInWorkDays": 0}
// after
"chaosMonkey": {"enabled": true, "meanTimeBetweenKillsInWorkDays": 5}
Defensive patterns

Strategy: validation

Validate before calling

var cm struct {
    Enabled *bool `json:"enabled"`
    Mean    *int  `json:"meanTimeBetweenKillsInWorkDays"`
}
json.Unmarshal(cmRaw, &cm)
if cm.Enabled != nil && *cm.Enabled && (cm.Mean == nil || *cm.Mean <= 0) {
    return errors.New("meanTimeBetweenKillsInWorkDays must be a positive integer")
}

Type guard

func meanIntervalIsValid(cmRaw []byte) bool {
    var p struct {
        Enabled *bool `json:"enabled"`
        Mean    *int  `json:"meanTimeBetweenKillsInWorkDays"`
    }
    if json.Unmarshal(cmRaw, &p) != nil || p.Enabled == nil || !*p.Enabled { return true }
    return p.Mean != nil && *p.Mean > 0
}

Try / catch

cfg, err := sp.Get(app)
if err != nil {
    if strings.Contains(err.Error(), "invalid attributes.chaosMonkey.meanTimeBetweenKillsInWorkDays") {
        return fmt.Errorf("app %s has non-positive kill interval: %w", app, err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling spinnaker.Get where chaosMonkey.enabled is true and meanTimeBetweenKillsInWorkDays <= 0 (e.g. 0 or a negative number).

Common situations: A UI or script defaulting the field to 0; manual config where the interval was never set; unit conversion bugs writing days as 0.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of Netflix/chaosmonkey@eaa28fb761 (2026-09-03). Data as JSON: /api/errors/d9e0969307f182bb. Report an issue: GitHub.