ObservabilityObservability
Part of the Cloud knowledge base — GCP deep dive. Complements DevOps Roadmap.
Tổng quan
Observability trên Google Cloud được cung cấp thông qua Cloud Operations suite (trước đây là Stackdriver): một bộ dịch vụ được tích hợp và phần lớn là managed, bao phủ ba trụ cột — metrics (Cloud Monitoring), logs (Cloud Logging) và traces (Cloud Trace) — cộng thêm các công cụ cấp cao hơn cho tổng hợp exception (Error Reporting) và profiling CPU/heap liên tục (Cloud Profiler). Với các team chuẩn hóa theo Prometheus, Google Cloud Managed Service for Prometheus (GMP) cung cấp một backend drop-in có khả năng mở rộng toàn cầu, và mọi thứ tích hợp với OpenTelemetry như một chuẩn instrumentation trung lập (vendor-neutral).
Bộ suite này được bật mặc định cho hầu hết tài nguyên: GCE VMs, GKE, Cloud Run và App Engine tự động phát ra platform metrics và logs, còn logs hạ tầng của Google (audit, VPC flow, load balancer) chảy vào Cloud Logging mà không cần agent nào. Bạn chủ yếu trả tiền cho khối lượng ingestion và retention, không phải cho một cluster đang chạy.
| Trụ cột | Dịch vụ GCP | Lưu trữ gì | Tương đương AWS |
|---|---|---|---|
| Metrics | Cloud Monitoring | Time series (built-in + custom) | CloudWatch Metrics |
| Metrics (Prometheus) | Managed Service for Prometheus | Prometheus samples | Amazon Managed Prometheus |
| Logs | Cloud Logging | Log entries dạng structured/text | CloudWatch Logs |
| Traces | Cloud Trace | Distributed spans | AWS X-Ray |
| Errors | Error Reporting | Exception đã dedup | (phần của CloudWatch/DevOps Guru) |
| Profiling | Cloud Profiler | Flame graph CPU/heap | CodeGuru Profiler |
| Dashboards | Cloud Monitoring / Managed Grafana | Charts, SLOs | CloudWatch Dashboards / AMG |
Kiến thức nền tảng
Cloud Monitoring — metrics
Một metric là monitored resource + một metric type tạo ra một time series. Metric type được đặt tên như compute.googleapis.com/instance/cpu/utilization. Mỗi time series mang resource labels (VM nào, zone nào) và metric labels (các chiều để slice).
- Built-in metrics — tự động phát ra bởi các dịch vụ GCP (CPU, disk, request count, Pub/Sub backlog, v.v.), miễn phí.
- Agent metrics — Ops Agent trên GCE VMs thu thập metrics cấp guest (memory, disk, process, và các integration bên thứ ba như Nginx/PostgreSQL) cùng logs. Ops Agent thay thế các agent Monitoring + Logging cũ.
- Custom metrics — metrics ứng dụng bạn ghi qua API, OpenTelemetry hoặc Prometheus. Tính phí theo time series.
Uptime checks thăm dò một endpoint HTTP(S)/TCP từ nhiều vị trí toàn cầu và ghi lại tính khả dụng cùng độ trễ. Chúng kết hợp tự nhiên với một alerting policy:
gcloud monitoring uptime create my-api-uptime \
--resource-type=uptime-url \
--resource-labels=host=api.example.com \
--path=/healthz --port=443 --protocol=https \
--period=60 --timeout=10
Metrics Scope cho phép một “scoping project” trung tâm quan sát metrics từ nhiều project được giám sát — mô hình observability đa project.
Truy vấn: MQL và PromQL
Cloud Monitoring hỗ trợ hai ngôn ngữ truy vấn:
- MQL (Monitoring Query Language) — ngôn ngữ native của Google, dựa trên pipe.
- PromQL — được hỗ trợ trực tiếp trên cả native metrics và dữ liệu Managed Service for Prometheus, nên người dùng Grafana/Prometheus thấy quen thuộc.
# MQL: CPU utilization trung bình theo instance, align 1m
fetch gce_instance
| metric 'compute.googleapis.com/instance/cpu/utilization'
| align mean_aligner(1m)
| group_by [resource.instance_id], mean(val())
# PromQL: p95 request latency theo service
histogram_quantile(0.95,
sum by (le, service_name) (
rate(run_googleapis_com:request_latencies_bucket[5m])))
Cloud Logging
Log entries là các document JSON có cấu trúc, được định tuyến qua Log Router, nơi đánh giá các sinks để quyết định mỗi entry đi đâu.
- Log buckets — container lưu trữ logs. Mỗi project có bucket
_Default(user logs, retention 30 ngày) và_Required(admin/audit, 400 ngày, không cấu hình được, miễn phí). Bạn có thể tạo bucket tùy chỉnh với retention tùy chỉnh (1–3650 ngày). - Sinks — một filter + destination. Destination: một log bucket khác, BigQuery (phân tích bằng SQL), Cloud Storage (lưu trữ lâu dài giá rẻ), hoặc Pub/Sub (stream tới SIEM/Splunk bên thứ ba).
- Log Analytics — nâng cấp một log bucket để bạn có thể chạy SQL (engine BigQuery) trực tiếp trên log entries, không cần export.
- Log-based metrics — biến các log match thành metrics: counter (đếm entries khớp) hoặc distribution (trích một trường số vào histogram).
# Route mọi log ERROR trở lên sang BigQuery để phân tích
gcloud logging sinks create errors-to-bq \
bigquery.googleapis.com/projects/PROJECT/datasets/app_logs \
--log-filter='severity>=ERROR'
# Cấp quyền writer identity của sink trên dataset (lệnh sẽ trả về identity đó)
Một logging query (Logging Query Language) lọc entries:
resource.type="cloud_run_revision"
resource.labels.service_name="my-api"
severity>=WARNING
httpRequest.status>=500
timestamp>="2026-07-18T00:00:00Z"
Một log-based metric dựng trên filter đó:
gcloud logging metrics create http_5xx_count \
--description="Đếm số response 5xx từ my-api" \
--log-filter='resource.type="cloud_run_revision"
resource.labels.service_name="my-api" httpRequest.status>=500'
Sau đó bạn alert trên logging.googleapis.com/user/http_5xx_count.
Cloud Trace
Cloud Trace thu thập dữ liệu độ trễ từ các request phân tán dưới dạng spans gộp thành traces. Nó tự động instrument App Engine và tích hợp với OpenTelemetry / các thư viện instrumentation ở nơi khác. Nó hiển thị phân phối độ trễ, phát hiện regression giữa các bản release, và cho thấy waterfall của một request qua các service. Không có phí ingestion riêng cho tier miễn phí hàng tháng lớn đầu tiên; bạn export spans qua OTel exporter hoặc Cloud Trace API.
Error Reporting
Error Reporting tự động nhóm và dedup các exception từ logs (stack trace trong stderr/structured logs) thành các nhóm lỗi riêng biệt, theo dõi first/last-seen và số lần xuất hiện, và có thể thông báo khi một loại lỗi mới xuất hiện. Nó hoạt động out-of-the-box cho Cloud Run, App Engine, GKE, GCE (có agent) và Cloud Functions.
Cloud Profiler
Cloud Profiler là một profiler production thống kê, luôn bật với overhead không đáng kể. Một thư viện nhỏ trong app định kỳ lấy mẫu CPU time, heap allocation, contention và threads, rồi vẽ flame graph trong console. Hỗ trợ Go, Java, Node.js và Python. Dùng nó để tìm hàm nóng và memory leak dưới traffic thực thay vì trên benchmark tổng hợp.
Managed Service for Prometheus (GMP)
GMP là backend managed tương thích Prometheus, có khả năng mở rộng toàn cầu, xây trên Monarch (chính time-series database quy mô hành tinh phía sau Cloud Monitoring). Bạn giữ PromQL, định dạng Prometheus exposition và các exporter hiện có, nhưng Google vận hành storage và query ở quy mô lớn mà không có Prometheus local để vận hành.
- Managed collection — collector do Google chạy trên GKE scrape các target
PodMonitoring/ClusterPodMonitoringcủa bạn. - Self-deployed collection — chạy binary drop-in
gmpvà remote-write tới GMP. - Truy vấn bằng PromQL qua Prometheus HTTP API, Cloud Monitoring hoặc Grafana.
# GKE PodMonitoring CR — scrape pod có label app=my-api trên port "metrics"
apiVersion: monitoring.googleapis.com/v1
kind: PodMonitoring
metadata:
name: my-api
spec:
selector:
matchLabels:
app: my-api
endpoints:
- port: metrics
interval: 30s
OpenTelemetry trên GCP
OpenTelemetry (OTel) là cách được khuyến nghị, trung lập vendor, để instrument ứng dụng. GCP cung cấp exporters cho traces (→ Cloud Trace), metrics (→ Cloud Monitoring) và logs, cùng OpenTelemetry Collector với exporter googlecloud cho một pipeline tập trung. Instrument một lần với OTel SDK; route tới backend Google hôm nay và giữ tính di động cho mai sau.
Khái niệm chính
Alerting policies
Một alerting policy = một hay nhiều conditions + notification channels + documentation tùy chọn. Condition có thể là metric-threshold, metric-absence, hoặc (với logs) log-match. Các policy hiện đại biểu diễn condition dưới dạng PromQL hoặc MQL và dùng notification channels (email, PagerDuty, Slack, Pub/Sub, SMS, webhook).
Ví dụ policy cảnh báo khi log-based metric 5xx vượt 5/phút trong 5 phút:
# gcloud alpha monitoring policies create --policy-from-file=policy.yaml
displayName: "my-api tỉ lệ 5xx cao"
combiner: OR
conditions:
- displayName: "5xx > 5/min trong 5m"
conditionThreshold:
filter: >
metric.type="logging.googleapis.com/user/http_5xx_count"
resource.type="cloud_run_revision"
comparison: COMPARISON_GT
thresholdValue: 5
duration: 300s
aggregations:
- alignmentPeriod: 60s
perSeriesAligner: ALIGN_RATE
notificationChannels:
- projects/PROJECT/notificationChannels/CHANNEL_ID
alertStrategy:
autoClose: 1800s
SLO và burn-rate alerting
Cloud Monitoring hỗ trợ SLO native: định nghĩa một SLI (availability hoặc latency) gắn với một service, đặt target (ví dụ 99.9% trong 28 ngày), và Google tính error budget. Burn-rate alerts kích hoạt khi bạn tiêu ngân sách quá nhanh — một policy burn-rate đa cửa sổ (nhanh + chậm) bắt được cả sự cố cấp tính lẫn suy giảm chậm mà vẫn giảm thiểu báo động giả.
Dashboards
Dashboards là tập hợp các chart (line, stacked, heatmap, scorecard, gauge). Định nghĩa chúng qua console, API, hoặc Terraform (google_monitoring_dashboard với body JSON) để được version-control. Với team muốn Grafana, Managed Service for Grafana và Cloud Monitoring Grafana data source đều làm việc trên cùng metrics.
Retention & mô hình chi phí của logs
Bạn bị tính phí cho log ingestion (theo GiB) và retention vượt mặc định. Bucket _Required miễn phí và bất biến. Tiết kiệm lớn đến từ exclusion filters (loại bỏ log ồn ào, ít giá trị tại router trước khi bị lưu/tính phí) và từ việc route bản archive sang Cloud Storage giá rẻ.
Best Practices
-
Cài Ops Agent trên mọi GCE VM. Lý do: không có nó bạn chỉ có metrics cấp hypervisor — không thấy memory, disk hay process, và không có guest logs. Ops Agent duy nhất thay thế các agent tách rời cũ.
-
Instrument ứng dụng bằng OpenTelemetry, không phải SDK của vendor. Lý do: một lớp instrumentation export tới Cloud Trace/Monitoring hôm nay và giữ tính di động nếu backend đổi, tránh chi phí re-instrument tốn kém.
-
Định nghĩa SLO và alert theo burn rate, không phải threshold thô. Lý do: burn-rate alert đa cửa sổ gắn paging với việc tiêu error budget mà người dùng thấy được, giảm alert fatigue so với threshold CPU/latency tĩnh.
-
Dùng alerting policy đa cửa sổ, đa điều kiện. Lý do: cửa sổ burn nhanh bắt sự cố cấp tính; cửa sổ burn chậm bắt suy giảm dần — kết hợp giảm cả bỏ sót sự cố lẫn báo động giả.
-
Ưu tiên log-based metric + metric alert thay vì alert log thô cho tín hiệu khối lượng lớn. Lý do: gộp thành metric rẻ hơn để đánh giá và cho phép tính rate/percentile cùng xu hướng lịch sử.
-
Loại trừ mạnh tay các log ít giá trị tại Log Router. Lý do: ingestion là chi phí Logging chính; exclusion filter loại bỏ noise health-check và debug trước khi bị tính phí, không đụng bucket
_Requiredmiễn phí. -
Export audit/security logs sang một sink riêng, retention dài. Lý do: compliance thường cần 1+ năm; route tới bucket tùy chỉnh hoặc BigQuery/GCS để đáp ứng retention mà không trả giá hot-storage cao cho mọi thứ.
-
Bật Log Analytics trên các bucket bạn truy vấn thường xuyên. Lý do: chạy SQL cấp BigQuery trực tiếp trên logs tránh một pipeline export riêng và cho phép join logs với dataset khác.
-
Tập trung observability bằng Metrics Scope / gộp logging. Lý do: một scoping project (hoặc log project cấp org) cho SRE một pane duy nhất qua nhiều project thay vì silo từng project.
-
Chuẩn hóa Managed Service for Prometheus cho metrics Kubernetes. Lý do: giữ PromQL và exporter trong khi giao việc mở rộng storage/query cho Monarch — không phải vận hành Prometheus HA, sharding hay long-term storage tự quản.
-
Bật Error Reporting và alert trên nhóm lỗi mới. Lý do: thông báo first-seen đã dedup phơi bày regression ngay khi một loại exception mới ship, nhanh hơn nhiều so với quét logs.
-
Chạy Cloud Profiler liên tục trong production. Lý do: lấy mẫu thống kê có overhead gần bằng không và phơi bày hot path và leak thực dưới traffic production mà benchmark bỏ lỡ.
-
Gắn uptime check cho endpoint public và alert trên chúng. Lý do: thăm dò bên ngoài đa vùng bắt được lỗi DNS, TLS và edge mà metrics nội bộ không thấy.
-
Quản lý dashboard và alerting policy như code (Terraform). Lý do: version control, review và tính tái lập thắng click-ops; bạn có thể triển khai monitoring giống hệt qua các môi trường.
-
Thêm resource và metric label có chủ đích, nhưng canh chừng cardinality. Lý do: label tốt cho phép slice theo service/version/tenant; label không giới hạn (user ID, request ID) làm bùng nổ số time-series và chi phí.
-
Đặt retention của log bucket rõ ràng theo loại dữ liệu. Lý do: 30 ngày ổn cho log debug app nhưng quá ngắn cho security/audit; khớp retention với mục đích kiểm soát cả rủi ro compliance lẫn chi phí.
Tài liệu tham khảo
- Cloud Operations (formerly Stackdriver) overview
- Cloud Monitoring documentation
- Alerting policies overview
- Monitoring Query Language (MQL)
- PromQL in Cloud Monitoring
- Uptime checks
- SLO monitoring
- Cloud Logging documentation
- Log Router & sinks
- Log-based metrics
- Log Analytics
- Logging Query Language
- Cloud Trace documentation
- Error Reporting documentation
- Cloud Profiler documentation
- Managed Service for Prometheus
- Ops Agent
- OpenTelemetry on Google Cloud
Part of the Cloud knowledge base — GCP deep dive. Complements DevOps Roadmap.
Overview
Observability on Google Cloud is delivered through the Cloud Operations suite (formerly Stackdriver): a set of integrated, mostly-managed services covering the three pillars — metrics (Cloud Monitoring), logs (Cloud Logging), and traces (Cloud Trace) — plus higher-level tooling for exception aggregation (Error Reporting) and continuous CPU/heap profiling (Cloud Profiler). For teams standardizing on Prometheus, Google Cloud Managed Service for Prometheus (GMP) offers a globally-scalable, drop-in backend, and everything integrates with OpenTelemetry as the vendor-neutral instrumentation standard.
The suite is enabled by default for most resources: GCE VMs, GKE, Cloud Run, and App Engine emit platform metrics and logs automatically, and Google’s infrastructure logs (audit, VPC flow, load balancer) flow into Cloud Logging without any agent. You pay mostly for ingestion and retention volume, not for a running cluster.
| Pillar | GCP service | What it stores | AWS equivalent |
|---|---|---|---|
| Metrics | Cloud Monitoring | Time series (built-in + custom) | CloudWatch Metrics |
| Metrics (Prometheus) | Managed Service for Prometheus | Prometheus samples | Amazon Managed Prometheus |
| Logs | Cloud Logging | Structured/text log entries | CloudWatch Logs |
| Traces | Cloud Trace | Distributed spans | AWS X-Ray |
| Errors | Error Reporting | Deduplicated exceptions | (part of CloudWatch/DevOps Guru) |
| Profiling | Cloud Profiler | CPU/heap flame graphs | CodeGuru Profiler |
| Dashboards | Cloud Monitoring / Managed Grafana | Charts, SLOs | CloudWatch Dashboards / AMG |
Fundamentals
Cloud Monitoring — metrics
A metric is a monitored resource + a metric type producing a time series. Metric types are named like compute.googleapis.com/instance/cpu/utilization. Every time series carries resource labels (which VM, which zone) and metric labels (dimensions you slice by).
- Built-in metrics — emitted automatically by GCP services (CPU, disk, request count, Pub/Sub backlog, etc.), free of charge.
- Agent metrics — the Ops Agent on GCE VMs collects guest-level metrics (memory, disk, process, and third-party integrations like Nginx/PostgreSQL) and logs. The Ops Agent replaces the legacy Monitoring + Logging agents.
- Custom metrics — application metrics you write via the API, OpenTelemetry, or Prometheus. Billed per time series.
Uptime checks probe an HTTP(S)/TCP endpoint from multiple global locations and record availability and latency. They pair naturally with an alerting policy:
gcloud monitoring uptime create my-api-uptime \
--resource-type=uptime-url \
--resource-labels=host=api.example.com \
--path=/healthz --port=443 --protocol=https \
--period=60 --timeout=10
Metrics Scope lets one central “scoping project” observe metrics from many monitored projects — the multi-project observability model.
Querying: MQL and PromQL
Cloud Monitoring supports two query languages:
- MQL (Monitoring Query Language) — Google’s native, pipe-based language.
- PromQL — supported directly against both native metrics and Managed Service for Prometheus data, so Grafana/Prometheus users feel at home.
# MQL: mean CPU utilization per instance, aligned to 1m
fetch gce_instance
| metric 'compute.googleapis.com/instance/cpu/utilization'
| align mean_aligner(1m)
| group_by [resource.instance_id], mean(val())
# PromQL equivalent flavor: p95 request latency by service
histogram_quantile(0.95,
sum by (le, service_name) (
rate(run_googleapis_com:request_latencies_bucket[5m])))
Cloud Logging
Log entries are structured JSON documents routed through the Log Router, which evaluates sinks to decide where each entry goes.
- Log buckets — storage containers for logs. Every project has
_Default(user logs, 30-day retention) and_Required(admin/audit, 400-day, non-configurable, free) buckets. You can create custom buckets with custom retention (1–3650 days). - Sinks — a filter + destination. Destinations: another log bucket, BigQuery (for SQL analytics), Cloud Storage (cheap long-term archive), or Pub/Sub (stream to third-party SIEM/Splunk).
- Log Analytics — upgrades a log bucket so you can run SQL (BigQuery engine) over log entries directly, without exporting.
- Log-based metrics — turn log matches into metrics: counter metrics (count matching entries) or distribution metrics (extract a numeric field into a histogram).
# Route all ERROR+ logs to BigQuery for analytics
gcloud logging sinks create errors-to-bq \
bigquery.googleapis.com/projects/PROJECT/datasets/app_logs \
--log-filter='severity>=ERROR'
# Grant the sink's writer identity permission on the dataset (returned by the command)
A logging query (Logging Query Language) filters entries:
resource.type="cloud_run_revision"
resource.labels.service_name="my-api"
severity>=WARNING
httpRequest.status>=500
timestamp>="2026-07-18T00:00:00Z"
A log-based metric built on top of that filter:
gcloud logging metrics create http_5xx_count \
--description="Count of 5xx responses from my-api" \
--log-filter='resource.type="cloud_run_revision"
resource.labels.service_name="my-api" httpRequest.status>=500'
You then alert on logging.googleapis.com/user/http_5xx_count.
Cloud Trace
Cloud Trace collects latency data from distributed requests as spans grouped into traces. It auto-instruments App Engine and integrates with OpenTelemetry / instrumentation libraries elsewhere. It surfaces latency distributions, detects regressions between releases, and shows a request’s waterfall across services. There is no separate ingestion charge for the first large monthly tier; you export spans via the OTel exporter or the Cloud Trace API.
Error Reporting
Error Reporting automatically groups and deduplicates exceptions from your logs (stack traces in stderr/structured logs) into distinct error groups, tracks first/last-seen and occurrence counts, and can notify you when a new error type appears. It works out of the box for Cloud Run, App Engine, GKE, GCE (with agent), and Cloud Functions.
Cloud Profiler
Cloud Profiler is a statistical, always-on production profiler with negligible overhead. A small library in your app periodically samples CPU time, heap allocation, contention, and threads, and renders flame graphs in the console. Supported for Go, Java, Node.js, and Python. Use it to find hot functions and memory leaks under real traffic rather than in synthetic benchmarks.
Managed Service for Prometheus (GMP)
GMP is a Prometheus-compatible, globally-scalable managed backend built on Monarch (the same planet-scale time-series database behind Cloud Monitoring). You keep PromQL, Prometheus exposition format, and existing exporters, but Google runs storage and query at scale with no local Prometheus to operate.
- Managed collection — Google-run collectors on GKE scrape your
PodMonitoring/ClusterPodMonitoringtargets. - Self-deployed collection — run the drop-in
gmpbinary and remote-write to GMP. - Query with PromQL via the Prometheus HTTP API, Cloud Monitoring, or Grafana.
# GKE PodMonitoring CR — scrape pods labeled app=my-api on port "metrics"
apiVersion: monitoring.googleapis.com/v1
kind: PodMonitoring
metadata:
name: my-api
spec:
selector:
matchLabels:
app: my-api
endpoints:
- port: metrics
interval: 30s
OpenTelemetry on GCP
OpenTelemetry (OTel) is the recommended, vendor-neutral way to instrument apps. GCP provides exporters for traces (→ Cloud Trace), metrics (→ Cloud Monitoring), and logs, plus the OpenTelemetry Collector with a googlecloud exporter for a centralized pipeline. Instrument once with OTel SDKs; route to Google backends today and stay portable tomorrow.
Key Concepts
Alerting policies
An alerting policy = one or more conditions + notification channels + optional documentation. Conditions can be metric-threshold, metric-absence, or (for logs) log-match. Modern policies express conditions as PromQL or MQL and use notification channels (email, PagerDuty, Slack, Pub/Sub, SMS, webhook).
Example policy that alerts when the 5xx log-based metric exceeds 5/min for 5 minutes:
# gcloud alpha monitoring policies create --policy-from-file=policy.yaml
displayName: "my-api high 5xx rate"
combiner: OR
conditions:
- displayName: "5xx > 5/min for 5m"
conditionThreshold:
filter: >
metric.type="logging.googleapis.com/user/http_5xx_count"
resource.type="cloud_run_revision"
comparison: COMPARISON_GT
thresholdValue: 5
duration: 300s
aggregations:
- alignmentPeriod: 60s
perSeriesAligner: ALIGN_RATE
notificationChannels:
- projects/PROJECT/notificationChannels/CHANNEL_ID
alertStrategy:
autoClose: 1800s
SLOs and burn-rate alerting
Cloud Monitoring has native SLO support: define an SLI (availability or latency) against a service, set a target (e.g., 99.9% over 28 days), and Google computes the error budget. Burn-rate alerts fire when you consume budget too fast — a multi-window (fast + slow) burn-rate policy catches both acute outages and slow degradations while minimizing false pages.
Dashboards
Dashboards are collections of charts (line, stacked, heatmap, scorecard, gauge). Define them via the console, the API, or Terraform (google_monitoring_dashboard with a JSON body) so they are version-controlled. For teams wanting Grafana, Managed Service for Grafana and the Cloud Monitoring Grafana data source both work against the same metrics.
Log retention & cost model
You are billed for log ingestion (per GiB) and retention beyond defaults. The _Required bucket is free and immutable. Big savings come from exclusion filters (drop noisy, low-value logs at the router before they are stored/billed) and from routing archive copies to cheap Cloud Storage.
Best Practices
-
Install the Ops Agent on every GCE VM. Rationale: without it you get hypervisor-level metrics only — no memory, disk, or process visibility, and no guest logs. The single Ops Agent replaces the legacy split agents.
-
Instrument applications with OpenTelemetry, not vendor SDKs. Rationale: one instrumentation layer exports to Cloud Trace/Monitoring today and keeps you portable if backends change, avoiding costly re-instrumentation.
-
Define SLOs and alert on burn rate, not raw thresholds. Rationale: multi-window burn-rate alerts tie paging to user-visible error-budget consumption, cutting alert fatigue versus static CPU/latency thresholds.
-
Use multi-window, multi-condition alerting policies. Rationale: a fast-burn window catches acute incidents; a slow-burn window catches gradual degradation — together they reduce both missed incidents and false pages.
-
Prefer log-based metrics + metric alerts over raw log alerts for high-volume signals. Rationale: aggregating into a metric is cheaper to evaluate and gives you rate/percentile math and historical trends.
-
Aggressively exclude low-value logs at the Log Router. Rationale: ingestion is the main Logging cost; exclusion filters drop health-check and debug noise before it is billed, without touching the free
_Requiredbucket. -
Export audit/security logs to a dedicated, long-retention sink. Rationale: compliance often needs 1+ year; route to a custom bucket or BigQuery/GCS so you meet retention without paying premium hot-storage rates for everything.
-
Enable Log Analytics on buckets you query often. Rationale: running BigQuery-grade SQL directly on logs avoids a separate export pipeline and lets you join logs with other datasets.
-
Centralize observability with a Metrics Scope / logging aggregation. Rationale: a single scoping (or org-level log) project gives SRE one pane of glass across many projects instead of per-project silos.
-
Standardize on Managed Service for Prometheus for Kubernetes metrics. Rationale: keep PromQL and exporters while offloading storage/query scaling to Monarch — no self-managed Prometheus HA, sharding, or long-term storage to operate.
-
Turn on Error Reporting and alert on new error groups. Rationale: deduplicated, first-seen notifications surface regressions the moment a new exception type ships, far faster than scanning logs.
-
Run Cloud Profiler continuously in production. Rationale: statistical sampling has near-zero overhead and reveals real hot paths and leaks under production traffic that benchmarks miss.
-
Attach uptime checks to public endpoints and alert on them. Rationale: multi-region external probes catch DNS, TLS, and edge failures that internal metrics cannot see.
-
Manage dashboards and alerting policies as code (Terraform). Rationale: version control, review, and reproducibility beat click-ops; you can promote identical monitoring across environments.
-
Add resource and metric labels deliberately, but watch cardinality. Rationale: good labels enable slicing by service/version/tenant; unbounded labels (user IDs, request IDs) explode time-series count and cost.
-
Set log bucket retention explicitly per data class. Rationale: 30 days is fine for app debug logs but too short for security/audit; matching retention to purpose controls both compliance risk and spend.
References
- Cloud Operations (formerly Stackdriver) overview
- Cloud Monitoring documentation
- Alerting policies overview
- Monitoring Query Language (MQL)
- PromQL in Cloud Monitoring
- Uptime checks
- SLO monitoring
- Cloud Logging documentation
- Log Router & sinks
- Log-based metrics
- Log Analytics
- Logging Query Language
- Cloud Trace documentation
- Error Reporting documentation
- Cloud Profiler documentation
- Managed Service for Prometheus
- Ops Agent
- OpenTelemetry on Google Cloud