msstc4symfony / slo-bundle
Declarative SLI/SLO for Symfony: discovery, coverage gate, good/bad counters, Prometheus rules and Grafana dashboards
Package info
github.com/msstc4symfony/slo-bundle
Type:symfony-bundle
pkg:composer/msstc4symfony/slo-bundle
Requires
- php: >=8.2
- composer-runtime-api: >=2.2
- msstc4symfony/metrics-bundle: ^2.3
- psr/log: ^2.0|^3.0
- symfony/config: ^7.4|^8.0
- symfony/console: ^7.4|^8.0
- symfony/dependency-injection: ^7.4|^8.0
- symfony/http-kernel: ^7.4|^8.0
- symfony/monolog-bundle: ^3.11|^4.0
- symfony/routing: ^7.4|^8.0
- symfony/yaml: ^7.4|^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.76
- justinrainbow/json-schema: ^6.6
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.1
- phpstan/phpstan-strict-rules: ^2.0
- phpstan/phpstan-symfony: ^2.0
- phpunit/phpunit: >=11.0
- rector/rector: ^2.1
- roave/security-advisories: dev-latest
- symfony/framework-bundle: ^7.4|^8.0
Suggests
- msstc4symfony/logic-bundle: To declare SLOs on logic-bundle Actions (with msstc4symfony/slo-bridge-logic)
- msstc4symfony/slo-bridge-logic: To discover and measure msstc4symfony/logic-bundle Actions as SLO points
- msstc4symfony/slo-bridge-profiling: To open a msstc4symfony/profiling-bundle span around every SLO operation
- symfony/messenger: To declare SLOs on Messenger messages
- symfony/scheduler: To declare SLOs on Symfony Scheduler tasks (#[AsCronTask], #[AsPeriodicTask])
Provides
None
Conflicts
Replaces
None
This package is auto-updated.
Last update: 2026-12-04 07:01:21 UTC
README
Declarative SLI/SLO for Symfony: discovery, coverage gate, good/bad counters, Prometheus rules and Grafana dashboards
Built on msstc4symfony/metrics-bundle 2.3: good and bad events
are counted as symfony_slo_events_total through its storage and exported on its metrics endpoint.
- Compatibility
- Installation
- Declaring SLOs
- What is measured
- Classification of events
- Strategies: existing series or dedicated counters
- Revisions and warming up
- Operations API
- Configuration reference
- Commands
- Generation and GitOps provisioning
- Failure semantics: fail-open and Redis outages
- Bridges and measurement points
- Public API
- Upgrade notes
- Layers
- Local development
- Running the rule tests
- Overhead
Compatibility
| Component | Supported |
|---|---|
| PHP | 8.2 - 8.5 (php82 profile of bundle-standard); 8.2 gets security fixes until 2026-12-31 UTC |
| Symfony | ^7.4 | ^8.0; Symfony 8.x needs PHP 8.4, on 8.2 and 8.3 Composer installs 7.4 |
| metrics-bundle | ^2.3 (2.3.0 is the minimum: HTTP 5xx are invisible to the universal series before it) |
| Prometheus | 3.x, rule files tested with promtool of 3.15; the rule format has not changed since 2.x |
| Alertmanager | any version that accepts Prometheus 3 alerting rules; optional routing and a full config are generated since 1.1 (generation.alertmanager), checked with amtool v0.34.0 |
| Grafana | 12.x - 13.x, classic dashboard JSON (schemaVersion 41) with file provisioning |
| RoadRunner | through baldinof/roadrunner-bundle ^3.4; services are reset on kernel.reset, see state isolation |
| Sloth | optional generator, spec prometheus/v1, validated with Sloth 0.16 |
Installation
composer require msstc4symfony/slo-bundle
Symfony Flex registers the bundle automatically; without Flex add it to config/bundles.php after MetricsBundle
(the container fails to compile with a hint when MetricsBundle is missing):
Msstc4Symfony\SloBundle\SloBundle::class => ['all' => true],
Minimal configuration for generation (the application name is never read from the runtime environment, so the output is the same on a laptop and in CI):
# config/packages/msstc4symfony_slo.yaml msstc4symfony_slo: generation: selector: application: shop # the "application" label of your metrics components: [web, worker] # optional, default: every component
Declaring SLOs
#[Slo] goes on a controller method, an invokable controller class or its __invoke, a Messenger handler class or
method, a Symfony Scheduler task (the class or method carrying #[AsCronTask] / #[AsPeriodicTask], or a scheduled
console command class), or a class of any service tagged as a measurement point.
The attribute is repeatable: different names are independent SLOs on the same point.
use Msstc4Symfony\SloBundle\Application\Attribute\Availability; use Msstc4Symfony\SloBundle\Application\Attribute\IgnoreMonitoring; use Msstc4Symfony\SloBundle\Application\Attribute\Latency; use Msstc4Symfony\SloBundle\Application\Attribute\Slo; #[Route('/payments', methods: ['POST'])] #[Slo( name: 'payment.create', objectives: [ new Availability(target: 99.95), new Latency(threshold: '200ms', target: 99.0), ], window: '30d', )] public function create(): Response { /* ... */ } #[IgnoreMonitoring(reason: 'Internal debug endpoint')] public function debug(): Response { /* ... */ }
| Attribute / argument | Meaning |
|---|---|
Availability(target) |
share of eligible events that are not bad, 0 < target < 100, up to 4 decimals |
Latency(threshold, target, includeErrors: false) |
share of eligible events not slower than threshold (<int>ms or <decimal>s, stored as whole milliseconds, 1ms to 999999999ms); includeErrors is HTTP only |
Combined(threshold, target) |
good = not bad and not slower than threshold; eligible like availability |
name |
unique per application, ^[a-z][a-z0-9_.-]{0,62}$; becomes the slo label |
window |
<N>h, <N>d, <N>w, <N>mo (month = 30 days; m is minutes and rejected), 1h - 90d, default defaults.window |
badStatuses, ineligibleStatuses |
HTTP only: codes, ranges (500-503) or classes (5xx) |
expectedFailureIsGood |
logic actions, operations and scheduled tasks only |
deadline |
scheduled tasks only: how long a run may take before it counts as unfinished, <int>ms, <decimal>s, <int>m or <int>h (1ms to 999999999ms); required when the SLO has neither a latency nor a combined objective, otherwise the threshold is the deadline |
countAttempts |
Messenger only |
strategy |
StrategyPreference::Auto (default) or StrategyPreference::Dedicated (Domain\Enum\StrategyPreference) to force dedicated counters |
IgnoreMonitoring(reason) |
excludes the point from the coverage gate; the reason is mandatory |
The same name on several points with identical declarations is one SLO over all of them (slo:list marks it
shared by N points). The same name with different declarations, or twice on one point, does not break the build:
the catalog keeps every declaration as a conflict, nothing is recorded for that name (one warning per process),
slo:list marks it DUPLICATE, slo:validate exits 1 and lists the differing fields, and coverage marks the points
invalid. Every other error (bad window, target out of range, #[Slo] on two handlers of one message, an option that
does not apply to the point type) is a container compilation error listing all problems at once.
What is measured
Events come from the metrics-bundle measurement observers, with the duration metrics-bundle measured (no second timer):
- HTTP: one event per recorded main request of a route whose controller has
#[Slo]. Unrouted requests,OPTIONS,http.ignored_routes, sub-requests and fragments are not events; the page that renders a fragment is one event. An uncaught exception is classified by the resulting status (500 by default), once. - Messenger: one event per final worker outcome of an envelope (
handled, orfailedafter the last retry); retries are events only withcountAttempts: true, anything consumed from a failure transport (messenger:failed:retry) never is. Batch handlers (BatchHandlerInterface) are counted per envelope like any async message. Synchronously handled messages are not measured (slo:coveragereports them asunsupported,slo:validatewarns about an SLO on a message that is not consumed by a worker: routed nowhere or only tosync://). A handler counts as worker-consumed when it is bound withfromTransportto a worker transport (notsync://, not a failure transport), when its message is routed to a transport other thansync://, or when the app does not route its message but has a receive-only transport (notsync://, not a failure transport, not a Schedulerschedule://transport, targeted by no routing entry or#[AsMessage]of a handled message): a consumer service whose producer owns the routing. Unrouted framework messages (Symfony\*) stay synchronous. Discovery cannot see two cases: a transport the app both sends its own messages to and consumes other services' messages from (it is a routing target, so a consumed unrouted message still looks synchronous), and a producer that targets a transport only through#[AsMessage]on messages it does not handle or aTransportNamesStamp(the transport looks receive-only, so the app's unrouted handlers look worker-consumed). For both, bind the handler with#[AsMessageHandler(fromTransport: '<transport>')]or add an explicitroutingentry. Hand-built schedules (RecurringMessagein a schedule provider) are not detected either: the schedule is built at runtime, so such a message is not recognised as worker-consumed through itsscheduler_<name>transport, which a separatemessenger:consume scheduler_<name>worker reads; its classification falls back to the routing and receive-only rules above. Bind its handler with#[AsMessageHandler(fromTransport: 'scheduler_<name>')]. Tasks declared with#[AsCronTask]/#[AsPeriodicTask]are supported directly, see the next bullet.#[Slo]on a handler is an SLO on the envelope of its message; a message with several handlers gets a validation warning. The handler must take a concrete message class: events are matched by the dispatched message's class, so#[Slo]on a handler of an interface or abstract class is a compilation error. - Operations: one event per finished handle, see Operations API.
- Scheduled tasks: Scheduler tasks declared with
#[AsCronTask]/#[AsPeriodicTask](thescheduler.tasktag), as the point<service id>::<method>(method from the attribute, default__invoke) orcommand:<command name>for console commands (symfony/schedulerandsymfony/messengerinstalled). A run starts when a bus hands the task message to its handlers: the bundle puts its middleware right beforehandle_messageof every bus, so a message that a worker listener refuses (WorkerMessageReceivedEvent::shouldHandle(false)) or another middleware skips is no run. One event per final run, wherever it runs: on a worker (a retried attempt is not an event), and inline — async://transport, a task withtransports: 'sync'(it runs inside theRedispatchMessagehandler), a dispatch the application does not route; an inline failure still reaches the caller. A replay from a failure transport (messenger:failed:retry) is no run at all: no event and no run metrics. The consuming transport is not filtered: aServiceCallMessage/RunCommandMessagethe application dispatches itself counts under the same point. A failing command task is always an error (RunCommandMessageHandlerwraps whatever the command threw); for a service task the handler's exception is classified like an operation's. The duration comes from the bundle's ownhrtimetimer around the run, so it can differ from the Messenger histogram by the middleware overhead. Runs that never finish are counted through the run metrics, see Generation. A run longer than its deadline plus one minute is no event of its own (per SLO, when the SLOs of a point have different deadlines): the rules already counted it, as unfinished. Aliases and abbreviations of a command name are not matched: use the name the task is dispatched with. Limits:- a bus whose default middleware is disabled has no
handle_messagein its list: its tasks are not measured, also on a worker (the container compilation log names the bus); - a Scheduler transport replaced by one with a retry strategy or a failure transport: retries of a
RedispatchMessageto a sync transport each count as a final run, and its replay as a run.
- a bus whose default middleware is disabled has no
- Console commands run outside Messenger (system cron, Kubernetes CronJob, CI, deploy hooks).
- What becomes a point: a console command registered in the container whose class declares
#[Slo](or#[IgnoreMonitoring]) is the scheduled-task pointcommand:<command name>. It is the same point as when Scheduler runs the command, so one#[Slo]covers both paths. - Coverage is opt-in: commands without either attribute are no points.
- On Symfony 8.1+ a class-level
#[Slo]applies to every command a class defines on its methods. - What is measured: a run when the command is the top-level command of a
bin/consoleprocess (CLI SAPI), standard input is not a terminal and no Messenger task run is in progress in the process.- A run from an interactive shell or
docker exec -itis not measured;-ndoes not change that. - A run with stdin redirected or piped (
< file,echo y |) counts as unattended and is measured, includingApplicationTesterruns in a test suite whose kernel has the bundle enabled. - A command run by a synchronous
RunCommandMessage(in an app server with the CLI SAPI such as RoadRunner or Swoole, a job runtime, an inline dispatch) is left to the Messenger path, so it counts once. - A command nested in another command is not measured here. Inside
messenger:consume, the Messenger path above measures it once.
- A run from an interactive shell or
- Outcome: the final exit code after every other listener. 0 is good; anything else, including an uncaught exception, is an error event; there are no expected failures.
- The duration comes from the bundle's own timer, and the run metrics and unfinished runs work as for Scheduler tasks. A process killed by SIGKILL or OOM counts as unfinished after its deadline.
- Limits:
- the command name must be the one Symfony registers the command under: a name changed with
setName()at runtime is not in the catalog and is silently not measured; - a command added to the
Applicationby hand, or run through$command->run()(no console events), is not measured;
- the command name must be the one Symfony registers the command under: a name changed with
- Short CLI processes need a metrics storage shared across processes (Redis): with an in-memory storage their counters die with the process.
- What becomes a point: a console command registered in the container whose class declares
- Logic actions: through the
slo-bridge-logicpackage, see Bridges.
Classification of events
Defaults, all overridable per SLO. An eligible event enters the denominator; bad events lower the ratio.
| Point | Eligible event | Availability: bad | Latency: eligible |
|---|---|---|---|
| HTTP route | finished main request of the route | status >= 500 (includes uncaught exceptions); 4xx are good, they are client errors |
only availability-good events |
| Messenger message | final outcome of the envelope on its source transport: handled or failed without retry; retried and every event on a failure transport are not eligible |
failed |
only handled |
| Logic action | action call | error; expected_failure is good |
success and expected_failure |
| Operation | finished handle | error |
everything except error |
| Scheduled task | final run outcome on a worker or inline, or exit code of a top-level non-interactive console run; retried and failure-transport runs are not eligible | error, expected_failure when expectedFailureIsGood is false, unfinished runs |
success and expected_failure, plus unfinished runs |
- HTTP and Messenger: latency is eligible only for availability-good events, unless
Latency(includeErrors: true)(then every availability-eligible event;includeErrorsapplies to HTTP routes only, elsewhere it is a compilation error). Logic actions and operations: latency covers every run that is not anerror, also withexpectedFailureIsGood: false(which changes availability andCombinedonly).Combinedis bad when the event is bad or slow. countAttempts: true(Messenger): every attempt is an event - handled is good, failed and retried are bad; failure-transport events stay ineligible.- Unfinished runs (a scheduled task started and not finished within its deadline) are bad events of every objective of
the task SLO, also of latency and
Combined: they enter both the bad and the total events. Near the deadline a run can be counted twice (its own event and unfinished), never lost, see Generation. - Failure transports are detected at compile time from the framework's failure-transport listener and can be set with
defaults.messenger.failure_transports. - Status sets are canonical:
['5xx', '500-599']is the same set as['5xx']. - Empty denominator is NoData, never 100 %.
Strategies: existing series or dedicated counters
For each objective the bundle either reads series metrics-bundle already exports (Strategy A, nothing extra is
written) or counts good and bad events itself (Strategy B, symfony_slo_events_total). The choice is visible in
slo:list and slo:validate.
| Point / objective | Strategy A when | otherwise B |
|---|---|---|
| HTTP availability | classification is the default or expressible through the status label |
observer |
| HTTP latency | includeErrors: true, and the threshold equals a bucket of request_duration_histogram_seconds |
observer |
| Messenger availability | countAttempts not set (handled + failed, failure transports excluded) and no other handled message shares the short class name (metrics-bundle labels messages by short name; slo:validate warns) |
observer |
| Messenger latency | countAttempts not set (countAttempts: false), the threshold is a bucket boundary, and no other handled message shares the short class name (slo:validate warns) |
observer |
| Logic action | the point has a metric_label no other point shares; availability: expectedFailureIsGood is default; latency: the threshold is a bucket of logic_action_duration_histogram_seconds |
slo-bridge-logic |
Operation, Combined |
never | always B |
| Scheduled task | never | always B (Auto resolves to dedicated, Dedicated is accepted) |
strategy: StrategyPreference::Dedicated forces B. A threshold matches a bucket when the bucket, as metrics-bundle exposes it, equals
thresholdMs / 1000 up to float noise (relative 1e-9): 0.25 matches 250ms, 0.2504 does not. The generated
le matcher uses the form Prometheus 3 stores on ingestion (Go's shortest float with .0 for integral values):
a bucket exposed as le="1" is selected as le="1.0", 1e6 as le="1e+06".
Revisions and warming up
Every dedicated series carries revision, the first 8 hex digits of a hash of the event semantics: objective kind,
eligibility and good rule, threshold, point type, classification overrides, and for Messenger SLOs the sorted list of
failure transports (it decides which deliveries are eligible). expectedFailureIsGood is not part of the latency
revision of logic actions and operations, whose latency does not depend on it. Target, window, name, the list of
points and the deadline of a scheduled task are not part of it (it changes what is read from the counters, not
what is written). Consequences:
- Changing a threshold from
200msto100mscreates a new revision. Generated rules filter only the current revision, so old and new data are never summed;slo:window:coverage_ratiostays below 1 until the new revision has covered the whole window. - While the coverage ratio is below 1 the SLO is warming up: dashboards show it together with the expected end
(
Warming up until, a UTC date computed astime() + (1 - coverage) * window), ticket alerts on the long windows are suppressed, page alerts on short windows stay active. - Prometheus retention must be at least the longest SLO window plus 1h. The coverage ratio looks one window back; with a shorter retention it never reaches 1, the SLO stays warming up forever and the ticket alerts never fire.
- Changing the target or the window is recomputed by the rules instantly from the same data.
- Changing the canonical form of the hash itself would change every revision; it is pinned by a test.
Operations API
Measure arbitrary operations that are not routes, handlers or actions. Declare them in the configuration (they are
always dedicated) and inject OperationMonitorInterface:
msstc4symfony_slo: operations: payment.validation: objectives: - { type: availability, target: 99.9 } - { type: latency, threshold: 50ms, target: 99 } window: 30d
$result = $monitor->measure('payment.validation', fn (): Result => $this->validator->validate($payment)); $handle = $monitor->start('payment.validation'); try { $this->validator->validate($payment); $handle->succeed(); } catch (ExpectedProblem $e) { $handle->failExpected($e); // good for availability when expectedFailureIsGood is true } catch (Throwable $e) { $handle->fail($e); } finally { $handle->end(); // idempotent; the first outcome wins, no outcome means success }
measure() rethrows the exception of the closure unchanged and classifies it as logic-bundle classifies its Actions
when logic-bundle is installed (ActionOutcome::of(): ExpectedFailureInterface and Symfony's
ValidationFailedException are expected failures); without logic-bundle every exception is an error. An undeclared or invalid
name records nothing and logs one warning per name until the next kernel.reset. The clock is hrtime(true), no sampling.
Configuration reference
msstc4symfony_slo: defaults: window: 30d # default window of every SLO http: bad_statuses: ['5xx'] ineligible_statuses: [] logic: expected_failure_is_good: true messenger: count_attempts: false failure_transports: null # null = detect at compile time, or a list of transport names coverage: http_routes: { required_percent: 95, ignored_routes: [] } messenger_handlers: { required_percent: 95 } logic_actions: { required_percent: 0 } scheduled_tasks: { required_percent: 0 } operations: {} # see "Operations API" generation: selector: application: ~ # required by slo:generate; [A-Za-z0-9_.:-]{1,128} components: [] # [] = no component filter; same pattern output_dir: '%kernel.project_dir%/infrastructure/observability' grafana: { datasource_uid: prometheus, folder: SLO } prometheus: rules: true alerts: true no_events_alert_hours: ~ # opt-in "no events for N hours" alert scrape_interval_seconds: 60 # slo:validate rejects a task deadline below it sloth: false alertmanager: enabled: false # opt-in routing + full config, see "Alertmanager" receivers: { page: slo-page, ticket: slo-ticket } # [A-Za-z0-9_.:-]{1,128}
Commands
| Command | Purpose | Exit codes |
|---|---|---|
slo:list [--format=text|json] |
declared SLOs with points, routes, strategy and revisions; shared and DUPLICATE names are marked |
0 ok, 1 the JSON cannot be encoded, 2 bad option |
slo:validate |
validates the catalog against the routes; prints ERROR, WARNING and NOTICE lines |
0 no errors (warnings allowed), 1 errors |
slo:coverage [--format=text|json] [--min=<0-100>] |
which routes, handlers, actions, operations and scheduled tasks have an SLO and which are already measured by a universal series; statuses monitored, unmonitored, ignored, invalid, unsupported |
0 passed, 1 any invalid point, a kind below its required percent (compared on the exact fraction in basis points, the requirement taken to 0.01: 2 of 3 is below 66.67, 7 of 10000 meets 0.07; --min overrides all kinds, scheduled tasks included) or the JSON cannot be encoded, 2 bad option |
slo:generate [--output=<dir>] [--check] [--page-receiver=<name>] [--ticket-receiver=<name>] |
writes Prometheus rules, Grafana dashboards, optional Sloth specs and optional Alertmanager files (generation.alertmanager.enabled); the receiver options override generation.alertmanager.receivers and are an error (exit 2) while Alertmanager generation is off; --check compares with the disk without writing and prints stale, missing, extra paths |
0 ok / up to date, 1 --check found differences, 2 missing generation.selector.application or output directory, a receiver option without generation.alertmanager.enabled, an invalid or empty receiver name, generation.alertmanager.enabled with generation.prometheus.alerts: false |
slo:coverage --format=json is stable and described by the JSON Schema doc/coverage-schema.json.
A CI gate is bin/console slo:validate && bin/console slo:coverage --min=95 && bin/console slo:generate --check.
Generation and GitOps provisioning
slo:generate is deterministic: sorted keys, stable UIDs and ids, no timestamps, a trailing newline, and it never
reads the runtime environment (only the explicit generation.selector). It manages only its own files in
output_dir, so other files next to them are safe:
<output_dir>/
prometheus/slo-recording.rules.yml
prometheus/slo-alerts.rules.yml
grafana/dashboards/slo-*.json # application overview, HTTP routes, Messenger, business
# operations, scheduled tasks, SLO overview, monitoring coverage
grafana/provisioning/dashboards/slo.yaml # file provider; options.path is /var/lib/grafana/dashboards
sloth/slo-<name>.yml # only with generation.sloth: true
alertmanager/slo-alertmanager.yml # only with generation.alertmanager.enabled: true
alertmanager/slo-alertmanager-routes.yml # same: routes + inhibit_rules fragment
Commit the directory, run slo:generate --check in CI ("rules are stale" fails the build), mount
prometheus/ into rule_files and grafana/dashboards plus the provisioning file into Grafana.
-
Recording rules per SLO and objective:
slo:events:rate<5m|30m|1h|6h|3d>,slo:error_ratio:rate<w>,slo:objective:target,slo:sli:ratio,slo:error_budget:remaining,slo:window:coverage_ratio, and for scheduled tasks, once per SLO (labelsapplication,slo,window, noobjective),slo:unfinished_runs:step(runs that passed their deadline without finishing in the last 1m evaluation) andslo:unfinished_runs:increase<w>(the step record summed over each rate window and over the SLO window). Every series is scoped byapplication(and bycomponentwhen configured). -
Scheduled tasks write per-task run metrics for every attempt of a task that has an SLO (retries included, on a worker or inline; not for replays from a failure transport):
Metric Labels symfony_slo_scheduled_task_started_totaltasksymfony_slo_scheduled_task_finished_totaltask,outcome(success,error,expected_failure,retried)symfony_slo_scheduled_task_duration_secondstask,outcome; buckets 0.005 ... 3600 s (the Messenger buckets plus 300, 600, 1800, 3600)taskis the point id. A run that never finishes (the worker was killed, the handler hangs) writesstartedand nofinished, so these series are the only way to see it. Unfinished runs of task SLOs are computed from them: the recordslo:unfinished_runs:stepcounts, once per minute and per series, the runs started in[t - d - 1m, t - d]minus the runs finished in[t - d - 1m, t](dis the run deadline; instant counter values, clamped at 0, the labeloutcomeignored), andslo:unfinished_runs:increase<w>sums it withsum_over_timefor every objective of the SLO. They are bad events and part of the total, so a task that always dies reads 100 % bad, not NoData; the coverage gate and theSloNoEventsalert of a task SLO also treat the started series as data. A run that finishes more than one scrape interval before its deadline is never counted as unfinished. What the formula misses, never inventing a run instead: a step in which a series is missing (outage, failed scrape, pod replacement) or its counters reset (Redis flush), or in which the rule evaluation was skipped; the very first run of a new series; and a hung run hidden by the finish of another run of the same task withind + 1m(a frequent task with a long deadline). Sloth specs cannot rely on the bundle's records, so they use the same per-series form over their own window, and long Sloth windows need series that live for the deadline plus the window; runs that finish late count only partially there, see below. -
Runs near the deadline: a run counts at most once outside the band of about
(d - scrape interval, d + 1m]of duration, where1mis the step ofslo:unfinished_runs:step. A shorter run is its own event only; a longer one was certainly seen by the step record, so the bundle writes no SLO event for it and it counts once, as unfinished. A run inside the band keeps its own event and may also be counted unfinished: twice, towards bad, never lost by the boundary in the bundle's own rules (only the misses listed above can lose it) as long as the deadline is a multiple of the scrape interval. Otherwise the start and finish samples, aligned to the scrape grid, can be closer than the run lasted: with a 60 s scrape and a 90 s deadline a run of about 151 s can be lost, so prefer deadlines that are multiples of the scrape interval. With the 1m step and Prometheus' default 60 s scrape interval the band is about two minutes wide, fromd - 60stod + 60s. With the default deadline (the latency threshold) a moderately slow run therefore weighs double on the latency objective; an explicitdeadlineabove the latency threshold (for example threshold plus 2m) gives slow runs a single latency-bad event of their own and leaves the unfinished count to runs that really hang. -
Sloth specs count late runs only partially: they have no step record, and their per-series form sees a run as unfinished only while it is still running. A run of duration
Dlonger thand + 1mloses its own event, so in a Sloth windowWit weighs about(D - d) / Winstead of one bad event. "Never lost" holds for the bundle's own rules only; prefer them for scheduled-task SLOs. -
A retried attempt that runs past its deadline is counted unfinished (the run metrics cover every attempt), and the final attempt then records its own event: two events for one logical run.
-
A replay from a failure transport writes no run metrics, so a replay that hangs is not counted unfinished; the Scheduled Tasks dashboard does not show replays (the metrics-bundle Messenger series of the failure transport do).
-
Long deadlines and pod replacement: the record needs each series alive for
d + 1m, Sloth's per-series form ford +its window; a series that disappears earlier (a pod replaced, a newinstancelabel) loses the detection of its runs. With storage shared by several pods (Redis), scrape a single target for the task series or dropinstance/podfrom them with relabelling, so a replacement does not start new series. -
Not a goal: "the task stopped running". A task that is never scheduled writes nothing, so it is neither bad nor unfinished; alert on it separately, for example
sum(increase(symfony_slo_scheduled_task_started_total{task="command:app:sync-partners"}[2h])) == 0. -
Alerts are multi-window multi-burn-rate (Google SRE workbook) named
SloErrorBudgetBurn: page - 2 % of the budget in 1h (long) / 5m (short) and 5 % in 6h / 30m; ticket - 10 % in 3d / 6h. The factors scale with the window (share * window / long window: 14.4, 6 and 1 for 30d). A pair whose long window exceeds the SLO window is omitted, as is a pair that can never fire (factor * (1 - target) >= 1;slo:validatewarns). An empty denominator never fires.no_events_alert_hoursadds the opt-inSloNoEventsalert. -
Sloth has no per-SLO window: with different windows
slo:generatewarns that one--default-slo-periodcannot match several of them, so SLOs whose window differs from the chosen period get wrong burn-rate thresholds. -
The Monitoring Coverage dashboard is a static table rendered at generation time; it is refreshed only by
slo:generate.
Failure semantics: fail-open and Redis outages
- Nothing thrown by SLO code (classification, catalog lookup, writing) reaches application code: it is logged on the
Monolog channel
slo_bundleas a warning and swallowed. Exceptions thrown by user code insidemeasure()are rethrown unchanged. Pinned bytests/Integration/Hardening/FailOpenTest.phpfor HTTP, Messenger andmeasure(). - Each event is one
incrementper objective on one counter withresult="good|bad", so good can never exceed the total. When the storage (Redis) is down, a lost write loses the whole event, not the ratio: the SLI is computed from the events that were written, and a long outage shows up as missing data, not as a skewed percentage. - Under long-running workers (RoadRunner, Messenger workers) every stateful service is reset through
kernel.reset: the per-process warning sets and every failed resolution. Successful resolutions (strategy and revision of an objective) and a successfully built route index survive the reset: catalog and routes are fixed per container. Two requests with different routes and outcomes are attributed to their own SLO (StateLeakageTest). A router that fails while the route index is built disables HTTP SLOs (one warning) until the nextkernel.resetretries it. - A storage outage logs one warning per SLO, objective and exception class until the next reset (at most 100, then one suppression notice), not one per event.
- A compiled catalog that cannot be read (a cache left over from another bundle version) never throws on the request
path: its SLOs record nothing and one warning asks to clear the cache; the
slo:*commands fail with that message. - Cardinality is bounded: labels are
slo(declared name),objective,revisionandresultonly. No path, query string, user or request value ever becomes a label (CardinalityTest: 1000 random URLs, at most tworesultvalues per objective).
Bridges and measurement points
Any service tagged msstc4symfony_slo.point becomes a measurement point of the catalog; the bundle reflects its class
for #[Slo] and #[IgnoreMonitoring]. Tag attributes: type (a PointType value), id (non-empty, without %,
unique across services), optional metric_label (the label value of the existing series; valid UTF-8 without control
characters, {{ or }}; one value per point). Points of one type that share a metric_label cannot be told apart in
that series: the label is dropped for all of them, their SLOs use dedicated counters and slo:validate warns.
slo-bundle never depends on logic-bundle: the slo-bridge-logic package tags msstc4symfony_logic.action services and
records their events through Application\Port\EventRecorderInterface (inject it, call
record(new RecordEvent\Input($point, $observation))). record() never throws, but building its argument does:
Observation::http() / outcome() and Input reject invalid values (InvalidArgumentException), so a bridge builds the
Input inside its own try to stay fail-open.
A bridge that adds the tag from its own compiler pass must register that pass with PassConfig::TYPE_BEFORE_OPTIMIZATION
and a priority of 10 or higher: discovery runs at priority -10 (after autoconfiguration at 100). The tag has to exist
by then. Discovery also reads the metric enums of
metrics-bundle, so an enum appended at priority 0 by a bundle registered after slo-bundle (such as the logic-action
histogram of metrics-bridge-logic) is seen in any bundle order. PointTag::TAG is the constant for the tag name.
A bridge that decorates OperationMonitorInterface (slo-bridge-profiling) injects
Application\Port\ExpectedFailureClassifierInterface to classify an exception exactly like measure() does, without
depending on logic-bundle.
Public API
Covered by semantic versioning; everything else is marked @internal and may change in any release. That includes the
few public methods of the types below that carry @internal (helpers of discovery and of the compiled catalog, such as
Classification::appliesTo(), SloDefinition::withWindow() or LatencyThreshold::fromMilliseconds()).
| Part | Contents |
|---|---|
| Attributes | Application\Attribute\* (Slo, Availability, Latency, Combined, IgnoreMonitoring, ObjectiveAttributeInterface) |
| Operations | Application\Port\OperationMonitorInterface, Application\Port\OperationHandleInterface, Application\Port\ExpectedFailureClassifierInterface |
| Bridges | Application\Discovery\PointTag, Application\Port\EventRecorderInterface (a public service, inject it), Application\Evaluation\RecordEvent\Input |
| Catalog | Domain\Repository\SloCatalogInterface, Domain\Entity\SloDefinition |
| Value objects | Domain\ValueObject\SloName, PointId, Objective, Target, LatencyThreshold, Window, Classification, StatusSet, Observation, Deadline |
| Enums | Domain\Enum\PointType, ObjectiveKind, StrategyPreference, DeliveryStatus, Outcome |
| Console | the commands slo:list, slo:validate, slo:coverage, slo:generate, their options, exit codes and the JSON of slo:coverage |
| Configuration | the msstc4symfony_slo configuration keys, the metrics symfony_slo_events_total, symfony_slo_scheduled_task_started_total, symfony_slo_scheduled_task_finished_total and symfony_slo_scheduled_task_duration_seconds with their labels, the generated recording rule and alert names |
| Bundle | SloBundle |
Upgrade notes
1.0 is the first release; there is nothing to migrate. Notes for the next ones:
- 1.2 adds the case
PointType::ScheduledTask: an exhaustivematchoverPointTypein your code needs an arm for it.Observation::outcome()gained a fourth argument$onFailureTransport(defaultfalse). - 1.2 changes the compiled catalog format to 4 (
deadline_ms,scheduled_tasks): clear the cache on upgrade. - 1.2 changes the generated output: the Scheduled Tasks dashboard is new and the Monitoring Coverage dashboard gains a
scheduled_taskrow, soslo:generate --checkreports drift until you regenerate.slo:coverage --minnow applies to scheduled tasks too, so an application with unmonitored Scheduler tasks fails a--mingate until they get an SLO or#[IgnoreMonitoring]. - 1.3 records the unfinished runs of a task SLO once per SLO:
slo:unfinished_runs:stephas noobjectiveandrevisionlabels any more, andslo:unfinished_runs:increase<w>is new. Queries of your own on the step record byobjectiveneed changing; regenerate the rules. Hung runs from before the upgrade are not counted in the windows. - 1.4 measures scheduled tasks handled inline (
transports: 'sync',sync://, unrouted dispatches): their SLOs get events where they had none, and their run metrics appear. Replays from a failure transport no longer write run metrics. The bundle adds two middlewares to every bus (first, and right beforehandle_message); a bus withouthandle_message(default middleware disabled) no longer measures scheduled tasks, also on a worker. - 1.5 measures console commands run outside Messenger.
- A command whose class has
#[Slo], including a Scheduler command task, now also gets events from cron, CronJob or CI runs without a terminal. - Commands that newly declare
#[Slo]becomescheduled_taskpoints, so regenerate the rules (slo:generate --checkreports drift for new points).
- A command whose class has
- metrics-bundle 2.3.0 is the minimum; with an older metrics-bundle the container does not compile.
- A change of event semantics (threshold, classification, point type) changes the
revision; the SLI of the new revision warms up for one window while the generated rules ignore the old one. Regenerate and commit the rules (slo:generate) together with such a change. - The label order of
symfony_slo_events_totalisapplication, component, slo, objective, revision, result. - Retired revisions are not removed: their series stay in the metrics-bundle storage and in its export until the
storage is cleared, so every revision ever deployed adds its
good/badseries per objective. The generated rules and dashboards read the current revision only, so the old series cost cardinality, not correctness.
Cleaning series of old revisions
With the default Redis storage (promphp/prometheus_client_php) the counter is one Redis hash,
PROMETHEUS_:counter:symfony_slo_events_total with the default key prefix, with one field per label set (the field
name is the JSON list of label values, so the revision is inside it). Redis sets no TTL on it: the fields of retired
revisions live until they are removed.
-
bin/console metrics:clearwipes the whole metrics-bundle storage. Every counter restarts from zero, which Prometheusrate()/increase()treat as a counter reset; nothing is lost but the samples of the scrape interval around the wipe. Run it after a deploy that changed revisions, when the cardinality matters. -
To drop only the old revisions, delete their fields from the hash, e.g. for revision
abcdef12:redis-cli -n 4 --scan --pattern 'PROMETHEUS_:counter:symfony_slo_events_total' | while read -r key; do redis-cli -n 4 hkeys "$key" | grep '"abcdef12"' | while read -r field; do redis-cli -n 4 hdel "$key" "$field"; done done
The key layout belongs to promphp, not to this bundle, and may change with it; prefer
metrics:clearwhen in doubt.
Layers
src/ follows the canonical layout of bundle-standard
(templates/deptrac.yaml). The list is closed - verify-standard rejects any other directory:
Domain/- data inEntity/,Document/,ValueObject/,Enum/,Event/,Repository/,DocumentRepository/; operations inService/,Helper/,Specification/;Application/,Infrastructure/,Presentation/,Framework/;DependencyInjection/(compiler passes inCompilerPass/);Resources/(configuration only, no classes) and the bundle classSloBundle.php.
Local development
Development uses the CI profile composer-ci.json (CI-only tools and optional libraries). A git-ignored
composer-local.json with path repositories for ../metrics-bundle and ../sql-labeller works the same way.
COMPOSER=composer-ci.json composer install COMPOSER=composer-ci.json make check # lint, PHPStan, CS, composer validate/audit, Rector, deptrac make test # unit + integration make infection # mutation testing of src/ with the unit suite make benchmark # per-event overhead, see "Overhead"
Alertmanager
Off by default; with generation.alertmanager.enabled: false the output is byte-identical to 1.0.1.
msstc4symfony_slo: generation: alertmanager: enabled: true receivers: { page: slo-page, ticket: slo-ticket } # these are the defaults
slo:generate then writes two files (files named slo-alertmanager*.yml in alertmanager/ belong to the bundle; your
own alertmanager/alertmanager.yml is never touched, and disabling the setting deletes only the owned files):
alertmanager/slo-alertmanager.yml- a complete config for trying things out or a dedicated Alertmanager: root receiverslo-unrouted, the receiversslo-page/slo-ticket, the routes and the inhibit rule. Receivers have no integrations: Slack, Jira, Telegram and the rest are your choice.alertmanager/slo-alertmanager-routes.yml- a fragment with the top-level keysinhibit_rulesandroutes. Paste it into your own config:routesunderroute.routes,inhibit_rulesat the top level, and declare the receivers it names. Paste it once perapplication: the route matchesapplication="<application>"ofgeneration.selector.
inhibit_rules: - equal: [application, slo, objective] source_matchers: ['alertname="SloErrorBudgetBurn"', 'severity="page"'] target_matchers: ['alertname="SloErrorBudgetBurn"', 'severity="ticket"'] routes: - group_by: [application, slo, objective] matchers: ['alertname=~"SloErrorBudgetBurn|SloNoEvents"', 'application="showcase"'] routes: - { matchers: ['severity="page"'], receiver: slo-page } - { matchers: ['severity="ticket"'], receiver: slo-ticket }
severity is the SRE Workbook urgency: page means act now, ticket means within days. A firing page burn alert
inhibits the ticket burn alert of the same application, slo and objective; SloNoEvents is never inhibited.
Grouping timings (group_wait, group_interval, repeat_interval) are not generated: Alertmanager defaults apply.
Use one receiver name for both severities to send everything to one channel; override per run with
--page-receiver / --ticket-receiver. A receiver name must match the pattern in the configuration reference
(an empty value, such as an unset environment variable, is rejected).
Running the rule tests
The generated Prometheus rules and Sloth specs are checked by the real tools, never skipped: promtool check rules,
promtool test rules (rule unit tests for fast burn, NoData, a revision change and warming up) and sloth validate,
all through docker run (prom/prometheus:v3.15.0, ghcr.io/slok/sloth:v0.16.0).
make test-promtool # needs Docker; about a minute
The generated Alertmanager files are checked by make test-amtool (amtool check-config of the full file
and of the fragment merged into a user config, amtool config routes test for page, ticket and no-events alerts;
prom/alertmanager:v0.34.0), CI job amtool.
Without Docker the tests fail instead of being skipped. They are not part of make test only because the reusable
bundle-standard job runs without Docker; CI runs them in the dedicated promtool and amtool jobs of
.github/workflows/checks.yml.
Overhead
make benchmark (PHPUnit group benchmark, tests/Benchmark, outside the test suites, no pass/fail threshold)
measures the cost of the classifier plus writer path for one event with two objectives (availability and latency;
10 % of the events are errors), best of 5 rounds of 100 000 events after a warm-up. Measured on 2026-11-21 UTC,
PHP 8.4.17 (CLI, no opcache/JIT tuning), Intel Core Ultra 7 155H, Linux 6.17, one core:
| Scenario | Cost per event |
|---|---|
| null recorder (classifier, binding, revision memo, writer call) | 4.5 us |
null recorder, kernel.reset after every event (RoadRunner request or consumed message) |
5.1 us |
| the same with revisions warmed into the cache | 5.6 us |
metrics-bundle in-memory storage (the full increment path) |
10.7 us |
Before 1.0 a reset also dropped the resolved strategy and revision of every objective: the reset scenario cost 28.7 us per event (6.4 us with warmed revisions) because every event resolved its binding and hashed its revision again.
A cold PHP-FPM request is benchmarked as well: every service is new, the catalog has 500 HTTP SLOs with two objectives
each, the route index comes from the warmed file and the request records the event of its dedicated latency objective
(availability reads the metrics-bundle series). It costs about 70 us per request (2026-11-21 UTC, the same machine,
opcache on in the CLI and the index file aged past opcache.file_update_protection; a file younger than that is
parsed on every include, about 1.4 ms). Most of it is hydrating the one SLO definition of the route (the value-object
invariants of the compiled catalog entry) and reading the route index entries. Before 1.0 the status-set overlap check
of that hydration walked every status code: the same run measured about 115 us per request with it (an earlier,
less loaded run of that code measured about 195 us).
A real Redis storage adds its network round trip per increment; the events are written after the response is
produced in the HTTP path (kernel.terminate) and in the worker loop for Messenger.
Route index, the cold path. HTTP SLOs need the route → SLO point index and the route names of each SLO.
FrameworkBundle's Router::getRouteCollection() reloads every route from the loaders on each call, and under PHP-FPM
"memoised per process" means once per request, so building the index lazily costs a full route load on the first SLO
event of every request (milliseconds to tens of milliseconds in large applications). The cache warmer avoids it; it
is not optional, so it also runs with --no-optional-warmers and when the kernel builds a fresh container. It writes
the index to %kernel.cache_dir%/msstc4symfony_slo/route_index.php, a var_export array that opcache keeps in shared
memory, and the request path reads only the entries it needs from that file: the SLO points of the matched route, the
precomputed strategy and revision of an objective and, when a revision is missing, the routes of one controller, each
entry validated on its own (the whole file is validated only by the commands). The compiled catalog is hydrated the
same way, per point on first use. The lazy build stays the fallback when the file is missing or unreadable (logged
once per process as degraded mode on the slo_bundle channel), and in debug mode, where routes may change without a
cache clear and the file is ignored. Outside debug mode the request path that had to build the index stores it, with
the objective revisions, in the same file (exclusive temporary file and rename), so the rebuild and the warning happen
once per deploy rather than on every request. Whether the cache directory can be written is checked before anything is
built: a read-only one costs a few stat calls, the degraded-mode warning says that every process reads the router,
and nothing is stored. The file carries a fingerprint of the compiled catalog, so an index stored by another container
(an old process finishing a request during an in-place cache:clear --no-warmup) is not trusted and is replaced, like
a malformed one. An application without HTTP SLOs never touches the router on the request path.
The warmer never fails the warm-up: problems are logged on the slo_bundle channel.
License
MIT - see LICENSE.