diff --git a/CHANGES.md b/CHANGES.md index ede8629..322a0aa 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,11 @@ # CHANGES +## develop + +- [ADD] `sora_cluster_node` のメトリクスに `node_type` を追加する + - `regular` または `temporary` のいずれかが入ります + - @tnamao + ## 2024.5.0 - [ADD] Sora の Stats Webhook の統計情報に対応する diff --git a/collector/cluster_node.go b/collector/cluster_node.go index fb01b5e..3d28529 100644 --- a/collector/cluster_node.go +++ b/collector/cluster_node.go @@ -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."), @@ -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) diff --git a/collector/sora_api.go b/collector/sora_api.go index 2d30d28..7c8de64 100644 --- a/collector/sora_api.go +++ b/collector/sora_api.go @@ -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 { diff --git a/main_test.go b/main_test.go index 40c1b1e..2c3756f 100644 --- a/main_test.go +++ b/main_test.go @@ -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": "node-03_canary_sora@10.211.55.41", @@ -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 = `[ @@ -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": "node-03_canary_sora@10.211.55.41", @@ -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 = `{ diff --git a/test/maximum.metrics b/test/maximum.metrics index 1138339..602a210 100644 --- a/test/maximum.metrics +++ b/test/maximum.metrics @@ -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="node-01_canary_sora@10.211.55.42"} 0 -sora_cluster_node{mode="block_new_connection",node_name="node-02_canary_sora@10.211.55.40"} 1 -sora_cluster_node{mode="normal",node_name="node-03_canary_sora@10.211.55.41"} 1 +sora_cluster_node{mode="",node_name="node-01_canary_sora@10.211.55.42",node_type="regular"} 0 +sora_cluster_node{mode="block_new_connection",node_name="node-02_canary_sora@10.211.55.40",node_type="regular"} 1 +sora_cluster_node{mode="normal",node_name="node-03_canary_sora@10.211.55.41",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 diff --git a/test/sora_cluster_metrics_enabled.metrics b/test/sora_cluster_metrics_enabled.metrics index d62ef9a..31b9f3e 100644 --- a/test/sora_cluster_metrics_enabled.metrics +++ b/test/sora_cluster_metrics_enabled.metrics @@ -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="node-03_canary_sora@10.211.55.41"} 1 -sora_cluster_node{mode="block_new_connection",node_name="node-02_canary_sora@10.211.55.40"} 1 -sora_cluster_node{mode="",node_name="node-01_canary_sora@10.211.55.42"} 0 +sora_cluster_node{mode="normal",node_name="node-03_canary_sora@10.211.55.41",node_type="temporary"} 1 +sora_cluster_node{mode="block_new_connection",node_name="node-02_canary_sora@10.211.55.40",node_type="regular"} 1 +sora_cluster_node{mode="",node_name="node-01_canary_sora@10.211.55.42",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