Merge pull request #3692 from yunkunrao/bug-fix

Add namespacedResourcesFilter field back in reqParams struct.
This commit is contained in:
KubeSphere CI Bot
2021-04-07 23:03:13 +08:00
committed by GitHub
2 changed files with 65 additions and 35 deletions

View File

@@ -60,35 +60,36 @@ const (
)
type reqParams struct {
metering bool
operation string
time string
start string
end string
step string
target string
order string
page string
limit string
metricFilter string
resourceFilter string
nodeName string
workspaceName string
namespaceName string
workloadKind string
workloadName string
podName string
containerName string
pvcName string
storageClassName string
componentType string
expression string
metric string
applications string
openpitrixs string
cluster string
services string
pvcFilter string
metering bool
operation string
time string
start string
end string
step string
target string
order string
page string
limit string
metricFilter string
namespacedResourcesFilter string
resourceFilter string
nodeName string
workspaceName string
namespaceName string
workloadKind string
workloadName string
podName string
containerName string
pvcName string
storageClassName string
componentType string
expression string
metric string
applications string
openpitrixs string
cluster string
services string
pvcFilter string
}
type queryOptions struct {
@@ -130,6 +131,7 @@ func parseRequestParams(req *restful.Request) reqParams {
r.page = req.QueryParameter("page")
r.limit = req.QueryParameter("limit")
r.metricFilter = req.QueryParameter("metrics_filter")
r.namespacedResourcesFilter = req.QueryParameter("namespaced_resources_filter")
r.resourceFilter = req.QueryParameter("resources_filter")
r.workspaceName = req.PathParameter("workspace")
r.namespaceName = req.PathParameter("namespace")
@@ -285,12 +287,13 @@ func (h handler) makeQueryOptions(r reqParams, lvl monitoring.Level) (q queryOpt
case monitoring.LevelPod:
q.identifier = model.IdentifierPod
q.option = monitoring.PodOption{
ResourceFilter: r.resourceFilter,
NodeName: r.nodeName,
NamespaceName: r.namespaceName,
WorkloadKind: r.workloadKind,
WorkloadName: r.workloadName,
PodName: r.podName,
NamespacedResourcesFilter: r.namespacedResourcesFilter,
ResourceFilter: r.resourceFilter,
NodeName: r.nodeName,
NamespaceName: r.namespaceName,
WorkloadKind: r.workloadKind,
WorkloadName: r.workloadName,
PodName: r.podName,
}
q.namedMetrics = model.PodMetrics

View File

@@ -291,6 +291,33 @@ func TestParseRequestParams(t *testing.T) {
lvl: monitoring.LevelOpenpitrix,
expectedErr: true,
},
{
params: reqParams{
time: "1585880000",
namespacedResourcesFilter: "test1|test2",
},
lvl: monitoring.LevelPod,
expected: queryOptions{
metricFilter: ".*",
identifier: "pod",
time: time.Unix(1585880000, 0),
namedMetrics: []string{
"pod_cpu_usage",
"pod_memory_usage",
"pod_memory_usage_wo_cache",
"pod_net_bytes_transmitted",
"pod_net_bytes_received",
"meter_pod_cpu_usage",
"meter_pod_memory_usage_wo_cache",
"meter_pod_net_bytes_transmitted",
"meter_pod_net_bytes_received",
"meter_pod_pvc_bytes_total",
},
Operation: OperationQuery,
option: monitoring.PodOption{NamespacedResourcesFilter: "test1|test2", ResourceFilter: ".*"},
},
expectedErr: false,
},
}
for i, tt := range tests {