This commit is contained in:
zw 2024-03-12 09:35:58 +08:00
parent 0e991c40aa
commit a06c8ab70f
1 changed files with 5 additions and 3 deletions

View File

@ -13,7 +13,7 @@ type ControllerMetricsReq struct {
Metrics []string `form:"metrics"`
Pod string `form:"pod"`
WorkloadName string `form:"workloadName"`
Steps string `form:"steps"`
Steps int `form:"steps"`
Start string `form:"start"`
End string `form:"end"`
Level string `form:"level"`
@ -29,14 +29,16 @@ func ControllerMetrics(c *gin.Context) {
Response(c, http.StatusBadRequest, "invalid request params.", "")
return
}
// steps parse
duration := time.Duration(p.Steps)
var result []monitoring.Metric
if len(p.Pod) != 0 {
result = apiserver.ApiServer.MonitoringClientMap[p.ClusterName].GetNamedMetricsByTime(p.Metrics, p.Start, p.End, 60*time.Minute, monitoring.PodOption{
result = apiserver.ApiServer.MonitoringClientMap[p.ClusterName].GetNamedMetricsByTime(p.Metrics, p.Start, p.End, duration*time.Minute, monitoring.PodOption{
PodName: p.Pod,
})
} else {
result = apiserver.ApiServer.MonitoringClientMap[p.ClusterName].GetNamedMetricsByTime(p.Metrics, p.Start, p.End, 60*time.Minute, monitoring.ControllerOption{
result = apiserver.ApiServer.MonitoringClientMap[p.ClusterName].GetNamedMetricsByTime(p.Metrics, p.Start, p.End, duration*time.Minute, monitoring.ControllerOption{
WorkloadName: p.WorkloadName,
})
}