Closed msvaillant closed 7 years ago
Am I right? Is it bug or some uncorrect configuration from me? If it is bug - i can fix it by adding some additional logic to replacer.
this issue happens just sometimes
I have investigated a little with your acceptance test and have found the difference in the results of executing FindDownstreamRoute
of DownsteamRouteFinder
. On acceptance tests it returns templateVariableNameAndValues
for {someid}, but for my case result is just empty collection
@msvaillant looks like it might be a bug..ill have a look ASAP!
@TomPallister , I have encountered bug - if you use Ocelot with request of http://localhost:5100/api/vacancy/1 - bug reproduces in templateVariableNameAndValues
, if http://localhost:5100/vacancy/1 - everything works right!
@TomPallister - so yes, it is so - on acceptance test there is also such behavior - the placeholder is not recognized when passing request with API before main part. (But strangely - test is OK and you will not see fault, but in debugger I see no placeholder data - actually failing in production).
As I see - this not really bug, but undocumented behavior. I think so because:
For myself - I will now use requests to Ocelot with no API prefix, or will configure ocelot explicitly to use this one (hope it will help if it would be needed).
To fix this behavior or document it? I don't know, but I can be not the only who received this problem. It should be blocked to use API implicitly, or fixed to use it implicitly with no care or at least documented to avoid implicitness, because it fails in some cases.
Would be nice to look if there are any cases close to mine to avoid bugs, and write acceptance test for my case :)
@msvaillant I'm trying to write a test to reproduce your issue but I am failing. This request is being forwarded to the downstream service with a path of "/api/v1/vacancy/1" see test below. What am I missing? :(
[Fact]
public void bug()
{
var configuration = new FileConfiguration
{
ReRoutes = new List<FileReRoute>
{
new FileReRoute
{
DownstreamPathTemplate = "/api/v1/vacancy",
DownstreamScheme = "http",
DownstreamHost = "localhost",
DownstreamPort = 51879,
UpstreamPathTemplate = "/vacancy/",
UpstreamHttpMethod = new List<string> { "Options", "Put", "Get", "Post", "Delete" },
ServiceName = "botCore",
LoadBalancer = "LeastConnection"
},
new FileReRoute
{
DownstreamPathTemplate = "/api/v1/vacancy/{vacancyId}",
DownstreamScheme = "http",
DownstreamHost = "localhost",
DownstreamPort = 51879,
UpstreamPathTemplate = "/vacancy/{vacancyId}",
UpstreamHttpMethod = new List<string> { "Options", "Put", "Get", "Post", "Delete" },
ServiceName = "botCore",
LoadBalancer = "LeastConnection"
}
}
};
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879/api/v1/vacancy/1", 200, "Hello from Laura"))
.And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning())
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/vacancy/1"))
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
.And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura"))
.BDDfy();
}
The other thing is..
@TomPallister , I have encountered bug - if you use Ocelot with request of http://localhost:5100/api/vacancy/1 - bug reproduces in templateVariableNameAndValues, if http://localhost:5100/vacancy/1 - everything works right!
If you dont have /api/vacancy/{vacancyId} in your config then Ocelot should not route your request to the downstream service at all...it should 404 unless I introduced a defect.....should have a test for this :(
@TomPallister
.When(x => _steps.WhenIGetUrlOnTheApiGateway("api/vacancy/1"))
And on debugging that test you will get empty collection (but strangely this test was not failing - maybe something do not depends on url data)
OK I think I understand.
That should return a 404 because you do not have the following set up..
{
"DownstreamPathTemplate": "/api/v1/vacancy/{vacancyId}",
"DownstreamScheme": "http",
"DownstreamPort": 5002,
"DownstreamHost": "localhost",
**"UpstreamPathTemplate": "api/vacancy/{vacancyId}",**
"UpstreamHttpMethod": [ "Options", "Put", "Get", "Post", "Delete" ],
"ServiceName": "botCore",
"LoadBalancer": "LeastConnection"
},
However it might have got broken...
Yes, it is so :) so now you have one more acceptance test, to check on 404 when somebody tries to use request with API, but without expected configuration.
@msvaillant yep...this is definitely a bug, guess I missed a test.
Good day, I have encountered a problem with downstream url forwarding. Let me express it on example:
send GET request to Ocelot by url like http://localhost:5100/api/vacancy/1 it should be downstreamed to http://localhost:5002/api/v1/vacancy/1 but it is http://localhost:5002/api/v1/vacancy/{vacancyid}
configuration looks like this:
I attach Logs to approve behavior.
Ocelot apigateway logs:
Resource server logs:
And as I have debugged your code - I see that solution must be somewhere there: