jpskill.com
🛠️ 開発・MCP コミュニティ

storage-debug-instrumentation

Add comprehensive debugging and observability tooling for backend storage layers (PostgreSQL, ChromaDB) and startup metrics. Includes storage drift detection, raw data inspection endpoints, and a Next.js admin dashboard.

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o storage-debug-instrumentation.zip https://jpskill.com/download/17507.zip && unzip -o storage-debug-instrumentation.zip && rm storage-debug-instrumentation.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/17507.zip -OutFile "$d\storage-debug-instrumentation.zip"; Expand-Archive "$d\storage-debug-instrumentation.zip" -DestinationPath $d -Force; ri "$d\storage-debug-instrumentation.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して storage-debug-instrumentation.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → storage-debug-instrumentation フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

ストレージデバッグインストルメンテーション

目的

以下を公開することで、ストレージの状態、同期の健全性、およびバックエンドのパフォーマンスボトルネックの迅速な診断を可能にします。

  • PostgreSQLとChromaDBの両方からの生のアーティクル検査
  • ストレージのドリフト検出(欠落/宙ぶらりんのエントリ)
  • 詳細な起動タイムラインの内訳(DB初期化、キャッシュプリロード、ベクターストア、RSSリフレッシュ)
  • すべての診断を統合した1ページのデバッグダッシュボード

範囲

  • バックエンド: app/services/startup_metrics.py, app/main.py, app/vector_store.py, app/database.py, app/api/routes/debug.py
  • フロントエンド: frontend/lib/api.ts, frontend/app/debug/page.tsx
  • スキーマの変更はありません。純粋に追加的なインストルメンテーションとデバッグルートです。

ワークフロー

1. 起動メトリクスサービスの作成

ファイル: backend/app/services/startup_metrics.py

  • フェーズのタイミングを記録するためのスレッドセーフな StartupMetrics クラスを実装します。
  • フェーズのキャプチャのために record_event(name, started_at, detail, metadata) を公開します。
  • 任意の注釈のために add_note(key, value) をサポートします。
  • アプリ全体で使用するためにシングルトンの startup_metrics をエクスポートします。

2. ベクターストアの初期化のインストルメント

ファイル: backend/app/vector_store.py

  • startup_metrics をインポートします。
  • VectorStore.__init__() で、初期化を time.time() タイマーでラップします。
  • メタデータとともにイベントを記録します: host, port, collection, documents
  • 接続エラーをキャッチして注釈を付けます。

3. FastAPI起動シーケンスのインストルメント

ファイル: backend/app/main.py

  • on_startup() の先頭で startup_metrics.mark_app_started() を呼び出します。
  • 各フェーズ(DB初期化、スケジューラ、キャッシュプリロード、RSSリフレッシュ、移行)を record_event() でラップします。
  • メタデータを含めます: cache_size, article_count, oldest_article_hours
  • 最後に startup_metrics.mark_app_completed() を呼び出します。
  • add_note() を介してアプリのバージョンノートを追加します。

4. データベースのページネーションヘルパーの追加

ファイル: backend/app/database.py

  • 以下をサポートするために fetch_articles_page() を実装します。
    • Limit/offset ページネーション
    • オプションのソースフィルター
    • 欠落した埋め込みのみのフラグ
    • 公開日の範囲フィルター
    • ソート方向 (asc/desc)
    • 最古/最新のタイムスタンプ境界を返します。
  • ドリフト分析のために、すべてのアーティクル→chroma IDマッピングを返す fetch_article_chroma_mappings() を実装します。

5. ベクターストアのページネーションヘルパーの追加

ファイル: backend/app/vector_store.py

  • メタデータとプレビューを含むページネーションされたChromaドキュメントを返す list_articles(limit, offset) を実装します。
  • ドリフト検出のために、保存されているすべてのChroma IDを返す list_all_ids() を実装します(/debug/storage/drift で使用されます)。

6. デバッグAPIエンドポイントの公開

ファイル: backend/app/api/routes/debug.py

  • GET /debug/startup を追加 → 起動メトリクスのタイムライン(イベント+ノート)を返します。
  • GET /debug/chromadb/articles を追加 → limit/offsetでページネーションされた生のChromaエントリを返します。
  • GET /debug/database/articles を追加 → フィルター(ソース、埋め込み、日付範囲、ソート)でページネーションされたPostgres行を返します。
  • GET /debug/storage/drift を追加 → Chroma IDとPostgresマッピングを比較し、欠落/宙ぶらりんの数+サンプルを返します。

7. フロントエンドAPIバインディングの追加

