Skip to content

Commit

Permalink
fix: config dedup for consumer-groups scoped plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
GGabriele committed Jan 25, 2024
1 parent 19a5a4b commit 3bb4afe
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/hashicorp/go-retryablehttp v0.7.5
github.com/hexops/gotextdiff v1.0.3
github.com/kong/deck v1.31.1
github.com/kong/go-kong v0.51.0
github.com/kong/go-kong v0.51.1-0.20240125175037-0c077f5b9ac7
github.com/shirou/gopsutil/v3 v3.23.12
github.com/ssgelm/cookiejarparser v1.0.1
github.com/stretchr/testify v1.8.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ github.com/kong/deck v1.31.1 h1:zH9Kgivap5iKR791B/dd1/AhOprUH0Z0QeX66yPT8s8=
github.com/kong/deck v1.31.1/go.mod h1:cyRu/KccI2GJCP+q6hPQY3iy5JJ1MkkDCx9u2jnIi6Q=
github.com/kong/go-apiops v0.1.27 h1:Jy9HSBtGtO0r0UpXSFenCfOUA0QmeX4i8iGQU0vnC+Q=
github.com/kong/go-apiops v0.1.27/go.mod h1:TYRNVbQ/lw6D3AUJBVP1w4zmMlJ59K83q+zCFa02uZ4=
github.com/kong/go-kong v0.51.0 h1:KuSvo+b265KuFGOkkdYONGtG6ci8WLomJ/5Xhs0XSHE=
github.com/kong/go-kong v0.51.0/go.mod h1:JdLpEwKi/Usq2TCTEtIS4f6ADWN7sdDMSS1PvvD1Ldw=
github.com/kong/go-kong v0.51.1-0.20240125175037-0c077f5b9ac7 h1:/iV93Gwv410lIeJx8VCfCA4fpuvSuTw2LqZpDXsIE9Q=
github.com/kong/go-kong v0.51.1-0.20240125175037-0c077f5b9ac7/go.mod h1:YNkLvjxfOqS+BZ1J2YWOy/83wc26JM5QJbAukoeg1sY=
github.com/kong/go-slugify v1.0.0 h1:vCFAyf2sdoSlBtLcrmDWUFn0ohlpKiKvQfXZkO5vSKY=
github.com/kong/go-slugify v1.0.0/go.mod h1:dbR2h3J2QKXQ1k0aww6cN7o4cIcwlWflr6RKRdcoaiw=
github.com/kong/semver/v4 v4.0.1 h1:DIcNR8W3gfx0KabFBADPalxxsp+q/5COwIFkkhrFQ2Y=
Expand Down
1 change: 1 addition & 0 deletions pkg/file/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func (b *stateBuilder) ingestConsumerGroupScopedPlugins(cg FConsumerGroupObject)
ID: cg.ID,
},
},
ConfigSource: plugin.ConfigSource,
})
}
return b.ingestPlugins(plugins)
Expand Down
3 changes: 3 additions & 0 deletions pkg/file/kong_json_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@
},
"ConsumerGroupPlugin": {
"properties": {
"_config": {
"type": "string"
},
"config": {
"additionalProperties": true,
"type": "object"
Expand Down
1 change: 1 addition & 0 deletions pkg/state/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func buildKong(kongState *KongState, raw *utils.KongRawState) error {
Name: p.Name,
Config: p.Config,
ConsumerGroup: cg.ConsumerGroup,
ConfigSource: p.ConfigSource,
},
},
)
Expand Down
147 changes: 147 additions & 0 deletions tests/integration/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4932,3 +4932,150 @@ func Test_Sync_PluginScopedToConsumerGroupAndRoute(t *testing.T) {
testKongState(t, client, false, expectedState, nil)

}

// test scope:
// - 3.5.0+
// - konnect
func Test_Sync_DeDupPluginsScopedToConsumerGroups(t *testing.T) {
t.Setenv("DECK_KONNECT_CONTROL_PLANE_NAME", "default")
runWhenEnterpriseOrKonnect(t, ">=3.5.0")
setup(t)

client, err := getTestClient()
if err != nil {
t.Fatalf(err.Error())
}

expectedState := utils.KongRawState{
ConsumerGroups: []*kong.ConsumerGroupObject{
{
ConsumerGroup: &kong.ConsumerGroup{
ID: kong.String("19275493-84d3-4c64-92e6-612e908a3a4f"),
Name: kong.String("gold"),
},
Consumers: []*kong.Consumer{
{
ID: kong.String("7b2c743c-2cec-4998-b9df-e7f8a9a20487"),
Username: kong.String("jeff"),
},
},
},
{
ConsumerGroup: &kong.ConsumerGroup{
ID: kong.String("48df7cd3-1cd0-4e53-af73-8f57f257be18"),
Name: kong.String("silver"),
},
},
},
Consumers: []*kong.Consumer{
{
ID: kong.String("7b2c743c-2cec-4998-b9df-e7f8a9a20487"),
Username: kong.String("jeff"),
},
},
Plugins: []*kong.Plugin{
{
ID: kong.String("1c93dd1f-f188-473d-bec8-053bd526a693"),
Name: kong.String("rate-limiting-advanced"),
ConsumerGroup: &kong.ConsumerGroup{
ID: kong.String("19275493-84d3-4c64-92e6-612e908a3a4f"),
},
Config: kong.Configuration{
"consumer_groups": nil,
"dictionary_name": string("kong_rate_limiting_counters"),
"disable_penalty": bool(false),
"enforce_consumer_groups": bool(false),
"error_code": float64(429),
"error_message": string("API rate limit exceeded"),
"header_name": nil,
"hide_client_headers": bool(false),
"identifier": string("consumer"),
"limit": []any{float64(1000)},
"namespace": string("OsFDaDQxdb1MFGHBdZENho51f3zqMLy"),
"path": nil,
"redis": map[string]any{
"cluster_addresses": nil,
"connect_timeout": nil,
"database": float64(0),
"host": nil,
"keepalive_backlog": nil,
"keepalive_pool_size": float64(256),
"password": nil,
"port": nil,
"read_timeout": nil,
"send_timeout": nil,
"sentinel_addresses": nil,
"sentinel_master": nil,
"sentinel_password": nil,
"sentinel_role": nil,
"sentinel_username": nil,
"server_name": nil,
"ssl": false,
"ssl_verify": false,
"timeout": float64(2000),
"username": nil,
},
"retry_after_jitter_max": float64(0),
"strategy": string("local"),
"sync_rate": float64(-1),
"window_size": []any{float64(60)},
"window_type": string("sliding"),
},
Enabled: kong.Bool(true),
Protocols: []*string{kong.String("grpc"), kong.String("grpcs"), kong.String("http"), kong.String("https")},
},
{
ID: kong.String("bcb296c3-22bb-46f6-99c8-4828af750b77"),
Name: kong.String("rate-limiting-advanced"),
ConsumerGroup: &kong.ConsumerGroup{
ID: kong.String("48df7cd3-1cd0-4e53-af73-8f57f257be18"),
},
Config: kong.Configuration{
"consumer_groups": nil,
"dictionary_name": string("kong_rate_limiting_counters"),
"disable_penalty": bool(false),
"enforce_consumer_groups": bool(false),
"error_code": float64(429),
"error_message": string("API rate limit exceeded"),
"header_name": nil,
"hide_client_headers": bool(false),
"identifier": string("consumer"),
"limit": []any{float64(100)},
"namespace": string("OsFDaDQxdb1MFGHBdZENho51f3zqMLy"),
"path": nil,
"redis": map[string]any{
"cluster_addresses": nil,
"connect_timeout": nil,
"database": float64(0),
"host": nil,
"keepalive_backlog": nil,
"keepalive_pool_size": float64(256),
"password": nil,
"port": nil,
"read_timeout": nil,
"send_timeout": nil,
"sentinel_addresses": nil,
"sentinel_master": nil,
"sentinel_password": nil,
"sentinel_role": nil,
"sentinel_username": nil,
"server_name": nil,
"ssl": false,
"ssl_verify": false,
"timeout": float64(2000),
"username": nil,
},
"retry_after_jitter_max": float64(0),
"strategy": string("local"),
"sync_rate": float64(-1),
"window_size": []any{float64(60)},
"window_type": string("sliding"),
},
Enabled: kong.Bool(true),
Protocols: []*string{kong.String("grpc"), kong.String("grpcs"), kong.String("http"), kong.String("https")},
},
},
}
require.NoError(t, sync("testdata/sync/030-plugin-dedup-consumer-groups/kong.yaml"))
testKongState(t, client, false, expectedState, nil)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
_format_version: "3.0"
_plugin_configs:
route-default-limit:
hide_client_headers: false
identifier: consumer
limit:
- 100
strategy: local
sync_rate: -1
window_size:
- 60
namespace: OsFDaDQxdb1MFGHBdZENho51f3zqMLy
gold-tier-limit:
hide_client_headers: false
identifier: consumer
limit:
- 1000
strategy: local
sync_rate: -1
window_size:
- 60
namespace: OsFDaDQxdb1MFGHBdZENho51f3zqMLy
consumer_groups:
- id: 19275493-84d3-4c64-92e6-612e908a3a4f
name: gold
plugins:
- id: 1c93dd1f-f188-473d-bec8-053bd526a693
name: rate-limiting-advanced
_config: gold-tier-limit
- id: 48df7cd3-1cd0-4e53-af73-8f57f257be18
name: silver
plugins:
- id: bcb296c3-22bb-46f6-99c8-4828af750b77
name: rate-limiting-advanced
_config: route-default-limit
consumers:
- groups:
- id: 19275493-84d3-4c64-92e6-612e908a3a4f
name: gold
id: 7b2c743c-2cec-4998-b9df-e7f8a9a20487
username: jeff

0 comments on commit 3bb4afe

Please sign in to comment.