ThreeMammals / Ocelot

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

UpstreamHost not working #1925

Closed nrllhylmz closed 7 months ago

nrllhylmz commented 7 months ago

Hi,

I upgraded ocelot. (18.0.0 -> 22.0.1) "UpstreamHost" worked without problems in the old version but it doesn't work in the latest version. Ocelot failed to match routes. I deleted this feature. Routes matched. But i want to seperate host(UpstreamHost).

Thanks

raman-m commented 7 months ago

UpstreamHost not working

Why do you think so? Our unit & acceptance tests are green! 😉


I upgraded ocelot. (18.0.0 -> 22.0.1)

Maybe something wrong with the upgrade process...


Ocelot failed to match routes.

Wow! Please provide more details: ocelot.json file, logs with errors info, and etc. Which routes? We don't see them! 😉


I deleted this feature. Routes matched. But i want to seperate host(UpstreamHost).

Sorry? What have you deleted and how?

raman-m commented 7 months ago

@nrllhylmz What's your full name? Please upload complete solution to your GitHub account for verification and review by our team!

nrllhylmz commented 7 months ago

Ocelot 18.0.0 working but Ocelot 22.0.1 not working. Deleted UpstreamHost. Working. But i want to seperate upstreamhost.

Warnings;

requestId: 0HN0MJFAEUU8F:00000009, previousRequestId: No PreviousRequestId, 
message: 'Error Code: UnableToFindDownstreamRouteError 
Message: Failed to match Route configuration for upstream path: /test/WeatherForecast, verb: GET.
errors found in ResponderMiddleware.
Setting error response for request path:/test/WeatherForecast, request method: GET'

requestId: 0HN0MJFAEUU8F:00000009, previousRequestId: No PreviousRequestId, 
message: 'DownstreamRouteFinderMiddleware setting pipeline errors. IDownstreamRouteFinder returned Error Code: UnableToFindDownstreamRouteError 
Message: Failed to match Route configuration for upstream path: /test/WeatherForecast, verb: GET.'

My ocelot.json 👉

{
  "Routes": [
    {
      "DownstreamPathTemplate": "/{everything}",
      "UpstreamPathTemplate": "/test/{everything}",
      "UpstreamHttpMethod": [
      ],
      "DownstreamHttpMethod": null,
      "AddHeadersToRequest": {
      },
      "UpstreamHeaderTransform": {
      },
      "DownstreamHeaderTransform": {
      },
      "AddClaimsToRequest": {
      },
      "RouteClaimsRequirement": {
      },
      "AddQueriesToRequest": {
      },
      "ChangeDownstreamPathTemplate": {
      },
      "RequestIdKey": null,
     "FileCacheOptions": {
        "TtlSeconds": 0,
        "Region": null
      },
      "RouteIsCaseSensitive": false,
      "ServiceName": null,
      "ServiceNamespace": null,
      "DownstreamScheme": "https",
      "QoSOptions": {
        "ExceptionsAllowedBeforeBreaking": 0,
        "DurationOfBreak": 0,
        "TimeoutValue": 0
      },
      "LoadBalancerOptions": {
        "Type": null,
        "Key": null,
        "Expiry": 0
      },
      "RateLimitOptions": {
        "ClientWhitelist": [
        ],
        "EnableRateLimiting": false,
        "Period": null,
        "PeriodTimespan": 0.0,
        "Limit": 0
      },
      "AuthenticationOptions": {
        "AuthenticationProviderKey": null,
        "AllowedScopes": [
        ]
      },
      "HttpHandlerOptions": {
        "AllowAutoRedirect": false,
        "UseCookieContainer": false,
        "UseTracing": false,
        "UseProxy": true,
        "MaxConnectionsPerServer": 2147483647
      },
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": 7071
        }
      ],
      "UpstreamHost": "localhost:6001",
      "Key": null,
      "DelegatingHandlers": [
      ],
      "Priority": 1,
      "Timeout": 0,
      "DangerousAcceptAnyServerCertificateValidator": false,
      "SecurityOptions": {
        "IPAllowedList": [
        ],
        "IPBlockedList": [
        ]
      },
      "DownstreamHttpVersion": null
    }
  ],
  "DynamicRoutes": [
  ],
  "Aggregates": [
  ],
  "GlobalConfiguration": {
    "RequestIdKey": null,
    "ServiceDiscoveryProvider": {
      "Scheme": null,
      "Host": null,
      "Port": 0,
      "Type": null,
      "Token": null,
      "ConfigurationKey": null,
      "PollingInterval": 0,
      "Namespace": null
    },
    "RateLimitOptions": {
      "ClientIdHeader": "ClientId",
      "QuotaExceededMessage": null,
      "RateLimitCounterPrefix": "ocelot",
      "DisableRateLimitHeaders": false,
      "HttpStatusCode": 429
    },
    "QoSOptions": {
      "ExceptionsAllowedBeforeBreaking": 0,
      "DurationOfBreak": 0,
      "TimeoutValue": 0
    },
    "BaseUrl": "https://localhost:6001",
    "LoadBalancerOptions": {
      "Type": null,
      "Key": null,
      "Expiry": 0
    },
    "DownstreamScheme": null,
    "HttpHandlerOptions": {
      "AllowAutoRedirect": false,
      "UseCookieContainer": false,
      "UseTracing": false,
      "UseProxy": true,
      "MaxConnectionsPerServer": 2147483647
    },
    "DownstreamHttpVersion": null
  }
}
nrllhylmz commented 7 months ago

