Skip to content

Commit

Permalink
Merge pull request #31 from openinfradev/alert
Browse files Browse the repository at this point in the history
feature. add attribute type & id to systemNotification
  • Loading branch information
ktkfree authored Apr 11, 2024
2 parents f487860 + 6007e14 commit bb66cf1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
24 changes: 14 additions & 10 deletions cmd/server/system_notification_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ import (
)

type RuleAnnotation struct {
CheckPoint string `yaml:"CheckPoint"`
Description string `yaml:"description"`
Discriminative string `yaml:"discriminative"`
Message string `yaml:"message"`
Summary string `yaml:"summary"`
CheckPoint string `yaml:"CheckPoint"`
Description string `yaml:"description"`
Discriminative string `yaml:"discriminative"`
Message string `yaml:"message"`
Summary string `yaml:"summary"`
AlertType string `json:"alertType"`
SystemNotificationRuleId string `json:"systemNotificationRuleId"`
}

type RuleLabels struct {
Expand Down Expand Up @@ -104,10 +106,12 @@ func processSystemNotificationRule() error {
Expr: expr,
For: rule.SystemNotificationCondition.Duration,
Annotations: RuleAnnotation{
CheckPoint: replaceMetricParameter(rule.SystemNotificationTemplate.MetricParameters, rule.MessageActionProposal),
Description: replaceMetricParameter(rule.SystemNotificationTemplate.MetricParameters, rule.MessageContent),
Message: replaceMetricParameter(rule.SystemNotificationTemplate.MetricParameters, rule.MessageTitle),
Discriminative: discriminative,
CheckPoint: replaceMetricParameter(rule.SystemNotificationTemplate.MetricParameters, rule.MessageActionProposal),
Description: replaceMetricParameter(rule.SystemNotificationTemplate.MetricParameters, rule.MessageContent),
Message: replaceMetricParameter(rule.SystemNotificationTemplate.MetricParameters, rule.MessageTitle),
Discriminative: discriminative,
AlertType: rule.NotificationType,
SystemNotificationRuleId: rule.ID.String(),
},
Labels: RuleLabels{
Severity: rule.SystemNotificationCondition.Severity,
Expand Down Expand Up @@ -178,7 +182,7 @@ func processSystemNotificationRule() error {
organizationRuleIds = append(organizationRuleIds, r.ID)
}
}
err = systemNotificationRuleAccessor.UpdateSystemNotificationRuleStatus(organizationRuleIds, domain.SystemNotificationRuleStatus_APPLYED)
err = systemNotificationRuleAccessor.UpdateSystemNotificationRuleStatus(organizationRuleIds, domain.SystemNotificationRuleStatus_APPLIED)
if err != nil {
log.Error(context.TODO(), err)
continue
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ toolchain go1.21.7

require (
github.com/gofrs/uuid v4.0.0+incompatible
github.com/openinfradev/tks-api v0.0.0-20240404091154-a3b290667109
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.18.2
gopkg.in/yaml.v2 v2.4.0
Expand Down Expand Up @@ -48,6 +47,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/openinfradev/tks-api v0.0.0-20240411053710-5b8a434e8797 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ github.com/onsi/ginkgo/v2 v2.4.0 h1:+Ig9nvqgS5OBSACXNk15PLdp0U9XPYROt9CFzVdFGIs=
github.com/onsi/ginkgo/v2 v2.4.0/go.mod h1:iHkDK1fKGcBoEHT5W7YBq4RFWaQulw+caOMkAt4OrFo=
github.com/onsi/gomega v1.23.0 h1:/oxKu9c2HVap+F3PfKort2Hw5DEU+HGlW8n+tguWsys=
github.com/onsi/gomega v1.23.0/go.mod h1:Z/NWtiqwBrwUt4/2loMmHL63EDLnYHmVbuBpDr2vQAg=
github.com/openinfradev/tks-api v0.0.0-20240404091154-a3b290667109 h1:fLqD+UXruMR9Chv0ZykLKlDqwT/OibQtO9+nL1Km9To=
github.com/openinfradev/tks-api v0.0.0-20240404091154-a3b290667109/go.mod h1:OGfXiL0YRby+OzOm+OI0d+wtPkOj3SMCiAv3lvpmaiU=
github.com/openinfradev/tks-api v0.0.0-20240409091158-eff7241c1731 h1:gmVBHSDzJGdf9p4wm28bDFcA3yFU6QjZl4prCd2fvIg=
github.com/openinfradev/tks-api v0.0.0-20240409091158-eff7241c1731/go.mod h1:OGfXiL0YRby+OzOm+OI0d+wtPkOj3SMCiAv3lvpmaiU=
github.com/openinfradev/tks-api v0.0.0-20240411053710-5b8a434e8797 h1:DQ5naso3RdA0XxQ2Fj70xZ4O3vBhtWYR9Kpdy7LQqRE=
github.com/openinfradev/tks-api v0.0.0-20240411053710-5b8a434e8797/go.mod h1:Ph4lPgdWg06R1GUNCtmXfzHNlNCW/XjUAvei+m5DD2o=
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand Down
2 changes: 2 additions & 0 deletions internal/system-notification-rule/syste-notification-rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type SystemNotificationTemplate struct {

ID uuid.UUID `gorm:"primarykey"`
Name string `gorm:"index:idx_name,unique"`
NotificationType string `gorm:"default:SYSTEM_NOTIFICATION"`
Organizations []Organization `gorm:"many2many:system_notification_template_organizations;constraint:OnUpdate:RESTRICT,OnDelete:RESTRICT"`
OrganizationIds []string `gorm:"-:all"`
Description string
Expand All @@ -58,6 +59,7 @@ type SystemNotificationRule struct {

ID uuid.UUID `gorm:"primarykey"`
Name string `gorm:"index,unique"`
NotificationType string `gorm:"default:SYSTEM_NOTIFICATION"`
Description string
OrganizationId string
Organization Organization `gorm:"foreignKey:OrganizationId"`
Expand Down

0 comments on commit bb66cf1

Please sign in to comment.