Skip to content

Commit

Permalink
Merge pull request #45 from shiguredo/feature/sora-2024-2
Browse files Browse the repository at this point in the history
Sora 2024.2 で追加予定の統計情報に対応する
  • Loading branch information
tnamao authored Sep 26, 2024
2 parents 559a4cd + c4f81a3 commit aa710cc
Show file tree
Hide file tree
Showing 13 changed files with 353 additions and 0 deletions.
23 changes: 23 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,29 @@

## develop

- [ADD] SRTP 統計情報を追加する
- Sora API の GetStatsReport API から取得可能な SRTP 統計情報を以下のメトリクス名で追加する
- `sora_srtp_received_packets_total`
- `sora_srtp_received_bytes_total`
- `sora_srtp_sent_packets_total`
- `sora_srtp_sent_bytes_total`
- `sora_srtp_decrypted_packets_total`
- `sora_srtp_decrypted_bytes_total`
- @tnamao
- [ADD] SCTP 統計情報を追加する
- Sora API の GetStatsReport API から取得可能な SCTP 統計情報を以下のメトリクス名で追加する
- `sora_sctp_received_packets_total`
- `sora_sctp_received_bytes_total`
- `sora_sctp_sent_packets_total`
- `sora_sctp_sent_bytes_total`
- @tnamao
- [ADD] 無視されたウェブフック数の統計情報を追加する
- Sora API の GetStatsReport API から取得可能な無視されたウェブフック数を以下のメトリクス名で追加する
- 既存の以下のメトリクスの `state` ラベルに `ignored` で値を返す
- `sora_event_webhook_total`
- `sora_session_webhook_total`
- `sora_stats_webhook_total`
- @tnamao
- [CHANGE] ログライブラリの変更
- `prometheus/exporter-toolkit` の依存ログライブラリが `go-kit/log` から Go 言語標準ライブラリの `log/slog` に変更されたため、Sora expoter 内で使用しているロガーも `log/slog` に切り替える
- 同様にテストコードで使用していた `NewNopLogger` は代替として `slog.New(slog.NewTextHandler(io.Discard, nil))` を使用する形に変更する
Expand Down
8 changes: 8 additions & 0 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type Collector struct {

ConnectionMetrics
WebhookMetrics
SrtpMetrics
SctpMetrics
ClientMetrics
SoraConnectionErrorMetrics
ErlangVMMetrics
Expand Down Expand Up @@ -85,6 +87,8 @@ func NewCollector(options *CollectorOptions) *Collector {

ConnectionMetrics: connectionMetrics,
WebhookMetrics: webhookMetrics,
SrtpMetrics: srtpMetrics,
SctpMetrics: sctpMetrics,
ClientMetrics: clientMetrics,
SoraConnectionErrorMetrics: soraConnectionErrorMetrics,
ErlangVMMetrics: erlangVMMetrics,
Expand Down Expand Up @@ -200,6 +204,8 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
c.LicenseMetrics.Collect(ch, licenseInfo)
c.ConnectionMetrics.Collect(ch, report.soraConnectionReport)
c.WebhookMetrics.Collect(ch, report.soraWebhookReport)
c.SrtpMetrics.Collect(ch, report.soraSrtpReport)
c.SctpMetrics.Collect(ch, report.soraSctpReport)

if c.enableSoraClientMetrics {
c.ClientMetrics.Collect(ch, report.SoraClientReport)
Expand All @@ -222,6 +228,8 @@ func (c *Collector) Describe(ch chan<- *prometheus.Desc) {
c.LicenseMetrics.Describe(ch)
c.ConnectionMetrics.Describe(ch)
c.WebhookMetrics.Describe(ch)
c.SrtpMetrics.Describe(ch)
c.SctpMetrics.Describe(ch)

if c.enableSoraClientMetrics {
c.ClientMetrics.Describe(ch)
Expand Down
33 changes: 33 additions & 0 deletions collector/sctp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package collector

import "github.com/prometheus/client_golang/prometheus"

var (
sctpMetrics = SctpMetrics{
totalReceivedSctp: newDesc("sctp_received_packets_total", "The total number of received SCTP packets."),
totalReceivedSctpByteSize: newDesc("sctp_received_bytes_total", "The total number of received SCTP bytes."),
totalSentSctp: newDesc("sctp_sent_packets_total", "The total number of sent SCTP packets."),
totalSentSctpByteSize: newDesc("sctp_sent_bytes_total", "The total number of sent SCTP bytes."),
}
)

type SctpMetrics struct {
totalReceivedSctp *prometheus.Desc
totalReceivedSctpByteSize *prometheus.Desc
totalSentSctp *prometheus.Desc
totalSentSctpByteSize *prometheus.Desc
}

func (m *SctpMetrics) Describe(ch chan<- *prometheus.Desc) {
ch <- m.totalReceivedSctp
ch <- m.totalReceivedSctpByteSize
ch <- m.totalSentSctp
ch <- m.totalSentSctpByteSize
}

func (m *SctpMetrics) Collect(ch chan<- prometheus.Metric, report soraSctpReport) {
ch <- newCounter(m.totalReceivedSctp, float64(report.TotalReceivedSctp))
ch <- newCounter(m.totalReceivedSctpByteSize, float64(report.TotalReceivedSctpByteSize))
ch <- newCounter(m.totalSentSctp, float64(report.TotalSentSctp))
ch <- newCounter(m.totalSentSctpByteSize, float64(report.TotalSentSctpByteSize))
}
21 changes: 21 additions & 0 deletions collector/sora_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ type soraGetStatsReport struct {
SoraVersion string `json:"version"`
soraConnectionReport
soraWebhookReport
soraSrtpReport
soraSctpReport
SoraClientReport soraClientReport `json:"sora_client,omitempty"`
SoraConnectionErrorReport soraConnectionErrorReport `json:"error,omitempty"`
ErlangVMReport erlangVMReport `json:"erlang_vm,omitempty"`
Expand Down Expand Up @@ -35,10 +37,29 @@ type soraWebhookReport struct {
TotalFailedAuthWebhook int64 `json:"total_failed_auth_webhook"`
TotalSuccessfulSessionWebhook int64 `json:"total_successful_session_webhook"`
TotalFailedSessionWebhook int64 `json:"total_failed_session_webhook"`
TotalIgnoredSessionWebhook int64 `json:"total_ignored_session_webhook"`
TotalSuccessfulEventWebhook int64 `json:"total_successful_event_webhook"`
TotalFailedEventWebhook int64 `json:"total_failed_event_webhook"`
TotalIgnoredEventWebhook int64 `json:"total_ignored_event_webhook"`
TotalSuccessfulStatsWebhook int64 `json:"total_successful_stats_webhook"`
TotalFailedStatsWebhook int64 `json:"total_failed_stats_webhook"`
TotalIgnoredStatsWebhook int64 `json:"total_ignored_stats_webhook"`
}

type soraSrtpReport struct {
TotalReceivedSrtp int64 `json:"total_received_srtp"`
TotalReceivedSrtpByteSize int64 `json:"total_received_srtp_byte_size"`
TotalSentSrtp int64 `json:"total_sent_srtp"`
TotalSentSrtpByteSize int64 `json:"total_sent_srtp_byte_size"`
TotalDecryptedSrtp int64 `json:"total_decrypted_srtp"`
TotalDecryptedSrtpByteSize int64 `json:"total_decrypted_srtp_byte_size"`
}

type soraSctpReport struct {
TotalReceivedSctp int64 `json:"total_received_sctp"`
TotalReceivedSctpByteSize int64 `json:"total_received_sctp_byte_size"`
TotalSentSctp int64 `json:"total_sent_sctp"`
TotalSentSctpByteSize int64 `json:"total_sent_sctp_byte_size"`
}

type soraClientStatistics struct {
Expand Down
41 changes: 41 additions & 0 deletions collector/srtp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package collector

import "github.com/prometheus/client_golang/prometheus"

var (
srtpMetrics = SrtpMetrics{
totalReceivedSrtp: newDesc("srtp_received_packets_total", "The total number of received SRTP packets."),
totalReceivedSrtpByteSize: newDesc("srtp_received_bytes_total", "The total number of received SRTP bytes."),
totalSentSrtp: newDesc("srtp_sent_packets_total", "The total number of sent SRTP packets."),
totalSentSrtpByteSize: newDesc("srtp_sent_bytes_total", "The total number of sent SRTP bytes."),
totalDecryptedSrtp: newDesc("srtp_decrypted_packets_total", "The total number of decrpyted SRTP packets."),
totalDecryptedSrtpByteSize: newDesc("srtp_decrpyted_bytes_total", "The total number of decrypted SRTP bytes."),
}
)

type SrtpMetrics struct {
totalReceivedSrtp *prometheus.Desc
totalReceivedSrtpByteSize *prometheus.Desc
totalSentSrtp *prometheus.Desc
totalSentSrtpByteSize *prometheus.Desc
totalDecryptedSrtp *prometheus.Desc
totalDecryptedSrtpByteSize *prometheus.Desc
}

func (m *SrtpMetrics) Describe(ch chan<- *prometheus.Desc) {
ch <- m.totalReceivedSrtp
ch <- m.totalReceivedSrtpByteSize
ch <- m.totalSentSrtp
ch <- m.totalSentSrtpByteSize
ch <- m.totalDecryptedSrtp
ch <- m.totalDecryptedSrtpByteSize
}

func (m *SrtpMetrics) Collect(ch chan<- prometheus.Metric, report soraSrtpReport) {
ch <- newCounter(m.totalReceivedSrtp, float64(report.TotalReceivedSrtp))
ch <- newCounter(m.totalReceivedSrtpByteSize, float64(report.TotalReceivedSrtpByteSize))
ch <- newCounter(m.totalSentSrtp, float64(report.TotalSentSrtp))
ch <- newCounter(m.totalSentSrtpByteSize, float64(report.TotalSentSrtpByteSize))
ch <- newCounter(m.totalDecryptedSrtp, float64(report.TotalDecryptedSrtp))
ch <- newCounter(m.totalDecryptedSrtpByteSize, float64(report.TotalDecryptedSrtpByteSize))
}
3 changes: 3 additions & 0 deletions collector/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ func (m *WebhookMetrics) Collect(ch chan<- prometheus.Metric, report soraWebhook
ch <- newCounter(m.totalAuthWebhook, float64(report.TotalFailedAuthWebhook), "failed")
ch <- newCounter(m.totalSessionWebhook, float64(report.TotalSuccessfulSessionWebhook), "successful")
ch <- newCounter(m.totalSessionWebhook, float64(report.TotalFailedSessionWebhook), "failed")
ch <- newCounter(m.totalSessionWebhook, float64(report.TotalIgnoredSessionWebhook), "ignored")
ch <- newCounter(m.totalEventWebhook, float64(report.TotalSuccessfulEventWebhook), "successful")
ch <- newCounter(m.totalEventWebhook, float64(report.TotalFailedEventWebhook), "failed")
ch <- newCounter(m.totalEventWebhook, float64(report.TotalIgnoredEventWebhook), "ignored")
ch <- newCounter(m.totalStatsWebhook, float64(report.TotalSuccessfulStatsWebhook), "successful")
ch <- newCounter(m.totalStatsWebhook, float64(report.TotalFailedStatsWebhook), "failed")
ch <- newCounter(m.totalStatsWebhook, float64(report.TotalIgnoredStatsWebhook), "ignored")
}
26 changes: 26 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,21 +149,34 @@ var (
"total_connection_created": 2,
"total_connection_destroyed": 2,
"total_connection_updated": 23,
"total_decrypted_srtp": 104,
"total_decrypted_srtp_byte_size": 105,
"total_duration_sec": 1412,
"total_failed_auth_webhook": 93,
"total_failed_connections": 0,
"total_failed_event_webhook": 94,
"total_failed_session_webhook": 95,
"total_failed_stats_webhook": 99,
"total_ignored_event_webhook": 101,
"total_ignored_session_webhook": 102,
"total_ignored_stats_webhook": 103,
"total_ongoing_connections": 0,
"total_received_invalid_turn_tcp_packet": 0,
"total_sent_sctp": 110,
"total_sent_sctp_byte_size": 111,
"total_sent_srtp": 106,
"total_sent_srtp_byte_size": 107,
"total_session_created": 1,
"total_session_destroyed": 0,
"total_successful_auth_webhook": 96,
"total_successful_connections": 2,
"total_successful_event_webhook": 97,
"total_successful_session_webhook": 98,
"total_successful_stats_webhook": 100,
"total_received_sctp": 112,
"total_received_sctp_byte_size": 113,
"total_received_srtp": 108,
"total_received_srtp_byte_size": 109,
"total_turn_tcp_connections": 2,
"total_turn_udp_connections": 0,
"version": "2022.1.0-canary.28"
Expand Down Expand Up @@ -405,21 +418,34 @@ func TestMinimumMetrics(t *testing.T) {
"total_connection_created": 3,
"total_connection_destroyed": 2,
"total_connection_updated": 23,
"total_decrypted_srtp": 104,
"total_decrypted_srtp_byte_size": 105,
"total_duration_sec": 1412,
"total_failed_auth_webhook": 93,
"total_failed_connections": 100,
"total_failed_event_webhook": 94,
"total_failed_session_webhook": 95,
"total_failed_stats_webhook": 99,
"total_ignored_event_webhook": 101,
"total_ignored_session_webhook": 102,
"total_ignored_stats_webhook": 103,
"total_ongoing_connections": 88,
"total_received_invalid_turn_tcp_packet": 123,
"total_sent_sctp": 110,
"total_sent_sctp_byte_size": 111,
"total_sent_srtp": 106,
"total_sent_srtp_byte_size": 107,
"total_session_created": 111,
"total_session_destroyed": 222,
"total_successful_auth_webhook": 96,
"total_successful_connections": 333,
"total_successful_event_webhook": 97,
"total_successful_session_webhook": 98,
"total_successful_stats_webhook": 100,
"total_received_sctp": 112,
"total_received_sctp_byte_size": 113,
"total_received_srtp": 108,
"total_received_srtp_byte_size": 109,
"total_turn_tcp_connections": 444,
"total_turn_udp_connections": 555,
"version": "2022.1.0-canary.28"
Expand Down
33 changes: 33 additions & 0 deletions test/maximum.metrics
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ sora_erlang_vm_wall_clock_wallclock_time_since_last_call 9090
# HELP sora_event_webhook_total The total number of event webhook.
# TYPE sora_event_webhook_total counter
sora_event_webhook_total{state="failed"} 94
sora_event_webhook_total{state="ignored"} 101
sora_event_webhook_total{state="successful"} 97
# HELP sora_license_expired_at_timestamp_seconds sora license file's expire seconds since epoch.
# TYPE sora_license_expired_at_timestamp_seconds gauge
Expand All @@ -187,13 +188,45 @@ sora_received_invalid_turn_tcp_packet_total 0
# TYPE sora_session_total counter
sora_session_total{state="created"} 1
sora_session_total{state="destroyed"} 0
# HELP sora_sctp_received_bytes_total The total number of received SCTP bytes.
# TYPE sora_sctp_received_bytes_total counter
sora_sctp_received_bytes_total 113
# HELP sora_sctp_received_packets_total The total number of received SCTP packets.
# TYPE sora_sctp_received_packets_total counter
sora_sctp_received_packets_total 112
# HELP sora_sctp_sent_bytes_total The total number of sent SCTP bytes.
# TYPE sora_sctp_sent_bytes_total counter
sora_sctp_sent_bytes_total 111
# HELP sora_sctp_sent_packets_total The total number of sent SCTP packets.
# TYPE sora_sctp_sent_packets_total counter
sora_sctp_sent_packets_total 110
# HELP sora_session_webhook_total The total number of session webhook.
# TYPE sora_session_webhook_total counter
sora_session_webhook_total{state="failed"} 95
sora_session_webhook_total{state="ignored"} 102
sora_session_webhook_total{state="successful"} 98
# HELP sora_srtp_decrpyted_bytes_total The total number of decrypted SRTP bytes.
# TYPE sora_srtp_decrpyted_bytes_total counter
sora_srtp_decrpyted_bytes_total 105
# HELP sora_srtp_decrypted_packets_total The total number of decrpyted SRTP packets.
# TYPE sora_srtp_decrypted_packets_total counter
sora_srtp_decrypted_packets_total 104
# HELP sora_srtp_received_bytes_total The total number of received SRTP bytes.
# TYPE sora_srtp_received_bytes_total counter
sora_srtp_received_bytes_total 109
# HELP sora_srtp_received_packets_total The total number of received SRTP packets.
# TYPE sora_srtp_received_packets_total counter
sora_srtp_received_packets_total 108
# HELP sora_srtp_sent_bytes_total The total number of sent SRTP bytes.
# TYPE sora_srtp_sent_bytes_total counter
sora_srtp_sent_bytes_total 107
# HELP sora_srtp_sent_packets_total The total number of sent SRTP packets.
# TYPE sora_srtp_sent_packets_total counter
sora_srtp_sent_packets_total 106
# HELP sora_stats_webhook_total The total number of stats webhook.
# TYPE sora_stats_webhook_total counter
sora_stats_webhook_total{state="failed"} 99
sora_stats_webhook_total{state="ignored"} 103
sora_stats_webhook_total{state="successful"} 100
# HELP sora_successful_auth_webhook_total The total number of successful auth webhook.
# TYPE sora_successful_auth_webhook_total counter
Expand Down
33 changes: 33 additions & 0 deletions test/minimum.metrics
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ sora_duration_seconds_total 1412
# HELP sora_event_webhook_total The total number of event webhook.
# TYPE sora_event_webhook_total counter
sora_event_webhook_total{state="failed"} 94
sora_event_webhook_total{state="ignored"} 101
sora_event_webhook_total{state="successful"} 97
# HELP sora_license_expired_at_timestamp_seconds sora license file's expire seconds since epoch.
# TYPE sora_license_expired_at_timestamp_seconds gauge
Expand All @@ -41,13 +42,45 @@ sora_received_invalid_turn_tcp_packet_total 123
# TYPE sora_session_total counter
sora_session_total{state="created"} 111
sora_session_total{state="destroyed"} 222
# HELP sora_sctp_received_bytes_total The total number of received SCTP bytes.
# TYPE sora_sctp_received_bytes_total counter
sora_sctp_received_bytes_total 113
# HELP sora_sctp_received_packets_total The total number of received SCTP packets.
# TYPE sora_sctp_received_packets_total counter
sora_sctp_received_packets_total 112
# HELP sora_sctp_sent_bytes_total The total number of sent SCTP bytes.
# TYPE sora_sctp_sent_bytes_total counter
sora_sctp_sent_bytes_total 111
# HELP sora_sctp_sent_packets_total The total number of sent SCTP packets.
# TYPE sora_sctp_sent_packets_total counter
sora_sctp_sent_packets_total 110
# HELP sora_session_webhook_total The total number of session webhook.
# TYPE sora_session_webhook_total counter
sora_session_webhook_total{state="failed"} 95
sora_session_webhook_total{state="ignored"} 102
sora_session_webhook_total{state="successful"} 98
# HELP sora_srtp_decrpyted_bytes_total The total number of decrypted SRTP bytes.
# TYPE sora_srtp_decrpyted_bytes_total counter
sora_srtp_decrpyted_bytes_total 105
# HELP sora_srtp_decrypted_packets_total The total number of decrpyted SRTP packets.
# TYPE sora_srtp_decrypted_packets_total counter
sora_srtp_decrypted_packets_total 104
# HELP sora_srtp_received_bytes_total The total number of received SRTP bytes.
# TYPE sora_srtp_received_bytes_total counter
sora_srtp_received_bytes_total 109
# HELP sora_srtp_received_packets_total The total number of received SRTP packets.
# TYPE sora_srtp_received_packets_total counter
sora_srtp_received_packets_total 108
# HELP sora_srtp_sent_bytes_total The total number of sent SRTP bytes.
# TYPE sora_srtp_sent_bytes_total counter
sora_srtp_sent_bytes_total 107
# HELP sora_srtp_sent_packets_total The total number of sent SRTP packets.
# TYPE sora_srtp_sent_packets_total counter
sora_srtp_sent_packets_total 106
# HELP sora_stats_webhook_total The total number of stats webhook.
# TYPE sora_stats_webhook_total counter
sora_stats_webhook_total{state="failed"} 99
sora_stats_webhook_total{state="ignored"} 103
sora_stats_webhook_total{state="successful"} 100
# HELP sora_successful_auth_webhook_total The total number of successful auth webhook.
# TYPE sora_successful_auth_webhook_total counter
Expand Down
Loading

0 comments on commit aa710cc

Please sign in to comment.