Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(diff+file): avoid filling defaults in config for kong #133

Merged
merged 2 commits into from
Aug 27, 2024

Conversation

samugi
Copy link
Member

@samugi samugi commented Aug 24, 2024

Summary

the previous logic was filling defaults in the configuration that was passed to Kong. This was problematic, especially where nils were populated as defaults, e.g. if a shorthand_field was passed with some value and the corresponding new field was auto-populated as nil by decK , the auto-populated nil value would take precedence in Kong thus causing the shorthand_field to be ignored (see linked issues).

This change applies the default values only to configurations used for diff, the original configuration from the file is passed to Kong as is.

Configuration

_format_version: "3.0"
plugins:
- config:
    endpoint: http://example.test
  enabled: true
  name: opentelemetry
  protocols:
  - grpc
  - grpcs
  - http
  - https

Before the change

deck gateway sync kong.yml --verbose 1

PUT /plugins/83c19ebe-4cd5-4ac2-8f6b-416af32bdfaf HTTP/1.1
Host: localhost:8001
User-Agent: Go-http-client/1.1
Content-Length: 743
Content-Type: application/json
Accept-Encoding: gzip

{
  "created_at":1724513513,
  "id":"83c19ebe-4cd5-4ac2-8f6b-416af32bdfaf",
  "name":"opentelemetry",
  "config":{"endpoint":"http://example.test","traces_endpoint":null,"batch_flush_delay":null,"batch_span_count":null,"connect_timeout":1000,"header_type":"preserve","headers":null,"http_response_header_for_traceid":null,"logs_endpoint":null,"propagation":{"clear":null,"default_format":"w3c","extract":null,"inject":null},"queue":{"concurrency_limit":1,"initial_retry_delay":0.01,"max_batch_size":200,"max_bytes":null,"max_coalescing_delay":1,"max_entries":10000,"max_retry_delay":60,"max_retry_time":60},"read_timeout":5000,"resource_attributes":null,"sampling_rate":null,"send_timeout":5000},
  "enabled":true,
  "protocols":["grpc","grpcs","http","https"]}

After the change

deck gateway sync kong.yml --verbose 1

PUT /plugins/83c19ebe-4cd5-4ac2-8f6b-416af32bdfaf HTTP/1.1
Host: localhost:8001
User-Agent: Go-http-client/1.1
Content-Length: 195
Content-Type: application/json
Accept-Encoding: gzip

{
  "created_at":1724513513,
  "id":"83c19ebe-4cd5-4ac2-8f6b-416af32bdfaf",
  "name":"opentelemetry",
  "config":{"endpoint":"http://example.test"},
  "enabled":true,
  "protocols":["grpc","grpcs","http","https"]
}

Issues resolved

KAG-5157
KAG-5210

Documentation

Testing

  • Unit tests
  • E2E tests
  • Manual testing on Universal
  • Manual testing on Kubernetes

@samugi samugi marked this pull request as draft August 24, 2024 11:46
@CLAassistant
Copy link

CLAassistant commented Aug 24, 2024

CLA assistant check
All committers have signed the CLA.

@codecov-commenter
Copy link

codecov-commenter commented Aug 24, 2024

Codecov Report

Attention: Patch coverage is 0% with 15 lines in your changes missing coverage. Please review.

Project coverage is 42.78%. Comparing base (64dd801) to head (decf4d3).

Files Patch % Lines
pkg/diff/diff.go 0.00% 15 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #133      +/-   ##
==========================================
+ Coverage   42.76%   42.78%   +0.01%     
==========================================
  Files          75       75              
  Lines        8820     8809      -11     
==========================================
- Hits         3772     3769       -3     
+ Misses       4586     4579       -7     
+ Partials      462      461       -1     

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

@samugi samugi force-pushed the fix/avoid-filling-defaults-in-config-for-kong branch 2 times, most recently from 510522f to 1d85e9c Compare August 24, 2024 15:51
@samugi samugi marked this pull request as ready for review August 24, 2024 15:51
@samugi samugi requested a review from randmonkey August 24, 2024 15:55
Copy link
Contributor

@randmonkey randmonkey left a comment

Choose a reason for hiding this comment

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

Does this change make the filling defaults only run for diff printing differences but not to sync really updating configuration? Would this approach still require changes in Kong/go-kong?

@samugi
Copy link
Member Author

samugi commented Aug 26, 2024

Does this change make the filling defaults only run for diff printing differences but not to sync really updating configuration?

Correct @randmonkey , I added examples of how the change affects deck in the PR description.

Would this approach still require changes in Kong/go-kong?

No, this PR replaces the other one I opened, I will close the old PR if/once this is approved

@randmonkey randmonkey closed this Aug 27, 2024
@randmonkey randmonkey reopened this Aug 27, 2024
kikito
kikito previously approved these changes Aug 27, 2024
bungle
bungle previously approved these changes Aug 27, 2024
@bungle
Copy link
Member

bungle commented Aug 27, 2024

Does decK or these tools ever use PATCH or POST?

@samugi samugi dismissed stale reviews from bungle and kikito via 9a81082 August 27, 2024 12:15
@samugi
Copy link
Member Author

samugi commented Aug 27, 2024

Does decK or these tools ever use PATCH or POST?

not that I'm aware of, but that's a good question for @Kong/team-apiops maybe

@samugi samugi enabled auto-merge (squash) August 27, 2024 14:58
samugi and others added 2 commits August 27, 2024 16:58
the previous logic was filling defaults in the configuration that was
passed to Kong. This was  problematic, especially where nils were
populated as defaults, e.g. if a shorthand_field was passed with some
value and the corresponding new field is auto-populated as `nil` by decK
, the auto-populated nil value would take precedence in Kong thus causing
the shorthand_field to be ignored
(https://konghq.atlassian.net/browse/KAG-5157).

This change applies the default values only to configurations used for
diff, the original configuration is always passed to Kong as is.
* add tests for plugin filling default values

---------

Co-authored-by: samugi <samuele@konghq.com>
@samugi samugi force-pushed the fix/avoid-filling-defaults-in-config-for-kong branch from 9a81082 to decf4d3 Compare August 27, 2024 14:58
@samugi
Copy link
Member Author

samugi commented Aug 27, 2024

failing CI because httpbin.org is down ... I'll try to rerun / merge later

@samugi samugi merged commit e72f4c2 into main Aug 27, 2024
18 checks passed
@samugi samugi deleted the fix/avoid-filling-defaults-in-config-for-kong branch August 27, 2024 16:58
Prashansa-K added a commit to Kong/deck that referenced this pull request Aug 28, 2024
The version of go-database-reconciler fixes the
default config filling of plugins that causes
config mismatch in case deprecated and new fields
are present together.

Refer: Kong/go-database-reconciler#133
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.

7 participants