ファイル: frontend/lib/api.ts

  • タイプをエクスポートします: StartupEventMetric, StartupMetricsResponse, ChromaDebugResponse, DatabaseDebugResponse, StorageDriftReport
  • フェッチャーをエクスポートします: fetchStartupMetrics(), fetchChromaDebugArticles(), fetchDatabaseDebugArticles(), fetchStorageDrift()
  • レスポンスフィールドに対して snake_casecamelCase マッピングを確実にします。

8. デバッグダッシュボードページの構築

ファイル: frontend/app/debug/page.tsx

  • マルチタブ検査UIで /debug ルートを作成します。
  • 起動タイムラインをレンダリングします: フェーズ名、期間、メタデータバッジ(キャッシュサイズ、ベクター、移行されたレコード)
  • Chromaブラウザを表示します: ID、タイトル、ソース、プレビューを含むページネーションされたテーブル
  • Postgresブラウザを表示します: フィルター(ソース、日付範囲、欠落した埋め込みのみのフラグ)を含むページネーションされたテーブル
  • ドリフトレポートを表示します: Chromaに欠落しているエントリとChromaで宙ぶらりんになっているエントリのサンプルテーブル
  • クイックメトリクスのサマリーカードを含めます(起動時間、合計アーティクル数、ベクター数、ドリフト数)。

実装チェックリスト

  • [ ] backend/app/services/startup_metrics.py を作成します。
  • [ ] backend/app/vector_store.py::VectorStore.__init__() をインストルメントします。
  • [ ] backend/app/main.py::on_startup() (すべてのフェーズ) をインストルメントします。
  • [ ] fetch_articles_page()fetch_article_chroma_mappings()backend/app/database.py に追加します。
  • [ ] list_articles()list_all_ids()backend/app/vector_store.py に追加します。
  • [ ] /debug/startup, /debug/chromadb/articles, /debug/database/articles, /debug/storage/driftbackend/app/api/routes/debug.py に追加します。
  • [ ] タイプとフェッチャーを frontend/lib/api.ts に追加します。
  • [ ] ダッシュボードレイアウトで frontend/app/debug/page.tsx を作成します。
  • [ ] uvx ruff check backend を実行 → すべてのチェックに合格します。
  • [ ] curlまたはPostmanでエンドポイントをテストして、レスポンス構造を確認します。

検証チェックリスト

  • [ ] GET http://localhost:8000/debug/startup は、イベントとノートを含む有効なタイムラインを返します。
  • [ ] GET http://localhost:8000/debug/chromadb/articles?limit=50&offset=0 は、ページネーションされたChromaドキュメントを返します。
  • [ ] GET http://localhost:8000/debug/database/articles?source=bbc&missing_embeddings_only=false は正しくフィルタリングします。
  • [ ] GET http://localhost:8000/debug/storage/drift は、カウントを比較し、ドリフトサンプルを返します。
  • [ ] http://localhost:3000/debug はエラーなしでロードされ、4つのセクションすべてを表示します。
  • [ ] 更新ボタンは、4つのAPI呼び出しすべてを並行してトリガーします。
  • [ ] ページネーションコントロールは、limit/offsetを正しく更新します。
  • [ ] データベースフィルター(ソース、日付範囲)は、データを更新してリフレッシュします。
  • [ ] バックエンドが起動したばかりの場合、起動タイムラインはゼロ以外のフェーズ期間を示します。

今後の機能拡張

  • SSEを介したストリーミング起動メトリクス(起動中のライブテール)
  • 時間経過に伴うパフォーマンストラッキングのために、起動レポートをJSON/CSVとしてエクスポートします。
  • 自動ドリフトアラート(宙ぶらりんが閾値を超えた場合にSlack/メールに投稿)
  • パフォーマンスグラフ(起動時間のトレンド、アーティクルのスループット)
  • オンデマンド同期アクション(欠落しているアーティクルのベクターストアリフレッシュを強制するボタン)
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

Storage Debug Instrumentation

Purpose

Enable rapid diagnosis of storage state, synchronization health, and backend performance bottlenecks by exposing:

  • Raw article inspection from both PostgreSQL and ChromaDB
  • Storage drift detection (missing/dangling entries)
  • Detailed startup timeline breakdown (DB init, cache preload, vector store, RSS refresh)
  • One-page debug dashboard consolidating all diagnostics

Scope

  • Backend: app/services/startup_metrics.py, app/main.py, app/vector_store.py, app/database.py, app/api/routes/debug.py
  • Frontend: frontend/lib/api.ts, frontend/app/debug/page.tsx
  • No schema changes; purely additive instrumentation and debug routes

Workflow

1. Create startup metrics service

File: backend/app/services/startup_metrics.py

  • Implement thread-safe StartupMetrics class to record phase timings
  • Expose record_event(name, started_at, detail, metadata) for phase capture
  • Support add_note(key, value) for arbitrary annotations
  • Export singleton startup_metrics for app-wide use

