Deep Dive: 運用・保守 / SRE — Observability と FinOps
本番 ML システムの SRE 観点を、Cloud Monitoring の aiplatform.googleapis.com 全メトリクス・
Google SRE Workbook の SLI/SLO フレームワーク・FinOps の実践 で深掘り。
📌 なぜ ML 運用は通常システムより難しいか
❶ 失敗が "silent"
「コードは正常」「200 を返す」のに「予測精度が下がっている」が起きる。通常の HTTP 監視では検知不能 → 専用 ML メトリクス + Model Monitoring が必須。
❷ コスト構造が特殊
GPU/TPU は CPU 比 10〜100 倍。1 行のミス(プロビジョン放置 / 大型モデル選定)で月数百万円。常時 FinOps 観点で監視する。
❸ データ品質が SLA を決める
「コード変更ゼロ」でもデータドリフトで品質劣化。データパイプライン健全性も SLO 対象。
❹ ロールバックが複雑
「旧モデルに戻す」だけでは不十分。旧 Feature Store・旧前処理・旧 Endpoint 設定 がセットでないと再現できない。Model Registry + Lineage が前提。
📡 オブザーバビリティの 4 シグナル + ML 拡張
SRE の伝統的「Four Golden Signals」に、ML 特有の指標を加える。
| カテゴリ | シグナル | 説明 | ML での測定方法 |
|---|---|---|---|
| 基本 4 シグナル | Latency | レスポンス時間(成功/失敗別) | prediction/online/prediction_latencies (p50/p95/p99) |
| Traffic | 需要量 | prediction/online/prediction_count | |
| Errors | 失敗率 | prediction/online/error_count, response_count{response_code} | |
| Saturation | リソース飽和度 | cpu/utilization, accelerator/duty_cycle, memory/bytes_used | |
| ML 拡張 | Drift | 入力分布変化 | model_monitoring/feature_drift_deviation |
| Attribution Drift | 特徴量寄与度変化 | model_monitoring/feature_attribution_deviation | |
| Prediction Drift | 予測値分布変化 | model_monitoring/prediction_output_drift_deviation | |
| Feature Freshness | 特徴量の鮮度 | featureonlinestore/serving_data_ages | |
| Accuracy | 真の精度(要ラベル) | カスタムメトリクス + Continuous Evaluation |
📊 Cloud Monitoring メトリクス全集(aiplatform.googleapis.com)
以下は本番監視で使う 130+ メトリクスの中から、PMLE 運用で必須のもの を抜粋・整理。すべて aiplatform.googleapis.com/ プレフィックス。
🚦 Endpoint / DeployedModel メトリクス
| メトリクス | 種別 | 用途 |
|---|---|---|
prediction/online/prediction_count | DELTA INT | QPS(per deployed_model_id / endpoint_display_name) |
prediction/online/prediction_latencies | DELTA DIST | p50/p95/p99 レイテンシ(per latency_type) |
prediction/online/error_count | DELTA INT | エラーカウント(error_rate = error/prediction) |
prediction/online/response_count | DELTA INT | レスポンスコード別カウント(HTTP 5xx / 4xx の比率) |
prediction/online/replicas | GAUGE INT | 現在のアクティブレプリカ数 |
prediction/online/target_replicas | GAUGE INT | オートスケールが目指す目標値(current < target なら scale out 中) |
prediction/online/machine_count | GAUGE INT | VM 数 |
prediction/online/cpu/utilization | GAUGE DBL | CPU 使用率(per replica) |
prediction/online/memory/bytes_used | GAUGE INT | メモリ使用量 |
prediction/online/accelerator/duty_cycle | GAUGE DBL | GPU/TPU 利用率(低いと過剰プロビジョン) |
prediction/online/accelerator/memory/bytes_used | GAUGE INT | HBM/VRAM 使用量(OOM の前兆) |
prediction/online/network/received_bytes_count | DELTA INT | 受信帯域 |
prediction/online/network/sent_bytes_count | DELTA INT | 送信帯域 |
prediction/online/private/prediction_latencies | DELTA DIST | Private Endpoint 専用レイテンシ |
spot の威力
上記メトリクスのほとんどに spot=true/false ラベルがあり、Spot VM 利用分とオンデマンド分のコスト/性能を分離できる。「Spot 採用で 60% コスト削減、レイテンシ p99 は + 5%」のような可視化が可能。
必須アラート(Endpoint)
# 例:error_rate > 1% (5 分間) で warn
fetch aiplatform.googleapis.com/Endpoint
| metric 'aiplatform.googleapis.com/prediction/online/error_count'
| align rate(5m)
| every 1m
| group_by [resource.endpoint_id], sum(value)
| join (
fetch aiplatform.googleapis.com/Endpoint
| metric 'aiplatform.googleapis.com/prediction/online/prediction_count'
| align rate(5m)
| every 1m
| group_by [resource.endpoint_id], sum(value)
)
| value [val(0) / val(1) * 100]
| condition val() > 1.0
🌟 Publisher(Gemini / 生成 AI)メトリクス
生成 AI 専用メトリクス群。トークン課金体系の可視化に必須。
| メトリクス | 種別 | 用途 |
|---|---|---|
publisher/online_serving/token_count | DELTA INT | 入出力トークン累積(per type, modality, explicit_caching) |
publisher/online_serving/character_count | DELTA INT | 文字数累積(Gemini の char-based pricing) |
publisher/online_serving/consumed_throughput | DELTA INT | 消費スループット(chars/sec) |
publisher/online_serving/consumed_token_throughput | DELTA INT | 消費トークン スループット |
publisher/online_serving/model_invocation_count | DELTA INT | 呼び出し回数(per response_code, error_category) |
publisher/online_serving/model_invocation_latencies | DELTA DIST | 全体レイテンシ(per latency_type, explicit_caching) |
publisher/online_serving/first_token_latencies | DELTA DIST | TTFT (Time To First Token) — ストリーミング UX の KPI |
publisher/online_serving/dedicated_token_limit | GAUGE INT | Provisioned Throughput の枠(tokens/sec) |
publisher/online_serving/dedicated_token_project_max_limit | GAUGE INT | プロジェクト最大上限 |
explicit_caching ラベルの活用
token_count{explicit_caching=true} を token_count 全体で割れば、Context Caching のヒット率 が算出できる。ヒット率が下がってきたら GCS 元データの更新事故(silent invalidation)を疑う。
🗂 Featurestore(旧版)メトリクス
レガシー Feature Store 用。新規プロジェクトは Feature Online Store を使うが、既存資産の監視は引き続き重要。
| メトリクス | 用途 |
|---|---|
featurestore/online_serving/request_count | サービング QPS(per entity_type_id, method, error_code) |
featurestore/online_serving/latencies | サービングレイテンシ |
featurestore/online_serving/response_size | レスポンスサイズ(大きいと帯域消費) |
featurestore/storage/stored_bytes | ストレージ容量(per storage_type) |
featurestore/node_count | オンラインノード数 |
featurestore/cpu_load | 平均 CPU 負荷 |
featurestore/cpu_load_hottest_node | 最も負荷の高いノード(ホットスポット検知) |
featurestore/online_entities_updated | 更新エンティティ数 |
featurestore/streaming_write/offline_write_delays | オフライン反映遅延 |
🟦 Feature Online Store(新版・Bigtable)メトリクス
| メトリクス | 用途 |
|---|---|
featureonlinestore/online_serving/request_count | QPS(per feature_view_id, storage_type) |
featureonlinestore/online_serving/serving_latencies | サーバ側レイテンシ(ms) |
featureonlinestore/online_serving/serving_bytes_count | レスポンス bytes |
featureonlinestore/serving_data_ages | 特徴量の鮮度(秒)。本番 ML の KPI |
featureonlinestore/serving_data_by_sync_time | sync 時刻別データ分布 |
featureonlinestore/running_sync | 実行中の sync 数(多すぎ = sync 詰まり) |
featureonlinestore/storage/bigtable_cpu_load | Bigtable ノードの平均 CPU 負荷 |
featureonlinestore/storage/bigtable_cpu_load_hottest_node | ホットスポット監視 |
featureonlinestore/storage/bigtable_nodes | Bigtable ノード数(オートスケール監視) |
featureonlinestore/storage/stored_bytes | ストレージ容量 |
serving_data_ages の p95 が 3600 秒(1 時間)以下を月間 99% で維持。
これを満たさないなら:sync スケジュール頻度↑、ETL 高速化、または許容鮮度の見直し。
⛓ Pipelines メトリクス
| メトリクス | 用途 |
|---|---|
executing_vertexai_pipeline_jobs | 実行中ジョブ数(同時実行の上限管理) |
executing_vertexai_pipeline_tasks | 実行中タスク数(並列度の可視化) |
pipelinejob/duration | ジョブ作成→完了の秒数 |
pipelinejob/task_completed_count | 累積完了タスク数 |
📡 Model Monitoring メトリクス
| メトリクス | 用途 |
|---|---|
model_monitoring/feature_drift_deviation | 特徴量ドリフト値(per feature_name, algorithm) |
model_monitoring/feature_attribution_deviation | 特徴量寄与度のドリフト |
model_monitoring/prediction_output_drift_deviation | 予測値分布のドリフト |
online_evaluator/evaluations_count | 継続評価ジョブ数 |
online_evaluator/scores | 評価スコア分布(LLM-as-a-judge 結果など) |
🔍 Vector Search (Matching Engine) メトリクス
| メトリクス | 用途 |
|---|---|
matching_engine/query/request_count | クエリ QPS(per is_private_endpoint, response_code) |
matching_engine/query/latencies | クエリレイテンシ(per index_type) |
matching_engine/current_replicas | 現在のレプリカ数 |
matching_engine/current_shards | シャード数 |
matching_engine/stream_update/request_count | ストリーミング更新の QPS |
matching_engine/stream_update/datapoint_count | upsert/remove 成功カウント |
matching_engine/cpu/request_utilization | CPU 利用率 |
matching_engine/memory/used_bytes | メモリ使用量 |
⚠️ Quota メトリクス
各種 quota の /usage, /limit, /exceeded を監視。「上限の 80% で warn、95% で critical」が定石。
quota/online_prediction_input_tokens_per_minute_per_base_model/usagequota/online_prediction_input_tokens_per_minute_per_base_model/limitquota/online_prediction_input_tokens_per_minute_per_base_model/exceeded
🎯 SLI / SLO / Error Budget — ML 向け実践
Google SRE Workbook より:「An SLI is the ratio of two numbers: the number of good events divided by the total number of events.」シンプルな ratio で表現するのが最強。
📐 ML 向け SLI の型
SRE Workbook の 3 分類 + ML 拡張:
| コンポーネント型 | 主要 SLI | ML での具体例 |
|---|---|---|
| Request-driven(Online Inference) | Availability | HTTP 2xx 数 / 全リクエスト数 ≥ 99.9% |
| Latency | 200 ms 以内のリクエスト数 / 全リクエスト数 ≥ 95% | |
| Quality(生成 AI) | Safety filter pass / 全生成数 ≥ 99% | |
| Pipeline(訓練・ETL) | Freshness | 特徴量の age が 1 時間以内のリクエスト ≥ 99% |
| Correctness | パイプライン出力が data validation 合格 ≥ 99.9% | |
| Coverage | 処理成功レコード / 全入力レコード ≥ 99.5% | |
| Storage(Model Registry / Feature Store) | Durability | 書き込みアーティファクトが後で取得成功 ≥ 99.999% |
| Retrieval | 特徴量取得が < 50ms ≥ 99% | |
| ML 特有 | Accuracy | 本番 accuracy が baseline の 95% 以上を維持する日数 ≥ 月の 95% |
| Fairness | 属性間の FPR 差が 0.05 以内である日数 ≥ 月の 95% |
具体的な ML SLO 設計例
# 例:商品レコメンデーション API の SLO 文書
SLO Title: Recommendation API Reliability
Approved by: Eng Lead, PM, SRE
Review cadence: 四半期
SLI 1: Availability
- Formula: count(response_code in [200, 304]) / count(all responses)
- Source: aiplatform.googleapis.com/prediction/online/response_count
- Window: rolling 28 days
- Target: ≥ 99.9% (error budget = 0.1% ≈ 2,419 errors per 3M requests)
SLI 2: Latency
- Formula: count(latency < 100ms) / count(all responses)
- Source: aiplatform.googleapis.com/prediction/online/prediction_latencies
- Window: rolling 28 days
- Target: ≥ 95%
SLI 3: Feature Freshness
- Formula: count(serving_data_ages < 3600s) / count(all requests)
- Source: aiplatform.googleapis.com/featureonlinestore/serving_data_ages
- Window: rolling 28 days
- Target: ≥ 99%
Error Budget Policy:
- 25% 消費: PM/Eng/SRE に通知
- 50% 消費: 全 feature work 一時停止、信頼性 backlog 優先
- 75% 消費: 全変更 freeze、必須 fix のみ
- 100% 消費: 経営層エスカレーション、リスク再評価
🔥 バーンレート アラート(Multi-burn-rate, Multi-window)
従来の「閾値割れで即 page」だと false positive 多発 + 検知遅延。SRE Workbook 推奨は multi-burn-rate。
バーンレートの基本
- バーンレート 1:通常の消費速度。28 日で予算をちょうど使い切る
- バーンレート 10:通常の 10 倍速。2.8 日で予算枯渇
- バーンレート 36:1 時間で 5% 消費。即座に重大事象
推奨 2-window / 2-burn-rate 構成
| Severity | 長い window | 短い window | バーンレート閾値 | 消費予算 |
|---|---|---|---|---|
| Critical(PagerDuty) | 1 時間 | 5 分 | ≥ 14.4 | 2% in 1h |
| Warning(Slack) | 6 時間 | 30 分 | ≥ 6 | 5% in 6h |
| Slow burn(チケット) | 3 日 | 6 時間 | ≥ 1 | 10% in 3 days |
2 window 必須の理由:短い window の急変だけで page すると瞬間的スパイクで誤発火、長い window だけでは検知遅延。両方が条件を満たした時のみ page。
📋 エラーバジェット・ポリシー
SRE Workbook:「Establishing an SLO creates measurement; an error budget policy creates accountability.」SLO を作っても、ポリシーがなければ "ただのダッシュボード"。
典型的なポリシー条項
- 予算 50% 消費:dev チームは信頼性バグを feature より優先
- 予算 100% 消費:feature freeze、信頼性復旧まで release 禁止
- 予算枯渇でも例外的に変更が必要:senior leadership 承認 + 文書化
- 四半期に 1 回 review:SLO が緩すぎないか、厳しすぎないか
📜 ログとトレース
Cloud Logging
Endpoint コンテナの stdout/stderr が自動収集。Custom Training は /var/log-storage/output*.log も。log-based metrics で「ERROR を含む log の rate」を Cloud Monitoring メトリクス化。
Cloud Trace
分散トレース。「API Gateway → モデル → DB」の各段階レイテンシを可視化。ボトルネック特定に必須。
Cloud Audit Logs
「誰がいつどのモデルを deploy したか」「誰が VPC SC を変更したか」が全て記録。監査・コンプライアンス対応の基盤。
Error Reporting
stack trace を集約してエラー単位でグループ化。「新エラー発生」を自動検知。
Cloud Profiler
CPU / Heap のサンプリングプロファイラ。「推論コードのどこが遅いか」 を本番で見られる。
Vertex AI TensorBoard
訓練ジョブのスカラ・分布・画像を可視化。本番モデルにも custom run を上げる ことで再現性確保。
推奨ログ設計
# 構造化ログを stdout に出す(Cloud Logging が自動取り込み)
import json, sys, time
def log(severity, message, **fields):
entry = {
"severity": severity,
"message": message,
"timestamp": time.time(),
**fields,
}
print(json.dumps(entry), file=sys.stdout, flush=True)
log("INFO", "prediction_completed",
model_version="v3.2",
latency_ms=87,
feature_age_seconds=420,
request_id=request_id,
user_segment="premium")
💰 コスト管理 (FinOps) — 本番運用の最大課題
4 つの防衛ライン
1. Quota の活用(最強の予防策)
- 事前に絞る:開発プロジェクトの GPU quota を「A100 ≤ 2 台」に制限
- サービス別に管理:Vertex AI / BQ / Gemini それぞれに quota
- quota メトリクスで監視:80% で warn、95% で critical
- quota 引き上げ申請にもポリシー:申請理由 + 期限 + 引き下げ計画
2. Budget Alerts
# 例:月次 budget $10,000 で 50/90/100% アラート
gcloud billing budgets create \
--billing-account=BILLING_ACCOUNT_ID \
--display-name="ML Production Monthly" \
--budget-amount=10000USD \
--threshold-rule=percent=0.5 \
--threshold-rule=percent=0.9 \
--threshold-rule=percent=1.0,basis=current-spend \
--notifications-rule-pubsub-topic=projects/PROJECT/topics/budget-alerts \
--notifications-rule-monitoring-notification-channels=...
3. Resource Labels によるコスト分解
- 全リソースに
team,env,model,cost-centerラベル - BQ Billing Export でラベルベース集計
- Looker / Data Studio で team / model 別ダッシュボード
4. サービス別コスト最適化レシピ
| サービス | 主要レバー | 削減幅目安 |
|---|---|---|
| Custom Training | Spot VM + checkpoint, DWS, BF16 mixed precision | 60〜80% |
| TPU 訓練 | v5e(推論寄り)/ v5p(訓練)の使い分け、Multislice 活用 | 30〜50% |
| Endpoint | min_replicas 適正化、L4 / TPU v5e、量子化、Cloud Run 代替 | 50〜70% |
| Gemini API | Flash / Pro 使い分け、プロンプトキャッシング、Batch API、ファインチューニングで短プロンプト化 | 70〜90% |
| Pipelines | caching 適切な有効化、failure_policy で早期停止、並列度制限 | 20〜40% |
| Feature Store | node 数最小化、不要 sync スケジュール削除 | 30〜50% |
| BigQuery ML | partition / cluster、dry run でコスト見積もり、Reserved Slots | 40〜70% |
| Workbench | idle shutdown 30 分、GPU 不要なら CPU、Persistent Disk サイズ最小 | 50〜80% |
| Cloud Logging | 不要ログを除外フィルタで sink せず、保持期間短縮 | 30〜60% |
- 「念のため min_replicas=10」は最大の浪費。SLO から逆算した最小値を設定
- 本番でも Spot VM + チェックポイント でバッチ推論コスト 60% 削減
- Gemini Pro 固定は怠惰。Flash 7 割 + Pro 3 割の使い分け でコスト 1/5
- Pipelines 並列実行は quota の見積もり ありき。GPU quota より並列度↓に
- BQ ML.GENERATE_TEXT は必ず dry run + 小サンプル試算
📈 キャパシティ計画
本番 ML のキャパシティ計画は通常 Web より 遥かに難しい:
- GPU/TPU は予約しないと取れない:オンデマンドで A100 100 台は突然取れない
- quota は申請から数日:直前申請では間に合わない
- モデルサイズ変更が CPU/メモリ要件を変える:軽い更新でも要件が激変することがある
計画プロセス
- 需要予測:traffic の季節性・キャンペーン・新機能 launch を反映
- per-replica capacity:負荷試験で「1 replica = X QPS @ p95 100ms」を実測
- 必要 replica 数の計算:peak QPS / per-replica capacity × 安全係数 1.5
- Quota & Reservation 確保:3 ヶ月先まで Committed Use Discount で押さえる
- Spot Pool 併用:ベース負荷をオンデマンドで、スパイクを Spot で
🚨 インシデント対応プレイブック
共通の対応フロー
ML 特有の典型シナリオ別プレイブック
| 症状 | 初動 | 復旧 |
|---|---|---|
| p99 レイテンシ急増 | replica 数確認、accelerator/duty_cycle 確認 | min_replicas↑、コールドスタート防止 |
| error_rate 急増 | response_code 別カウント、最近の deploy 確認 | 旧 model_version へ traffic_split で戻す |
| OOM kill 多発 | memory/bytes_used 確認、新モデルのサイズ確認 | machine_type 拡大、量子化検討 |
| data drift alert | feature_drift_deviation でどの特徴量か特定 | 再訓練 pipeline trigger、上流データ確認 |
| quota exceeded | quota usage 確認、超過した API 特定 | 緊急 quota 引き上げ申請、rate limit 強化 |
| Gemini レイテンシ悪化 | first_token_latencies, cached token ratio 確認 | Flash へ fallback、別 region へルーティング |
| Pipeline 連続失敗 | Cloud Logging で失敗 task ログ、ML Metadata で lineage 確認 | scheduled run pause、修正後再走 |
🛡 セキュリティ運用
Audit Logs の定期 review
四半期に 1 回、Cloud Audit Logs で「予期せぬ deploy」「IAM 変更」「VPC SC 変更」を review。 Cloud Logging の log-based metric 化で異常を自動検知。
IAM の最小権限と Access Reviews
月次で IAM Recommender の提案を review。Service Account の キーローテーション(推奨:90 日)。 Workload Identity Federation で長期キー排除。
Secrets 管理
Secret Manager で集中管理。Notebook や訓練コードに 絶対に 平文書き込み禁止。 Secret Manager 自動ローテーション設定。
VPC SC 監視
境界違反は Audit Logs で全て記録。Dry-run モードで事前検証してから enforce。 境界変更は change management 必須。
Model Armor 運用
Inspect Only ログを 週次レビュー、誤検知パターンを抽出して閾値調整。 Block 化は段階的に。
OSS モデル監査
Model Garden の suspicious flag を org policy で deny。 独自に HuggingFace モデルをロードする場合は事前スキャンを義務化。
🔁 Toil(繰り返し作業)削減
SRE Workbook:「If high toil accompanies SLO misses, reduce toil through automation or loosen objectives—but never accept both simultaneously.」
ML 運用の典型的 Toil と自動化
| Toil | 自動化 |
|---|---|
| 毎週の再訓練を手動 trigger | Cloud Scheduler + Pipelines |
| data drift を毎日目視確認 | Model Monitoring + alert → 自動再訓練 |
| release 前にメトリクス手動比較 | Pipelines にモデル検証ステップ + 条件分岐 |
| 本番デプロイ後の手動カナリア観察 | Cloud Monitoring + automatic rollback(バーンレート連動) |
| 毎月のコストレポート作成 | BQ Billing export + 定期 query + Looker dashboard |
| Workbench 起動の手動停止 | Idle shutdown |
| quota 超過の都度申請 | 定期キャパシティ計画 + Reservation |
| Audit log 監視 | log-based metric + alert |
📊 推奨ダッシュボード構成(4 階層)
Layer 1: Executive(経営層・週次レビュー)
- 全プロジェクト合計コスト推移(前月比)
- 主要 SLO 達成率(緑/黄/赤)
- 本番モデル数、月次 prediction 数
Layer 2: Service Owner(モデルオーナー・日次)
- 該当モデルの SLI ダッシュボード(availability, latency, freshness)
- Error budget 残量と burn rate
- 本月コスト + 内訳(compute / storage / prediction tokens)
- Drift 監視サマリー
Layer 3: On-call(オンコール対応・リアルタイム)
- p50/p95/p99 latency time series
- error_count / replica_count / accelerator_duty_cycle
- 最近の deploy ログ(traffic_split 変更)
- active incidents
Layer 4: ML Engineer(モデル開発・週次)
- Pipelines 成功率、duration 推移
- Drift メトリクスの詳細(feature 別)
- continuous evaluation スコア
- Experiments 比較