subscription

package
v0.7.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 20, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDuplicate = errors.New("urn already exist")
	ErrRelation  = errors.New("namespace id does not exist")
)

Functions

func ClassifyReceivers added in v0.7.5

func ClassifyReceivers(newReceiver []subscriptionreceiver.Relation, existingReceiver []subscriptionreceiver.Relation) (toUpsert []subscriptionreceiver.Relation, toDelete []subscriptionreceiver.Relation)

ClassifyReceivers compare existing and new receivers of a subscription

func CreateReceiversMap

func CreateReceiversMap(ctx context.Context, receiverService ReceiverService, subscriptions []Subscription) (map[uint64]*receiver.Receiver, error)

func MergeConfigsMap

func MergeConfigsMap(subscriptionConfigMap map[string]any, receiverConfigsMap map[string]any) map[string]any

Types

type Filter

type Filter struct {
	NamespaceID       uint64
	Match             map[string]string
	NotificationMatch map[string]string
	Metadata          map[string]any
	SilenceID         string
	IDs               []int64
}

type LogService

type LogService interface {
	ListSubscriptionIDsBySilenceID(ctx context.Context, silenceID string) ([]int64, error)
}

type NotFoundError

type NotFoundError struct {
	ID uint64
}

func (NotFoundError) Error

func (err NotFoundError) Error() string

type Receiver

type Receiver struct {
	ID            uint64         `json:"id"`
	Configuration map[string]any `json:"configuration"`

	// Type won't be exposed to the end-user, this is used to add more details for notification purposes
	Type string
}

type ReceiverService

type ReceiverService interface {
	List(ctx context.Context, flt receiver.Filter) ([]receiver.Receiver, error)
	PostHookDBTransformConfigs(ctx context.Context, receiverType string, configs map[string]any) (map[string]any, error)
}

type ReceiverView added in v0.7.5

type ReceiverView struct {
	ID             uint64            `json:"id"` // receiver_id
	Name           string            `json:"name"`
	Labels         map[string]string `json:"labels"`
	Type           string            `json:"type"`
	Configurations map[string]any    `json:"configurations"`
	ParentID       uint64            `json:"parent_id"`
	CreatedAt      time.Time         `json:"created_at"`
	UpdatedAt      time.Time         `json:"updated_at"`
	SubscriptionID uint64            `json:"subscription_id"`
	Match          map[string]string `json:"match"`
}

type Repository

type Repository interface {
	Transactor
	List(context.Context, Filter) ([]Subscription, error)
	Create(context.Context, *Subscription) error
	Get(context.Context, uint64) (*Subscription, error)
	Update(context.Context, *Subscription) error
	Delete(context.Context, uint64) error
	MatchLabelsFetchReceivers(ctx context.Context, flt Filter) ([]ReceiverView, error)
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service handles business logic

func NewService

func NewService(
	repository Repository,
	logService LogService,
	namespaceService NamespaceService,
	receiverService ReceiverService,
	subscriptionReceiverService SubscriptionReceiverService,
) *Service

NewService returns service struct

func (*Service) Create

func (s *Service) Create(ctx context.Context, sub *Subscription) error

func (*Service) CreateV2 added in v0.7.5

func (s *Service) CreateV2(ctx context.Context, sub *Subscription) error

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, id uint64) error

func (*Service) DeleteV2 added in v0.7.5

func (s *Service) DeleteV2(ctx context.Context, id uint64) error

func (*Service) Get

func (s *Service) Get(ctx context.Context, id uint64) (*Subscription, error)

func (*Service) GetV2 added in v0.7.5

func (s *Service) GetV2(ctx context.Context, id uint64) (*Subscription, error)

func (*Service) List

func (s *Service) List(ctx context.Context, flt Filter) ([]Subscription, error)

func (*Service) ListV2 added in v0.7.5

func (s *Service) ListV2(ctx context.Context, flt Filter) ([]Subscription, error)

func (*Service) MatchByLabels

func (s *Service) MatchByLabels(ctx context.Context, namespaceID uint64, notificationLabels map[string]string) ([]Subscription, error)

func (*Service) MatchByLabelsV2 added in v0.7.5

func (s *Service) MatchByLabelsV2(ctx context.Context, namespaceID uint64, notificationLabels map[string]string) ([]ReceiverView, error)

func (*Service) Update

func (s *Service) Update(ctx context.Context, sub *Subscription) error

func (*Service) UpdateV2 added in v0.7.5

func (s *Service) UpdateV2(ctx context.Context, sub *Subscription) error

type Subscription

type Subscription struct {
	ID        uint64            `json:"id"`
	URN       string            `json:"urn"`
	Namespace uint64            `json:"namespace"`
	Receivers []Receiver        `json:"receivers"`
	Match     map[string]string `json:"match"`
	Metadata  map[string]any    `json:"metadata"`
	CreatedAt time.Time         `json:"created_at"`
	UpdatedAt time.Time         `json:"updated_at"`
	CreatedBy string            `json:"created_by"`
	UpdatedBy string            `json:"updated_by"`
}

func AssignReceivers

func AssignReceivers(receiversMap map[uint64]*receiver.Receiver, subscriptions []Subscription) ([]Subscription, error)

func (Subscription) ReceiversAsMap

func (s Subscription) ReceiversAsMap() map[uint64]Receiver

func (Subscription) SilenceReceivers

func (s Subscription) SilenceReceivers(silences []silence.Silence) (map[uint64][]silence.Silence, []Receiver, error)

type Transactor added in v0.7.5

type Transactor interface {
	WithTransaction(ctx context.Context) context.Context
	Rollback(ctx context.Context, err error) error
	Commit(ctx context.Context) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL