Skip to content

SLOs

A service level objective (SLO) is a target for how often a service behaves, like 99.9% of checkouts succeeding over 30 days. Its indicator (SLI) is what’s measured: the share of good requests, or the share of good periods. The error budget is what the target leaves you, here 0.1% of requests, and how fast you spend it tells you whether to slow down.

AWS has two kinds. Application Signals SLOs read CloudWatch’s classic metrics, so they work on what every AWS service already reports. CloudWatch Omni SLOs read OpenTelemetry metrics with PromQL, and live in an Omni space with the people who own them.

On CloudWatch metrics: Application Signals

Section titled “On CloudWatch metrics: Application Signals”

Count good requests against all requests. Here a Function’s invocations are the total, and its errors are the bad ones:

alchemy.run.ts
const api = yield* Api;
const lambdaMetric = (MetricName: string) => ({
Namespace: "AWS/Lambda",
MetricName,
Dimensions: [{ Name: "FunctionName", Value: api.functionName }],
});
yield* AWS.ApplicationSignals.ServiceLevelObjective("Availability", {
requestBasedSliConfig: {
RequestBasedSliMetricConfig: {
TotalRequestCountMetric: [
{ Id: "total", MetricStat: { Metric: lambdaMetric("Invocations"), Period: 60, Stat: "Sum" }, ReturnData: true },
],
MonitoredRequestCountMetric: {
BadCountMetric: [
{ Id: "bad", MetricStat: { Metric: lambdaMetric("Errors"), Period: 60, Stat: "Sum" }, ReturnData: true },
],
},
},
},
goal: { AttainmentGoal: 99.9 },
});

A period-based SLO judges each minute instead: sliConfig with one metric, a threshold, and a comparison, such as p99 Duration at or under 2000 ms.

An Omni SLO counts good events against total events with two PromQL queries over the metrics your code exports. It belongs to a space:

alchemy.run.ts
yield* AWS.CloudWatchOmni.Slo("CheckoutAvailability", {
spaceId: space.spaceId,
serviceAttributes: { serviceName: "checkout" },
sli: {
events: {
good: { language: "PROMQL", expression: 'sum(rate(checkouts_total{outcome="ok"}[$__interval]))' },
total: { language: "PROMQL", expression: "sum(rate(checkouts_total[$__interval]))" },
},
},
objective: { target: 99.9, timeWindow: { rolling: { days: 30 } } },
});

Each expression must use $__interval as its range: Omni fills it in for each window it evaluates. For a period-based SLO, sli.periods takes one query and a threshold, and timeWindow can be a calendar month instead of a rolling window.

Both kinds give a runtime a binding that reads the SLO’s budget, so a deploy pipeline or a feature flag can act on it. For an Omni SLO:

src/gate.ts
Effect.gen(function* () {
const getReport = yield* AWS.CloudWatchOmni.BatchGetOmniSloReport(CheckoutAvailability);
return {
fetch: Effect.gen(function* () {
const { reports } = yield* getReport({ burnRate: { windowMinutes: 60 } });
return HttpServerResponse.json({ consumed: reports[0]?.errorBudgetConsumedRatio });
}),
};
});

For Application Signals, the binding is AWS.ApplicationSignals.BatchGetServiceLevelObjectiveBudgetReport.