package monitoring import ( "context" v1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" v12 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" "github.com/zeromicro/go-zero/core/logx" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" ) type CreateAlertRuleLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } func NewCreateAlertRuleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateAlertRuleLogic { return &CreateAlertRuleLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } func (l *CreateAlertRuleLogic) CreateAlertRule(req *types.CreateAlertRuleReq) error { // todo: add your logic here and delete this line ruleDuration := v1.Duration(req.Duration) rule := &v1.PrometheusRule{ ObjectMeta: v12.ObjectMeta{ Name: req.Name, Namespace: req.Namespace, Labels: map[string]string{ "release": "prometheus", }, }, Spec: v1.PrometheusRuleSpec{ Groups: []v1.RuleGroup{ { Name: "example-group", Rules: []v1.Rule{ { Alert: req.Name, Expr: intstr.FromString(req.PromQL), For: &ruleDuration, Labels: map[string]string{ "severity": req.AlertLevel, }, Annotations: req.Annotations, }, }, }, }, }, } println(rule.Kind) return nil }