You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When receiving a merged response for multiple backends, if one of the backends fails, we get a non nil err that is a mergeError.
The error contains a slice with one entry per failed backend.
Tested a simple fix, check if resp is nil, this still returns error and does not call the response modifier when all backends fail or is just one that failed, while allowing for the modifier to still be called.
Configuration check output:
Result of krakend check -dtc krakend_conditional.json --lint command
Parsing configuration file: krakend_conditional.json
Global settings
Name: conditional test
Port: 8080
Folder: ./plugins/
Pattern: .so
1 global component configuration(s):
- telemetry/logging
1 API endpoint(s):
- GET /services
Timeout: 50m0s
1 endpoint component configuration(s):
- plugin/req-resp-modifier
Connecting to 3 backend(s):
[+] GET /pattern1
Timeout: 50m0s
Hosts: [http://localhost:8090]
1 backend component configuration(s):
- validation/cel
[+] GET /pattern1
Timeout: 50m0s
Hosts: [http://localhost:8090]
1 backend component configuration(s):
- validation/cel
[+] GET /pattern2
Timeout: 50m0s
Hosts: [http://localhost:8090]
1 backend component configuration(s):
- validation/cel
0 async agent(s):
Syntax OK!
Commands used:
How did you start the software?
krakend run -d -c krakend_conditional.json
Expected behavior
The objective is to call multiple backends on a endpoint conditionally and return each backend response as a JSON collection where each element is the backend response.
Each backend is called if an HTTP header values matches a condition.
Each backend has a group defined and I have written a response modifier plugin that applied to the endpoint gets the merged response and then collapses each group response and moves the group key name to the value of "name" into the each backend response and adds the response collection to a "collection" object.
Call to services endpoint should return the expected collection resulting of the custom plugin response modification but instead returns an empty JSON collection
curl http://localhost:8080/services -H 'x-group-id: group1'| jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2 100 2 0 0 163 0 --:--:-- --:--:-- --:--:-- 181
[]
Setting the endpoint's output_encoding to json shows that the backend responses were merged but the response modifier was not triggered.
@alombarte sorry for the late reply, nothing to do with the code, I agree that it is a bug that needs fixing.
We are currently trying to clarify some legal constraints about contributing to the project.
Hopefully we'll be able to unblock the PR soon.
Environment info:
Describe the bug
plugin/req-resp-modifier in an endpoint is not called if one of the backend CEL evaluations fails
this was initially submitted in krakend/krakend-ce#542
After some debugging it looks like it's an issue in the plugin.go in the proxy pkg https://github.com/luraproject/lura/blob/master/proxy/plugin.go#L91-L96
When receiving a merged response for multiple backends, if one of the backends fails, we get a non nil err that is a mergeError.
The error contains a slice with one entry per failed backend.
Tested a simple fix, check if resp is nil, this still returns error and does not call the response modifier when all backends fail or is just one that failed, while allowing for the modifier to still be called.
Your configuration file:
Configuration check output:
Result of
krakend check -dtc krakend_conditional.json --lint
commandCommands used:
How did you start the software?
Expected behavior
The objective is to call multiple backends on a endpoint conditionally and return each backend response as a JSON collection where each element is the backend response.
Each backend is called if an HTTP header values matches a condition.
Each backend has a group defined and I have written a response modifier plugin that applied to the endpoint gets the merged response and then collapses each group response and moves the group key name to the value of
"name"
into the each backend response and adds the response collection to a"collection"
object.So each backend returns something in the likes of
Merged response would look like
And modified response by the custom plugin:
With
output_encoding
asjson-collection
we would get:Call to
services
endpoint should return the expected collection resulting of the custom plugin response modification but instead returns an empty JSON collectionSetting the endpoint's
output_encoding
tojson
shows that the backend responses were merged but the response modifier was not triggered.Logs:
The custom-plugin has logging and it should be visible with debug
Additional comments:
Changing the CEL expression with group2 to group1 so that all backends pass the CEL evaluation proves that the custom plugin works when called
Logs
The text was updated successfully, but these errors were encountered: