From 2321650bb10f9146d717cae12a16a83321d7d367 Mon Sep 17 00:00:00 2001 From: zhangwei <894646498@qq.com> Date: Wed, 6 Dec 2023 16:48:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96promeclient?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: 65192221776602c864603b6dbf9de9cbbd9de853 --- api/internal/cron/cron.go | 5 ++++ api/internal/cron/participant.go | 41 ++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 api/internal/cron/participant.go diff --git a/api/internal/cron/cron.go b/api/internal/cron/cron.go index 2b440c28..ef07bdcd 100644 --- a/api/internal/cron/cron.go +++ b/api/internal/cron/cron.go @@ -24,4 +24,9 @@ func AddCronGroup(svc *svc.ServiceContext) { ClearMetricsData(svc) }) + // 同步任务信息到core端 + svc.Cron.AddFunc("*/5 * * * * ?", func() { + SyncParticipantRpc(svc) + }) + } diff --git a/api/internal/cron/participant.go b/api/internal/cron/participant.go new file mode 100644 index 00000000..47aef8eb --- /dev/null +++ b/api/internal/cron/participant.go @@ -0,0 +1,41 @@ +/* + + Copyright (c) [2023] [pcm] + [pcm-coordinator] is licensed under Mulan PSL v2. + You can use this software according to the terms and conditions of the Mulan PSL v2. + You may obtain a copy of Mulan PSL v2 at: + http://license.coscl.org.cn/MulanPSL2 + THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + See the Mulan PSL v2 for more details. + +*/ + +package cron + +import ( + "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/constants" + "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/models" + "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/tracker" +) + +func SyncParticipantRpc(svc *svc.ServiceContext) { + // 查询出所有p端信息 + var participants []*models.ScParticipantPhyInfo + svc.DbEngin.Where("type in (?)", []string{constants.CLOUD, constants.SEALOS}).Find(&participants) + if len(participants) != 0 { + for _, participant := range participants { + if len(participant.MetricsUrl) != 0 { + // 初始化p端prometheus client + promClient, err := tracker.NewPrometheus(participant.MetricsUrl) + if err != nil { + return + } + svc.PromClient[participant.Id] = promClient + } + } + } + +}