Skip to content

Commit

Permalink
feat: handled duplicate instance issue in clustersoftware plugin (#3486)
Browse files Browse the repository at this point in the history
* feat: handled duplicate instance issue in clustersoftware plugin
  • Loading branch information
Hardikl authored Feb 26, 2025
1 parent e0539ce commit bc787f7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 9 deletions.
22 changes: 14 additions & 8 deletions cmd/collectors/rest/plugins/clustersoftware/clustersoftware.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ func (c *ClusterSoftware) createStatusMetrics() error {
instanceKeys.NewChildS("", "state")
instanceKeys.NewChildS("", "node")
instanceKeys.NewChildS("", "name")
instanceKeys.NewChildS("", "startTime")
instanceKeys.NewChildS("", "endTime")

mat.SetExportOptions(exportOptions)

Expand Down Expand Up @@ -195,11 +197,13 @@ func (c *ClusterSoftware) handleStatusDetails(statusDetailsJSON gjson.Result, gl
// Set all global labels
c.data[statusMatrix].SetGlobalLabels(globalLabels)

for _, updateDetail := range statusDetailsJSON.Array() {
name := updateDetail.Get("name").ClonedString()
state := updateDetail.Get("state").ClonedString()
nodeName := updateDetail.Get("node.name").ClonedString()
key = name + state + nodeName
for _, statusDetail := range statusDetailsJSON.Array() {
name := statusDetail.Get("name").ClonedString()
state := statusDetail.Get("state").ClonedString()
nodeName := statusDetail.Get("node.name").ClonedString()
startTime := statusDetail.Get("start_time").ClonedString()
endTime := statusDetail.Get("end_time").ClonedString()
key = name + state + nodeName + startTime

if clusterStatusInstance, err = c.data[statusMatrix].NewInstance(key); err != nil {
c.SLogger.Error("Failed to create instance", slogx.Err(err), slog.String("key", key))
Expand All @@ -208,6 +212,8 @@ func (c *ClusterSoftware) handleStatusDetails(statusDetailsJSON gjson.Result, gl
clusterStatusInstance.SetLabel("node", nodeName)
clusterStatusInstance.SetLabel("state", state)
clusterStatusInstance.SetLabel("name", name)
clusterStatusInstance.SetLabel("startTime", startTime)
clusterStatusInstance.SetLabel("endTime", endTime)

// populate numeric data
value := 0.0
Expand Down Expand Up @@ -237,9 +243,9 @@ func (c *ClusterSoftware) handleValidationDetails(validationDetailsJSON gjson.Re
// Set all global labels
c.data[validationMatrix].SetGlobalLabels(globalLabels)

for _, updateDetail := range validationDetailsJSON.Array() {
updateCheck := updateDetail.Get("update_check").ClonedString()
status := updateDetail.Get("status").ClonedString()
for _, validationDetail := range validationDetailsJSON.Array() {
updateCheck := validationDetail.Get("update_check").ClonedString()
status := validationDetail.Get("status").ClonedString()
key = updateCheck + status

if clusterValidationInstance, err = c.data[validationMatrix].NewInstance(key); err != nil {
Expand Down
32 changes: 31 additions & 1 deletion grafana/dashboards/cmode/cluster.json
Original file line number Diff line number Diff line change
Expand Up @@ -4819,6 +4819,30 @@
"value": "color-background"
}
]
},
{
"matcher": {
"id": "byName",
"options": "Start Time"
},
"properties": [
{
"id": "unit",
"value": "dateTimeAsIso"
}
]
},
{
"matcher": {
"id": "byName",
"options": "End Time"
},
"properties": [
{
"id": "unit",
"value": "dateTimeAsIso"
}
]
}
]
},
Expand Down Expand Up @@ -4865,7 +4889,9 @@
"cluster",
"name",
"node",
"datacenter"
"datacenter",
"startTime",
"endTime"
]
}
}
Expand All @@ -4877,12 +4903,16 @@
"indexByName": {
"cluster": 1,
"datacenter": 0,
"endtime": 6,
"name": 3,
"node": 2,
"startTime": 5,
"state": 4
},
"renameByName": {
"endTime": "End Time",
"name": "Job Name",
"startTime": "Start Time",
"state": "Status"
}
}
Expand Down

0 comments on commit bc787f7

Please sign in to comment.