Pular para o conteúdo

Métricas, SLI, SLO e SLA

SLI mede o que o cliente sente, SLO fixa a meta (99,9% em 30 dias), error budget diz quanto de falha cabe e o alerta dispara pelo burn rate em duas janelas. SLA é o contrato derivado do SLO.

passos
4
arquivos
4
testes
0
tecnologias
2

Cenário

Queda do SPI faz 1 em 4 PIX falhar por 10 min: burn > 14,4x, page acionado; 10 min após a recuperação o page some e o ticket fica.

Planta

Fluxo
7/7
Requisições PIXSLI: fração boaSLO 99,9%Error budget - 43,2min em 30 diasBurn rate - 1h e 5mPageTicketSLA com o clienteambas >= 14,46h e 30m >= 6
7

7 passos — reproduza para seguir o fluxo

Como funciona

4passos

SLI mede o que o cliente sente, SLO fixa a meta (99,9% em 30 dias), error budget diz quanto de falha cabe e o alerta dispara pelo burn rate em duas janelas

Esconde cada passo: lembre antes de tocar para revelar.

  1. 1

    Evento por requisição (minuto, sucesso); SLI = fração boa

  2. 2

    99,9% em 30 dias = 43,2 min de budget; budgetSpent mostra o gasto

  3. 3

    burnRate = fração ruim ÷ fração permitida

  4. 4

    Page em 1h/5m ≥ 14,4; ticket em 6h/30m ≥ 6

Trade-offs

O que se ganha, o que se paga

2 vantagenscada ganho tem um preço2 custos

Vantagens

  • Mede o que o cliente sente

  • Page rápido no incidente real

Custos

  • Janelas e limiares exigem calibração

  • Produto e engenharia acordam o uso do budget

Código

pattern/observability/metrics-sli-slo-sla

4 arquivos

./

  • package.jsoninfra
  • README.md
  • tsconfig.jsoninfra

src/

  • demo.tsdemo

Executar só Bun

  1. bun install# dependências
  2. bun run demo# roda o cenário

Saída: budget de 43,2 min; hora normal sem alerta; na queda, burn 1h 42,4x e 5m 250x com ALERT page+ticket e 5,8% do budget gasto; 10 min após a recuperação, só ALERT ticket.

Requisitos
Bun

Código

src/demo.ts

// Demo: 80 simulated minutes of PIX traffic against a 99.9% availability SLO — normal hour, 10-minute SPI outage, recovery — with error budget and multi-window burn-rate alerts.
type RequestEvent = { at: number; ok: boolean };

const SLO_TARGET = 99.9;
const WINDOW_30D_MIN = 30 * 24 * 60;
const PIX_PER_MINUTE = 20;
// Google SRE multi-window, multi-burn-rate alerts: the long window proves the burn is sustained, the short one that it is still happening.
const BURN_ALERTS = [
  { severity: "page", longMin: 60, shortMin: 5, threshold: 14.4 },
  { severity: "ticket", longMin: 360, shortMin: 30, threshold: 6 },
];

const events: RequestEvent[] = [];
let minuteNow = 0;
const eventsSince = (windowMin: number) => events.filter((event) => event.at > minuteNow - windowMin);
// SLI: the fraction of PIX the payer saw succeed.
const sliRatio = (window: RequestEvent[]) => (window.length === 0 ? 1 : window.filter((event) => event.ok).length / window.length);
// 1x empties the budget exactly at the end of the 30 days; 14.4x empties it in about two days.
const burnRate = (windowMin: number) => (1 - sliRatio(eventsSince(windowMin))) / (1 - SLO_TARGET / 100);
// 99.9% over 30 days allows 43.2 bad minutes, i.e. this share of all requests in the window.
const budgetSpent = () => events.filter((event) => !event.ok).length / (PIX_PER_MINUTE * WINDOW_30D_MIN * (1 - SLO_TARGET / 100));
const alertsFiring = () => BURN_ALERTS.filter((alert) => burnRate(alert.longMin) >= alert.threshold && burnRate(alert.shortMin) >= alert.threshold).map((alert) => alert.severity);

// One step = one minute of 20 PIX; `failEvery` makes 1 PIX in N fail, as the SPI outage does.
function minutesRun(minutes: number, failEvery = 0) {
  for (let minute = 0; minute < minutes; minute++, minuteNow++) {
    for (let index = 1; index <= PIX_PER_MINUTE; index++) events.push({ at: minuteNow, ok: failEvery === 0 || index % failEvery !== 0 });
  }
}

function checkpoint(label: string) {
  const alerts = alertsFiring();
  console.log(`  [${label}] SLI 1h ${(sliRatio(eventsSince(60)) * 100).toFixed(2)}% | burn 1h ${burnRate(60).toFixed(1)}x 5m ${burnRate(5).toFixed(1)}x | budget spent ${(budgetSpent() * 100).toFixed(1)}% | ${alerts.length ? `ALERT ${alerts.join("+")}` : "no alert"}`);
}

console.log(`  [SLO] ${SLO_TARGET}% over 30 days → error budget ${(WINDOW_30D_MIN * (1 - SLO_TARGET / 100)).toFixed(1)} min`);
minutesRun(60);
checkpoint("normal hour");
minutesRun(10, 4);
checkpoint("SPI outage, 1 in 4 fails");
minutesRun(10);
checkpoint("10 min after recovery");

Por que se relacionam

Teste rápido

Qual padrão vem antes de Métricas, SLI, SLO e SLA?

Próximo projeto, Segurança & AuditoriaAPI Key Management
Esc

↑ ↓ navegarEnter abrir239 resultados