ThreeMammals / Ocelot

.NET API Gateway
https://www.nuget.org/packages/Ocelot
MIT License
8.37k stars 1.64k forks source link

Error: Failed to match ReRoute configuration for upstream path: / #1064

Closed Panos80 closed 7 months ago

Panos80 commented 4 years ago

Expected Behavior

We are using ocelot to create an API gateway for microservices / APIs which are deployed in Azure Kubernetes. We use a global configuration:

{
  "GlobalConfiguration": {
    "ServiceDiscoveryProvider": {
      "Namespace": "default",
      "Type": "kube"
    }
  }
}
// And configuration for each microservice where we use the service name in AKS.
{
  "ReRoutes": [
    {
      "DownstreamPathTemplate": "/api/{everything}",
      "DownstreamScheme": "http",
      "RateLimitOptions": {
        "ClientWhitelist": [],
        "ClientIdHeader": "LoginId",
        "EnableRateLimiting": true,
        "Period": "1s",
        "PeriodTimespan": 1,
        "Limit": 50
      },
      "ServiceName": "clientserviceapi",
      "UpstreamPathTemplate": "/api/client-service/{everything}",
      "UpstreamHttpMethod": ["Options", "Get", "Post", "Put", "Delete"]
    }
  ]
}

Actual Behavior

Everything works find but we are seeing continuously the following error:

previousRequestId: no previous request id, message: Error Code: UnableToFindDownstreamRouteError Message: Failed to match ReRoute configuration for upstream path: /, verb: GET. errors found in ResponderMiddleware. Setting error response for request path:/, request method: GET

It seems like the ocelot is trying to find a configuration for some root path (/) which is though not required. Can we add a configuration to ignore this error? Many thanks

Specifications

raman-m commented 7 months ago

https://github.com/ThreeMammals/Ocelot/blob/develop/src/Ocelot/Responder/ErrorsToHttpStatusCodeMapper.cs#L41-L44

This is important error of logic! It cannot be ignored or switched off.

But if you don't want to see it in the log, you can define a fake route to nowhere.

{
  "Routes": [
    {
      "DownstreamPathTemplate": "/api/{everything}",
      "DownstreamScheme": "http",
      "RateLimitOptions": {
        "ClientWhitelist": [],
        "ClientIdHeader": "LoginId",
        "EnableRateLimiting": true,
        "Period": "1s",
        "PeriodTimespan": 1,
        "Limit": 50
      },
      "ServiceName": "clientserviceapi",
      "UpstreamPathTemplate": "/api/client-service/{everything}",
      "UpstreamHttpMethod": ["Options", "Get", "Post", "Put", "Delete"]
    },
    // fake route
    {
      "DownstreamPathTemplate": "/",
      "UpstreamPathTemplate": "/",
      "UpstreamHttpMethod": ["Options", "Get", "Post", "Put", "Delete"]
      "DownstreamScheme": "https",
      "DownstreamHostAndPorts": [
           {
             "Host": "www.google.com",
             "Port": 443
           }
      ]
    }
  ]
}

:rofl: