Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: log activity for cluster metric collection mode changes #152

Merged
merged 2 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/content.en/docs/release-notes/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions docs/content.zh/docs/release-notes/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ title: "版本历史"
### Features
- 告警功能支持根据桶之间文档数差值和内容差异告警 (#119)
- 当使用 Easysearch 存储指标时,增加 Rollup 索引生命周期 (#128)
- 增加集群指标采集模式变更事件 (#152)

### Bug fix
- 修复 Insight API 处理多时间序列数据时数据丢失的问题 (#127)
Expand Down
51 changes: 50 additions & 1 deletion modules/elastic/api/manage.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"context"
"encoding/json"
"fmt"
"infini.sh/framework/core/queue"
"math"
"net/http"
"strconv"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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")
Expand Down
14 changes: 14 additions & 0 deletions web/src/pages/Overview/components/Activities/GenerateDesc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,20 @@ export default (props) => {
</>
);
}
case "metric_collection_mode_change":
if (type == "update") {
return (
<>
metric collection mode of cluster{" "}
<Link
to={`/resource/cluster/${hit._source.metadata.labels.cluster_id}/edit`}
>
{hit._source.metadata.labels.cluster_name}
</Link>{" "}
was <b>changed from {hit._source.metadata.labels.from} to {hit._source.metadata.labels.to}</b>
</>
);
}
}
return <></>;
};
Expand Down
Loading