I delete "UpstreamHost":"localhost:6001" and it worked. I want to use "UpstreamHost"

raman-m commented 7 months ago

@nrllhylmz commented on Jan 16:


I delete "UpstreamHost":"localhost:6001" and it worked. I want to use "UpstreamHost"

But why do you need to use UpstreamHost if you have single route in development environment? Maybe some firewall tool will help you? 😄

Read UpstreamHost docs and you will get that feature is based on Host header! You just cannot make request from Ocelot instance app to itself!


Your very zipped JSON

{
  "Routes": [
    {
      "DownstreamPathTemplate": "/{everything}",
      "UpstreamPathTemplate": "/test/{everything}",
      "DownstreamScheme": "https",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost", "Port": 7071
        }
      ],
      "UpstreamHost": "localhost:6001",
    }
  ],
  "GlobalConfiguration": {
    "BaseUrl": "https://localhost:6001",
    "DownstreamHttpVersion": null
  }
}

Don't you see the issue? You cannot use "UpstreamHost" with value localhost:6001 because "BaseUrl" is https://localhost:6001 !!! You cannot make requests from Ocelot instance to itself! "UpstreamHost" property is used to filter incoming requests from various domains in DNS form but not from Base URL of Ocelot host & port! It is impossible! That is why you have error: Failed to match Route configuration for upstream path: /test/WeatherForecast which says that Ocelot cannot find route!

What are you doing? 🤯

raman-m commented 7 months ago

Nurullah Yılmaz!

I recommend you to

I see misconfiguration problem which should be fixed by your own. Our all tests are green and UpstreamHost feature should not be broken. For invalid configs the feature can be broken.

nrllhylmz commented 7 months ago

Dear @raman-m I created a sample project for you.


My ocelot.json

{
    "Routes": [
        {
            "UpstreamHost": "localhost:6001",
            "UpstreamPathTemplate": "/test/{everything}",
            "DownstreamPathTemplate": "/{everything}",
            "DownstreamHostAndPorts": [
                {
                    "Host": "localhost",
                    "Port": 7071
                }
            ]
        },
        {
            "UpstreamHost": "localhost:6002",
            "UpstreamPathTemplate": "/test/{everything}",
            "DownstreamPathTemplate": "/{everything}",
            "DownstreamHostAndPorts": [
                {
                    "Host": "localhost",
                    "Port": 7072
                }
            ]
        }
    ],
    "GlobalConfiguration": {
        "BaseUrl": "https://localhost:6001"
    }
}

Projects started

Ocelot18.Api(version 18.0.0) => https://localhost:6001;
             => https://localhost:6002, 
Test1.Api => https://localhost:7071,
Test2.Api => https://localhost:7072

https://localhost:6001/test/WeatherForecast route matched https://localhost:6002/test/WeatherForecast route matched

Projects stop


Projects started

Ocelot22.Api (version 22.0.1) => https://localhost:6001;
             => https://localhost:6002, 
Test1.Api => https://localhost:7071,
Test2.Api => https://localhost:7072

https://localhost:6001/test/WeatherForecast route not found https://localhost:6002/test/WeatherForecast route not found

Projects stop

Repository link: https://github.com/nrllhylmz/Example

Thanks.

raman-m commented 7 months ago

Your next created #1926 will be checked by our QA engineer... You can talk to him.