Skip to content

Commit 46a5976

Browse files
authored
feat: splitting metric query, adding query param key for query metric api to support single metric query (#7)
* feat: support query es cluster metrics with special key * feat: adding context param to control metric request timeout * feat: splitting metric query, adding query param `key` for query metric api to support single metric query * chore: clean unused code * fix: wrong metric key
1 parent 004f4bd commit 46a5976

16 files changed

+3081
-4460
lines changed

modules/elastic/api/cluster_overview.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
package api
2525

2626
import (
27+
"context"
2728
"fmt"
2829
"infini.sh/framework/modules/elastic/adapter"
2930
"net/http"
@@ -254,7 +255,7 @@ func (h *APIHandler) FetchClusterInfo(w http.ResponseWriter, req *http.Request,
254255
},
255256
},
256257
}
257-
indexMetrics := h.getMetrics(query, indexMetricItems, bucketSize)
258+
indexMetrics := h.getMetrics(context.Background(), query, indexMetricItems, bucketSize)
258259
indexingMetricData := util.MapStr{}
259260
for _, line := range indexMetrics["cluster_indexing"].Lines {
260261
// remove first metric dot

modules/elastic/api/host.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
package api
2929

3030
import (
31+
"context"
3132
"fmt"
3233
log "github.com/cihub/seelog"
3334
httprouter "infini.sh/framework/core/api/router"
@@ -604,10 +605,10 @@ func (h *APIHandler) getSingleHostMetric(agentID string, min, max int64, bucketS
604605
},
605606
},
606607
}
607-
return h.getSingleMetrics(metricItems, query, bucketSize)
608+
return h.getSingleMetrics(context.Background(), metricItems, query, bucketSize)
608609
}
609610

610-
func (h *APIHandler) getSingleHostMetricFromNode(nodeID string, min, max int64, bucketSize int) map[string]*common.MetricItem {
611+
func (h *APIHandler) getSingleHostMetricFromNode(ctx context.Context, nodeID string, min, max int64, bucketSize int) map[string]*common.MetricItem {
611612
var must = []util.MapStr{
612613
{
613614
"term": util.MapStr{
@@ -669,7 +670,7 @@ func (h *APIHandler) getSingleHostMetricFromNode(nodeID string, min, max int64,
669670
return 100 - value*100/value2
670671
}
671672
metricItems = append(metricItems, metricItem)
672-
return h.getSingleMetrics(metricItems, query, bucketSize)
673+
return h.getSingleMetrics(ctx, metricItems, query, bucketSize)
673674
}
674675

675676
func (h *APIHandler) GetSingleHostMetrics(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
@@ -696,7 +697,7 @@ func (h *APIHandler) GetSingleHostMetrics(w http.ResponseWriter, req *http.Reque
696697
return
697698
}
698699
if hostInfo.AgentID == "" {
699-
resBody["metrics"] = h.getSingleHostMetricFromNode(hostInfo.NodeID, min, max, bucketSize)
700+
resBody["metrics"] = h.getSingleHostMetricFromNode(context.Background(), hostInfo.NodeID, min, max, bucketSize)
700701
h.WriteJSON(w, resBody, http.StatusOK)
701702
return
702703
}
@@ -866,7 +867,7 @@ func (h *APIHandler) getGroupHostMetric(agentIDs []string, min, max int64, bucke
866867
},
867868
},
868869
}
869-
return h.getMetrics(query, hostMetricItems, bucketSize)
870+
return h.getMetrics(context.Background(), query, hostMetricItems, bucketSize)
870871
}
871872

872873
func getHost(hostID string) (*host.HostInfo, error) {

0 commit comments

Comments
 (0)