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:
parent
c843711135
commit
edaa276ac3
|
@ -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.
|
- Add allocation to activities if is cluster health change and changed to red.
|
||||||
|
|
||||||
### Bug fix
|
### Bug fix
|
||||||
- Fix query thread pool metrics when cluster uuid is empty
|
- Fixed query thread pool metrics when cluster uuid is empty
|
||||||
|
|
||||||
### Improvements
|
### Improvements
|
||||||
- Optimize UI of agent list when its columns are overflow.
|
- Optimize UI of agent list when its columns are overflow.
|
||||||
- Add loading to each row in overview table.
|
- Add loading to each row in overview table.
|
||||||
|
- Adapter metrics query with cluster id and cluster uuid
|
||||||
|
|
||||||
|
|
||||||
## 1.27.0 (2024-12-09)
|
## 1.27.0 (2024-12-09)
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,6 @@ import (
|
||||||
"infini.sh/framework/core/global"
|
"infini.sh/framework/core/global"
|
||||||
"infini.sh/framework/core/radix"
|
"infini.sh/framework/core/radix"
|
||||||
"infini.sh/framework/core/util"
|
"infini.sh/framework/core/util"
|
||||||
"infini.sh/framework/modules/elastic/adapter"
|
|
||||||
"infini.sh/framework/modules/elastic/common"
|
"infini.sh/framework/modules/elastic/common"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -40,21 +39,41 @@ import (
|
||||||
"time"
|
"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){
|
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)
|
bucketSizeStr:=fmt.Sprintf("%vs",bucketSize)
|
||||||
clusterUUID, err := adapter.GetClusterUUID(clusterID)
|
clusterUUID, err := h.getClusterUUID(clusterID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
should := []util.MapStr{
|
||||||
var must = []util.MapStr{
|
|
||||||
{
|
{
|
||||||
|
"term":util.MapStr{
|
||||||
|
"metadata.labels.cluster_id":util.MapStr{
|
||||||
|
"value": clusterID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if clusterUUID != "" {
|
||||||
|
should = append(should, util.MapStr{
|
||||||
"term":util.MapStr{
|
"term":util.MapStr{
|
||||||
"metadata.labels.cluster_uuid":util.MapStr{
|
"metadata.labels.cluster_uuid":util.MapStr{
|
||||||
"value": clusterUUID,
|
"value": clusterUUID,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var must = []util.MapStr{
|
||||||
{
|
{
|
||||||
"term": util.MapStr{
|
"term": util.MapStr{
|
||||||
"metadata.category": 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{
|
query["query"]=util.MapStr{
|
||||||
"bool": util.MapStr{
|
"bool": util.MapStr{
|
||||||
"must": must,
|
"must": must,
|
||||||
|
"minimum_should_match": 1,
|
||||||
|
"should": should,
|
||||||
"must_not": []util.MapStr{
|
"must_not": []util.MapStr{
|
||||||
{
|
{
|
||||||
"term": util.MapStr{
|
"term": util.MapStr{
|
||||||
|
@ -747,7 +768,7 @@ func (h *APIHandler) getTopIndexName(req *http.Request, clusterID string, top in
|
||||||
max = now.UnixNano()/1e6
|
max = now.UnixNano()/1e6
|
||||||
min = now.Add(-time.Duration(lastMinutes) * time.Minute).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 {
|
if err != nil {
|
||||||
return nil, err
|
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{
|
"term": util.MapStr{
|
||||||
"metadata.labels.cluster_uuid": 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,
|
"must": must,
|
||||||
|
"should": should,
|
||||||
|
"minimum_should_match": 1,
|
||||||
"filter": []util.MapStr{
|
"filter": []util.MapStr{
|
||||||
{
|
{
|
||||||
"range": util.MapStr{
|
"range": util.MapStr{
|
||||||
|
|
|
@ -38,7 +38,6 @@ import (
|
||||||
"infini.sh/framework/core/model"
|
"infini.sh/framework/core/model"
|
||||||
"infini.sh/framework/core/orm"
|
"infini.sh/framework/core/orm"
|
||||||
"infini.sh/framework/core/util"
|
"infini.sh/framework/core/util"
|
||||||
"infini.sh/framework/modules/elastic/adapter"
|
|
||||||
"infini.sh/framework/modules/elastic/common"
|
"infini.sh/framework/modules/elastic/common"
|
||||||
"math"
|
"math"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -1085,13 +1084,21 @@ func (h *APIHandler) GetClusterIndexMetrics(ctx context.Context, id string, buck
|
||||||
panic("unknown metric key: " + metricKey)
|
panic("unknown metric key: " + metricKey)
|
||||||
}
|
}
|
||||||
query := map[string]interface{}{}
|
query := map[string]interface{}{}
|
||||||
clusterUUID, err := adapter.GetClusterUUID(id)
|
clusterUUID, err := h.getClusterUUID(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
query["query"] = util.MapStr{
|
query["query"] = util.MapStr{
|
||||||
"bool": 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{
|
"term": util.MapStr{
|
||||||
"metadata.labels.cluster_uuid": 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{
|
"term": util.MapStr{
|
||||||
"metadata.category": 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) {
|
func (h *APIHandler) getCircuitBreakerMetric(ctx context.Context, id string, min, max int64, bucketSize int) (map[string]*common.MetricItem, error) {
|
||||||
bucketSizeStr := fmt.Sprintf("%vs", bucketSize)
|
clusterUUID, err := h.getClusterUUID(id)
|
||||||
query := util.MapStr{
|
if err != nil {
|
||||||
"query": util.MapStr{
|
return nil, err
|
||||||
"bool": util.MapStr{
|
}
|
||||||
"must": []util.MapStr{
|
should := []util.MapStr{
|
||||||
{
|
{
|
||||||
"term": util.MapStr{
|
"term": util.MapStr{
|
||||||
"metadata.labels.cluster_id": 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{
|
"term": util.MapStr{
|
||||||
"metadata.category": util.MapStr{
|
"metadata.category": util.MapStr{
|
||||||
|
|
|
@ -30,7 +30,6 @@ import (
|
||||||
"infini.sh/framework/core/elastic"
|
"infini.sh/framework/core/elastic"
|
||||||
"infini.sh/framework/core/global"
|
"infini.sh/framework/core/global"
|
||||||
"infini.sh/framework/core/util"
|
"infini.sh/framework/core/util"
|
||||||
"infini.sh/framework/modules/elastic/adapter"
|
|
||||||
"infini.sh/framework/modules/elastic/common"
|
"infini.sh/framework/modules/elastic/common"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"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){
|
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)
|
bucketSizeStr:=fmt.Sprintf("%vs",bucketSize)
|
||||||
clusterUUID, err := adapter.GetClusterUUID(clusterID)
|
clusterUUID, err := h.getClusterUUID(clusterID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var must = []util.MapStr{
|
should := []util.MapStr{
|
||||||
{
|
|
||||||
"bool": util.MapStr{
|
|
||||||
"minimum_should_match": 1,
|
|
||||||
"should": []util.MapStr{
|
|
||||||
{
|
{
|
||||||
"term": util.MapStr{
|
"term": util.MapStr{
|
||||||
"metadata.labels.cluster_id": 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,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -39,7 +39,6 @@ import (
|
||||||
"infini.sh/framework/core/orm"
|
"infini.sh/framework/core/orm"
|
||||||
"infini.sh/framework/core/radix"
|
"infini.sh/framework/core/radix"
|
||||||
"infini.sh/framework/core/util"
|
"infini.sh/framework/core/util"
|
||||||
"infini.sh/framework/modules/elastic/adapter"
|
|
||||||
"infini.sh/framework/modules/elastic/common"
|
"infini.sh/framework/modules/elastic/common"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
@ -587,14 +586,19 @@ const (
|
||||||
|
|
||||||
func (h *APIHandler) GetSingleNodeMetrics(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (h *APIHandler) GetSingleNodeMetrics(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
clusterID := ps.MustGetParameter("id")
|
clusterID := ps.MustGetParameter("id")
|
||||||
clusterUUID, err := adapter.GetClusterUUID(clusterID)
|
clusterUUID, err := h.getClusterUUID(clusterID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
|
||||||
h.WriteError(w, err.Error(), http.StatusInternalServerError)
|
h.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
nodeID := ps.MustGetParameter("node_id")
|
should := []util.MapStr{
|
||||||
var must = []util.MapStr{
|
{
|
||||||
|
"term":util.MapStr{
|
||||||
|
"metadata.labels.cluster_id":util.MapStr{
|
||||||
|
"value": clusterID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"term":util.MapStr{
|
"term":util.MapStr{
|
||||||
"metadata.labels.cluster_uuid":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{
|
"term": util.MapStr{
|
||||||
"metadata.category": util.MapStr{
|
"metadata.category": util.MapStr{
|
||||||
|
@ -636,6 +643,8 @@ func (h *APIHandler) GetSingleNodeMetrics(w http.ResponseWriter, req *http.Reque
|
||||||
query["query"]=util.MapStr{
|
query["query"]=util.MapStr{
|
||||||
"bool": util.MapStr{
|
"bool": util.MapStr{
|
||||||
"must": must,
|
"must": must,
|
||||||
|
"minimum_should_match": 1,
|
||||||
|
"should": should,
|
||||||
"filter": []util.MapStr{
|
"filter": []util.MapStr{
|
||||||
{
|
{
|
||||||
"range": util.MapStr{
|
"range": util.MapStr{
|
||||||
|
@ -675,14 +684,9 @@ func (h *APIHandler) GetSingleNodeMetrics(w http.ResponseWriter, req *http.Reque
|
||||||
"size": 0,
|
"size": 0,
|
||||||
"query": util.MapStr{
|
"query": util.MapStr{
|
||||||
"bool": util.MapStr{
|
"bool": util.MapStr{
|
||||||
|
"minimum_should_match": 1,
|
||||||
|
"should": should,
|
||||||
"must": []util.MapStr{
|
"must": []util.MapStr{
|
||||||
{
|
|
||||||
"term":util.MapStr{
|
|
||||||
"metadata.labels.cluster_uuid":util.MapStr{
|
|
||||||
"value": clusterUUID,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"term": util.MapStr{
|
"term": util.MapStr{
|
||||||
"metadata.category": 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 {
|
if !hasAllPrivilege && len(allowedIndices) == 0 {
|
||||||
return []interface{}{}, nil
|
return []interface{}{}, nil
|
||||||
}
|
}
|
||||||
clusterUUID, err := adapter.GetClusterUUID(clusterID)
|
clusterUUID, err := h.getClusterUUID(clusterID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -1296,7 +1300,7 @@ func (h *APIHandler) GetNodeShards(w http.ResponseWriter, req *http.Request, ps
|
||||||
WildcardIndex: true,
|
WildcardIndex: true,
|
||||||
CollapseField: "metadata.labels.shard_id",
|
CollapseField: "metadata.labels.shard_id",
|
||||||
}
|
}
|
||||||
clusterUUID, err := adapter.GetClusterUUID(clusterID)
|
clusterUUID, err := h.getClusterUUID(clusterID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
h.WriteError(w, err.Error(), http.StatusInternalServerError)
|
h.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
|
|
@ -30,7 +30,6 @@ import (
|
||||||
"infini.sh/framework/core/elastic"
|
"infini.sh/framework/core/elastic"
|
||||||
"infini.sh/framework/core/global"
|
"infini.sh/framework/core/global"
|
||||||
"infini.sh/framework/core/util"
|
"infini.sh/framework/core/util"
|
||||||
"infini.sh/framework/modules/elastic/adapter"
|
|
||||||
"infini.sh/framework/modules/elastic/common"
|
"infini.sh/framework/modules/elastic/common"
|
||||||
"strings"
|
"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){
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -135,13 +134,7 @@ func (h *APIHandler) getThreadPoolMetrics(ctx context.Context, clusterID string,
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
should := []util.MapStr{
|
||||||
query:=map[string]interface{}{}
|
|
||||||
query["query"]=util.MapStr{
|
|
||||||
"bool": util.MapStr{
|
|
||||||
"must": must,
|
|
||||||
"minimum_should_match": 1,
|
|
||||||
"should": []util.MapStr{
|
|
||||||
{
|
{
|
||||||
"term": util.MapStr{
|
"term": util.MapStr{
|
||||||
"metadata.labels.cluster_id": util.MapStr{
|
"metadata.labels.cluster_id": util.MapStr{
|
||||||
|
@ -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{
|
"filter": []util.MapStr{
|
||||||
{
|
{
|
||||||
"range": util.MapStr{
|
"range": util.MapStr{
|
||||||
|
|
Loading…
Reference in New Issue