diff options
Diffstat (limited to 'internal')
-rw-r--r-- | internal/api/handlers.go | 204 |
1 files changed, 204 insertions, 0 deletions
diff --git a/internal/api/handlers.go b/internal/api/handlers.go index 277552d..7f8f5d1 100644 --- a/internal/api/handlers.go +++ b/internal/api/handlers.go @@ -20,6 +20,8 @@ import ( "encoding/json" "fmt" "io" + "math" + "math/rand" "net" "net/http" "regexp" @@ -186,6 +188,73 @@ func init() { status.maintenanceEvents = []maintenanceEvent{} status.uptimeEvents = []uptimeEvent{} + + // For runChance + rand.Seed(time.Now().UnixNano()) + + incidentId := 42 + + go func() { + tick20ms := time.NewTicker(20 * time.Millisecond) + tick1s := time.NewTicker(1 * time.Second) + tick10s := time.NewTicker(10 * time.Second) + + defer tick20ms.Stop() + defer tick1s.Stop() + defer tick10s.Stop() + + for { + select { + case <-tick20ms.C: + // Update response times + for i := range status.services { + runChance(0.08, func() { + status.services[i].ResponseTime = int(math.Max(7.0, float64(status.services[i].ResponseTime+rand.Intn(10)-5))) + }) + } + status.overallStatus.ResponseTime = 0 + for _, s := range status.services { + status.overallStatus.ResponseTime = int(math.Max(float64(status.overallStatus.ResponseTime), float64(s.ResponseTime))) + } + status.metrics.ResponseTime = status.overallStatus.ResponseTime + + case <-tick1s.C: + fmt.Println("1 s tick") + case <-tick10s.C: + runChance(1.0, func() { + severity := SeverityMinor + if rand.Float64() < 0.3 { + severity = SeverityMajor + } + status.incidents = append(status.incidents, incident{ + Id: fmt.Sprintf("%d", incidentId), + Title: "", + Description: "", + Status: "", + Severity: severity, + StartTime: time.Now().UTC(), + AffectedServices: []string{}, + }) + incidentId++ + }) + status.overallStatus.ActiveIncidents = len(status.incidents) + } + } + }() +} + +func runChance(likelihood float64, action func()) { + if likelihood <= 0 { + return // never run + } + if likelihood >= 1 { + action() + return + } + + if rand.Float64() < likelihood { + action() + } } type overallStatus struct { @@ -331,3 +400,138 @@ func addRotLog(logs *[LogLength]string, last *int, parser chan string, value str } } } + +const ( + normalIncidentTitles = []string{ + "Database connection timeout", + "Unexpected 500 Internal Server Error", + "API rate limit exceeded", + "Missing authentication token", + "Service unavailable due to maintenance", + "Invalid request payload", + "Cross‑domain request blocked", + "SSL certificate expired", + "Memory leak detected in worker process", + "Database deadlock detected", + "Failed to serialize response", + "Cache miss leading to latency spike", + "Outdated API endpoint usage", + "Insufficient permissions for resource", + "Concurrent request overload", + "Unexpected null reference", + "Data consistency violation", + "Failed to enqueue background job", + "Rate limiter misconfigured", + "Unexpected null pointer exception", + } + normalIncidentDescriptions = []string{ + "The database server failed to establish a connection within the allotted timeout period, causing API requests to hang and eventually fail.", + "The web service returned a generic 500 Internal Server Error due to an unhandled exception in the request handler.", + "Clients exceeded the predefined rate limit, resulting in throttled responses and temporary denial of service.", + "Incoming requests lacked a valid authentication token, leading to unauthorized access attempts.", + "The service was temporarily unavailable because of scheduled maintenance and infrastructure upgrades.", + "The request payload was malformed or missing required fields, causing validation errors.", + "Cross‑origin resource sharing (CORS) policy blocked the request from an unauthorized domain.", + "The SSL/TLS certificate had expired, preventing secure connections from clients.", + "A memory leak in the worker process caused gradual exhaustion of available RAM.", + "A deadlock occurred between database transactions, blocking all pending queries.", + "The response could not be serialized into JSON, leading to malformed output.", + "Cache misses caused a spike in latency as the backend had to recompute data.", + "Clients used deprecated API endpoints that are no longer supported.", + "The user lacked sufficient permissions to access the requested resource.", + "The server was overwhelmed by concurrent requests, exceeding its capacity limits.", + "A null reference exception was thrown during request processing.", + "Data integrity constraints were violated, causing transaction rollbacks.", + "Background job enqueuing failed due to a full queue or missing worker.", + "The rate limiter was misconfigured, allowing too many requests per interval.", + "A null pointer exception caused the service to crash during execution.", + } + mixedIncidentTitels = []string{ + "Database connection timeout", + "Unexpected 500 error on /api/v1/users", + "Missing authentication token", + "Rate limit exceeded for client IP 192.168.1.42", + "Service unavailable due to maintenance", + "Malformed JSON payload", + "Cache miss leading to slow response", + "Duplicate request IDs detected", + "Circular dependency in microservices", + "Out-of-memory exception in worker thread", + "DNS resolution failure for external API", + "Malformed URL in webhook callback", + "Cat in the server room", + "Unexpected emoji in user profile", + "Randomly generated error: 42 is the answer", + } + mixedIncidentDescriptions = []string{ + "The database server stopped accepting connections, causing a timeout for all client queries.", + "The `/api/v1/users` endpoint returned a 500 Internal Server Error due to an unhandled exception.", + "Requests were rejected because the authentication token was missing or malformed.", + "Requests from the IP `192.168.1.42` exceeded the rate limit, resulting in 429 responses.", + "The service was temporarily unavailable due to scheduled maintenance.", + "The API received malformed JSON, leading to a 400 Bad Request response.", + "The cache layer missed the key, forcing a slow database lookup.", + "Duplicate request IDs were detected, causing duplicate processing.", + "A circular dependency in the microservice architecture caused a deadlock.", + "The worker thread ran out of memory and crashed.", + "DNS resolution failed for an external API, blocking outbound calls.", + "A webhook callback URL contained invalid characters, causing a 400 error.", + "A stray cat wandered into the server room and triggered a physical security alarm.", + "User profiles contained unexpected emoji characters that broke rendering.", + "A random error message appeared: \"42 is the answer\", indicating a placeholder bug.", + } + sillyIncidentTitles = []string{ + "The API returned a rainbow instead of JSON", + "All requests were answered with a GIF of a dancing cat", + "The service responded with a random haiku", + "The endpoint started singing opera", + "All data was encrypted with a secret handshake", + "The server replied with a fortune cookie message", + "The service accidentally sent a selfie of the developer", + "All responses were wrapped in a Shakespearean sonnet", + "The API returned a random meme image", + "The service responded with a countdown to the moon landing", + "All requests were answered with a joke about HTTP", + "The server sent back a playlist of elevator music", + "The endpoint replied with a random dad joke", + "All data was sorted alphabetically by the last letter", + "The service responded with a random emoji string", + "The API returned a random recipe", + "All responses were encoded in Morse code", + "The server replied with a random motivational quote", + "The endpoint responded with a random crossword clue", + "All requests were answered with a random song lyric", + "The service returned a random conspiracy theory", + "The API responded with a random horoscope", + "All data was shuffled like a deck of cards", + "The server replied with a random conspiracy theory", + "The endpoint responded with a random tongue twister", + } + sillyIncidentDescriptions = []string{ + "The JSON parser returned a holographic rainbow that demanded cookies in exchange for schema validation.", + "Every API response included a looping dancing cat that judged your headers and sashayed through your CORS policy.", + "The server replied only in haiku and refused to switch out of seventeen syllables even when begged with ramen.", + "The endpoint belted operatic arias at 120 dB and required earplugs for POST requests.", + "Payloads were encrypted with a secret handshake, a wink, and a kazoo solo — mobile apps kept failing the kazoo step.", + "Responses arrived as fortune-cookie slips predicting uncanny laptop weather and advising investments in rubber ducks.", + "The API accidentally uploaded the lead dev's selfie wearing a cape and labeled it 'new JSON schema'.", + "Every error was delivered as a Shakespearean sonnet, complete with stage directions and a tragic '404 Romeo'.", + "Endpoints served meme PNGs captioned 'When your query times out but you're still fabulous' instead of data.", + "Responses counted down to the next moon landing in reverse, prompting clients to RSVP and NASA to ask why.", + "Headers contained nothing but increasingly elaborate HTTP puns, causing an epidemic of groans across the office.", + "Requests yielded a 45-minute elevator-music playlist narrated by a bored brass section and an oddly philosophical sheep.", + "Each response began with a groan-inducing dad joke and ended with 'Did you get it? No? Okay.'", + "Data was alphabetized by the last letter of each word, resulting in sentences like 'zoo apes banana' and much confusion.", + "Every field turned into a cryptic emoji cipher that required a three-hour romance with an online emoji oracle to decode.", + "The API returned microwave recipes involving glitter, two bananas, and an optional unicycle for garnish.", + "Responses blinked in Morse via server LEDs; clients had to tap along on toast to translate the payload.", + "The server replied with overenthusiastic motivational quotes, some signed 'Sincerely, Your Router'.", + "Each endpoint answered with a crossword clue so obscure it demanded a PhD in Breakfast Cereals.", + "Responses contained obscure song lyrics that led to several lawsuits from very offended shower singers.", + "The service offered a handcrafted conspiracy about pigeons, quantum routers, and a secret society of baristas.", + "Users received horoscopes telling their IPs to avoid Tuesdays and to invest heavily in chamomile tea.", + "Records were shuffled like a magician's deck, with the ace of spades mysteriously serving as the primary key.", + "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.", + } +) |