Skip to content

Commit 5dbbe96

Browse files
authored
fix: Change quota type in domain subscription msg (#4676)
The disk quota sent in a domain subscription change RabbitMQ message is an integer, not a string so the handler failed to unmarshal it.
2 parents 598c607 + 77ab7ed commit 5dbbe96

2 files changed

Lines changed: 5 additions & 17 deletions

File tree

pkg/rabbitmq/handlers.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"encoding/json"
77
"errors"
88
"fmt"
9-
"strconv"
109
"strings"
1110

1211
amqp "github.com/rabbitmq/amqp091-go"
@@ -304,7 +303,7 @@ type SubscriptionFeatures struct {
304303

305304
type SubscriptionStackFeatures struct {
306305
FeatureSets []string `json:"featureSets"`
307-
DiskQuota string `json:"diskQuota"`
306+
DiskQuota int64 `json:"diskQuota"`
308307
}
309308

310309
func (h *DomainSubscriptionChangedHandler) Handle(ctx context.Context, d amqp.Delivery) error {
@@ -327,14 +326,6 @@ func (h *DomainSubscriptionChangedHandler) Handle(ctx context.Context, d amqp.De
327326
if msg.Features.Stack.FeatureSets == nil {
328327
return fmt.Errorf("domain.subscription.changed: missing feature sets for organization %s: %v", msg.Domain, msg.Features)
329328
}
330-
if msg.Features.Stack.DiskQuota == "" {
331-
return fmt.Errorf("domain.subscription.changed: missing disk quota for organization %s: %v", msg.Domain, msg.Features)
332-
}
333-
334-
quota, err := strconv.ParseInt(msg.Features.Stack.DiskQuota, 10, 64)
335-
if err != nil {
336-
return fmt.Errorf("domain.subscription.changed: invalid disk quota for organization %s: %w", msg.Domain, err)
337-
}
338329

339330
list, err := lifecycle.ListOrgInstances(msg.Domain)
340331
if err != nil {
@@ -347,7 +338,7 @@ func (h *DomainSubscriptionChangedHandler) Handle(ctx context.Context, d amqp.De
347338

348339
for _, inst := range list {
349340
if err := lifecycle.Patch(inst, &lifecycle.Options{
350-
DiskQuota: quota,
341+
DiskQuota: msg.Features.Stack.DiskQuota,
351342
FeatureSets: msg.Features.Stack.FeatureSets,
352343
FromCloudery: true, // XXX: do not update the instance on the Cloudery as the message comes from the Cloudery
353344
}); err != nil {

pkg/rabbitmq/rabbitmq_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"os"
1010
"path/filepath"
1111
"runtime"
12-
"strconv"
1312
"strings"
1413
"testing"
1514
"time"
@@ -470,7 +469,7 @@ func TestHandlers(t *testing.T) {
470469
Features: rabbitmq.SubscriptionFeatures{
471470
Stack: rabbitmq.SubscriptionStackFeatures{
472471
FeatureSets: []string{"plan-uuid"},
473-
DiskQuota: "50000000000",
472+
DiskQuota: 50000000000,
474473
},
475474
},
476475
}
@@ -520,17 +519,15 @@ func TestHandlers(t *testing.T) {
520519
// orgInst1 is updated
521520
updated, err := lifecycle.GetInstance(orgInst1.Domain)
522521
require.NoError(t, err)
523-
msgQuota, err := strconv.ParseInt(msg.Features.Stack.DiskQuota, 10, 64)
524522
quota := updated.DiskQuota()
525-
require.Equal(t, msgQuota, quota)
523+
require.Equal(t, msg.Features.Stack.DiskQuota, quota)
526524
require.ElementsMatch(t, msg.Features.Stack.FeatureSets, updated.FeatureSets)
527525

528526
// orgInst2 is updated
529527
updated, err = lifecycle.GetInstance(orgInst2.Domain)
530528
require.NoError(t, err)
531-
msgQuota, err = strconv.ParseInt(msg.Features.Stack.DiskQuota, 10, 64)
532529
quota = updated.DiskQuota()
533-
require.Equal(t, msgQuota, quota)
530+
require.Equal(t, msg.Features.Stack.DiskQuota, quota)
534531
require.ElementsMatch(t, msg.Features.Stack.FeatureSets, updated.FeatureSets)
535532

536533
// inst is not updated

0 commit comments

Comments
 (0)