-
Notifications
You must be signed in to change notification settings - Fork 40
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
feat: return error response bodies in config updates and fold config service into Kong client #271
Conversation
bc8191f
to
3fb76bc
Compare
Codecov ReportBase: 53.41% // Head: 53.52% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #271 +/- ##
==========================================
+ Coverage 53.41% 53.52% +0.11%
==========================================
Files 51 50 -1
Lines 4647 4652 +5
==========================================
+ Hits 2482 2490 +8
+ Misses 1637 1634 -3
Partials 528 528
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're running tests in this repo against actual Kong instances we should add a tests for this functionality (guarded by a version check)
We are stuck for lack of an actual Kong version that includes this, however. Kong/kong#10161 isn't in |
Yup, hence my proposing to guard this by a version check (when we know which version it will be). |
On further thought, is there anything we want to test re the body? go-kong isn't (yet) responsible for anything beyond receiving and returning it. All more complex logic is currently downstream (i.e. the error parsing in Kong/kubernetes-ingress-controller#3446). go-kong could be responsible for error parsing and probably should be responsible for it long-term, but at present we only have the existing Kong error format, which we effectively cannot parse, and the as-yet unreleased Kong/kong#10161 format, which we can parse and do parse in KIC#3446 Both the new Kong error format and KIC parsing are completely new, however, so I expect we may encounter things we want to change on either side. Does therefore it make sense to keep the go-kong body handling loose (i.e. it provides the body to downstream as-is and doesn't care about the contents at all itself) or lock that into go-kong now? With the controller as the sole user of the new format for the time being, I think we may want to leave the body parsing logic (and associated version-gated tests) there for now, see if we get feedback from the field, and if the initial implementation seems solid, graduate body parsing into go-kong functionality? IMO we create an issue to collect any feedback on the KIC usage and follow-up on making it generic go-kong functionality later. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just 2 nits.
As for processing/manipulating the body in go-kong vs KIC: I'm fine with leaving it here. It's actually better I'd say.
As for the tests: I just wanted to suggest a test where we assert for a given request/endpoint/payload tuple we get an expected body returned from ReloadDeclarativeRawConfig
.
golangci-lint apparently decided it should be upset about year-old code in this PR. I opened #273 since IDK exactly what we're doing with that copy instead of read, and fixing it is out of scope for this PR. |
2f15d71
to
badc1ed
Compare
Remove the config service and wrap its functionality into the Kong client.
badc1ed
to
7008ad7
Compare
7008ad7 makes the suggested change from chat discussion, which removes the config service and folds its functionality into the Kong client. |
Now that ReloadDeclarativeRawConfig returns config bodies always, the original error checking path didn't quite make sense. This extracts the body read and error check from the status error check and removes the response body from the status error.
1cbdb01
to
a61b0d5
Compare
Alright, one more for the road. Added an additional breaking feature, a61b0d5, because Kong/kong#10161 requires a new query string to return the error format that Kong/kubernetes-ingress-controller#3446 wants to use. |
I made some minor tweaks to the test itself and added the body contents to the error we return in case the response code indicates an error. But there's actually a more important thing here: the test fails with the following error:
The reason for this is that we don't test against a dbless kong 😱 Line 49 in 4b75690
I've created #274 to track this. |
Do we indeed want to do this? I'd actually removed this from the original error since we're now always returning bodies unless we can't read them, so if you get an error back you have the body, and can either log it or inspect it as needed. That body could be quite large, so I figured it made sense to omit it from the error string if you don't care beyond a brief explanation.
This is... odd. Is it somehow interpreting the query string as a field in some cases? Doing a packet capture shows no https://gist.github.com/rainest/b956bf4db29abb04418fd002bf3b0a1a That looks like a gateway-side bug maybe. |
Alright, 348dd08 to fix the error. Kong has an odd "bug" (not sure, since we appear to be aware of the behavior--we code around it--but keep it as-is) where query string fields are treated as part of the config body. Special-case known fields ( I have no idea why we do this, but the upshot is we need version-dependent behavior for part of the test only. This isn't something go-kong typically does, so the change adds some borrowed code from the "skip entire test by version" helper. |
For some more background, this is an unfortunate quirk of the web framework that the admin API uses. It lumps query args, form parameters, and I believe even request body JSON all into one single object (
So |
If CheckHash or FlattenErrors are not set (i.e. zero value false) when calling ReloadDeclarativeRawConfig, omit them from the query string. Kong versions that do not recognize these parameters interpret them as part of the config and reject the config as invalid due to unrecognized fields: #271 (comment)
Returns Kong
POST /config
bodies fromReloadDeclarativeRawConfig()
.Folds
ConfigService
intokong.Client
. go-kong services generally interact with a single distinct Kong entity (a route, service, consumer, etc.) whereasPOST /config
sends a blob of various kinds of entities in a single request.Releases 0.37.0. Note that these are both breaking changes, but, the config service was only recently added and only used in one place in KIC, and we're updating that part of KIC (in part to make use of the now-returned response body) anyway, so shouldn't be cause for concern.