Skip to content

Commit

Permalink
Merge pull request #1405 from openmeterio/fix/notification-issues
Browse files Browse the repository at this point in the history
fix: issues around balance snapshots
  • Loading branch information
turip authored Aug 22, 2024
2 parents 09c5c34 + 3317bf5 commit 6a7f913
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion internal/entitlement/entitlement.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ type Entitlement struct {

// All none-core fields are optional
// metered
MeasureUsageFrom *time.Time `json:"-"`
MeasureUsageFrom *time.Time `json:"measureUsageFrom,omitempty"`
IssueAfterReset *float64 `json:"issueAfterReset,omitempty"`
IssueAfterResetPriority *uint8 `json:"issueAfterResetPriority,omitempty"`
IsSoftLimit *bool `json:"isSoftLimit,omitempty"`
Expand Down
6 changes: 3 additions & 3 deletions internal/notification/consumer/balancetreshold.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (b *BalanceThresholdEventHandler) Handle(ctx context.Context, event snapsho

// TODO[issue-1364]: this must be cached to prevent going to the DB for each balance.snapshot event
affectedRulesPaged, err := b.Notification.ListRules(ctx, notification.ListRulesInput{
Namespaces: []string{event.Entitlement.Namespace},
Namespaces: []string{event.Namespace.ID},
Types: []notification.RuleType{notification.RuleTypeBalanceThreshold},
})
if err != nil {
Expand Down Expand Up @@ -101,7 +101,7 @@ func (b *BalanceThresholdEventHandler) handleRule(ctx context.Context, balSnapsh
PageSize: 1,
PageNumber: 1,
},
Namespaces: []string{balSnapshot.Entitlement.Namespace},
Namespaces: []string{balSnapshot.Namespace.ID},

From: balSnapshot.Entitlement.CurrentUsagePeriod.From,
To: balSnapshot.Entitlement.CurrentUsagePeriod.To,
Expand Down Expand Up @@ -185,7 +185,7 @@ func (b *BalanceThresholdEventHandler) createEvent(ctx context.Context, in creat

_, err = b.Notification.CreateEvent(ctx, notification.CreateEventInput{
NamespacedModel: models.NamespacedModel{
Namespace: in.Snapshot.Entitlement.Namespace,
Namespace: in.Snapshot.Namespace.ID,
},
Annotations: annotations,
Type: notification.EventTypeBalanceThreshold,
Expand Down
9 changes: 5 additions & 4 deletions internal/notification/consumer/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ func New(opts Options) (*Consumer, error) {
),
)

return &Consumer{
opts: opts,
router: router,
}, nil
return consumer, nil
}

func (c *Consumer) Handle(ctx context.Context, event snapshot.SnapshotEvent) error {
return c.balanceThresholdHandler.Handle(ctx, event)
}

func (c *Consumer) Run(ctx context.Context) error {
Expand Down

0 comments on commit 6a7f913

Please sign in to comment.