Skip to content

Commit

Permalink
fix: metrics collection after cluster recovery from unavailability (#37)
Browse files Browse the repository at this point in the history
* fix: issue where collection tasks were not updated after metadata changes

* fix: the issue with cluster health status reporting success incorrectly
  • Loading branch information
silenceqi authored Dec 28, 2024
1 parent e388a19 commit 928a3c9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion modules/elastic/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,18 @@ func (module *ElasticModule) clusterHealthCheck(clusterID string, force bool) {
}
log.Tracef("cluster [%v] health [%v] updated", clusterID, metadata.Health)
}
metadata.ReportSuccess()
changes, err := util.DiffTwoObject(metadata.Health, health)
if err != nil {
log.Errorf("diff cluster health error: %v", err)
}
if len(changes) > 0 {
//copy metadata and update metadata safely
newMeta := *metadata
newMeta.ReportSuccess()
newMeta.Health = health
elastic.SetMetadata(metadata.Config.ID, &newMeta)
}else{
metadata.ReportSuccess()
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion modules/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,17 @@ func (module *MetricsModule) Setup() {
elastic2.RegisterMetadataChangeEvent(func(meta, oldMeta *elastic2.ElasticsearchMetadata, action elastic2.EventAction) {
if action == elastic2.EventActionUpdate && oldMeta != nil {
//skip if no monitor config changed
hasChanged := false
changelog, _ := util.DiffTwoObject(oldMeta.Config.MonitorConfigs, meta.Config.MonitorConfigs)
if len(changelog) == 0 {
if len(changelog) > 0 {
hasChanged = true
}else if meta != nil {
// check other conditions
hasChanged = meta.IsAvailable() != oldMeta.IsAvailable() ||
meta.Config.Enabled != oldMeta.Config.Enabled ||
meta.Config.Monitored != oldMeta.Config.Monitored
}
if !hasChanged {
return
}
}
Expand Down

0 comments on commit 928a3c9

Please sign in to comment.