@@ -27,6 +27,7 @@ import (
27
27
"context"
28
28
"encoding/json"
29
29
"fmt"
30
+ "infini.sh/framework/core/queue"
30
31
"math"
31
32
"net/http"
32
33
"strconv"
@@ -107,6 +108,9 @@ func (h *APIHandler) HandleCreateClusterAction(w http.ResponseWriter, req *http.
107
108
if conf .Distribution == "" {
108
109
conf .Distribution = elastic .Elasticsearch
109
110
}
111
+ if conf .MetricCollectionMode == "" {
112
+ conf .MetricCollectionMode = elastic .ModeAgentless
113
+ }
110
114
err = orm .Create (ctx , conf )
111
115
if err != nil {
112
116
log .Error (err )
@@ -183,6 +187,7 @@ func (h *APIHandler) HandleUpdateClusterAction(w http.ResponseWriter, req *http.
183
187
h .Error404 (w )
184
188
return
185
189
}
190
+ var oldCollectionMode = originConf .MetricCollectionMode
186
191
buf := util .MustToJSONBytes (originConf )
187
192
source := map [string ]interface {}{}
188
193
util .MustFromJSONBytes (buf , & source )
@@ -255,7 +260,10 @@ func (h *APIHandler) HandleUpdateClusterAction(w http.ResponseWriter, req *http.
255
260
h .WriteError (w , err .Error (), http .StatusInternalServerError )
256
261
return
257
262
}
258
-
263
+ // record cluster metric collection mode change activity
264
+ if oldCollectionMode != newConf .MetricCollectionMode {
265
+ recordCollectionModeChangeActivity (newConf .ID , newConf .Name , oldCollectionMode , newConf .MetricCollectionMode )
266
+ }
259
267
basicAuth , err := common .GetBasicAuth (newConf )
260
268
if err != nil {
261
269
h .WriteError (w , err .Error (), http .StatusInternalServerError )
@@ -273,6 +281,47 @@ func (h *APIHandler) HandleUpdateClusterAction(w http.ResponseWriter, req *http.
273
281
h .WriteUpdatedOKJSON (w , id )
274
282
}
275
283
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
+
276
325
func (h * APIHandler ) HandleDeleteClusterAction (w http.ResponseWriter , req * http.Request , ps httprouter.Params ) {
277
326
resBody := map [string ]interface {}{}
278
327
id := ps .MustGetParameter ("id" )
0 commit comments