监控添加校验

Former-commit-id: 3f71c6c2bd75918aa275449f1c0779436c5670e6
This commit is contained in:
zhangwei 2024-01-02 17:06:00 +08:00
parent c42afa719a
commit 277a1b3549
1 changed files with 14 additions and 8 deletions

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types" "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" "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/tracker"
"time" "time"
@ -26,6 +27,7 @@ func NewControllerMetricsLogic(ctx context.Context, svcCtx *svc.ServiceContext)
func (l *ControllerMetricsLogic) ControllerMetrics(req *types.ControllerMetricsReq) (resp *types.ControllerMetricsResp, err error) { func (l *ControllerMetricsLogic) ControllerMetrics(req *types.ControllerMetricsReq) (resp *types.ControllerMetricsResp, err error) {
resp = &types.ControllerMetricsResp{} resp = &types.ControllerMetricsResp{}
if _, ok := l.svcCtx.PromClient[req.ParticipantId]; ok {
if len(req.Pod) != 0 { if len(req.Pod) != 0 {
resp.Data = l.svcCtx.PromClient[req.ParticipantId].GetNamedMetricsByTime(req.Metrics, req.Start, req.End, 60*time.Minute, tracker.PodOption{ resp.Data = l.svcCtx.PromClient[req.ParticipantId].GetNamedMetricsByTime(req.Metrics, req.Start, req.End, 60*time.Minute, tracker.PodOption{
PodName: req.Pod, PodName: req.Pod,
@ -36,5 +38,9 @@ func (l *ControllerMetricsLogic) ControllerMetrics(req *types.ControllerMetricsR
WorkloadName: req.WorkloadName, WorkloadName: req.WorkloadName,
}) })
} }
} else {
return nil, error2.NewCodeError(400, "prometheus endpoint invalid!")
}
return resp, nil return resp, nil
} }