Merge pull request #3715 from zhu733756/fix-bug-for-node-metrics-on-overview-page
fix bug for node metrics on overview page
This commit is contained in:
@@ -90,6 +90,7 @@ type reqParams struct {
|
||||
cluster string
|
||||
services string
|
||||
pvcFilter string
|
||||
queryType string
|
||||
}
|
||||
|
||||
type queryOptions struct {
|
||||
@@ -145,6 +146,7 @@ func parseRequestParams(req *restful.Request) reqParams {
|
||||
r.componentType = req.PathParameter("component")
|
||||
r.expression = req.QueryParameter("expr")
|
||||
r.metric = req.QueryParameter("metric")
|
||||
r.queryType = req.QueryParameter("type")
|
||||
|
||||
return r
|
||||
}
|
||||
@@ -213,6 +215,7 @@ func (h handler) makeQueryOptions(r reqParams, lvl monitoring.Level) (q queryOpt
|
||||
NodeName: r.nodeName,
|
||||
PVCFilter: r.pvcFilter, // metering pvc
|
||||
StorageClassName: r.storageClassName, // metering pvc
|
||||
QueryType: r.queryType,
|
||||
}
|
||||
q.namedMetrics = model.NodeMetrics
|
||||
|
||||
|
||||
@@ -80,6 +80,7 @@ func AddToContainer(c *restful.Container, k8sClient kubernetes.Interface, monito
|
||||
Param(ws.QueryParameter("sort_type", "Sort order. One of asc, desc.").DefaultValue("desc.").DataType("string").Required(false)).
|
||||
Param(ws.QueryParameter("page", "The page number. This field paginates result data of each metric, then returns a specific page. For example, setting **page** to 2 returns the second page. It only applies to sorted metric data.").DataType("integer").Required(false)).
|
||||
Param(ws.QueryParameter("limit", "Page size, the maximum number of results in a single page. Defaults to 5.").DataType("integer").Required(false).DefaultValue("5")).
|
||||
Param(ws.QueryParameter("type", "The query type. This field can be set to 'rank' for node ranking query or '' for others. Defaults to ''.").DataType("string").Required(false).DefaultValue("")).
|
||||
Metadata(restfulspec.KeyOpenAPITags, []string{constants.NodeMetricsTag}).
|
||||
Writes(model.Metrics{}).
|
||||
Returns(http.StatusOK, respOK, model.Metrics{})).
|
||||
|
||||
@@ -115,16 +115,23 @@ func (mo monitoringOperator) GetMetricOverTime(expr, namespace string, start, en
|
||||
func (mo monitoringOperator) GetNamedMetrics(metrics []string, time time.Time, opt monitoring.QueryOption) Metrics {
|
||||
ress := mo.prometheus.GetNamedMetrics(metrics, time, opt)
|
||||
|
||||
if mo.metricsserver != nil {
|
||||
opts := &monitoring.QueryOptions{}
|
||||
opt.Apply(opts)
|
||||
|
||||
var isNodeRankingQuery bool
|
||||
if opts.QueryType == "rank" {
|
||||
isNodeRankingQuery = true
|
||||
}
|
||||
|
||||
if mo.metricsserver != nil {
|
||||
//Merge edge node metrics data
|
||||
edgeMetrics := make(map[string]monitoring.MetricData)
|
||||
|
||||
for i, ressMetric := range ress {
|
||||
metricName := ressMetric.MetricName
|
||||
ressMetricValues := ressMetric.MetricData.MetricValues
|
||||
if len(ressMetricValues) == 0 {
|
||||
// this metric has no prometheus metrics data
|
||||
if len(ressMetricValues) == 0 || isNodeRankingQuery {
|
||||
// this metric has no prometheus metrics data or the request need to list all nodes metrics
|
||||
if len(edgeMetrics) == 0 {
|
||||
// start to request monintoring metricsApi data
|
||||
mr := mo.metricsserver.GetNamedMetrics(metrics, time, opt)
|
||||
|
||||
@@ -67,6 +67,7 @@ type QueryOptions struct {
|
||||
Level Level
|
||||
|
||||
NamespacedResourcesFilter string
|
||||
QueryType string
|
||||
ResourceFilter string
|
||||
NodeName string
|
||||
WorkspaceName string
|
||||
@@ -98,6 +99,7 @@ type NodeOption struct {
|
||||
NodeName string
|
||||
PVCFilter string
|
||||
StorageClassName string
|
||||
QueryType string
|
||||
}
|
||||
|
||||
func (no NodeOption) Apply(o *QueryOptions) {
|
||||
@@ -106,6 +108,7 @@ func (no NodeOption) Apply(o *QueryOptions) {
|
||||
o.NodeName = no.NodeName
|
||||
o.PVCFilter = no.PVCFilter
|
||||
o.StorageClassName = no.StorageClassName
|
||||
o.QueryType = no.QueryType
|
||||
}
|
||||
|
||||
type WorkspaceOption struct {
|
||||
|
||||
Reference in New Issue
Block a user