Clarification on Shadowing and Return Error Configuration in Krakend

28 views
Skip to first unread message

ejie tung

unread,
Jan 24, 2025, 9:03:30 AMJan 24
to KrakenD Community

Hi, I have a question and would like to confirm a few details about implementing shadowing in Krakend.

Currently, I am implementing shadowing for specific endpoints in my configuration. Most of my endpoints use the no-op encoding, but I noticed that I cannot use it when implementing shadowing. For now, shadowing works well in the "happy case" scenarios for the designated endpoints.

After deploying this setup to production, we encountered an issue: the behavior of the return status codes and response bodies is different between no-op and json encodings during error scenarios. Specifically, when clients send an invalid payload, they do not receive a proper response body (status code and message) when no-op is used.

I reviewed the documentation and reproduced the issue in my local environment using Docker Compose. I managed to fix the issue locally by applying the following global router configuration:

- Works as expected in local

{
"version": 3,
"name": "My API Gateway with Shadowing",
"port": 8080,
"extra_config": {
"router": {
"return_error_msg": true
}
},
"endpoints": [
{
"endpoint": "/error",
"method": "GET",
"output_encoding": "json",

"backend": [
{
"host": [
],
"url_pattern": "/error",
"extra_config": {
"backend/http": {
"return_error_code": true
}
}
},
{
"host": [
],
"url_pattern": "/error",
"extra_config": {
"backend/http": {
"return_error_code": true
},
"proxy": {
"shadow": true
}
}
}
]
}, }

- Works as expected for "2XX" respond from backend, but 500 for non 2XX
{
"version": 3,
"name": "My API Gateway with Shadowing",
"port": 8080,
"endpoints": [
{
"endpoint": "/data/{data_id}",
"method": "GET",
"output_encoding": "json",
"backend": [
{
"host": [
],
"url_pattern": "/data/{data_id}"
},
{
"host": [
],
"url_pattern": "/data/{data_id}",
"extra_config": {
"proxy": {
"shadow": true
}
}
}
]
}, }

While the fix works in the local environment, I’m a bit concerned about applying this change in production, as it affects the global router configuration. Specifically, I want to ensure that this update will not inadvertently affect other endpoints in my gateway, as I am only implementing shadowing for a single endpoint.

Anyone can confirm whether this change is isolated to shadowing-related endpoints or if it might impact other routes as well? - if there are some docs, can also share, currently i cannot find any. 

Thank you for your assistance. I appreciate any insights and help !!

Reply all
Reply to author
Forward
0 new messages