Skip to content
Telemetry
API reliability SQL recipe

Measure API availability against an SLO

Calculate daily availability and show whether a service met its explicit objective.

Intermediateapi_requestsReviewed 2026-07-27Tested with Apache DataFusion 45.2.0

Reviewed by the Telemetry product team on . We checked the SQL syntax, required event fields, sample results, and limits on using the query. Who reviews this page

Question answered

Did each service meet its daily availability objective?

An SLO sets the reliability target. Show events that met the target, total eligible events, and the target together so reviewers can check the result.

Event schema

Fields the query expects

FieldTypeWhy it exists
timestamp_utcTimestampRequest completion time.
serviceUtf8Stable service name.
slo_eligibleBooleanWhether the request belongs in the SLO denominator.
slo_goodBooleanWhether the request satisfied the SLO.
DataFusion SQL

Copy the query

sql
SELECT
  date_trunc('day', timestamp_utc) AS day,
  service,
  SUM(CASE WHEN slo_eligible THEN 1 ELSE 0 END) AS eligible_requests,
  SUM(CASE WHEN slo_eligible AND slo_good THEN 1 ELSE 0 END)
    AS good_requests,
  100.0 * SUM(CASE WHEN slo_eligible AND slo_good THEN 1 ELSE 0 END)
    / NULLIF(SUM(CASE WHEN slo_eligible THEN 1 ELSE 0 END), 0)
    AS availability_pct,
  99.9 AS objective_pct
FROM api_requests
WHERE timestamp_utc >= now() - INTERVAL '30 days'
GROUP BY date_trunc('day', timestamp_utc), service
HAVING SUM(CASE WHEN slo_eligible THEN 1 ELSE 0 END) > 0
ORDER BY day, service;

This read-only query is planned and executed against an empty typed table with Apache DataFusion 45.2.0. We review the synthetic sample output separately. Check field types, thresholds, and counting rules against your own data. Read the testing methodology.

Query result

Daily service availability

Query API missed the 99.9% objective on July 26.

dayserviceeligible_requestsgood_requestsavailability_pctobjective_pct
2026-07-25query_api182,400182,27499.9399.9
2026-07-26query_api176,820176,50199.8299.9
2026-07-27ingestion_api248,100247,97699.9599.9

Synthetic example output. Run the query against your own event schema and thresholds before using it for operational decisions.

Daily service availability: static chart of synthetic availability_pct values from the Measure API availability against an SLO example result
Download this SVG chart of the sample results for an article, runbook, or design review. Please credit Telemetry.

Reproduce the example

Download the sample data

The JSON bundle includes the event schema with field types, illustrative input rows, exact SQL, expected output, review notes, and engine version. The CSV contains the displayed result.

How the SQL works

  1. 1Explicit eligibility protects the denominator from health checks or unsupported traffic.
  2. 2slo_good can encode both correctness and latency when the objective requires both.
  3. 3The query returns the target beside the measured value so charts show whether the service met it.

Edge cases to check

  • Use complete time buckets for paging and compliance reports.
  • Document excluded traffic so the SLO cannot improve through silent denominator changes.
  • A daily view is useful for review; fast error-budget alerts usually need shorter windows.

Recommended dashboard

  • Trend: availability_pct with objective line
  • Stat: compliant days in the selected period
  • Table: bad events for missed service-days

Alert guidance

Use multi-window error-budget burn alerts for paging and this daily view for compliance review.

Read alert setup

Set up the events this query needs

Related instrumentation and guides

Continue the analysis

Run it on your events

Create a table, adapt the fields, and save the result

Start free, send structured events, and use the query result as a chart, shared dashboard widget, or alert input.

Get an API key