Skip to content

Commit

Permalink
chore: add resource ids and remove matcher for now
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Sep 9, 2024
1 parent cd3679e commit d3eca54
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 29 deletions.
15 changes: 14 additions & 1 deletion models/notifications.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package models

import (
"fmt"
"time"

"github.com/flanksource/duty/types"
Expand Down Expand Up @@ -111,12 +112,24 @@ func (t *NotificationSendHistory) End() *NotificationSendHistory {
return t
}

type NotificationSilenceResource struct {
ConfigID *string `json:"config_id,omitempty"`
CanaryID *string `json:"canary_id,omitempty"`
ComponentID *string `json:"component_id,omitempty"`
CheckID *string `json:"check_id,omitempty"`
}

func (t NotificationSilenceResource) Key() string {
return fmt.Sprintf("%s:%s:%s:%s", lo.FromPtr(t.ConfigID), lo.FromPtr(t.CanaryID), lo.FromPtr(t.ComponentID), lo.FromPtr(t.CheckID))
}

type NotificationSilence struct {
NotificationSilenceResource `json:",inline" yaml:",inline"`

ID uuid.UUID `json:"id"`
Namespace string `json:"namespace"`
From time.Time `json:"from"`
Until time.Time `json:"until"`
Matcher *string `json:"matcher,omitempty"`
Source string `json:"source"`
CreatedBy *uuid.UUID `json:"created_by,omitempty"`
CreatedAt time.Time `json:"created_at" time_format:"postgres_timestamp" gorm:"<-:false"`
Expand Down
19 changes: 0 additions & 19 deletions query/getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,22 +173,3 @@ func FindTeam(ctx context.Context, identifier string, opts ...GetterOption) (*mo

return team, nil
}

func GetAllNotificationSilences(ctx context.Context) ([]models.NotificationSilence, error) {
var silences []models.NotificationSilence

cacheKey := "allNotificationSilences"
if value, ok := getterCache.Get(cacheKey); ok {
if cache, ok := value.([]models.NotificationSilence); ok {
return cache, nil
}
}

err := ctx.DB().Where("deleted_at is NULL ").Find(&silences).Error
if err != nil {
return nil, err
}

getterCache.SetDefault(cacheKey, silences)
return silences, err
}
30 changes: 21 additions & 9 deletions schema/notifications.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -178,20 +178,32 @@ table "notification_silences" {
type = text
}
column "from" {
null = false
type = timestamptz
null = false
type = timestamptz
}
column "until" {
null = false
type = timestamptz
null = false
type = timestamptz
}
column "matcher" {
column "config_id" {
null = true
type = text
type = uuid
}
column "check_id" {
null = true
type = uuid
}
column "canary_id" {
null = true
type = uuid
}
column "component_id" {
null = true
type = uuid
}
column "source" {
null = true
type = enum.source
null = true
type = enum.source
}
column "created_by" {
null = true
Expand All @@ -202,7 +214,7 @@ table "notification_silences" {
type = timestamptz
default = sql("now()")
}
column "updated_at" {
column "updated_at" {
null = false
type = timestamptz
default = sql("now()")
Expand Down

0 comments on commit d3eca54

Please sign in to comment.