Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #13 from coder-hugo/feature/fix-volume-status
Browse files Browse the repository at this point in the history
Fix unmarshalling of volume status
  • Loading branch information
ofesseler authored Apr 25, 2017
2 parents 250ac73 + 369c00e commit 9beb3a0
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 18 deletions.
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,16 +304,16 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
if err != nil {
log.Errorf("couldn't parse xml of peer status: %v", err)
}
for _, vol := range volumeStatusAll.VolStatus.Volumes {
for _, node := range vol.Volume.Node {
for _, vol := range volumeStatusAll.VolStatus.Volumes.Volume {
for _, node := range vol.Node {
if node.Status != 1 {
}
ch <- prometheus.MustNewConstMetric(
nodeSizeTotalBytes, prometheus.CounterValue, float64(node.SizeTotal), node.Hostname, node.Path, vol.Volume.VolName,
nodeSizeTotalBytes, prometheus.CounterValue, float64(node.SizeTotal), node.Hostname, node.Path, vol.VolName,
)

ch <- prometheus.MustNewConstMetric(
nodeSizeFreeBytes, prometheus.CounterValue, float64(node.SizeFree), node.Hostname, node.Path, vol.Volume.VolName,
nodeSizeFreeBytes, prometheus.CounterValue, float64(node.SizeFree), node.Hostname, node.Path, vol.VolName,
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions structs/xmlStructs.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ type VolumeStatusXML struct {
OpErrno int `xml:"opErrno"`
OpErrstr string `xml:"opErrstr"`
VolStatus struct {
Volumes []struct {
Volume struct {
Volumes struct {
Volume []struct {
VolName string `xml:"volName"`
NodeCount int `xml:"nodeCount"`
Node []struct {
Expand Down
30 changes: 19 additions & 11 deletions structs/xmlStructs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestPeerStatusXMLUnmarshall(t *testing.T) {

func TestVolumeStatusAllDetailXMLUnmarshall(t *testing.T) {
testXMLPath := "../test/gluster_volume_status_all_detail.xml"
t.Log("Test xml unmarshal for 'gluster peer status' with file: ", testXMLPath)
t.Log("Test xml unmarshal for 'gluster volume status all detail' with file: ", testXMLPath)
dat, err := ioutil.ReadFile(testXMLPath)
if err != nil {
t.Errorf("error reading testxml in Path: %v", testXMLPath)
Expand All @@ -106,26 +106,34 @@ func TestVolumeStatusAllDetailXMLUnmarshall(t *testing.T) {
t.Error(volumeStatus.OpErrstr)
}

for _, vol := range volumeStatus.VolStatus.Volumes {
if vol.Volume.NodeCount != 4 {
t.Errorf("nodecount mismatch %v instead of 4", vol.Volume.NodeCount)
for _, vol := range volumeStatus.VolStatus.Volumes.Volume {
if vol.NodeCount != 4 {
t.Errorf("nodecount mismatch %v instead of 4", vol.NodeCount)
}

for _, node := range vol.Volume.Node {
for _, node := range vol.Node {
if node.BlockSize != 4096 {
t.Errorf("blockSize mismatch %v and 4096 expected", node.BlockSize)
}

}

if vol.Volume.Node[0].SizeFree != 19517558784 {
t.Errorf("SizeFree doesn't match 19517558784: %v", vol.Volume.Node[0].SizeFree)
if vol.Node[0].SizeFree != 19517558784 {
t.Errorf("SizeFree doesn't match 19517558784: %v", vol.Node[0].SizeFree)
}

if vol.Volume.Node[0].SizeTotal != 20507914240 {
t.Errorf("SizeFree doesn't match 20507914240: %v", vol.Volume.Node[0].SizeTotal)
if vol.Node[0].SizeTotal != 20507914240 {
t.Errorf("SizeFree doesn't match 20507914240: %v", vol.Node[0].SizeTotal)
}
}

if volumeStatus.VolStatus.Volumes.Volume[0].VolName != "gv_test" {
t.Errorf("VolName of first volume doesn't match gv_test: %v", volumeStatus.VolStatus.Volumes.Volume[0].VolName)
}

if volumeStatus.VolStatus.Volumes.Volume[1].VolName != "gv_test2" {
t.Errorf("VolName of first volume doesn't match gv_test2: %v", volumeStatus.VolStatus.Volumes.Volume[1].VolName)
}
}

func TestVolumeProfileGvInfoCumulativeXMLUnmarshall(t *testing.T) {
Expand Down Expand Up @@ -245,13 +253,13 @@ func TestVolumeQuotaListXMLUnmarshall(t *testing.T) {
}
nb_limits := len(volumeQuotaXML.VolQuota.QuotaLimits)
if nb_limits != nodeCount {
t.Error("Expected %v Limits and len is %v", nodeCount, nb_limits)
t.Errorf("Expected %v Limits and len is %v", nodeCount, nb_limits)
}

for _, limit := range volumeQuotaXML.VolQuota.QuotaLimits {
if limit.Path == "/foo" {
if limit.AvailSpace != 10309258240 {
t.Error(
t.Errorf(
"Expected %v for available space in path %v, got %v",
1811939328,
limit.Path,
Expand Down
78 changes: 77 additions & 1 deletion test/gluster_volume_status_all_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,82 @@
<fsName>ext4</fsName>
</node>
</volume>
<volume>
<volName>gv_test2</volName>
<nodeCount>4</nodeCount>
<node>
<hostname>node1.example.local</hostname>
<path>/mnt/gluster/gv_test2</path>
<peerid>a049c424-bd82-4436-abd4-ef3fc37c76ba</peerid>
<status>1</status>
<port>49153</port>
<ports>
<tcp>49153</tcp>
<rdma>N/A</rdma>
</ports>
<pid>1342</pid>
<sizeTotal>20507914240</sizeTotal>
<sizeFree>19517558784</sizeFree>
<device>/dev/loop0</device>
<blockSize>4096</blockSize>
<mntOptions>rw,relatime,data=ordered</mntOptions>
<fsName>ext4</fsName>
</node>
<node>
<hostname>node2.example.local</hostname>
<path>/mnt/gluster/gv_test2</path>
<peerid>f6fa44e7-5139-4f6e-8404-6d2ce7d66231</peerid>
<status>1</status>
<port>49153</port>
<ports>
<tcp>49153</tcp>
<rdma>N/A</rdma>
</ports>
<pid>1303</pid>
<sizeTotal>20507914240</sizeTotal>
<sizeFree>19517558784</sizeFree>
<device>/dev/loop0</device>
<blockSize>4096</blockSize>
<mntOptions>rw,relatime,data=ordered</mntOptions>
<fsName>ext4</fsName>
</node>
<node>
<hostname>node3.example.local</hostname>
<path>/mnt/gluster/gv_test2</path>
<peerid>073c4354-f8eb-4474-95b3-c2bc235ca44d</peerid>
<status>1</status>
<port>49153</port>
<ports>
<tcp>49153</tcp>
<rdma>N/A</rdma>
</ports>
<pid>1284</pid>
<sizeTotal>20507914240</sizeTotal>
<sizeFree>19517558784</sizeFree>
<device>/dev/loop0</device>
<blockSize>4096</blockSize>
<mntOptions>rw,relatime,data=ordered</mntOptions>
<fsName>ext4</fsName>
</node>
<node>
<hostname>node4.example.local</hostname>
<path>/mnt/gluster/gv_test2</path>
<peerid>1d5d9c25-211c-4db6-8fd6-274cf3774d88</peerid>
<status>1</status>
<port>49153</port>
<ports>
<tcp>49153</tcp>
<rdma>N/A</rdma>
</ports>
<pid>1312</pid>
<sizeTotal>20507914240</sizeTotal>
<sizeFree>19517566976</sizeFree>
<device>/dev/loop0</device>
<blockSize>4096</blockSize>
<mntOptions>rw,relatime,data=ordered</mntOptions>
<fsName>ext4</fsName>
</node>
</volume>
</volumes>
</volStatus>
</cliOutput>
</cliOutput>

0 comments on commit 9beb3a0

Please sign in to comment.