Skip to content

Commit

Permalink
feat: add with_relation_labels flag in list subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
mabdh committed Jul 9, 2024
1 parent 96cc6ba commit 772669d
Show file tree
Hide file tree
Showing 8 changed files with 403 additions and 347 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ NAME="github.com/goto/siren"
LAST_COMMIT := $(shell git rev-parse --short HEAD)
LAST_TAG := "$(shell git rev-list --tags --max-count=1)"
APP_VERSION := "$(shell git describe --tags ${LAST_TAG})-next"
PROTON_COMMIT := "f3199ce75d2c74c545bae14c646b10516f062a3a"
PROTON_COMMIT := "94a0a51e63fa3c6c2292242b5b4c425ef467ccbe"

.PHONY: all build test clean dist vet proto install

Expand Down
1 change: 1 addition & 0 deletions core/subscription/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ type Filter struct {
IDs []int64
SubscriptionReceiverLabels map[string]string
ReceiverID uint64
WithRelationLabels bool
}
21 changes: 15 additions & 6 deletions core/subscription/servicev2.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,24 @@ func (s *Service) ListV2(ctx context.Context, flt Filter) ([]Subscription, error
var receiversMap = map[uint64][]Receiver{}
for _, subRcv := range subscriptionsReceivers {
if len(receiversMap[subRcv.SubscriptionID]) == 0 {
receiversMap[subRcv.SubscriptionID] = []Receiver{
{
ID: subRcv.ReceiverID,
},
rcv := &Receiver{
ID: subRcv.ReceiverID,
}

if flt.WithRelationLabels {
rcv.RelationLabels = subRcv.Labels
}

receiversMap[subRcv.SubscriptionID] = []Receiver{*rcv}
} else {
receiversMap[subRcv.SubscriptionID] = append(receiversMap[subRcv.SubscriptionID], Receiver{
rcv := &Receiver{
ID: subRcv.ReceiverID,
})
}

if flt.WithRelationLabels {
rcv.RelationLabels = subRcv.Labels
}
receiversMap[subRcv.SubscriptionID] = append(receiversMap[subRcv.SubscriptionID], *rcv)
}
}

Expand Down
5 changes: 3 additions & 2 deletions core/subscription/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ func (rcv *ReceiverView) FromReceiver(r receiver.Receiver) {
}

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

// Type won't be exposed to the end-user, this is used to add more details for notification purposes
Type string
Expand Down
1 change: 1 addition & 0 deletions internal/api/v1beta1/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func (s *GRPCServer) ListSubscriptions(ctx context.Context, req *sirenv1beta1.Li
NotificationMatch: req.GetNotificationMatch(),
ReceiverID: req.GetReceiverId(),
SubscriptionReceiverLabels: req.GetSubscriptionReceiverLabels(),
WithRelationLabels: req.GetWithRelationLabels(),
})
} else {
subscriptions, err = s.subscriptionService.List(ctx, subscription.Filter{
Expand Down
708 changes: 370 additions & 338 deletions proto/gotocompany/siren/v1beta1/siren.pb.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions proto/gotocompany/siren/v1beta1/siren.pb.validate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions proto/siren.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,10 @@ paths:
required: false
type: string
format: uint64
- name: with_relation_labels
in: query
required: false
type: boolean
tags:
- Subscription
post:
Expand Down Expand Up @@ -1627,6 +1631,10 @@ definitions:
format: uint64
configuration:
type: object
relation_labels:
type: object
additionalProperties:
type: string
ReceiverSelector:
type: object
properties:
Expand Down

0 comments on commit 772669d

Please sign in to comment.