Prometheusメトリクス公開#39
Draft
yuu1111 wants to merge 5 commits into
Draft
Conversation
Bot/サーバー単位 + 日次で読み上げ文字数とメッセージ数をDBに集計記録する。 SQLite/MySQL双方でアトミックUPSERTにより同時書き込みでもロストしない。 - 新規テーブル tts_count_data (bot_id, server_id, target_date 単位) - TTSCountRecorder で読み上げ確定時に非同期記録 - Micrometer Prometheus レジストリで /metrics エンドポイント公開 (デフォルト 127.0.0.1:9095, 設定で無効化可) - /stat コマンド (today/week/all/server) で Bot 所有者向けに集計表示 - 起動時に DB 累計値を Counter に注入し再起動後も整合
- server_id = 0 をBot全体合計の予約値とし、server_id IS NULLの分岐を削除
unique制約とON CONFLICT/ON DUPLICATE KEY UPDATE単一クエリに統一しrace conditionを解消
- /stat week でメッセージ数も表示
- TTSCountData#getRecord を追加し、StatCommand での2重SELECTを解消
- 起動時のCounter累計注入を削除 (Prometheusのrate計算を狂わせるため)
- MetricsRegistry の getOrCreate{Char,Message}Counter を共通化
- DataRepositoryImpl の sum 系ボイラープレートをwithConnectionヘルパで集約
- botId解決を getBot().getBotId() に統一
- RELATIVE_TIME_FORMAT を BaseCommand に集約
- PrometheusHttpExposer に固定スレッドプールを設定し詰まりを回避
- MetricsRegistryをinterface化しPrometheus実装とNoOp実装を分離 メトリクス無効時もnon-nullになり呼び出し側のnullチェックを削除 - ITTSRuntimeUseにgetTTSCountRecorder/getMetricsRegistryのdefaultを追加 VoiceAudioSchedulerのITTSRuntime.getInstance()プルを既存パターンに統一 - ITTSRuntime#initMetricsを生成と起動に限定し、シャットダウンフック登録を registerShutdownHooksに分離
集計機能のマージ後に別PRで対応する方針のため、 Prometheus関連の実装を本PRから取り除く - core/metrics配下を削除 - MetricsConfigを削除 - ITTSRuntime/Use・Config・selfhost ConfigImplから参照を除去 - Micrometer依存を削除 - TTSCountRecorderはDB書き込みのみに簡略化
This reverts commit b994008.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
#38 (読み上げ文字数の集計) の後続PR。集計データをPrometheus
/metricsで外部公開する/metrics公開 (デフォルト127.0.0.1:9095、設定で無効化可)メトリクス例
itts_up,itts_uptime_secondsitts_spoken_chars_total{bot_id, server_id}itts_spoken_messages_total{bot_id, server_id}設定
config.json5のmetricsセクション:外部公開はリバプロ前提のオプトイン。
検証
./gradlew :core:compileJava./gradlew :core:checkstyleMain(warning 0)./gradlew :selfhost:shadowJarTest plan
metrics.enable: trueで起動 →curl http://127.0.0.1:9095/metricsでitts_spoken_chars_totalが出ることitts_spoken_chars_totalがDB累計から再開することmetrics.enable: falseでHTTPサーバーが起動しないこと留意点
/stat側で対応