diff --git a/api/internal/logic/cloud/controllermetricslogic.go b/api/internal/logic/cloud/controllermetricslogic.go index 3e7a3389..4a463d1f 100644 --- a/api/internal/logic/cloud/controllermetricslogic.go +++ b/api/internal/logic/cloud/controllermetricslogic.go @@ -4,6 +4,7 @@ import ( "context" "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types" + error2 "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/repository/error" "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/tracker" "time" @@ -26,15 +27,20 @@ func NewControllerMetricsLogic(ctx context.Context, svcCtx *svc.ServiceContext) func (l *ControllerMetricsLogic) ControllerMetrics(req *types.ControllerMetricsReq) (resp *types.ControllerMetricsResp, err error) { resp = &types.ControllerMetricsResp{} - if len(req.Pod) != 0 { - resp.Data = l.svcCtx.PromClient[req.ParticipantId].GetNamedMetricsByTime(req.Metrics, req.Start, req.End, 60*time.Minute, tracker.PodOption{ - PodName: req.Pod, - }) - } else { + if _, ok := l.svcCtx.PromClient[req.ParticipantId]; ok { + if len(req.Pod) != 0 { + resp.Data = l.svcCtx.PromClient[req.ParticipantId].GetNamedMetricsByTime(req.Metrics, req.Start, req.End, 60*time.Minute, tracker.PodOption{ + PodName: req.Pod, + }) + } else { - resp.Data = l.svcCtx.PromClient[req.ParticipantId].GetNamedMetricsByTime(req.Metrics, req.Start, req.End, 60*time.Minute, tracker.ControllerOption{ - WorkloadName: req.WorkloadName, - }) + resp.Data = l.svcCtx.PromClient[req.ParticipantId].GetNamedMetricsByTime(req.Metrics, req.Start, req.End, 60*time.Minute, tracker.ControllerOption{ + WorkloadName: req.WorkloadName, + }) + } + } else { + return nil, error2.NewCodeError(400, "prometheus endpoint invalid!") } + return resp, nil }