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)
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 <>>;
};