diff options
author | Robby Zambito <contact@robbyzambito.me> | 2025-08-08 11:59:13 -0400 |
---|---|---|
committer | Robby Zambito <contact@robbyzambito.me> | 2025-08-08 11:59:32 -0400 |
commit | f1552ea8c2b5e3f09533c08b40ad7331a82d7a33 (patch) | |
tree | 9f540a62330528daeb6821e0fef31f258315cd3d | |
parent | 0c4d50017842ee2bd07f6a0fcc7c8b28fb3a5345 (diff) |
Add random incidents
-rw-r--r-- | internal/api/handlers.go | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/internal/api/handlers.go b/internal/api/handlers.go index 97cd569..2fedcdd 100644 --- a/internal/api/handlers.go +++ b/internal/api/handlers.go @@ -223,14 +223,19 @@ func init() { case <-tick10s.C: runChance(1.0, func() { severity := SeverityMinor - if rand.Float64() < 0.3 { + runChance(0.3, func(){ severity = SeverityMajor - } + }) + i := rand.Intn(int(math.Min(float64(len(allIncidentTitles)), float64(len(allIncidentDescriptions))))) + serviceStatus := StatusDown + runChance(0.5, func(){ + serviceStatus = StatusDegraded + }) status.incidents = append(status.incidents, incident{ Id: fmt.Sprintf("%d", incidentId), - Title: "", - Description: "", - Status: "", + Title: allIncidentTitles[i], + Description: allIncidentDescriptions[i], + Status: serviceStatus, Severity: severity, StartTime: time.Now().UTC(), AffectedServices: []string{}, @@ -401,7 +406,8 @@ func addRotLog(logs *[LogLength]string, last *int, parser chan string, value str } } -const ( +// Not const because can't use runtime append in const definition +var ( normalIncidentTitles = []string{ "Database connection timeout", "Unexpected 500 Internal Server Error", @@ -534,4 +540,7 @@ const ( "The server spun a conspiracy about sentient staplers plotting to replace USB‑C with fashionable shoelaces.", "Replies were impossible tongue twisters typed by the server while giggling, causing voice assistants to short out.", } + + allIncidentTitles = append(append(append([]string{}, normalIncidentTitles...), mixedIncidentTitels...), sillyIncidentTitles...) + allIncidentDescriptions = append(append(append([]string{}, normalIncidentDescriptions...), mixedIncidentTitels...), sillyIncidentDescriptions...) ) |