2. Instrument vector store initialization

File: backend/app/vector_store.py

  • Import startup_metrics
  • In VectorStore.__init__(), wrap initialization with time.time() timer
  • Record event with metadata: host, port, collection, documents
  • Catch connection errors and annotate them

3. Instrument FastAPI startup sequence

File: backend/app/main.py

  • Call startup_metrics.mark_app_started() at beginning of on_startup()
  • Wrap each phase (DB init, schedulers, cache preload, RSS refresh, migration) with record_event()
  • Include metadata: cache_size, article_count, oldest_article_hours
  • Call startup_metrics.mark_app_completed() at end
  • Add app version notes via add_note()

4. Add database pagination helpers

File: backend/app/database.py

  • Implement fetch_articles_page() to support:
    • Limit/offset pagination
    • Optional source filter
    • Missing-embeddings-only flag
    • Published date range filters
    • Sort direction (asc/desc)
    • Return oldest/newest timestamp bounds
  • Implement fetch_article_chroma_mappings() to return all article→chroma ID mappings for drift analysis

5. Add vector store pagination helpers

File: backend/app/vector_store.py

  • Implement list_articles(limit, offset) to return paginated Chroma documents with metadata and previews
  • Implement list_all_ids() to return all stored Chroma IDs for drift detection (used by /debug/storage/drift)

6. Expose debug API endpoints

File: backend/app/api/routes/debug.py

  • Add GET /debug/startup → returns startup metrics timeline (events + notes)
  • Add GET /debug/chromadb/articles → returns paginated raw Chroma entries with limit/offset
  • Add GET /debug/database/articles → returns paginated Postgres rows with filters (source, embeddings, date range, sort)
  • Add GET /debug/storage/drift → compares Chroma IDs vs Postgres mappings, returns missing/dangling counts + samples

7. Add frontend API bindings

File: frontend/lib/api.ts

  • Export types: StartupEventMetric, StartupMetricsResponse, ChromaDebugResponse, DatabaseDebugResponse, StorageDriftReport
  • Export fetchers: fetchStartupMetrics(), fetchChromaDebugArticles(), fetchDatabaseDebugArticles(), fetchStorageDrift()
  • Ensure snake_case→camelCase mapping for response fields

8. Build debug dashboard page

File: frontend/app/debug/page.tsx

  • Create /debug route with multi-tab inspection UI
  • Render startup timeline: phase name, duration, metadata badges (cache size, vectors, migrated records)
  • Display Chroma browser: paginated table with ID, title, source, preview
  • Display Postgres browser: paginated table with filters (source, date range, missing-embeddings-only flag)
  • Display drift report: sample tables for missing-in-chroma and dangling-in-chroma entries
  • Include summary cards for quick metrics (boot time, total articles, vector count, drift count)

Implementation checklist

  • [ ] Create backend/app/services/startup_metrics.py
  • [ ] Instrument backend/app/vector_store.py::VectorStore.__init__()
  • [ ] Instrument backend/app/main.py::on_startup() (all phases)
  • [ ] Add fetch_articles_page() and fetch_article_chroma_mappings() to backend/app/database.py
  • [ ] Add list_articles() and list_all_ids() to backend/app/vector_store.py
  • [ ] Add /debug/startup, /debug/chromadb/articles, /debug/database/articles, /debug/storage/drift to backend/app/api/routes/debug.py
  • [ ] Add types and fetchers to frontend/lib/api.ts
  • [ ] Create frontend/app/debug/page.tsx with dashboard layout
  • [ ] Run uvx ruff check backend → all checks pass
  • [ ] Test endpoints in curl or Postman to verify response structure

Verification checklist

  • [ ] GET http://localhost:8000/debug/startup returns valid timeline with events and notes
  • [ ] GET http://localhost:8000/debug/chromadb/articles?limit=50&offset=0 returns paginated Chroma docs
  • [ ] GET http://localhost:8000/debug/database/articles?source=bbc&missing_embeddings_only=false filters correctly
  • [ ] GET http://localhost:8000/debug/storage/drift compares counts and returns drift samples
  • [ ] http://localhost:3000/debug loads without errors and displays all four sections
  • [ ] Refresh button triggers all four API calls in parallel
  • [ ] Pagination controls update limit/offset correctly
  • [ ] Database filters (source, date range) update and refresh data
  • [ ] Startup timeline shows non-zero phase durations if backend just started

Future enhancements

  • Streaming startup metrics via SSE (live tail during boot)
  • Export startup report as JSON/CSV for performance tracking over time
  • Automated drift alerts (post to Slack/email if dangling > threshold)
  • Performance graphs (startup time trends, article throughput)
  • Sync-on-demand action (button to force vector store refresh for missing articles)