Skip to content

Commit

Permalink
Merge pull request #42 from shiguredo/feature/temporary-node-label
Browse files Browse the repository at this point in the history
メトリクスのテンポラリーノード対応
  • Loading branch information
tnamao authored Jun 20, 2024
2 parents 94c0eb4 + b506ad0 commit f3c1051
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGES

## develop

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

## 2024.5.0

- [ADD] Sora の Stats Webhook の統計情報に対応する
Expand Down
12 changes: 9 additions & 3 deletions collector/cluster_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

var (
soraClusterMetrics = SoraClusterMetrics{
clusterNode: newDescWithLabel("cluster_node", "The sora server known cluster node.", []string{"node_name", "mode"}),
clusterNode: newDescWithLabel("cluster_node", "The sora server known cluster node.", []string{"node_name", "mode", "node_type"}),
raftState: newDescWithLabel("cluster_raft_state", "The current Raft state. The state name is indicated by the label 'state'. The value of this metric is always set to 1.", []string{"state"}),
raftTerm: newDesc("cluster_raft_term", "The current Raft term."),
raftCommitIndex: newDesc("cluster_raft_commit_index", "The latest committed Raft log index."),
Expand Down Expand Up @@ -47,10 +47,16 @@ func (m *SoraClusterMetrics) Collect(ch chan<- prometheus.Metric, nodeList []sor
if node.Connected {
value = 1.0
}
// connected の状態によらず、基本の状態は regular
// temporary_node が true の場合だけ temporary になる
nodeType := "regular"
if node.TemporaryNode {
nodeType = "temporary"
}
if node.ClusterNodeName != "" {
ch <- newGauge(m.clusterNode, value, node.ClusterNodeName, node.Mode)
ch <- newGauge(m.clusterNode, value, node.ClusterNodeName, node.Mode, nodeType)
} else {
ch <- newGauge(m.clusterNode, value, node.NodeName, node.Mode)
ch <- newGauge(m.clusterNode, value, node.NodeName, node.Mode, nodeType)
}
}
ch <- newGauge(m.raftState, 1.0, report.RaftState)
Expand Down
1 change: 1 addition & 0 deletions collector/sora_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ type soraClusterNode struct {
NodeName string `json:"node_name"`
Mode string `json:"mode"`
Connected bool `json:"connected"`
TemporaryNode bool `json:"temporary_node"`
}

type soraClusterRelay struct {
Expand Down
12 changes: 8 additions & 4 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ var (
"license_max_connections": 100,
"license_serial_code": "SAMPLE-SRA-E001-202212-N10-100",
"license_type": "Experimental",
"connected": true
"connected": true,
"temporary_node": false
},
{
"node_name": "[email protected]",
Expand All @@ -198,7 +199,8 @@ var (
"license_max_connections": 100,
"license_serial_code": "SAMPLE-SRA-E001-202212-N10-100",
"license_type": "Experimental",
"connected": true
"connected": true,
"temporary_node": true
}
]`
listClusterNodesCurrentJSONData = `[
Expand All @@ -217,7 +219,8 @@ var (
"license_type": "Experimental",
"cluster_signaling_url": "ws://127.0.0.1:5002/signaling",
"cluster_api_url": "http://10.1.1.3:3000/",
"connected": true
"connected": true,
"temporary_node": false
},
{
"node_name": "[email protected]",
Expand All @@ -231,7 +234,8 @@ var (
"license_max_connections": 100,
"license_serial_code": "SAMPLE-SRA-E001-202212-N10-100",
"license_type": "Experimental",
"connected": true
"connected": true,
"temporary_node": true
}
]`
getLicenseJSONDATA = `{
Expand Down
6 changes: 3 additions & 3 deletions test/maximum.metrics
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ sora_average_duration_seconds 706
sora_average_setup_time_seconds 0
# HELP sora_cluster_node The sora server known cluster node.
# TYPE sora_cluster_node gauge
sora_cluster_node{mode="",node_name="[email protected]"} 0
sora_cluster_node{mode="block_new_connection",node_name="[email protected]"} 1
sora_cluster_node{mode="normal",node_name="[email protected]"} 1
sora_cluster_node{mode="",node_name="[email protected]",node_type="regular"} 0
sora_cluster_node{mode="block_new_connection",node_name="[email protected]",node_type="regular"} 1
sora_cluster_node{mode="normal",node_name="[email protected]",node_type="temporary"} 1
# HELP sora_cluster_raft_commit_index The latest committed Raft log index.
# TYPE sora_cluster_raft_commit_index counter
sora_cluster_raft_commit_index 10
Expand Down
6 changes: 3 additions & 3 deletions test/sora_cluster_metrics_enabled.metrics
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ sora_average_duration_seconds 706
sora_average_setup_time_seconds 0
# HELP sora_cluster_node The sora server known cluster node.
# TYPE sora_cluster_node gauge
sora_cluster_node{mode="normal",node_name="[email protected]"} 1
sora_cluster_node{mode="block_new_connection",node_name="[email protected]"} 1
sora_cluster_node{mode="",node_name="[email protected]"} 0
sora_cluster_node{mode="normal",node_name="[email protected]",node_type="temporary"} 1
sora_cluster_node{mode="block_new_connection",node_name="[email protected]",node_type="regular"} 1
sora_cluster_node{mode="",node_name="[email protected]",node_type="regular"} 0
# HELP sora_cluster_raft_commit_index The latest committed Raft log index.
# TYPE sora_cluster_raft_commit_index counter
sora_cluster_raft_commit_index 10
Expand Down

0 comments on commit f3c1051

Please sign in to comment.