Bird
Raised Fist0
Rest APIprogramming~20 mins

SLA and uptime tracking in Rest API - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
SLA and Uptime Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Calculate uptime percentage from logs
Given a list of service status logs with timestamps and status ("up" or "down"), what is the output of the following code that calculates the uptime percentage?
Rest API
logs = [
    {"timestamp": "2024-06-01T00:00:00Z", "status": "up"},
    {"timestamp": "2024-06-01T01:00:00Z", "status": "down"},
    {"timestamp": "2024-06-01T02:00:00Z", "status": "up"},
    {"timestamp": "2024-06-01T03:00:00Z", "status": "up"}
]

up_count = sum(1 for log in logs if log["status"] == "up")
total = len(logs)
uptime_percentage = (up_count / total) * 100
print(f"Uptime: {uptime_percentage:.2f}%")
AUptime: 75.00%
BUptime: 25.00%
CUptime: 50.00%
DUptime: 100.00%
Attempts:
2 left
💡 Hint
Count how many logs have status 'up' and divide by total logs.
🧠 Conceptual
intermediate
1:30remaining
Understanding SLA breach conditions
Which of the following conditions correctly describes when an SLA breach occurs for a service with 99.9% uptime guarantee over a 30-day period?
AService downtime exceeds 43.2 minutes in 30 days
BService downtime exceeds 4.32 hours in 30 days
CService downtime exceeds 432 minutes in 30 days
DService downtime exceeds 0.432 minutes in 30 days
Attempts:
2 left
💡 Hint
Calculate allowed downtime as 0.1% of total minutes in 30 days.
🔧 Debug
advanced
2:00remaining
Identify the error in uptime calculation code
What error does the following code produce when calculating uptime percentage from a list of status logs?
Rest API
logs = [
    {"timestamp": "2024-06-01T00:00:00Z", "status": "up"},
    {"timestamp": "2024-06-01T01:00:00Z", "status": "down"}
]

up_count = sum(1 for log in logs if log.status == "up")
total = len(logs)
uptime_percentage = (up_count / total) * 100
print(f"Uptime: {uptime_percentage:.2f}%")
AZeroDivisionError: division by zero
BAttributeError: 'dict' object has no attribute 'status'
CSyntaxError: invalid syntax
DNo error, prints 'Uptime: 50.00%'
Attempts:
2 left
💡 Hint
Check how dictionary keys are accessed in Python.
📝 Syntax
advanced
1:30remaining
Find the syntax error in SLA JSON response
Which option contains a syntax error in this JSON response representing SLA status?
Rest API
{
  "service": "API",
  "uptime": 99.95,
  "status": "up",
  "last_downtime": null
}
A
}
llun :"emitnwod_tsal"  
,"pu" :"sutats"  
,59.99 :"emitpu"  
,"IPA" :"ecivres"  
{
B
{
  "service": "API",
  "uptime": "99.95",
  "status": "up",
  "last_downtime": null
}
C
{
  "service": "API",
  "uptime": 99.95,
  "status": "up",
  "last_downtime": null
}
D

  "service": "API",
  "uptime": 99.95,
  "status": "up",
  "last_downtime": null
}
Attempts:
2 left
💡 Hint
Check for trailing commas in JSON objects.
🚀 Application
expert
3:00remaining
Calculate monthly SLA uptime from daily logs
Given daily uptime percentages for a 30-day month, which option correctly calculates the overall monthly uptime percentage?
Rest API
daily_uptimes = [99.9, 100, 99.8, 99.7, 100, 99.9, 99.95, 100, 99.85, 99.9, 100, 99.9, 99.8, 99.7, 100, 99.9, 99.95, 100, 99.85, 99.9, 100, 99.9, 99.8, 99.7, 100, 99.9, 99.95, 100, 99.85]

# Calculate monthly uptime here
Asum(daily_uptimes) / len(daily_uptimes)
Bmin(daily_uptimes)
Cmax(daily_uptimes)
D
prod = 1
for d in daily_uptimes:
    prod *= d / 100
prod * 100
Attempts:
2 left
💡 Hint
Monthly uptime is the product of daily uptimes as fractions, not the average.

Practice

