Skip to content

feat: Added changes to support crud for graphql-cost-decoration custo…#428

Open
shivaygupta-dotcom wants to merge 8 commits intomainfrom
feature/decK-1909
Open

feat: Added changes to support crud for graphql-cost-decoration custo…#428
shivaygupta-dotcom wants to merge 8 commits intomainfrom
feature/decK-1909

Conversation

@shivaygupta-dotcom
Copy link
Contributor

@shivaygupta-dotcom shivaygupta-dotcom commented Mar 11, 2026

https://konghq.atlassian.net/browse/FTI-7307
Kong/deck#1909

Summary

This PR adds full CRUD support for the graphql_ratelimiting_cost_decorations custom entity used by Kong's GraphQL Rate Limiting Advanced plugin.

Full changelog

  1. Added state management for graphql_ratelimiting_cost_decorations by adding support for collecting entities, indexing them by ID and TypePath, and enabling CRUD operations in the state package so decorations can be properly tracked during sync and diff operations.
  2. Added the new entity into the sync/diff pipeline by registering it in the differ, post-processor, and entity order definitions, ensuring decorations are correctly created, updated, and deleted during deck sync and deck apply.
  3. Added dump support using the CustomEntityTypes configuration, along with custom handling to map the entity type to Kong’s actual API endpoint (/graphql-rate-limiting-advanced/costs).
  4. Added integration tests covering sync, apply, and dump operations, including scenarios for basic usage, multiple decorations, full field coverage, and error cases.

Issues resolved

Fix #XXX

Documentation

Testing

  • Unit tests
  • E2E tests
  • Manual testing on Universal
  • Manual testing on Kubernetes
  • - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ]

@codecov-commenter
Copy link

codecov-commenter commented Mar 13, 2026

Codecov Report

❌ Patch coverage is 13.12910% with 397 lines in your changes missing coverage. Please review.
✅ Project coverage is 28.38%. Comparing base (a02660e) to head (5aa63f3).

Files with missing lines Patch % Lines
pkg/types/graphql_ratelimiting_cost_decoration.go 0.00% 99 Missing ⚠️
pkg/file/types.go 0.00% 85 Missing ⚠️
pkg/file/builder.go 2.59% 75 Missing ⚠️
pkg/state/builder.go 0.00% 60 Missing ⚠️
pkg/state/types.go 19.04% 17 Missing ⚠️
pkg/file/writer.go 20.00% 12 Missing and 4 partials ⚠️
pkg/types/core.go 0.00% 15 Missing ⚠️
pkg/dump/dump.go 0.00% 10 Missing ⚠️
pkg/state/graphql_ratelimiting_cost_decoration.go 82.14% 5 Missing and 5 partials ⚠️
pkg/types/postProcess.go 0.00% 9 Missing ⚠️
... and 1 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #428      +/-   ##
==========================================
- Coverage   28.80%   28.38%   -0.42%     
==========================================
  Files         121      123       +2     
  Lines       16480    16928     +448     
==========================================
+ Hits         4747     4805      +58     
- Misses      11116    11497     +381     
- Partials      617      626       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@shivaygupta-dotcom shivaygupta-dotcom marked this pull request as ready for review March 13, 2026 11:45
if !skipCustomEntities && len(config.CustomEntityTypes) > 0 {
// Get custom entities with types given in config.CustomEntityTypes.
// Register all entity types first (sequentially) to avoid data race on the registry map.
// The registry is not thread-safe, so we must complete all registrations before
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were using a mutex for that. What was the issue here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So basically, mutex only protected the Register() (write) operation, but not the subsequent Lookup() (read) that happens inside GetAllCustomEntitiesWithType.

I have got race conditions on one test where we were adding multiple decorations simultaneously, there i have faced this issue and then added this fix.

for _, entityType := range config.CustomEntityTypes {
if err := tryRegisterEntityType(client, custom.Type(entityType)); err != nil {
group.Go(func() error {
return fmt.Errorf("custom entity %s: %w", entityType, err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this goroutine?

Copy link
Contributor Author

@shivaygupta-dotcom shivaygupta-dotcom Mar 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function getProxyConfiguration doesn't return an error directly - it uses errgroup.Group to collect errors from concurrent operations.

}
for i := 0; i < len(want); i++ {
for i := range want {
if want[i] == nil || have[i] == nil {
Copy link
Collaborator

@Prashansa-K Prashansa-K Mar 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this test fix? Saw similar one in some other PR of yours too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comment on another PR, I will remove this fix from one of the PR, once another one gets merged.
#376 (comment)

@Prashansa-K
Copy link
Collaborator

Last check under Testing in your PR description seems like a typing error.

@shivaygupta-dotcom
Copy link
Contributor Author

shivaygupta-dotcom commented Mar 13, 2026

Last check under Testing in your PR description seems like a typing error.

Didn't got this, I have added error case in sync_test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants