Communitygithub.com

可觀測性與服務等級目標 (Observability and SLOs)

當需要加入記錄、指標、追蹤、健康檢查、SLO 或警報時,或是建置需要可操作且可除錯的服務表面時使用。關鍵字:結構化日誌、OpenTelemetry、關聯 ID、RED 指標、存活度、就緒度、SLI、SLO、錯誤預算、警報。

可觀測性與服務等級目標 (Observability and SLOs) 是什麼?

這個技能提供了一套完整的指南,幫助開發人員將可觀測性與服務等級目標 (SLO) 設計到 AI 代理技能中。它強調透過結構化日誌、指標和追蹤來實現系統的可觀測性,並遵循 RED (速率、錯誤、持續時間) 原則。支援的平台包括 AKS、Azure Monitor / Application Insights,以及 OpenTelemetry 和 Prometheus/Grafana 等技術棧。該指南詳細說明了如何實施健康檢查端點、傳播關聯 ID、定義 SLO,以及建立基於症狀的警報系統,以確保系統既可除錯又可靠。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/lguidolin/agent-skills/tree/main/skills/observability-and-slos

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

可觀測性與服務等級目標 (Observability and SLOs) 是做什麼的?

概述

你無法操作、除錯或改善你看不見的東西。可觀測性必須是設計的一部分,而不是在第一次故障發生後才硬塞進去。每個事件的首要問題是「什麼變了,誰受到了影響」——一個無法回答這個問題的系統會把五分鐘就能解決的問題變成一場考古挖掘。

原則(通用)

  • 三大信號。 發射結構化日誌(機器可解析,非純文字)、指標(計數、比率、持續時間)和追蹤(請求在服務間的路徑)。一個請求會從頭到尾攜帶一個關聯/追蹤 ID。
  • 為每個表面檢測黃金信號:每個端點/操作上的速率、錯誤、持續時間 (RED),加上資源飽和度。新端點在變得可觀測之前不算「完成」。
  • 健康狀況是一個端點,而非猜測。 將存活度(「我還在運行嗎?」)和就緒度(「我能處理流量嗎?」)作為獨立的檢查公開。
  • 為關鍵旅程定義 SLO,搭配衡量它們的 SLI,以及一個讓可靠性與功能之間的取捨變得明確且資料驅動的錯誤預算。
  • 根據症狀而非原因發出警報。 當使用者受到影響時(SLO 燃燒、就緒度失敗)才發訊息,而不是在每個內部小問題出現時。每個警報都必須是可執行的——一個無人理會的警報會訓練人們忽略所有警報。

機制(此技術棧)

  • 輸出結構化 JSON 日誌到 stdout,由平台收集(例如 AKS → Azure Monitor / Log Analytics)。服務內部不得使用純文字記錄。
  • 在應用伺服器和 PostGraphile 中使用 OpenTelemetry;將追蹤/指標導出到 Azure Monitor / Application Insights(或 Prometheus / Grafana)。
  • 在資料路徑中傳播關聯 ID——在邊緣生成,通過瀏覽器 → 應用 → PostGraphile,與上下文標頭一起傳遞,並附加到每一條日誌行和跨度中。
  • 每個 HTTP 路由和 GraphQL 操作的 RED 指標;PostgreSQL 慢查詢日誌 + pg_stat_statements。
  • 存活度/就緒度端點連接到 Kubernetes 探針(請參閱 cloud-delivery-aks)。就緒度應反映真實的依賴健康狀況(它能否連接到資料庫?),而不僅僅是程序是否運行。
  • 前端: 將 Web Vitals 和用戶端錯誤報告給同一個後端。
  • 每個旅程的 SLO,搭配儀表板和燃燒速率警報。

何時擴展此方案

一個預啟動/本地專案現在可以實施結構化日誌 + 健康端點,但將 SLO / 警報推遲到有真正使用者需要保護時。在第一個決策記錄中說明模式。

完整理由:參見憲法第 IX 條與第 XVI 條,這些內容位於 engineering-constitution/references/engineering-constitution.md。

Individual skills in this repo

This repo contains 18 individual skills — each has its own dedicated page.

lguidolin/change-hygiene-and-code-craft

Use when writing or refactoring code, structuring a commit or PR, or deciding whether to abstract duplication. Symptoms — mixing reorg with logic changes, a PR doing several things at once, a file growing large, the second copy of similar code, or unsure whether to DRY something up.

lguidolin/cloud-delivery-aks

