diff --git a/docs/content.en/docs/release-notes/_index.md b/docs/content.en/docs/release-notes/_index.md index 6b15d269..2d0f74bc 100644 --- a/docs/content.en/docs/release-notes/_index.md +++ b/docs/content.en/docs/release-notes/_index.md @@ -15,11 +15,13 @@ Information about release notes of INFINI Console is provided here. - Add allocation to activities if is cluster health change and changed to red. ### Bug fix -- Fix query thread pool metrics when cluster uuid is empty +- Fixed query thread pool metrics when cluster uuid is empty ### Improvements - Optimize UI of agent list when its columns are overflow. - Add loading to each row in overview table. +- Adapter metrics query with cluster id and cluster uuid + ## 1.27.0 (2024-12-09) diff --git a/modules/elastic/api/index_metrics.go b/modules/elastic/api/index_metrics.go index 587ae2a9..1936af01 100644 --- a/modules/elastic/api/index_metrics.go +++ b/modules/elastic/api/index_metrics.go @@ -32,7 +32,6 @@ import ( "infini.sh/framework/core/global" "infini.sh/framework/core/radix" "infini.sh/framework/core/util" - "infini.sh/framework/modules/elastic/adapter" "infini.sh/framework/modules/elastic/common" "net/http" "sort" @@ -40,21 +39,41 @@ import ( "time" ) +//getClusterUUID reads the cluster uuid from metadata +func (h *APIHandler) getClusterUUID(clusterID string) (string, error){ + meta := elastic.GetMetadata(clusterID) + if meta == nil { + return "", fmt.Errorf("metadata of cluster [%s] was not found", clusterID) + } + return meta.Config.ClusterUUID, nil +} + func (h *APIHandler) getIndexMetrics(ctx context.Context, req *http.Request, clusterID string, bucketSize int, min, max int64, indexName string, top int, shardID string, metricKey string) (map[string]*common.MetricItem, error){ bucketSizeStr:=fmt.Sprintf("%vs",bucketSize) - clusterUUID, err := adapter.GetClusterUUID(clusterID) + clusterUUID, err := h.getClusterUUID(clusterID) if err != nil { return nil, err } - - var must = []util.MapStr{ + should := []util.MapStr{ { + "term":util.MapStr{ + "metadata.labels.cluster_id":util.MapStr{ + "value": clusterID, + }, + }, + }, + } + if clusterUUID != "" { + should = append(should, util.MapStr{ "term":util.MapStr{ "metadata.labels.cluster_uuid":util.MapStr{ "value": clusterUUID, }, }, - }, + }) + } + + var must = []util.MapStr{ { "term": util.MapStr{ "metadata.category": util.MapStr{ @@ -664,6 +683,8 @@ func (h *APIHandler) getIndexMetrics(ctx context.Context, req *http.Request, clu query["query"]=util.MapStr{ "bool": util.MapStr{ "must": must, + "minimum_should_match": 1, + "should": should, "must_not": []util.MapStr{ { "term": util.MapStr{ @@ -747,7 +768,7 @@ func (h *APIHandler) getTopIndexName(req *http.Request, clusterID string, top in max = now.UnixNano()/1e6 min = now.Add(-time.Duration(lastMinutes) * time.Minute).UnixNano()/1e6 ) - clusterUUID, err := adapter.GetClusterUUID(clusterID) + clusterUUID, err := h.getClusterUUID(clusterID) if err != nil { return nil, err } @@ -766,6 +787,15 @@ func (h *APIHandler) getTopIndexName(req *http.Request, clusterID string, top in }, }, }, + } + should := []util.MapStr{ + { + "term": util.MapStr{ + "metadata.labels.cluster_uuid": util.MapStr{ + "value": clusterID, + }, + }, + }, { "term": util.MapStr{ "metadata.labels.cluster_uuid": util.MapStr{ @@ -807,6 +837,8 @@ func (h *APIHandler) getTopIndexName(req *http.Request, clusterID string, top in }, }, "must": must, + "should": should, + "minimum_should_match": 1, "filter": []util.MapStr{ { "range": util.MapStr{ diff --git a/modules/elastic/api/manage.go b/modules/elastic/api/manage.go index cd83e67b..1fb19019 100644 --- a/modules/elastic/api/manage.go +++ b/modules/elastic/api/manage.go @@ -38,7 +38,6 @@ import ( "infini.sh/framework/core/model" "infini.sh/framework/core/orm" "infini.sh/framework/core/util" - "infini.sh/framework/modules/elastic/adapter" "infini.sh/framework/modules/elastic/common" "math" "net/http" @@ -1085,13 +1084,21 @@ func (h *APIHandler) GetClusterIndexMetrics(ctx context.Context, id string, buck panic("unknown metric key: " + metricKey) } query := map[string]interface{}{} - clusterUUID, err := adapter.GetClusterUUID(id) + clusterUUID, err := h.getClusterUUID(id) if err != nil { return nil, err } query["query"] = util.MapStr{ "bool": util.MapStr{ - "must": []util.MapStr{ + "minimum_should_match": 1, + "should": []util.MapStr{ + { + "term": util.MapStr{ + "metadata.labels.cluster_id": util.MapStr{ + "value": id, + }, + }, + }, { "term": util.MapStr{ "metadata.labels.cluster_uuid": util.MapStr{ @@ -1099,6 +1106,8 @@ func (h *APIHandler) GetClusterIndexMetrics(ctx context.Context, id string, buck }, }, }, + }, + "must": []util.MapStr{ { "term": util.MapStr{ "metadata.category": util.MapStr{ @@ -1192,18 +1201,33 @@ func (h *APIHandler) getShardsMetric(ctx context.Context, id string, min, max in } func (h *APIHandler) getCircuitBreakerMetric(ctx context.Context, id string, min, max int64, bucketSize int) (map[string]*common.MetricItem, error) { + clusterUUID, err := h.getClusterUUID(id) + if err != nil { + return nil, err + } + should := []util.MapStr{ + { + "term": util.MapStr{ + "metadata.labels.cluster_id": util.MapStr{ + "value": id, + }, + }, + }, + { + "term": util.MapStr{ + "metadata.labels.cluster_uuid": util.MapStr{ + "value": clusterUUID, + }, + }, + }, + } bucketSizeStr := fmt.Sprintf("%vs", bucketSize) query := util.MapStr{ "query": util.MapStr{ "bool": util.MapStr{ + "minimum_should_match": 1, + "should": should, "must": []util.MapStr{ - { - "term": util.MapStr{ - "metadata.labels.cluster_id": util.MapStr{ - "value": id, - }, - }, - }, { "term": util.MapStr{ "metadata.category": util.MapStr{ diff --git a/modules/elastic/api/node_metrics.go b/modules/elastic/api/node_metrics.go index d42d3cf2..8f4ac425 100644 --- a/modules/elastic/api/node_metrics.go +++ b/modules/elastic/api/node_metrics.go @@ -30,7 +30,6 @@ import ( "infini.sh/framework/core/elastic" "infini.sh/framework/core/global" "infini.sh/framework/core/util" - "infini.sh/framework/modules/elastic/adapter" "infini.sh/framework/modules/elastic/common" "sort" "strings" @@ -110,31 +109,32 @@ const ( func (h *APIHandler) getNodeMetrics(ctx context.Context, clusterID string, bucketSize int, min, max int64, nodeName string, top int, metricKey string) (map[string]*common.MetricItem, error){ bucketSizeStr:=fmt.Sprintf("%vs",bucketSize) - clusterUUID, err := adapter.GetClusterUUID(clusterID) + clusterUUID, err := h.getClusterUUID(clusterID) if err != nil { return nil, err } + should := []util.MapStr{ + { + "term": util.MapStr{ + "metadata.labels.cluster_id": util.MapStr{ + "value": clusterID, + }, + }, + }, + { + "term": util.MapStr{ + "metadata.labels.cluster_uuid": util.MapStr{ + "value": clusterUUID, + }, + }, + }, + } var must = []util.MapStr{ { "bool": util.MapStr{ "minimum_should_match": 1, - "should": []util.MapStr{ - { - "term": util.MapStr{ - "metadata.labels.cluster_id": util.MapStr{ - "value": clusterID, - }, - }, - }, - { - "term": util.MapStr{ - "metadata.labels.cluster_uuid": util.MapStr{ - "value": clusterUUID, - }, - }, - }, - }, + "should": should, }, }, { diff --git a/modules/elastic/api/node_overview.go b/modules/elastic/api/node_overview.go index 872eaaed..bd19a017 100644 --- a/modules/elastic/api/node_overview.go +++ b/modules/elastic/api/node_overview.go @@ -39,7 +39,6 @@ import ( "infini.sh/framework/core/orm" "infini.sh/framework/core/radix" "infini.sh/framework/core/util" - "infini.sh/framework/modules/elastic/adapter" "infini.sh/framework/modules/elastic/common" "net/http" "time" @@ -587,14 +586,19 @@ const ( func (h *APIHandler) GetSingleNodeMetrics(w http.ResponseWriter, req *http.Request, ps httprouter.Params) { clusterID := ps.MustGetParameter("id") - clusterUUID, err := adapter.GetClusterUUID(clusterID) + clusterUUID, err := h.getClusterUUID(clusterID) if err != nil { - log.Error(err) h.WriteError(w, err.Error(), http.StatusInternalServerError) return } - nodeID := ps.MustGetParameter("node_id") - var must = []util.MapStr{ + should := []util.MapStr{ + { + "term":util.MapStr{ + "metadata.labels.cluster_id":util.MapStr{ + "value": clusterID, + }, + }, + }, { "term":util.MapStr{ "metadata.labels.cluster_uuid":util.MapStr{ @@ -602,6 +606,9 @@ func (h *APIHandler) GetSingleNodeMetrics(w http.ResponseWriter, req *http.Reque }, }, }, + } + nodeID := ps.MustGetParameter("node_id") + var must = []util.MapStr{ { "term": util.MapStr{ "metadata.category": util.MapStr{ @@ -636,6 +643,8 @@ func (h *APIHandler) GetSingleNodeMetrics(w http.ResponseWriter, req *http.Reque query["query"]=util.MapStr{ "bool": util.MapStr{ "must": must, + "minimum_should_match": 1, + "should": should, "filter": []util.MapStr{ { "range": util.MapStr{ @@ -675,14 +684,9 @@ func (h *APIHandler) GetSingleNodeMetrics(w http.ResponseWriter, req *http.Reque "size": 0, "query": util.MapStr{ "bool": util.MapStr{ + "minimum_should_match": 1, + "should": should, "must": []util.MapStr{ - { - "term":util.MapStr{ - "metadata.labels.cluster_uuid":util.MapStr{ - "value": clusterUUID, - }, - }, - }, { "term": util.MapStr{ "metadata.category": util.MapStr{ @@ -1144,7 +1148,7 @@ func (h *APIHandler) getLatestIndices(req *http.Request, min string, max string, if !hasAllPrivilege && len(allowedIndices) == 0 { return []interface{}{}, nil } - clusterUUID, err := adapter.GetClusterUUID(clusterID) + clusterUUID, err := h.getClusterUUID(clusterID) if err != nil { return nil, err } @@ -1296,7 +1300,7 @@ func (h *APIHandler) GetNodeShards(w http.ResponseWriter, req *http.Request, ps WildcardIndex: true, CollapseField: "metadata.labels.shard_id", } - clusterUUID, err := adapter.GetClusterUUID(clusterID) + clusterUUID, err := h.getClusterUUID(clusterID) if err != nil { log.Error(err) h.WriteError(w, err.Error(), http.StatusInternalServerError) diff --git a/modules/elastic/api/threadpool_metrics.go b/modules/elastic/api/threadpool_metrics.go index e4c2dd87..a7bae610 100644 --- a/modules/elastic/api/threadpool_metrics.go +++ b/modules/elastic/api/threadpool_metrics.go @@ -30,7 +30,6 @@ import ( "infini.sh/framework/core/elastic" "infini.sh/framework/core/global" "infini.sh/framework/core/util" - "infini.sh/framework/modules/elastic/adapter" "infini.sh/framework/modules/elastic/common" "strings" ) @@ -82,7 +81,7 @@ const ( ) func (h *APIHandler) getThreadPoolMetrics(ctx context.Context, clusterID string, bucketSize int, min, max int64, nodeName string, top int, metricKey string) (map[string]*common.MetricItem, error){ - clusterUUID, err := adapter.GetClusterUUID(clusterID) + clusterUUID, err := h.getClusterUUID(clusterID) if err != nil { return nil, err } @@ -135,28 +134,29 @@ func (h *APIHandler) getThreadPoolMetrics(ctx context.Context, clusterID string, }) } + should := []util.MapStr{ + { + "term": util.MapStr{ + "metadata.labels.cluster_id": util.MapStr{ + "value": clusterID, + }, + }, + }, + { + "term":util.MapStr{ + "metadata.labels.cluster_uuid":util.MapStr{ + "value": clusterUUID, + }, + }, + }, + } query:=map[string]interface{}{} query["query"]=util.MapStr{ "bool": util.MapStr{ "must": must, "minimum_should_match": 1, - "should": []util.MapStr{ - { - "term":util.MapStr{ - "metadata.labels.cluster_id":util.MapStr{ - "value": clusterID, - }, - }, - }, - { - "term":util.MapStr{ - "metadata.labels.cluster_uuid":util.MapStr{ - "value": clusterUUID, - }, - }, - }, - }, + "should": should, "filter": []util.MapStr{ { "range": util.MapStr{