(1/5)
1. What does SLA stand for in the context of uptime tracking?
easy
A. Service Level Agreement
B. System Log Analysis
C. Server Load Average
D. Standard Latency Assessment

Solution

  1. Step 1: Understand SLA meaning

    SLA is a contract that defines expected service performance and uptime.
  2. Step 2: Match SLA to options

    Only "Service Level Agreement" correctly describes this contract.
  3. Final Answer:

    Service Level Agreement -> Option A
  4. Quick Check:

    SLA = Service Level Agreement [OK]
Hint: Remember SLA means agreement on service quality [OK]
Common Mistakes:
  • Confusing SLA with system logs
  • Thinking SLA measures latency
  • Mixing SLA with server load
2. Which HTTP method is typically used to retrieve uptime data from a REST API?
easy
A. POST
B. DELETE
C. PUT
D. GET

Solution

  1. Step 1: Identify REST API methods for data retrieval

    GET method is used to request data without changing server state.
  2. Step 2: Match method to uptime data retrieval

    Since uptime data is fetched, GET is the correct method.
  3. Final Answer:

    GET -> Option D
  4. Quick Check:

    Retrieve data with GET [OK]
Hint: Use GET to fetch data from REST APIs [OK]
Common Mistakes:
  • Using POST to fetch data
  • Confusing DELETE with retrieval
  • Using PUT for reading data
3. Given this JSON response from an uptime API:
{"uptime_percentage": 99.5, "downtime_minutes": 30}

What is the actual uptime in minutes if the total period is 1440 minutes (1 day)?
medium
A. 1440 minutes
B. 1395 minutes
C. 1410 minutes
D. 1430 minutes

Solution

  1. Step 1: Calculate uptime from total and downtime

    Uptime = Total minutes - Downtime minutes = 1440 - 30 = 1410 minutes.
  2. Step 2: Confirm with options

    1410 minutes matches 1410 minutes. The percentage is a separate metric.
  3. Final Answer:

    1410 minutes -> Option C
  4. Quick Check:

    Uptime = 1440 - 30 = 1410 [OK]
Hint: Subtract downtime from total time for uptime [OK]
Common Mistakes:
  • Using downtime as uptime
  • Ignoring total period
  • Confusing percentage with minutes
4. You have this REST API call to get uptime:
import requests
response = requests.get('https://api.example.com/uptime')
data = response.json()
uptime = data['up_time_percentage']

What is the error in this code?
medium
A. Incorrect key name 'up_time_percentage' instead of 'uptime_percentage'
B. Missing import for requests module
C. Using GET instead of POST method
D. No error, code is correct

Solution

  1. Step 1: Check JSON key names

    The API returns key 'uptime_percentage', but code uses 'up_time_percentage'.
  2. Step 2: Identify key mismatch error

    This causes a KeyError because the key name is incorrect.
  3. Final Answer:

    Incorrect key name 'up_time_percentage' instead of 'uptime_percentage' -> Option A
  4. Quick Check:

    Key name must match JSON exactly [OK]
Hint: Match JSON keys exactly to avoid errors [OK]
Common Mistakes:
  • Typos in key names
  • Using wrong HTTP method
  • Forgetting to import requests
5. You want to check if a service meets its SLA of 99.9% uptime over a month (43200 minutes). The API returns:
{"uptime_percentage": 99.85}

Which statement correctly describes the SLA status?
hard
A. Service meets SLA because uptime is above 99.8%.
B. Service fails SLA because uptime is below 99.9%.
C. Service meets SLA because downtime is less than 60 minutes.
D. Service fails SLA because uptime percentage is not provided.

Solution

  1. Step 1: Compare reported uptime to SLA target

    The SLA requires at least 99.9%, but actual uptime is 99.85%, which is less.
  2. Step 2: Determine SLA compliance

    Since 99.85% < 99.9%, the service fails the SLA.
  3. Final Answer:

    Service fails SLA because uptime is below 99.9% -> Option B
  4. Quick Check:

    Actual uptime < SLA target means failure [OK]
Hint: Compare actual uptime directly to SLA percentage [OK]
Common Mistakes:
  • Assuming close enough meets SLA
  • Ignoring SLA threshold
  • Confusing downtime with uptime
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard