From 5ad5fd56daf4b52ebfbff9258386f46eb928a0c3 Mon Sep 17 00:00:00 2001 From: liugq Date: Thu, 20 Feb 2025 15:12:34 +0800 Subject: [PATCH 1/2] feat: log activity for cluster metric collection mode changes --- modules/elastic/api/manage.go | 51 ++++++++++++++++++- .../components/Activities/GenerateDesc.jsx | 14 +++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/modules/elastic/api/manage.go b/modules/elastic/api/manage.go index d3d68c56..f777e1b8 100644 --- a/modules/elastic/api/manage.go +++ b/modules/elastic/api/manage.go @@ -27,6 +27,7 @@ import ( "context" "encoding/json" "fmt" + "infini.sh/framework/core/queue" "math" "net/http" "strconv" @@ -107,6 +108,9 @@ func (h *APIHandler) HandleCreateClusterAction(w http.ResponseWriter, req *http. if conf.Distribution == "" { conf.Distribution = elastic.Elasticsearch } + if conf.MetricCollectionMode == "" { + conf.MetricCollectionMode = elastic.ModeAgentless + } err = orm.Create(ctx, conf) if err != nil { log.Error(err) @@ -183,6 +187,7 @@ func (h *APIHandler) HandleUpdateClusterAction(w http.ResponseWriter, req *http. h.Error404(w) return } + var oldCollectionMode = originConf.MetricCollectionMode buf := util.MustToJSONBytes(originConf) source := map[string]interface{}{} util.MustFromJSONBytes(buf, &source) @@ -255,7 +260,10 @@ func (h *APIHandler) HandleUpdateClusterAction(w http.ResponseWriter, req *http. h.WriteError(w, err.Error(), http.StatusInternalServerError) return } - + // record cluster metric collection mode change activity + if oldCollectionMode != newConf.MetricCollectionMode { + recordCollectionModeChangeActivity(newConf.ID, newConf.Name, oldCollectionMode, newConf.MetricCollectionMode) + } basicAuth, err := common.GetBasicAuth(newConf) if err != nil { h.WriteError(w, err.Error(), http.StatusInternalServerError) @@ -273,6 +281,47 @@ func (h *APIHandler) HandleUpdateClusterAction(w http.ResponseWriter, req *http. h.WriteUpdatedOKJSON(w, id) } +func recordCollectionModeChangeActivity(clusterID, clusterName, oldMode, newMode string) { + activityInfo := &event.Activity{ + ID: util.GetUUID(), + Timestamp: time.Now(), + Metadata: event.ActivityMetadata{ + Category: "elasticsearch", + Group: "platform", + Name: "metric_collection_mode_change", + Type: "update", + Labels: util.MapStr{ + "cluster_id": clusterID, + "cluster_name": clusterName, + "from": oldMode, + "to": newMode, + }, + }, + } + + queueConfig := queue.GetOrInitConfig("platform##activities") + if queueConfig.Labels == nil { + queueConfig.ReplaceLabels(util.MapStr{ + "type": "platform", + "name": "activity", + "category": "elasticsearch", + "activity": true, + }) + } + err := queue.Push(queueConfig, util.MustToJSONBytes(event.Event{ + Timestamp: time.Now(), + Metadata: event.EventMetadata{ + Category: "elasticsearch", + Name: "activity", + }, + Fields: util.MapStr{ + "activity": activityInfo, + }})) + if err != nil { + log.Error(err) + } +} + func (h *APIHandler) HandleDeleteClusterAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) { resBody := map[string]interface{}{} id := ps.MustGetParameter("id") diff --git a/web/src/pages/Overview/components/Activities/GenerateDesc.jsx b/web/src/pages/Overview/components/Activities/GenerateDesc.jsx index b601c793..8d39a40c 100644 --- a/web/src/pages/Overview/components/Activities/GenerateDesc.jsx +++ b/web/src/pages/Overview/components/Activities/GenerateDesc.jsx @@ -234,6 +234,20 @@ export default (props) => { ); } + case "metric_collection_mode_change": + if (type == "update") { + return ( + <> + metric collection mode of cluster{" "} + + {hit._source.metadata.labels.cluster_name} + {" "} + was changed from {hit._source.metadata.labels.from} to {hit._source.metadata.labels.to} + + ); + } } return <>; }; From 81dac27bd0c6045a1447179f321300e51540d452 Mon Sep 17 00:00:00 2001 From: liugq Date: Thu, 20 Feb 2025 15:17:08 +0800 Subject: [PATCH 2/2] chore: update release notes --- docs/content.en/docs/release-notes/_index.md | 1 + docs/content.zh/docs/release-notes/_index.md | 1 + 2 files changed, 2 insertions(+) diff --git a/docs/content.en/docs/release-notes/_index.md b/docs/content.en/docs/release-notes/_index.md index 439d9ed8..38b341f6 100644 --- a/docs/content.en/docs/release-notes/_index.md +++ b/docs/content.en/docs/release-notes/_index.md @@ -30,6 +30,7 @@ Information about release notes of INFINI Console is provided here. ### Features - Support alerts based on bucket diff state (#119) - Add rollup ilm when use Easysearch (#128) +- Log activity for cluster metric collection mode changes (#152) ### Bug fix - Fixed missing data when processing multiple time series in a group with insight data API (#127) diff --git a/docs/content.zh/docs/release-notes/_index.md b/docs/content.zh/docs/release-notes/_index.md index d1cf4fab..f7b0e027 100644 --- a/docs/content.zh/docs/release-notes/_index.md +++ b/docs/content.zh/docs/release-notes/_index.md @@ -30,6 +30,7 @@ title: "版本历史" ### Features - 告警功能支持根据桶之间文档数差值和内容差异告警 (#119) - 当使用 Easysearch 存储指标时,增加 Rollup 索引生命周期 (#128) +- 增加集群指标采集模式变更事件 (#152) ### Bug fix - 修复 Insight API 处理多时间序列数据时数据丢失的问题 (#127)