chore: adapter metrics query with cluster id and cluster uuid (#56)

* chore: adapter metrics query with cluster id and cluster uuid

* chore: reads cluster uuid from metadata

* chore: update release notes

* chore: update release notes

---------

Co-authored-by: Hardy <luohoufu@163.com>
This commit is contained in:
silenceqi 2024-12-24 15:29:14 +08:00 committed by GitHub
parent c843711135
commit edaa276ac3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 129 additions and 67 deletions

View File

@ -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)

View File

@ -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{

View File

@ -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,11 +1201,11 @@ 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) {
bucketSizeStr := fmt.Sprintf("%vs", bucketSize)
query := util.MapStr{
"query": util.MapStr{
"bool": util.MapStr{
"must": []util.MapStr{
clusterUUID, err := h.getClusterUUID(id)
if err != nil {
return nil, err
}
should := []util.MapStr{
{
"term": util.MapStr{
"metadata.labels.cluster_id": util.MapStr{
@ -1204,6 +1213,21 @@ func (h *APIHandler) getCircuitBreakerMetric(ctx context.Context, id string, min
},
},
},
{
"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.category": util.MapStr{

View File

@ -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,16 +109,12 @@ 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
}
var must = []util.MapStr{
{
"bool": util.MapStr{
"minimum_should_match": 1,
"should": []util.MapStr{
should := []util.MapStr{
{
"term": util.MapStr{
"metadata.labels.cluster_id": util.MapStr{
@ -134,7 +129,12 @@ func (h *APIHandler) getNodeMetrics(ctx context.Context, clusterID string, bucke
},
},
},
},
}
var must = []util.MapStr{
{
"bool": util.MapStr{
"minimum_should_match": 1,
"should": should,
},
},
{

View File

@ -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)

View File

@ -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,16 +134,10 @@ func (h *APIHandler) getThreadPoolMetrics(ctx context.Context, clusterID string,
})
}
query:=map[string]interface{}{}
query["query"]=util.MapStr{
"bool": util.MapStr{
"must": must,
"minimum_should_match": 1,
"should": []util.MapStr{
should := []util.MapStr{
{
"term":util.MapStr{
"metadata.labels.cluster_id":util.MapStr{
"term": util.MapStr{
"metadata.labels.cluster_id": util.MapStr{
"value": clusterID,
},
},
@ -156,7 +149,14 @@ func (h *APIHandler) getThreadPoolMetrics(ctx context.Context, clusterID string,
},
},
},
},
}
query:=map[string]interface{}{}
query["query"]=util.MapStr{
"bool": util.MapStr{
"must": must,
"minimum_should_match": 1,
"should": should,
"filter": []util.MapStr{
{
"range": util.MapStr{