Skip to content

Commit

Permalink
Split test in 2 test differnt
Browse files Browse the repository at this point in the history
  • Loading branch information
MalloZup committed Dec 13, 2019
1 parent 4601777 commit 10a0b83
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 34 deletions.
24 changes: 22 additions & 2 deletions drbd_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package main

import (
"os"
"strings"
"testing"

"github.com/prometheus/client_golang/prometheus/testutil"
)

func TestDrbdParsing(t *testing.T) {
Expand Down Expand Up @@ -229,6 +232,14 @@ func TestNewDrbdCollectorChecksDrbdsetupExecutableBits(t *testing.T) {

func TestDRBDCollector(t *testing.T) {
clock = StoppedClock{}

collector, _ := NewDrbdCollector("test/fake_drbdsetup.sh", "fake")
expectMetrics(t, collector, "drbd.metrics")

}

func TestDRBDSplitbrainCollector(t *testing.T) {
clock = StoppedClock{}
splitBrainDir := "/var/tmp/drbd/splitbrain"
testFiles := [3]string{
"drbd-split-brain-detected-resource01-vol01",
Expand All @@ -247,8 +258,17 @@ func TestDRBDCollector(t *testing.T) {
os.Create(splitBrainDir + "/" + testFile)
}
defer os.RemoveAll(splitBrainDir)
// we use by intent a wrong exec (cibadmin) so we can just have splitbrain metrics
collector, _ := NewDrbdCollector("test/fake_cibadmin.sh", splitBrainDir)

collector, _ := NewDrbdCollector("test/fake_drbdsetup.sh", splitBrainDir)
expectMetrics(t, collector, "drbd.metrics")
expect := `
# HELP ha_cluster_drbd_split_brain Whether a split brain has been detected; 1 line per resource, per volume.
# TYPE ha_cluster_drbd_split_brain gauge
ha_cluster_drbd_split_brain{resource="resource01",volume="vol01"} 1 1234
ha_cluster_drbd_split_brain{resource="resource02",volume="vol02"} 1 1234
`

if err := testutil.CollectAndCompare(collector, strings.NewReader(expect)); err != nil {
t.Fatal(err)
}
}
60 changes: 28 additions & 32 deletions test/drbd.metrics
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
# HELP ha_cluster_drbd_al_writes Writes to activity log; 1 line per res, per volume
# TYPE ha_cluster_drbd_al_writes gauge
ha_cluster_drbd_al_writes{resource="1-single-0",volume="0"} 123 1234
ha_cluster_drbd_al_writes{resource="1-single-1",volume="0"} 123 1234
# HELP ha_cluster_drbd_bm_writes Writes to bitmap; 1 line per res, per volume
# TYPE ha_cluster_drbd_bm_writes gauge
ha_cluster_drbd_bm_writes{resource="1-single-0",volume="0"} 321 1234
ha_cluster_drbd_bm_writes{resource="1-single-1",volume="0"} 321 1234
# HELP ha_cluster_drbd_connections The DRBD resource connections; 1 line per per resource, per peer_node_id
# TYPE ha_cluster_drbd_connections gauge
ha_cluster_drbd_connections{peer_disk_state="uptodate",peer_node_id="1",peer_role="Primary",resource="1-single-0",volume="0"} 1 1234
ha_cluster_drbd_connections{peer_disk_state="uptodate",peer_node_id="1",peer_role="Primary",resource="1-single-1",volume="0"} 1 1234
# HELP ha_cluster_drbd_connections_sync The in sync percentage value for DRBD resource connections
# TYPE ha_cluster_drbd_connections_sync gauge
ha_cluster_drbd_connections_sync{peer_node_id="1",resource="1-single-0",volume="0"} 100 1234
ha_cluster_drbd_connections_sync{peer_node_id="1",resource="1-single-1",volume="0"} 100 1234
# HELP ha_cluster_drbd_connections_pending Pending value per connection
# TYPE ha_cluster_drbd_connections_pending gauge
ha_cluster_drbd_connections_pending{peer_node_id="1",resource="1-single-0",volume="0"} 3 1234
ha_cluster_drbd_connections_pending{peer_node_id="1",resource="1-single-1",volume="0"} 3 1234
# HELP ha_cluster_drbd_connections_received KiB received per connection
# TYPE ha_cluster_drbd_connections_received gauge
ha_cluster_drbd_connections_received{peer_node_id="1",resource="1-single-0",volume="0"} 456 1234
Expand All @@ -14,34 +22,14 @@ ha_cluster_drbd_connections_received{peer_node_id="1",resource="1-single-1",volu
# TYPE ha_cluster_drbd_connections_sent gauge
ha_cluster_drbd_connections_sent{peer_node_id="1",resource="1-single-0",volume="0"} 654 1234
ha_cluster_drbd_connections_sent{peer_node_id="1",resource="1-single-1",volume="0"} 654 1234
# HELP ha_cluster_drbd_connections_pending Pending value per connection
# TYPE ha_cluster_drbd_connections_pending gauge
ha_cluster_drbd_connections_pending{peer_node_id="1",resource="1-single-0",volume="0"} 3 1234
ha_cluster_drbd_connections_pending{peer_node_id="1",resource="1-single-1",volume="0"} 3 1234
# HELP ha_cluster_drbd_connections_sync The in sync percentage value for DRBD resource connections
# TYPE ha_cluster_drbd_connections_sync gauge
ha_cluster_drbd_connections_sync{peer_node_id="1",resource="1-single-0",volume="0"} 100 1234
ha_cluster_drbd_connections_sync{peer_node_id="1",resource="1-single-1",volume="0"} 100 1234
# HELP ha_cluster_drbd_connections_unacked Unacked value per connection
# TYPE ha_cluster_drbd_connections_unacked gauge
ha_cluster_drbd_connections_unacked{peer_node_id="1",resource="1-single-0",volume="0"} 4 1234
ha_cluster_drbd_connections_unacked{peer_node_id="1",resource="1-single-1",volume="0"} 4 1234
# HELP ha_cluster_drbd_written KiB written to DRBD; 1 line per res, per volume
# TYPE ha_cluster_drbd_written gauge
ha_cluster_drbd_written{resource="1-single-0",volume="0"} 123456 1234
ha_cluster_drbd_written{resource="1-single-1",volume="0"} 123456 1234
# HELP ha_cluster_drbd_read KiB read from DRBD; 1 line per res, per volume
# TYPE ha_cluster_drbd_read gauge
ha_cluster_drbd_read{resource="1-single-0",volume="0"} 654321 1234
ha_cluster_drbd_read{resource="1-single-1",volume="0"} 654321 1234
# HELP ha_cluster_drbd_al_writes Writes to activity log; 1 line per res, per volume
# TYPE ha_cluster_drbd_al_writes gauge
ha_cluster_drbd_al_writes{resource="1-single-0",volume="0"} 123 1234
ha_cluster_drbd_al_writes{resource="1-single-1",volume="0"} 123 1234
# HELP ha_cluster_drbd_bm_writes Writes to bitmap; 1 line per res, per volume
# TYPE ha_cluster_drbd_bm_writes gauge
ha_cluster_drbd_bm_writes{resource="1-single-0",volume="0"} 321 1234
ha_cluster_drbd_bm_writes{resource="1-single-1",volume="0"} 321 1234
# HELP ha_cluster_drbd_upper_pending Upper pending; 1 line per res, per volume
# TYPE ha_cluster_drbd_upper_pending gauge
ha_cluster_drbd_upper_pending{resource="1-single-0",volume="0"} 1 1234
ha_cluster_drbd_upper_pending{resource="1-single-1",volume="0"} 1 1234
# HELP ha_cluster_drbd_lower_pending Lower pending; 1 line per res, per volume
# TYPE ha_cluster_drbd_lower_pending gauge
ha_cluster_drbd_lower_pending{resource="1-single-0",volume="0"} 2 1234
Expand All @@ -50,11 +38,19 @@ ha_cluster_drbd_lower_pending{resource="1-single-1",volume="0"} 2 1234
# TYPE ha_cluster_drbd_quorum gauge
ha_cluster_drbd_quorum{resource="1-single-0",volume="0"} 1 1234
ha_cluster_drbd_quorum{resource="1-single-1",volume="0"} 0 1234
# HELP ha_cluster_drbd_read KiB read from DRBD; 1 line per res, per volume
# TYPE ha_cluster_drbd_read gauge
ha_cluster_drbd_read{resource="1-single-0",volume="0"} 654321 1234
ha_cluster_drbd_read{resource="1-single-1",volume="0"} 654321 1234
# HELP ha_cluster_drbd_resources The DRBD resources; 1 line per name, per volume
# TYPE ha_cluster_drbd_resources gauge
ha_cluster_drbd_resources{disk_state="uptodate",resource="1-single-0",role="Secondary",volume="0"} 1 1234
ha_cluster_drbd_resources{disk_state="uptodate",resource="1-single-1",role="Secondary",volume="0"} 1 1234
# HELP ha_cluster_drbd_split_brain Whether a split brain has been detected; 1 line per resource, per volume.
# TYPE ha_cluster_drbd_split_brain gauge
ha_cluster_drbd_split_brain{resource="resource01",volume="vol01"} 1 1234
ha_cluster_drbd_split_brain{resource="resource02",volume="vol02"} 1 1234
# HELP ha_cluster_drbd_upper_pending Upper pending; 1 line per res, per volume
# TYPE ha_cluster_drbd_upper_pending gauge
ha_cluster_drbd_upper_pending{resource="1-single-0",volume="0"} 1 1234
ha_cluster_drbd_upper_pending{resource="1-single-1",volume="0"} 1 1234
# HELP ha_cluster_drbd_written KiB written to DRBD; 1 line per res, per volume
# TYPE ha_cluster_drbd_written gauge
ha_cluster_drbd_written{resource="1-single-0",volume="0"} 123456 1234
ha_cluster_drbd_written{resource="1-single-1",volume="0"} 123456 1234

0 comments on commit 10a0b83

Please sign in to comment.