Skip to content

Commit

Permalink
fix: added fix to allow one consumer to be in >1 consumer-groups. (#140)
Browse files Browse the repository at this point in the history
* fix: added fix to allow one consumer to
be in >1 consumer-groups.

gdr version 1.39.2 introduced a bug where a consumer
was limited to only one consumer-group.
Adding the consumer in >1 group was resulting in an
error on deck. This PR adds the fix for the same and
an integration test.

See: Kong/deck#1384

* fix: scoped the test to >3.4.0

* chore: clarified test scope in integration sync_test

* tests: added test for gateway v2.8.x for >1 consumer-group for a consumer
  • Loading branch information
Prashansa-K authored Sep 5, 2024
1 parent 7c622bd commit da91179
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pkg/state/consumer_group_consumers.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,21 @@ func getConsumerGroupConsumer(txn *memdb.Txn, consumerGroupID string, IDs ...str

for _, id := range IDs {
for _, index := range indexes {
res, err := txn.First(consumerGroupConsumerTableName, index, id)
res, err := txn.Get(consumerGroupConsumerTableName, index, id)
if err != nil {
return nil, err
}
if res != nil {
consumer := res.(*ConsumerGroupConsumer)

for {
resultValue := res.Next()
if resultValue == nil {
break
}
consumer, ok := resultValue.(*ConsumerGroupConsumer)
if !ok {
break
}

if *consumer.ConsumerGroup.ID == consumerGroupID {
return consumer, nil
}
Expand Down
86 changes: 86 additions & 0 deletions tests/integration/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5667,3 +5667,89 @@ func Test_Sync_PluginAutoFields(t *testing.T) {
"Should error out due to missing provision_key")
})
}

// test scope:
// - enterprise
// - >=3.4.0
func Test_Sync_MoreThanOneConsumerGroupForOneConsumer(t *testing.T) {
runWhen(t, "enterprise", ">=3.4.0")
setup(t)

client, err := getTestClient()
require.NoError(t, err)

expectedState := utils.KongRawState{
ConsumerGroups: []*kong.ConsumerGroupObject{
{
ConsumerGroup: &kong.ConsumerGroup{
Name: kong.String("group1"),
},
Consumers: []*kong.Consumer{
{
Username: kong.String("my-test-consumer"),
},
},
},
{
ConsumerGroup: &kong.ConsumerGroup{
Name: kong.String("group2"),
},
Consumers: []*kong.Consumer{
{
Username: kong.String("my-test-consumer"),
},
},
},
},
Consumers: []*kong.Consumer{
{
Username: kong.String("my-test-consumer"),
},
},
}
require.NoError(t, sync("testdata/sync/xxx-more-than-one-consumer-group-with-a-consumer/kong3x.yaml"))
testKongState(t, client, false, expectedState, nil)
}

// test scope:
// - enterprise
// - 2.8.0
func Test_Sync_MoreThanOneConsumerGroupForOneConsumer_2_8(t *testing.T) {
runWhen(t, "enterprise", ">=2.8.0 <3.0.0")
setup(t)

client, err := getTestClient()
require.NoError(t, err)

expectedState := utils.KongRawState{
ConsumerGroups: []*kong.ConsumerGroupObject{
{
ConsumerGroup: &kong.ConsumerGroup{
Name: kong.String("group1"),
},
Consumers: []*kong.Consumer{
{
Username: kong.String("my-test-consumer"),
},
},
},
{
ConsumerGroup: &kong.ConsumerGroup{
Name: kong.String("group2"),
},
Consumers: []*kong.Consumer{
{
Username: kong.String("my-test-consumer"),
},
},
},
},
Consumers: []*kong.Consumer{
{
Username: kong.String("my-test-consumer"),
},
},
}
require.NoError(t, sync("testdata/sync/xxx-more-than-one-consumer-group-with-a-consumer/kong.yaml"))
testKongState(t, client, false, expectedState, nil)
}
1 change: 1 addition & 0 deletions tests/integration/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ func testKongState(t *testing.T, client *kong.Client, isKonnect bool,
cmpopts.IgnoreFields(kong.Vault{}, "ID", "CreatedAt", "UpdatedAt"),
cmpopts.IgnoreFields(kong.Certificate{}, "ID", "CreatedAt"),
cmpopts.IgnoreFields(kong.SNI{}, "ID", "CreatedAt"),
cmpopts.IgnoreFields(kong.Consumer{}, "CreatedAt", "ID"),
cmpopts.IgnoreFields(kong.ConsumerGroup{}, "CreatedAt", "ID"),
cmpopts.IgnoreFields(kong.ConsumerGroupPlugin{}, "CreatedAt", "ID"),
cmpopts.IgnoreFields(kong.KeyAuth{}, "ID", "CreatedAt"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
_format_version: "1.0"
consumer_groups:
- name: group1
- name: group2
consumers:
- username: my-test-consumer
groups:
- name: group1
- name: group2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
_format_version: "3.0"
consumer_groups:
- name: group1
- name: group2
consumers:
- username: my-test-consumer
groups:
- name: group1
- name: group2

0 comments on commit da91179

Please sign in to comment.