Skip to content

Commit 78cdd44

Browse files
authored
feat: log activity for cluster metric collection mode changes (#152)
* feat: log activity for cluster metric collection mode changes * chore: update release notes
1 parent 932a2a4 commit 78cdd44

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

docs/content.en/docs/release-notes/_index.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Information about release notes of INFINI Console is provided here.
3030
### Features
3131
- Support alerts based on bucket diff state (#119)
3232
- Add rollup ilm when use Easysearch (#128)
33+
- Log activity for cluster metric collection mode changes (#152)
3334

3435
### Bug fix
3536
- Fixed missing data when processing multiple time series in a group with insight data API (#127)

docs/content.zh/docs/release-notes/_index.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ title: "版本历史"
3030
### Features
3131
- 告警功能支持根据桶之间文档数差值和内容差异告警 (#119)
3232
- 当使用 Easysearch 存储指标时,增加 Rollup 索引生命周期 (#128)
33+
- 增加集群指标采集模式变更事件 (#152)
3334

3435
### Bug fix
3536
- 修复 Insight API 处理多时间序列数据时数据丢失的问题 (#127)

modules/elastic/api/manage.go

+50-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"context"
2828
"encoding/json"
2929
"fmt"
30+
"infini.sh/framework/core/queue"
3031
"math"
3132
"net/http"
3233
"strconv"
@@ -107,6 +108,9 @@ func (h *APIHandler) HandleCreateClusterAction(w http.ResponseWriter, req *http.
107108
if conf.Distribution == "" {
108109
conf.Distribution = elastic.Elasticsearch
109110
}
111+
if conf.MetricCollectionMode == "" {
112+
conf.MetricCollectionMode = elastic.ModeAgentless
113+
}
110114
err = orm.Create(ctx, conf)
111115
if err != nil {
112116
log.Error(err)
@@ -183,6 +187,7 @@ func (h *APIHandler) HandleUpdateClusterAction(w http.ResponseWriter, req *http.
183187
h.Error404(w)
184188
return
185189
}
190+
var oldCollectionMode = originConf.MetricCollectionMode
186191
buf := util.MustToJSONBytes(originConf)
187192
source := map[string]interface{}{}
188193
util.MustFromJSONBytes(buf, &source)
@@ -255,7 +260,10 @@ func (h *APIHandler) HandleUpdateClusterAction(w http.ResponseWriter, req *http.
255260
h.WriteError(w, err.Error(), http.StatusInternalServerError)
256261
return
257262
}
258-
263+
// record cluster metric collection mode change activity
264+
if oldCollectionMode != newConf.MetricCollectionMode {
265+
recordCollectionModeChangeActivity(newConf.ID, newConf.Name, oldCollectionMode, newConf.MetricCollectionMode)
266+
}
259267
basicAuth, err := common.GetBasicAuth(newConf)
260268
if err != nil {
261269
h.WriteError(w, err.Error(), http.StatusInternalServerError)
@@ -273,6 +281,47 @@ func (h *APIHandler) HandleUpdateClusterAction(w http.ResponseWriter, req *http.
273281
h.WriteUpdatedOKJSON(w, id)
274282
}
275283

284+
func recordCollectionModeChangeActivity(clusterID, clusterName, oldMode, newMode string) {
285+
activityInfo := &event.Activity{
286+
ID: util.GetUUID(),
287+
Timestamp: time.Now(),
288+
Metadata: event.ActivityMetadata{
289+
Category: "elasticsearch",
290+
Group: "platform",
291+
Name: "metric_collection_mode_change",
292+
Type: "update",
293+
Labels: util.MapStr{
294+
"cluster_id": clusterID,
295+
"cluster_name": clusterName,
296+
"from": oldMode,
297+
"to": newMode,
298+
},
299+
},
300+
}
301+
302+
queueConfig := queue.GetOrInitConfig("platform##activities")
303+
if queueConfig.Labels == nil {
304+
queueConfig.ReplaceLabels(util.MapStr{
305+
"type": "platform",
306+
"name": "activity",
307+
"category": "elasticsearch",
308+
"activity": true,
309+
})
310+
}
311+
err := queue.Push(queueConfig, util.MustToJSONBytes(event.Event{
312+
Timestamp: time.Now(),
313+
Metadata: event.EventMetadata{
314+
Category: "elasticsearch",
315+
Name: "activity",
316+
},
317+
Fields: util.MapStr{
318+
"activity": activityInfo,
319+
}}))
320+
if err != nil {
321+
log.Error(err)
322+
}
323+
}
324+
276325
func (h *APIHandler) HandleDeleteClusterAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
277326
resBody := map[string]interface{}{}
278327
id := ps.MustGetParameter("id")

web/src/pages/Overview/components/Activities/GenerateDesc.jsx

+14
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,20 @@ export default (props) => {
234234
</>
235235
);
236236
}
237+
case "metric_collection_mode_change":
238+
if (type == "update") {
239+
return (
240+
<>
241+
metric collection mode of cluster{" "}
242+
<Link
243+
to={`/resource/cluster/${hit._source.metadata.labels.cluster_id}/edit`}
244+
>
245+
{hit._source.metadata.labels.cluster_name}
246+
</Link>{" "}
247+
was <b>changed from {hit._source.metadata.labels.from} to {hit._source.metadata.labels.to}</b>
248+
</>
249+
);
250+
}
237251
}
238252
return <></>;
239253
};

0 commit comments

Comments
 (0)