THINK FIRST·CODE LATER

← All labs

Error-budget tracker

Problem

Track StudyBuddy's availability error budget.

Input: first line sloPercent windowDays (e.g. 99.5 30). Then incidents, one per line: name minutesDown, until the end of input.

Compute the budget in minutes: (100 - slo) / 100 * windowDays * 24 * 60. Process the incidents in order; after each print

name: -m min, remaining r min (p% used)

with r and p printed with one decimal (r may become negative). Finally print the achieved availability Availability: a% (three decimals; 100 * (1 - totalDown / windowMinutes)) and the policy:

  • Policy: SHIP (budget healthy) if less than 50% of the budget is used;
  • Policy: CAUTION (canary releases only) if 50% to 100% is used (100% exactly counts as caution);
  • Policy: FREEZE (reliability work only) if more than 100% is used.

Input:

99.5 30
login-outage 90
buddy-timeouts 45
db-migration 60

Output:

Budget: 216.0 min
login-outage: -90 min, remaining 126.0 min (41.7% used)
buddy-timeouts: -45 min, remaining 81.0 min (62.5% used)
db-migration: -60 min, remaining 21.0 min (90.3% used)
Availability: 99.549%
Policy: CAUTION (canary releases only)

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

s13-1-data-1.txt

99.5 30
login-outage 90
buddy-timeouts 45
db-migration 60
What your program must print for s13-1-data-1.txt
Budget: 216.0 min
login-outage: -90 min, remaining 126.0 min (41.7% used)
buddy-timeouts: -45 min, remaining 81.0 min (62.5% used)
db-migration: -60 min, remaining 21.0 min (90.3% used)
Availability: 99.549%
Policy: CAUTION (canary releases only)

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < s13-1-data-1.txt

Windows PowerShell does not understand <:

Get-Content s13-1-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.