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 Dec 18, 2024
2 parents 6f134f4 + 5c42fb3 commit c87e03c
Show file tree
Hide file tree
Showing 20 changed files with 544 additions and 137 deletions.
29 changes: 14 additions & 15 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
runs-on: ubuntu-24.04
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
27 changes: 20 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
jobs:
build:
name: build
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -46,9 +46,22 @@ jobs:
gzip dist/*
- name: Release
run: |
ghr -t "${{ secrets.GITHUB_TOKEN }}" \
-u "${{ github.repository_owner }}" \
-r "sora_exporter" \
-n "${{ github.ref }}" \
--replace "${GITHUB_REF##*/}" \
dist/
VERSION=$(git describe --tag --abbrev=0)
if [[ "${VERSION}" == *"canary"* ]]; then
ghr -t "${{ secrets.GITHUB_TOKEN }}" \
-u "${{ github.repository_owner }}" \
-r "sora_exporter" \
-n "${VERSION}" \
-replace \
-prerelease \
"${GITHUB_REF##*/}" \
dist/
else
ghr -t "${{ secrets.GITHUB_TOKEN }}" \
-u "${{ github.repository_owner }}" \
-r "sora_exporter" \
-n "${VERSION}" \
-replace \
"${GITHUB_REF##*/}" \
dist/
fi
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

build:
name: go test
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4

Expand Down
74 changes: 73 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,77 @@
# CHANGES
# 変更履歴

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

## 2024.7.0

**リリース日**: 2024-12-18

- [CHANGE] クラスターメトリクスを収集する際の `ListClusterNodes` API の呼び出し時にリクエストパラメータの指定を削除する
- 破壊的変更になるため、バージョンアップの際に注意してください
- Sora 2024.2.0 での `include_all_known_nodes` パラメータ廃止への対応です
- Sora 2023.2 以前と Sora 2024.1 以降で、exporter が返すメトリクスの結果が変わります
- @tnamao
- [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.5
- prometheus/common 0.54.0 => 0.61.0
- prometheus/exporter-toolkit 0.11.0 => 0.13.2
- `prometheus/exporter-toolkit` のログライブラリ切り替えにより `go-kit/log` への依存はなくなりました
- @tnamao
- [UPDATE] Go を 1.23 に上げる
- @tnamao

### misc

- [CHANGE] GitHub Actions の ubuntu-latest を ubuntu-24.04 に変更する
- @voluntas
- [UPDATE] Github Actions のイメージを更新する
- actions/setup-go v4 => v5
- dominikh/staticcheck-action v1.3.0 => v1.3.1
- @tnamao
- [UPDATE] CI で実行する staticcheck のバージョンを更新する
- 2023.1.6 => 2024.1.1
- @tnamao
- [ADD] CI のリリースに canary リリースの対応を追加する
- @tnamao

## 2024.6.0

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

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

## 2024.5.0

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

- [ADD] Sora の Stats Webhook の統計情報に対応する
- `sora_stats_webhook_total` メトリクスを追加し、ラベルに `successful` `failed` を設ける
- @tnamao
Expand Down
50 changes: 21 additions & 29 deletions collector/collector.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package collector

import (
"bytes"
"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 +19,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 +35,8 @@ type Collector struct {

ConnectionMetrics
WebhookMetrics
SrtpMetrics
SctpMetrics
ClientMetrics
SoraConnectionErrorMetrics
ErlangVMMetrics
Expand All @@ -49,7 +49,7 @@ type CollectorOptions struct {
SkipSslVerify bool
Timeout time.Duration
FreezeTimeSeconds bool
Logger log.Logger
Logger *slog.Logger
EnableSoraClientMetrics bool
EnableSoraConnectionErrorMetrics bool
EnableErlangVMMetrics bool
Expand All @@ -60,10 +60,6 @@ type HTTPClient interface {
Do(*http.Request) (*http.Response, error)
}

type SoraListClusterNodesRequest struct {
IncludeAllKnownNodes bool `json:"include_all_known_nodes"`
}

func NewCollector(options *CollectorOptions) *Collector {
return &Collector{
URI: options.URI,
Expand All @@ -86,6 +82,8 @@ func NewCollector(options *CollectorOptions) *Collector {

ConnectionMetrics: connectionMetrics,
WebhookMetrics: webhookMetrics,
SrtpMetrics: srtpMetrics,
SctpMetrics: sctpMetrics,
ClientMetrics: clientMetrics,
SoraConnectionErrorMetrics: soraConnectionErrorMetrics,
ErlangVMMetrics: erlangVMMetrics,
Expand All @@ -103,7 +101,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,73 +115,63 @@ 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
}

var nodeList []soraClusterNode
if c.EnableSoraClusterMetrics {
requestParams := SoraListClusterNodesRequest{
IncludeAllKnownNodes: true,
}
encodedParams, err := json.Marshal(requestParams)
if err != nil {
level.Error(c.logger).Log("msg", "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))
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.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 +189,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 +213,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))
}
Loading

0 comments on commit c87e03c

Please sign in to comment.