Repository: ClusterLabs/ha_cluster_exporter
Pull request #191 (2021-04-26 07:32:45)

Don't create metrics for non-running OCFS resources
Since the non-running OCFS resources have no associated node, those are
duplicate entries making the whole exporter fail. Here is a typical
error message:

    * collected metric "ha_cluster_pacemaker_resources"
      { label:<name:"agent" value:"ocf::heartbeat:Filesystem" > [...] }
    was collected before with the same name and label values

This change just skips those entries.


Patch:
diff --git a/collector/pacemaker/pacemaker.go b/collector/pacemaker/pacemaker.go
index 3e81761..be7c681 100644
--- a/collector/pacemaker/pacemaker.go
+++ b/collector/pacemaker/pacemaker.go
@@ -146,6 +146,11 @@ func (c *pacemakerCollector) recordResource(resource crmmon.Resource, group stri
 		"failure_ignored": resource.FailureIgnored,
 	}
 
+	// Don't create metric for OCFS nodes that aren't running since those would generate duplicate entries
+	if resource.Agent == "ocf::heartbeat:Filesystem" && resource.NodesRunningOn == 0 {
+		return
+	}
+
 	// since we have a combined cardinality of resource * status, we cycle through all the possible statuses
 	// and we record a new metric if the flag for that status is on
 	for resourceStatus, flag := range resourceStatuses {


Test patch:
diff --git a/collector/pacemaker/crmmon/parser_test.go b/collector/pacemaker/crmmon/parser_test.go
index fc48bb9..6f97ba8 100644
--- a/collector/pacemaker/crmmon/parser_test.go
+++ b/collector/pacemaker/crmmon/parser_test.go
@@ -57,9 +57,10 @@ func TestParseClones(t *testing.T) {
 	p := NewCrmMonParser("../../../test/fake_crm_mon.sh")
 	data, err := p.Parse()
 	assert.NoError(t, err)
-	assert.Equal(t, 2, len(data.Clones))
+	assert.Equal(t, 3, len(data.Clones))
 	assert.Equal(t, "msl_SAPHana_PRD_HDB00", data.Clones[0].Id)
 	assert.Equal(t, "cln_SAPHanaTopology_PRD_HDB00", data.Clones[1].Id)
+	assert.Equal(t, "c-clusterfs", data.Clones[2].Id)
 	assert.Equal(t, 2, len(data.Clones[0].Resources))
 	assert.Equal(t, 2, len(data.Clones[1].Resources))
 	assert.Equal(t, "rsc_SAPHana_PRD_HDB00", data.Clones[0].Resources[0].Id)
diff --git a/test/fake_crm_mon.sh b/test/fake_crm_mon.sh
index 3a85220..12a8959 100755
--- a/test/fake_crm_mon.sh
+++ b/test/fake_crm_mon.sh
@@ -43,6 +43,16 @@ cat <<EOF
                 <node name="node02" id="1084783376" cached="false"/>
             </resource>
         </clone>
+        <clone id="c-clusterfs" multi_state="false" unique="false" managed="true" failed="false" failure_ignored="false">
+            <resource id="clusterfs" resource_agent="ocf::heartbeat:Filesystem" role="Started" active="true" orphaned="false" blocked="false" managed="true" failed="false" failure_ignored="false" nodes_running_on="1">
+                <node name="node01" id="1084783225" cached="true"/>
+            </resource>
+            <resource id="clusterfs" resource_agent="ocf::heartbeat:Filesystem" role="Started" active="true" orphaned="false" blocked="false" managed="true" failed="false" failure_ignored="false" nodes_running_on="1">
+                <node name="node02" id="1084783226" cached="true"/>
+            </resource>
+            <resource id="clusterfs" resource_agent="ocf::heartbeat:Filesystem" role="Stopped" active="false" orphaned="false" blocked="false" managed="true" failed="false" failure_ignored="false" nodes_running_on="0"/>
+            <resource id="clusterfs" resource_agent="ocf::heartbeat:Filesystem" role="Stopped" active="false" orphaned="false" blocked="false" managed="true" failed="false" failure_ignored="false" nodes_running_on="0"/>
+        </clone>
         <group id="grp_HA1_ASCS00" number_resources="3" >
              <resource id="rsc_ip_HA1_ASCS00" resource_agent="ocf::heartbeat:IPaddr2" role="Started" active="true" orphaned="false" blocked="false" managed="true" failed="false" failure_ignored="false" nodes_running_on="1" >
                  <node name="node01" id="1084783375" cached="false"/>
diff --git a/test/pacemaker.metrics b/test/pacemaker.metrics
index 8ae674f..6cd052e 100644
--- a/test/pacemaker.metrics
+++ b/test/pacemaker.metrics
@@ -93,6 +93,16 @@ ha_cluster_pacemaker_resources{agent="ocf::heartbeat:Filesystem",clone="",group=
 ha_cluster_pacemaker_resources{agent="ocf::heartbeat:Filesystem",clone="",group="grp_HA1_ERS10",managed="true",node="node02",resource="rsc_fs_HA1_ERS10",role="started",status="failed"} 0
 ha_cluster_pacemaker_resources{agent="ocf::heartbeat:Filesystem",clone="",group="grp_HA1_ERS10",managed="true",node="node02",resource="rsc_fs_HA1_ERS10",role="started",status="failure_ignored"} 0
 ha_cluster_pacemaker_resources{agent="ocf::heartbeat:Filesystem",clone="",group="grp_HA1_ERS10",managed="true",node="node02",resource="rsc_fs_HA1_ERS10",role="started",status="orphaned"} 0
+ha_cluster_pacemaker_resources{agent="ocf::heartbeat:Filesystem",clone="c-clusterfs",group="",managed="true",node="node01",resource="clusterfs",role="started",status="active"} 1
+ha_cluster_pacemaker_resources{agent="ocf::heartbeat:Filesystem",clone="c-clusterfs",group="",managed="true",node="node01",resource="clusterfs",role="started",status="blocked"} 0
+ha_cluster_pacemaker_resources{agent="ocf::heartbeat:Filesystem",clone="c-clusterfs",group="",managed="true",node="node01",resource="clusterfs",role="started",status="failed"} 0
+ha_cluster_pacemaker_resources{agent="ocf::heartbeat:Filesystem",clone="c-clusterfs",group="",managed="true",node="node01",resource="clusterfs",role="started",status="failure_ignored"} 0
+ha_cluster_pacemaker_resources{agent="ocf::heartbeat:Filesystem",clone="c-clusterfs",group="",managed="true",node="node01",resource="clusterfs",role="started",status="orphaned"} 0
+ha_cluster_pacemaker_resources{agent="ocf::heartbeat:Filesystem",clone="c-clusterfs",group="",managed="true",node="node02",resource="clusterfs",role="started",status="active"} 1
+ha_cluster_pacemaker_resources{agent="ocf::heartbeat:Filesystem",clone="c-clusterfs",group="",managed="true",node="node02",resource="clusterfs",role="started",status="blocked"} 0
+ha_cluster_pacemaker_resources{agent="ocf::heartbeat:Filesystem",clone="c-clusterfs",group="",managed="true",node="node02",resource="clusterfs",role="started",status="failed"} 0
+ha_cluster_pacemaker_resources{agent="ocf::heartbeat:Filesystem",clone="c-clusterfs",group="",managed="true",node="node02",resource="clusterfs",role="started",status="failure_ignored"} 0
+ha_cluster_pacemaker_resources{agent="ocf::heartbeat:Filesystem",clone="c-clusterfs",group="",managed="true",node="node02",resource="clusterfs",role="started",status="orphaned"} 0
 ha_cluster_pacemaker_resources{agent="ocf::heartbeat:IPaddr2",clone="",group="",managed="true",node="node01",resource="rsc_ip_PRD_HDB00",role="started",status="active"} 1
 ha_cluster_pacemaker_resources{agent="ocf::heartbeat:IPaddr2",clone="",group="",managed="true",node="node01",resource="rsc_ip_PRD_HDB00",role="started",status="blocked"} 0
 ha_cluster_pacemaker_resources{agent="ocf::heartbeat:IPaddr2",clone="",group="",managed="true",node="node01",resource="rsc_ip_PRD_HDB00",role="started",status="failed"} 0