Use when deploying to Kubernetes or Azure Kubernetes Service (AKS), configuring cloud secrets, setting up progressive rollout/canary, per-PR ephemeral environments, or k8s health probes. Keywords — Kubernetes, AKS, Key Vault, Argo Rollouts, Flagger, canary, blue-green, liveness, readiness, PodDisruptionBudget, HPA, rollback, GHCR.

lguidolin/commit-history-rewrite

Use when an existing repository has messy commit history that needs to conform to conventional commits before adopting release-please, or when intermediate WIP/fixup/merge commits need to be cleaned up.

lguidolin/conventional-commits-and-releases

Use when committing, writing a commit message, opening a PR that will be squash-merged, or configuring automated versioning/changelogs. Keywords — conventional commits, release-please, semver, feat/fix/chore, breaking change, changelog.

lguidolin/defense-in-depth-security

Use when handling untrusted input, secrets, authentication/authorization, or dependencies — or threat-modeling a new surface. Keywords — STRIDE, threat model, least privilege, secrets management, supply chain, dependency scanning, input validation, audit log, defense in depth.

lguidolin/designing-before-building

Use when starting a feature, fixing a non-trivial bug, or about to write implementation code — before any code exists. Symptoms you need this: "this is simple, I'll just code it", reaching for the editor before a design is approved, or an idea that hasn't been turned into a spec and plan.

lguidolin/engineering-constitution

Use when starting work in a project that follows the engineering constitution, orienting to its rules, or deciding which engineering practice applies to a task — spec writing, commits, testing, security, deploys, database, or UI work.

lguidolin/graphql-contract-testing

Use when writing a GraphQL query/mutation that the UI and a test will share, or building route/schema contract or smoke tests. Symptoms — copying a query into a test, a test asserting on query text, schema change that didn't break the UI build, or RLS/permission drift. Keywords — graphql-codegen, typed document, contract test, route smoke test.

lguidolin/init-repo-CI

Use when setting up a new repository with conventional commits, release-please, and CI automation, or when retrofitting an existing repository that lacks automated versioning and PR validation workflows.

lguidolin/interface-craft-and-accessibility

Use when building or styling UI — components, layouts, forms, design tokens — or making accessibility decisions. Keywords — a11y, WCAG, keyboard navigation, focus state, contrast, design system, minimalist UI, component reuse, ARIA, semantic HTML.

lguidolin/merge-gates-and-automation

Use when setting up or changing CI, pre-push hooks, or a task runner, or deciding what must pass before merge. Symptoms — tempted to put authoritative checks only in a local hook, skip CI, bypass with --no-verify, or unsure what gates a merge vs. runs locally.

lguidolin/performance-and-scale

Use when working on hot paths, list endpoints, pagination, data-access in loops, or public interfaces/schemas. Symptoms — unbounded queries, N+1 access, no latency budget, optimizing without measuring, or changing an interface many consumers depend on. Keywords — pagination, N+1, Hyrum's Law, performance budget, bundle size.

lguidolin/postgres-postgraphile-rls-and-sql

Use when writing PostgreSQL, PostGraphile config, Row-Level Security policies, SQL schema files, or working on the Browser→App→PostGraphile→Postgres data path. Keywords — RLS, SECURITY DEFINER, search_path, pgSettings, grants, roles, GraphQL depth limit, query cost, statement_timeout, SQL file organization.

lguidolin/recording-decisions

Use when a design or architecture decision has been made and needs to be captured — writing a decision record or ADR, updating a decision index, noting a deferred idea, or superseding a past decision. Keywords — ADR, decision record, rationale, rejected alternatives, dependency index.

lguidolin/resilience-and-deploy-safety

Use when planning a deploy, designing a rollback, or responding to an incident or writing a postmortem. Keywords — deploy safety, rollback, immutable artifact, progressive delivery, canary, blast radius, incident response, blameless postmortem, error budget.

lguidolin/ship-it

Use when the user wants to ship work — push, PR, archive decision records, merge, and clean up. Handles the full lifecycle from committing final changes through post-merge cleanup including converting specs/plans to compact decision records.

lguidolin/tests-as-a-control

Use when writing or modifying tests, when a test breaks during a refactor, or when testing permission/role rules. Symptoms — tempted to edit a test to make it pass, testing only the happy path, a deny-test that started passing, flaky tests, or unsure what to assert.

lguidolin/zero-downtime-migrations

Use when changing a database schema where data must survive the change — adding/removing/renaming columns, constraints, indexes, or backfilling. Symptoms — a destructive migration bundled with a code deploy, a NOT NULL column with a backfill, a table-locking UPDATE, or a rename. Keywords — expand/contract, parallel change, backfill, NOT VALID, CREATE INDEX CONCURRENTLY, graphile-migrate.

相關技能