Search code examples
goapi-gatewaygatewaysequentialkrakend

KrakenD sequential endpoint wrong response


krakenD version: 2.2.1 go version: go1.19.3

I want to send sequential requests to two different endpoints using krakenD's sequential feature.

To summarize my case briefly:

  • These two services can return both success (200) and error (4**).
  • If the first service returns an error, I can see the error in postman as a response. (this is a situation I want)
  • If the second service returns an error (4**) after the first service returns success (200), I see the success response from postman while waiting to see the error returned from the second service.

sequential endpoint example:

{
   "endpoint": "/companies/validate",
   "method": "GET",
   {{ include "input_headers.txt" }},
   "backend": [
    {
      "host": ["{{ .service.credential_service_url }}"],
      "url_pattern": "/tokens/validate",
      "method": "GET",
      "extra_config": {
         "backend/http": {
            "return_error_code": true
         }
      }
    },
    {
      "host": ["{{ .service.company_service_url }}"],
      "url_pattern": "/companies/{resp0_companyId}/validate",
      "method": "GET",
      "extra_config": {
         "backend/http": {
            "return_error_code": true
         }
      }
    }
   ],
   "extra_config": {
      "proxy": {
         "sequential": true
      }
   }
 }

ide logs

postman response

As you can see, the first service works correctly, the second service returns an error, but the postman response returns a success.


Solution

  • This is the expected behavior of KrakenD.

    When you do more than one call, if at least one of the requests succeed, KrakenD will return any available content together with a 200 status code. But in exchange, you receive a header X-KrakenD-Complete: false telling you that something failed. You can read more about aggregation here

    As you are using the sequential proxy, when the first request fails, there is nothing else to do as the next sequential call is automatically aborted. In consequence, ALL content failed and KrakenD cannot return anything, and this is why you get the desired failure.

    On the other case, because the first call works, KrakenD has something to return, and you receive partial data.

    You should check in your client de content of the X-KrakenD-Complete header to decide what to do