最後のメトリクスを取得するAPIを実装する#24
Conversation
fix nil check few change
23b93c2 to
9b42f6d
Compare
There was a problem hiding this comment.
Pull request overview
logreport に Unix Domain Socket 経由の内部 API を追加し、直近のメトリクス(キー一覧 / 値)をリアルタイム取得できるようにする PR です。設定で API を有効化し、集計処理から API 用の「最後のメトリクス」を更新します。
Changes:
internal/apiに/keysと/metricsを提供する API サーバー実装を追加- 設定 (
API.Enabled,API.SocketPath) とドキュメント/サンプル設定を追加 cmd/logreportでソケット listen・サーバ起動・メトリクス更新の呼び出しを追加
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/api/api.go | 内部 API サーバーと last metrics 保持・取得ロジックを追加 |
| cmd/logreport/main.go | API サーバー起動(UDS)と集計結果の API 反映処理を追加 |
| config.go | API 設定項目(Enabled/SocketPath)を追加 |
| cmd/logreport/config.sample.yaml | API 設定例を追加 |
| README.md | 内部 API の利用方法を追記 |
| go.mod / go.sum | golang.org/x/sync を追加 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
logreport に Unix Domain Socket 経由の内部 API を追加し、最新のメトリクス値をリアルタイムに取得できるようにする PR です(/keys, /metrics)。
Changes:
internal/apiに最新メトリクスを保持し提供する HTTP API を新規追加- 設定 (
API.Enabled,API.SocketPath) を追加し、起動時に UDS で API サーバを立ち上げ - サンプル設定と README に内部 API の利用方法を追記
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/api/api.go | 最新メトリクスの保持と /keys /metrics 提供を追加 |
| cmd/logreport/main.go | API サーバ起動(UDS)と集計ループからの最新メトリクス反映を追加 |
| config.go | API 設定項目(Enabled/SocketPath)を追加 |
| cmd/logreport/config.sample.yaml | API 設定のサンプルを追加 |
| README.md | 内部 API の設定例と curl 例を追記 |
| go.mod / go.sum | golang.org/x/sync(singleflight)を追加 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
このPRのBodyはRooCode+AI Engine+Qwen3-Coder-480B-A35B-Instruct-FP8にて生成しました。
PR概要
logreportに内部API機能を追加し、リアルタイムでのメトリックデータ取得を可能にしました。設定により有効化でき、Unix Domain Socketを使用して通信します。
変更内容の詳細説明
APIサーバーの起動処理:
メトリックデータの更新処理:
メトリックデータの保存構造:
使用方法
APIエンドポイント
キー一覧の取得
利用可能なメトリックキーの一覧を取得します。
レスポンス例:
メトリックの取得
指定されたキーのメトリック値を取得します。キーはカンマ区切りで複数指定可能です。
curl --unix-socket /var/run/logreport-api.sock http://localhost/metrics?keys=http.request,https.request,http.status.200,https.status.200レスポンス例:
{"http.request":5,"http.status.200":0,"https.request":5,"https.status.200":1,"time":"2026-03-16T21:29:42+09:00"}設定例
APIを有効化する最小限の設定例: