Skip to content

Commit

Permalink
Merge branch 'release/2024.7.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
tnamao committed Sep 26, 2024
2 parents 6f134f4 + c7be741 commit 103c03d
Show file tree
Hide file tree
Showing 18 changed files with 505 additions and 110 deletions.
27 changes: 13 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,29 @@ name: Go Static Check
on:
push:
branches-ignore:
- 'main'
- "main"
tags-ignore:
- '*'
- "*"
paths:
- "**.go"

jobs:

build:
name: static-check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: "./go.mod"
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: "./go.mod"

- run: go version
- run: go version

- run: go fmt .
- run: go fmt .

- uses: dominikh/[email protected].0
with:
version: "2023.1.6"
install-go: false
- uses: dominikh/[email protected].1
with:
version: "2024.1.1"
install-go: false
63 changes: 62 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,66 @@
# CHANGES
# 変更履歴

- CHANGE
- 後方互換性のない変更
- UPDATE
- 後方互換性がある変更
- ADD
- 後方互換性がある追加
- FIX
- バグ修正

## 2024.7.0

**リリース日**: 2024-09-26

- [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))` を使用する形に変更する
- @tnamao
- [UPDATE] 依存パッケージを更新する
- prometheus/client_golang 1.19.1 => 1.20.4
- prometheus/common 0.54.0 => 0.59.1
- prometheus/exporter-toolkit 0.11.0 => 0.13.0
- `prometheus/exporter-toolkit` のログライブラリ切り替えにより `go-kit/log` への依存はなくなりました
- @tnamao
- [UPDATE] Go を 1.23 に上げる
- @tnamao

### misc

- [UPDATE] Github Actions のイメージを更新する
- actions/setup-go v4 => v5
- dominikh/staticcheck-action v1.3.0 => v1.3.1
- [UPDATE] CI で実行する staticcheck のバージョンを更新する
- 2023.1.6 => 2024.1.1

## 2024.6.0

**リリース日**: 2024-06-20

- [ADD] `sora_cluster_node` のメトリクスに `node_type` を追加する
- `regular` または `temporary` のいずれかが入ります
- @tnamao
Expand All @@ -16,6 +75,8 @@

## 2024.5.0

**リリース日**: 2024-06-05

- [ADD] Sora の Stats Webhook の統計情報に対応する
- `sora_stats_webhook_total` メトリクスを追加し、ラベルに `successful` `failed` を設ける
- @tnamao
Expand Down
35 changes: 21 additions & 14 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import (
"context"
"crypto/tls"
"encoding/json"
"log/slog"
"net/http"
"sync"
"time"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
)

Expand All @@ -21,7 +20,7 @@ var (

type Collector struct {
mutex sync.RWMutex
logger log.Logger
logger *slog.Logger
timeout time.Duration
URI string
skipSslVerify bool
Expand All @@ -37,6 +36,8 @@ type Collector struct {

ConnectionMetrics
WebhookMetrics
SrtpMetrics
SctpMetrics
ClientMetrics
SoraConnectionErrorMetrics
ErlangVMMetrics
Expand All @@ -49,7 +50,7 @@ type CollectorOptions struct {
SkipSslVerify bool
Timeout time.Duration
FreezeTimeSeconds bool
Logger log.Logger
Logger *slog.Logger
EnableSoraClientMetrics bool
EnableSoraConnectionErrorMetrics bool
EnableErlangVMMetrics bool
Expand Down Expand Up @@ -86,6 +87,8 @@ func NewCollector(options *CollectorOptions) *Collector {

ConnectionMetrics: connectionMetrics,
WebhookMetrics: webhookMetrics,
SrtpMetrics: srtpMetrics,
SctpMetrics: sctpMetrics,
ClientMetrics: clientMetrics,
SoraConnectionErrorMetrics: soraConnectionErrorMetrics,
ErlangVMMetrics: erlangVMMetrics,
Expand All @@ -103,7 +106,7 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {

req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.URI, nil)
if err != nil {
level.Error(c.logger).Log("msg", "failed to create request to sora", "err", err)
c.logger.Error("failed to create request to sora", "err", err)
ch <- newGauge(c.soraUp, 0)
return
}
Expand All @@ -117,15 +120,15 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {

resp, err := client.Do(req)
if err != nil {
level.Error(c.logger).Log("msg", "failed to request to Sora GetStatsReport API", "err", err)
c.logger.Error("failed to request to Sora GetStatsReport API", "err", err)
ch <- newGauge(c.soraUp, 0)
return
}
defer resp.Body.Close()

var report soraGetStatsReport
if err := json.NewDecoder(resp.Body).Decode(&report); err != nil {
level.Error(c.logger).Log("msg", "failed to decode response body from Sora GetStatsReport API", "err", err)
c.logger.Error("failed to decode response body from Sora GetStatsReport API", "err", err)
ch <- newGauge(c.soraUp, 0)
return
}
Expand All @@ -137,53 +140,53 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
}
encodedParams, err := json.Marshal(requestParams)
if err != nil {
level.Error(c.logger).Log("msg", "failed to encode Sora ListClusterNodes API request parameters", "err", err)
c.logger.Error("failed to encode Sora ListClusterNodes API request parameters", "err", err)
ch <- newGauge(c.soraUp, 0)
return
}

req, err = http.NewRequestWithContext(ctx, http.MethodPost, c.URI, bytes.NewBuffer(encodedParams))
if err != nil {
level.Error(c.logger).Log("msg", "failed to create request to sora", "err", err)
c.logger.Error("failed to create request to sora", "err", err.Error())
ch <- newGauge(c.soraUp, 0)
return
}
req.Header.Set("x-sora-target", "Sora_20211215.ListClusterNodes")

nodeResp, err := client.Do(req)
if err != nil {
level.Error(c.logger).Log("msg", "failed to request to Sora ListClusterNodes API", "err", err)
c.logger.Error("failed to request to Sora ListClusterNodes API", "err", err)
ch <- newGauge(c.soraUp, 0)
return
}
defer nodeResp.Body.Close()

if err := json.NewDecoder(nodeResp.Body).Decode(&nodeList); err != nil {
level.Error(c.logger).Log("msg", "failed to decode response body from Sora ListClusterNodes API", "err", err)
c.logger.Error("failed to decode response body from Sora ListClusterNodes API", "err", err)
ch <- newGauge(c.soraUp, 0)
return
}
}

req, err = http.NewRequestWithContext(ctx, http.MethodPost, c.URI, nil)
if err != nil {
level.Error(c.logger).Log("msg", "failed to create request to sora", "err", err)
c.logger.Error("failed to create request to sora", "err", err)
ch <- newGauge(c.soraUp, 0)
return
}
req.Header.Set("x-sora-target", "Sora_20171218.GetLicense")

licenseResp, err := client.Do(req)
if err != nil {
level.Error(c.logger).Log("msg", "failed to request to Sora GetLicense API", "err", err)
c.logger.Error("failed to request to Sora GetLicense API", "err", err)
ch <- newGauge(c.soraUp, 0)
return
}
defer licenseResp.Body.Close()

var licenseInfo soraLicenseInfo
if err := json.NewDecoder(licenseResp.Body).Decode(&licenseInfo); err != nil {
level.Error(c.logger).Log("msg", "failed to decode response body from Sora GetLicense API", "err", err)
c.logger.Error("failed to decode response body from Sora GetLicense API", "err", err)
ch <- newGauge(c.soraUp, 0)
return
}
Expand All @@ -201,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 @@ -223,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))
}
Loading

0 comments on commit 103c03d

Please sign in to comment.