You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

createalertrulelogic.go 1.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package monitoring
  2. import (
  3. "context"
  4. v1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
  5. v12 "k8s.io/apimachinery/pkg/apis/meta/v1"
  6. "k8s.io/apimachinery/pkg/util/intstr"
  7. "github.com/zeromicro/go-zero/core/logx"
  8. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
  9. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
  10. )
  11. type CreateAlertRuleLogic struct {
  12. logx.Logger
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. }
  16. func NewCreateAlertRuleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateAlertRuleLogic {
  17. return &CreateAlertRuleLogic{
  18. Logger: logx.WithContext(ctx),
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. }
  22. }
  23. func (l *CreateAlertRuleLogic) CreateAlertRule(req *types.CreateAlertRuleReq) error {
  24. // todo: add your logic here and delete this line
  25. ruleDuration := v1.Duration(req.Duration)
  26. rule := &v1.PrometheusRule{
  27. ObjectMeta: v12.ObjectMeta{
  28. Name: req.Name,
  29. Namespace: req.Namespace,
  30. Labels: map[string]string{
  31. "release": "prometheus",
  32. },
  33. },
  34. Spec: v1.PrometheusRuleSpec{
  35. Groups: []v1.RuleGroup{
  36. {
  37. Name: "example-group",
  38. Rules: []v1.Rule{
  39. {
  40. Alert: req.Name,
  41. Expr: intstr.FromString(req.PromQL),
  42. For: &ruleDuration,
  43. Labels: map[string]string{
  44. "severity": req.AlertLevel,
  45. },
  46. Annotations: req.Annotations,
  47. },
  48. },
  49. },
  50. },
  51. },
  52. }
  53. println(rule.Kind)
  54. return nil
  55. }

PCM is positioned as Software stack over Cloud, aiming to build the standards and ecology of heterogeneous cloud collaboration for JCC in a non intrusive and autonomous peer-to-peer manner.