From 928a3c947423858de6be4bc771e9ac6ef3227df9 Mon Sep 17 00:00:00 2001 From: silenceqi Date: Sat, 28 Dec 2024 15:16:26 +0800 Subject: [PATCH] fix: metrics collection after cluster recovery from unavailability (#37) * fix: issue where collection tasks were not updated after metadata changes * fix: the issue with cluster health status reporting success incorrectly --- modules/elastic/metadata.go | 4 +++- modules/metrics/metrics.go | 11 ++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/modules/elastic/metadata.go b/modules/elastic/metadata.go index a2851870..358c1cb3 100644 --- a/modules/elastic/metadata.go +++ b/modules/elastic/metadata.go @@ -85,7 +85,6 @@ 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) @@ -93,8 +92,11 @@ func (module *ElasticModule) clusterHealthCheck(clusterID string, force bool) { 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() } } } diff --git a/modules/metrics/metrics.go b/modules/metrics/metrics.go index e38bb906..2c7e963b 100755 --- a/modules/metrics/metrics.go +++ b/modules/metrics/metrics.go @@ -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 } }