-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#1672 Custom Default Version Policy #1673
#1672 Custom Default Version Policy #1673
Conversation
Hi Ibnu! I'll return to your PR back after merging all PRs with lower numbers... Or will find you a mentor 😉 |
@ggnaegi You are the mentor of this PR! Assigned! 😉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have written some comments, you should add a few more test cases and use string constants for the policies.
test/Ocelot.UnitTests/Configuration/VersionPolicyCreatorTests.cs
Outdated
Show resolved
Hide resolved
@ggnaegi, sorry for pinging you. i couldn't resolve this conflict. would you please resolve this conflict when you merge this pr? the difference is only whitespace and the intended change. thanks in advance. |
Hello, Ibnu! |
hello raman. thanks, the conflict is resolved. and might be off-topic. but in ocelot will support net8, yes? |
Hello, I think it's safe, we can add it to the november release. Maybe, we could implement some acceptance tests... |
hello folks, thanks for the answer. |
@ibnuda You should add a new class in test\Ocelot.AcceptanceTests. I have created a template, you can use it if you want, you might have several combinations to test...
I'm just wondering if, instead of using exact, downgradable, upgradeable, you should use the terms using Ocelot.Configuration.File;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
namespace Ocelot.AcceptanceTests;
public class DefaultVersionPolicyTests : IDisposable
{
private readonly Steps _steps;
private const string Body = "supercalifragilistic";
public DefaultVersionPolicyTests()
{
_steps = new Steps();
}
[Fact]
public async Task should_return_bad_gateway()
{
var port = PortFinder.GetRandomPort();
var configuration = new FileConfiguration
{
Routes = new List<FileRoute>
{
new()
{
DownstreamPathTemplate = "/",
DownstreamHostAndPorts = new List<FileHostAndPort>
{
new()
{
Host = "localhost",
Port = port,
},
},
DownstreamScheme = "https",
DownstreamHttpVersion = "2.0",
DownstreamVersionPolicy = "upgradeable",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = new List<string> { "GET" },
},
},
};
this.Given(x => x.GivenThereIsAServiceRunningOn($"https://localhost:{port}", HttpProtocols.Http1))
.And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning())
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.BadGateway))
.BDDfy();
}
private void GivenThereIsAServiceRunningOn(string url, HttpProtocols protocols)
{
var builder = new WebHostBuilder()
.UseUrls(url)
.UseKestrel()
.ConfigureKestrel(serverOptions =>
{
serverOptions.ConfigureEndpointDefaults(listenOptions => { listenOptions.Protocols = protocols; });
})
.UseContentRoot(Directory.GetCurrentDirectory())
.Configure(app =>
{
app.Run(async context =>
{
context.Response.StatusCode = (int)HttpStatusCode.OK;
await context.Response.WriteAsync(Body);
});
})
.Build();
builder.Start();
}
public void Dispose()
{
_steps?.Dispose();
}
} |
namespace Ocelot.AcceptanceTests;
public class DefaultVersionPolicyTests : IDisposable
{ } If we will create all test classes in the root folder then we will make long list of them. |
Yes, you are right, we should reorganize the tests structure, maybe a new PR? |
hello folks, seems like there's a problem when testing with http2 and https. the test pass just fine in local, but it seems the circle ci setup needs to trust dotnet issued cert. i made change in the what can i do to pass the ci? thanks in advance. |
@ibnuda uuupppss... Let me check that |
Ok, the problem is on ocelot side too... Ok, will have a look later, sorry. |
Thank, ggnaegi. but please don't feel pressured. please do it in your own pace and. |
Guys, we have the new commits in |
Binary copy! :LoL:
Re-add sweet props
…_json_options_for_custom_builder
Add DownstreamVersionPolicy section
1145c54
to
201f296
Compare
@ibnuda Congrats! 🥳 |
* feature written, tests passed * actualy passes almost all the test. * resolve conflict, hopefully. * please. * let it cook. * uses constants instead of string for version policies. * conflict res * swapped downstream method and version. * #1731 Read the Docs configuration file v2 (#1733) * fixing the documentation, using Release/20.0 as base branch * using latest conf.py, created with sphinx-quickstart, fixing the warnings during documentation generation * Update .readthedocs.yaml * switching to threemammals.org for copyright * adding requirements file, updating readthedocs.yaml, adding formats pdf / epub and config for requirements file * fixing code block in websockets.rst * ok, now it should be fine... * Update kubernetes.rst: Review and fix markup code * Update websockets.rst: Review and fix markup * Update conf.py: Update release, author and copyright --------- Co-authored-by: Raman Maksimchuk <dotnet044@gmail.com> * * When using the QoS option "ExceptionsAllowedBeforeBreaking" the circuit breaker never opens the circuit. * merge issue, PortFinder * some code improvements, using httpresponsemessage status codes as a base for circuit breaker * Adding more unit tests, and trying to mitigate the test issues with the method "GivenThereIsAPossiblyBrokenServiceRunningOn" * fixing some test issues * setting timeout value to 5000 to avoid side effects * again timing issues * timing issues again * ok, first one ok * Revert "ok, first one ok" This reverts commit 2e4a673. * inline method * putting back logging for http request exception * removing logger configuration, back to default * adding a bit more tests to check the policy wrap * Removing TimeoutStrategy from parameters, it's set by default to pessimistic, at least one policy will be returned, so using First() in circuit breaker and removing the branch Policy == null from delegating handler. * Fix StyleCop warnings * Format parameters * Sort usings * since we might have two policies wrapped, timeout and circuit breaker, we can't use the name CircuitBreaker for polly qos provider, it's not right. Using PollyPolicyWrapper and AsnycPollyPolicy instead. * modifying circuit breaker delegating handler name, usin Polly policies instead * renaming CircuitBreakerFactory to PolicyWrapperFactory in tests * DRY for FileConfiguration, using FileConfigurationFactory * Add copy constructor * Refactor setup * Use expression body for method * Fix acceptance test * IDE1006 Naming rule violation: These words must begin with upper case characters * CA1816 Change ReturnsErrorTests.Dispose() to call GC.SuppressFinalize(object) * Sort usings * Use expression body for method * Return back named arguments --------- Co-authored-by: raman-m <dotnet044@gmail.com> * feature written, tests passed * actualy passes almost all the test. * resolve conflict, hopefully. * missed this one. * please. * come on... * let it build. * let it cook. * copied from main branch. * conflict res * resolving conflicts. * another attempt. * lf * re-incorporate downstream version policy. * renamed the version policies and added acceptance tests. * trust the dotnet dev cert. * accepts cert from dotnet. * Fix compiling errors * Refactor tests * a bit of code cleanup, removing some usings * a bit more cleanup in fileroute * try and error with the tests * "Yahoo!...", said @ibnuda :) * FileRoute: let it go... Binary copy! :LoL: * FileRoute: let it cook... Re-add sweet props * `dotnet dev-certs` for the `build` job * Recover `kubernetes.rst` * docs/make.bat original version * OcelotBuilderExtensions * original src/Ocelot.Provider.Polly/v7/PollyPolicyWrapper.cs * `IVersionPolicyCreator` XML docs * Code review by @raman-m (part 1) * RequestMapper : care about diff * Code review by @raman-m (part 2) * Fix Should_return_OK_status_and_multiline_indented_json_response_with_json_options_for_custom_builder * Update configuration.rst Add DownstreamVersionPolicy section * Update docs * Rename `DownstreamVersionPolicy` to `DownstreamHttpVersionPolicy` * update docs after prop renaming * Sort props --------- Co-authored-by: Guillaume Gnaegi <58469901+ggnaegi@users.noreply.github.com> Co-authored-by: Raman Maksimchuk <dotnet044@gmail.com>
Feature commit in develop → 176a4c8 |
Closes #1672
New Feature
Configurable
HttpRequestMessage.VersionPolicy
.Motivation for New Feature
The following setup:
All components above configured to use Kestrel with the following snippet:
All components above should only talk to each other using HTTP/2 and no TLS (plain HTTP).
User Scenario
With plain Ocelot 18.0.0, I couldn't make them talk to each other with plain HTTP from frontend to the service.
The services will print out error messages like the following:
Solution
Found out that I need to make sure that
HttpRequestMessage
has itsVersionPolicy
to be setRequestVersionOrHigher
.Changes I made
Ocelot.Request.Mapper
class:
RequestMapper
method:
Task<Response<HttpRequestMessage>> Map(HttpRequest request, DownstreamRoute downstreamRoute)
changes:
VersionPolicy = HttpVersionPolicy.RequestVersionOrHigher,
inHttpRequestMessage
instantiation.Ocelot.Requester
class:
HttpClientBuilder
method:
IHttpClient Create(DownstreamRoute downstreamRoute)
changes:
DefaultRequestVersion = downstreamRoute.DownstreamHttpVersion,
andDefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrHigher,
inHttpClient
instantiation.Then all those components above can talk to each other in HTTP/2.
And I think
DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrHigher
could beDefaultVersionPolicy downstreamRoute.DownstreamHttpVersionPolicy
.And I am willing to make a PR if you fine folks think this kind of changes is welcome.
Specifications