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(utils): support record-level default schema values #431

Merged
merged 1 commit into from
Apr 3, 2024

Conversation

samugi
Copy link
Member

@samugi samugi commented Mar 28, 2024

Before this change, during the process of filling default configuration values, if a record existed in the schema with a structure similar to the following:

{
  "default": {
   "some_field": "record_level_default"
 },
 "fields": [
  {
   "some_field": {
    "type": "string",
    "default": "field_level_default"
   }
  }
 ]
}

the value record_level_default would be ignored and the field set to the field_level_default value. Similarly, in case of no field-level default, the field would be set to null.

This commit modifies the utils/fillConfigRecord logic to assign fields with record-level default values when available.

Example of default configuration values that were previously ignored: https://github.com/Kong/kong/blob/8fe14097a17cf904676672fc8cdaabe5e02e4a2d/kong/plugins/opentelemetry/schema.lua#L49 https://github.com/Kong/kong/blob/8fe14097a17cf904676672fc8cdaabe5e02e4a2d/kong/plugins/opentelemetry/schema.lua#L90

fixes: KAG-4149

@samugi samugi requested a review from a team as a code owner March 28, 2024 16:36
@samugi samugi requested a review from a team March 28, 2024 16:36
@CLAassistant
Copy link

CLAassistant commented Mar 28, 2024

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@samugi samugi marked this pull request as draft March 28, 2024 16:39
@samugi samugi force-pushed the fix/default-record-values branch 2 times, most recently from f68d1af to e1234b7 Compare March 28, 2024 16:49
@samugi samugi marked this pull request as ready for review March 28, 2024 16:52
@codecov-commenter
Copy link

codecov-commenter commented Mar 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 57.92%. Comparing base (241dbb8) to head (fa2ff62).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #431      +/-   ##
==========================================
- Coverage   59.32%   57.92%   -1.41%     
==========================================
  Files          69       69              
  Lines        4219     4223       +4     
==========================================
- Hits         2503     2446      -57     
- Misses       1134     1206      +72     
+ Partials      582      571      -11     
Flag Coverage Δ
2.1 ?
2.2 49.18% <100.00%> (-0.83%) ⬇️
2.3 49.79% <100.00%> (-0.88%) ⬇️
2.4 49.84% <100.00%> (-0.88%) ⬇️
2.5 49.84% <100.00%> (-0.88%) ⬇️
2.6 49.84% <100.00%> (-0.88%) ⬇️
2.7 51.55% <100.00%> (-0.88%) ⬇️
2.8 51.55% <100.00%> (-0.88%) ⬇️
3.0 55.17% <100.00%> (-1.36%) ⬇️
3.1 56.87% <100.00%> (-1.36%) ⬇️
3.2 56.87% <100.00%> (-1.41%) ⬇️
3.3 56.87% <100.00%> (-1.41%) ⬇️
3.4 54.60% <100.00%> (-4.02%) ⬇️
community ?
enterprise 57.92% <100.00%> (+0.03%) ⬆️
integration 57.92% <100.00%> (-1.41%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

Copy link
Member

@pmalek pmalek left a comment

Choose a reason for hiding this comment

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

Minor nits regarding tests. Please rebase against latest main to pull in the changes in CI that test against 3.5 and 3.6

kong/utils_test.go Outdated Show resolved Hide resolved
kong/utils_test.go Show resolved Hide resolved
Before this change, during the process of filling default configuration
values, if a record existed in the schema with a structure similar to the
following:
```
{
	"default": {
			"some_field": "record_level_default"
	},
	"fields": [
		{
			"some_field": {
				"type": "string",
				"default": "field_level_default"
			}
		}
	]
}
```
the value `record_level_default` would be ignored and the field set to
the `field_level_default` value. Similarly, in case of no field-level
default, the field would be set to `null`.

This commit modifies the utils/fillConfigRecord logic to assign fields
with record-level default values when available.

Example of default configuration values that were previously ignored:
https://github.com/Kong/kong/blob/8fe14097a17cf904676672fc8cdaabe5e02e4a2d/kong/plugins/opentelemetry/schema.lua#L49
https://github.com/Kong/kong/blob/8fe14097a17cf904676672fc8cdaabe5e02e4a2d/kong/plugins/opentelemetry/schema.lua#L90
@samugi samugi force-pushed the fix/default-record-values branch from fa2ff62 to e544d45 Compare April 3, 2024 15:45
@samugi samugi requested a review from pmalek April 3, 2024 15:49
@pmalek pmalek merged commit 2b721b4 into main Apr 3, 2024
79 checks passed
@pmalek pmalek deleted the fix/default-record-values branch April 3, 2024 15:52
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.

5 participants