Skip to content

Commit

Permalink
Merge branch 'release-3.0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Pallister authored and Tom Pallister committed Feb 13, 2018
2 parents ec7b4ff + 947a145 commit 065a013
Show file tree
Hide file tree
Showing 65 changed files with 2,620 additions and 1,183 deletions.
2 changes: 1 addition & 1 deletion Ocelot.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.15
VisualStudioVersion = 15.0.27130.2024
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{5CFB79B7-C9DC-45A4-9A75-625D92471702}"
EndProject
Expand Down
11 changes: 6 additions & 5 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,15 @@ if(-Not $SkipToolPackageRestore.IsPresent) {
if((!(Test-Path $PACKAGES_CONFIG_MD5)) -Or
($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) {
Write-Verbose -Message "Missing or changed package.config hash..."
Remove-Item * -Recurse -Exclude packages.config,nuget.exe
Get-ChildItem -Exclude packages.config,nuget.exe,Cake.Bakery |
Remove-Item -Recurse
}

Write-Verbose -Message "Restoring tools from NuGet..."
$NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`""

if ($LASTEXITCODE -ne 0) {
Throw "An error occured while restoring NuGet tools."
Throw "An error occurred while restoring NuGet tools."
}
else
{
Expand All @@ -185,7 +186,7 @@ if (Test-Path $ADDINS_PACKAGES_CONFIG) {
$NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$ADDINS_DIR`""

if ($LASTEXITCODE -ne 0) {
Throw "An error occured while restoring NuGet addins."
Throw "An error occurred while restoring NuGet addins."
}

Write-Verbose -Message ($NuGetOutput | out-string)
Expand All @@ -202,7 +203,7 @@ if (Test-Path $MODULES_PACKAGES_CONFIG) {
$NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$MODULES_DIR`""

if ($LASTEXITCODE -ne 0) {
Throw "An error occured while restoring NuGet modules."
Throw "An error occurred while restoring NuGet modules."
}

Write-Verbose -Message ($NuGetOutput | out-string)
Expand Down Expand Up @@ -231,4 +232,4 @@ $cakeArguments += $ScriptArgs
# Start Cake
Write-Host "Running build script..."
&$CAKE_EXE $cakeArguments
exit $LASTEXITCODE
exit $LASTEXITCODE
3 changes: 2 additions & 1 deletion docs/features/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ Here is an example ReRoute configuration, You don't need to set all of these thi
},
"HttpHandlerOptions": {
"AllowAutoRedirect": true,
"UseCookieContainer": true
"UseCookieContainer": true,
"UseTracing": true
},
"UseServiceDiscovery": false
}
Expand Down
43 changes: 43 additions & 0 deletions docs/features/delegatinghandlers.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Delegating Handers
==================

Ocelot allows the user to add delegating handlers to the HttpClient transport. This feature was requested `GitHub #208 <https://github.com/TomPallister/Ocelot/issues/208>`_ and I decided that it was going to be useful in various ways.

Usage
^^^^^^

In order to add delegating handlers to the HttpClient transport you need to do the following.

.. code-block:: csharp
services.AddOcelot()
.AddDelegatingHandler(() => new FakeHandler())
.AddDelegatingHandler(() => new FakeHandler());
Or for singleton like behaviour..

.. code-block:: csharp
var handlerOne = new FakeHandler();
var handlerTwo = new FakeHandler();
services.AddOcelot()
.AddDelegatingHandler(() => handlerOne)
.AddDelegatingHandler(() => handlerTwo);
You can have as many DelegatingHandlers as you want and they are run in a first in first out order. If you are using Ocelot's QoS functionality then that will always be run after your last delegating handler.

In order to create a class that can be used a delegating handler it must look as follows

.. code-block:: csharp
public class FakeHandler : DelegatingHandler
{
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
//do stuff and optionally call the base handler..
return await base.SendAsync(request, cancellationToken);
}
}
Hopefully other people will find this feature useful!
31 changes: 31 additions & 0 deletions docs/features/tracing.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Tracing
=======

Ocelot providers tracing functionality from the excellent `Butterfly <https://github.com/ButterflyAPM>`_ project.

In order to use the tracing please read the Butterfly documentation.

In ocelot you need to do the following if you wish to trace a ReRoute.

In your ConfigureServices method

.. code-block:: csharp
services
.AddOcelot(Configuration)
.AddOpenTracing(option =>
{
//this is the url that the butterfly collector server is running on...
option.CollectorUrl = "http://localhost:9618";
option.Service = "Ocelot";
});
Then in your configuration.json add the following to the ReRoute you want to trace..

.. code-block:: json
"HttpHandlerOptions": {
"UseTracing": true
},
Ocelot will now send tracing information to Butterfly when this ReRoute is called.
3 changes: 3 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ Thanks for taking a look at the Ocelot documentation. Please use the left hand n
features/headerstransformation
features/claimstransformation
features/logging
features/tracing
features/requestid
features/middlewareinjection
features/loadbalancer
features/delegatinghandlers


.. toctree::
:maxdepth: 2
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"projects": [ "src", "test" ],
"sdk": {
"version": "2.0.2"
"version": "2.1.4"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class HttpHandlerOptionsCreator : IHttpHandlerOptionsCreator
public HttpHandlerOptions Create(FileReRoute fileReRoute)
{
return new HttpHandlerOptions(fileReRoute.HttpHandlerOptions.AllowAutoRedirect,
fileReRoute.HttpHandlerOptions.UseCookieContainer);
fileReRoute.HttpHandlerOptions.UseCookieContainer, fileReRoute.HttpHandlerOptions.UseTracing);
}
}
}
2 changes: 2 additions & 0 deletions src/Ocelot/Configuration/File/FileHttpHandlerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ public FileHttpHandlerOptions()
public bool AllowAutoRedirect { get; set; }

public bool UseCookieContainer { get; set; }

public bool UseTracing { get; set; }
}
}
8 changes: 7 additions & 1 deletion src/Ocelot/Configuration/HttpHandlerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
/// </summary>
public class HttpHandlerOptions
{
public HttpHandlerOptions(bool allowAutoRedirect, bool useCookieContainer)
public HttpHandlerOptions(bool allowAutoRedirect, bool useCookieContainer, bool useTracing)
{
AllowAutoRedirect = allowAutoRedirect;
UseCookieContainer = useCookieContainer;
UseTracing = useTracing;
}

/// <summary>
Expand All @@ -21,5 +22,10 @@ public HttpHandlerOptions(bool allowAutoRedirect, bool useCookieContainer)
/// Specify is handler has to use a cookie container
/// </summary>
public bool UseCookieContainer { get; private set; }

// <summary>
/// Specify is handler has to use a opentracing
/// </summary>
public bool UseTracing { get; private set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Ocelot.DependencyInjection
{
public interface IOcelotAdministrationBuilder
{
IOcelotAdministrationBuilder AddRafty();
}
}
28 changes: 16 additions & 12 deletions src/Ocelot/DependencyInjection/IOcelotBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
using CacheManager.Core;
using System;

namespace Ocelot.DependencyInjection
{
public interface IOcelotBuilder
{
IOcelotBuilder AddStoreOcelotConfigurationInConsul();
IOcelotBuilder AddCacheManager(Action<ConfigurationBuilderCachePart> settings);
IOcelotAdministrationBuilder AddAdministration(string path, string secret);
}
}
using Butterfly.Client.AspNetCore;
using CacheManager.Core;
using System;
using System.Net.Http;

namespace Ocelot.DependencyInjection
{
public interface IOcelotBuilder
{
IOcelotBuilder AddStoreOcelotConfigurationInConsul();
IOcelotBuilder AddCacheManager(Action<ConfigurationBuilderCachePart> settings);
IOcelotBuilder AddOpenTracing(Action<ButterflyOptions> settings);
IOcelotAdministrationBuilder AddAdministration(string path, string secret);
IOcelotBuilder AddDelegatingHandler(Func<DelegatingHandler> delegatingHandler);
}
}
34 changes: 34 additions & 0 deletions src/Ocelot/DependencyInjection/OcelotAdministrationBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Ocelot.Raft;
using Rafty.Concensus;
using Rafty.FiniteStateMachine;
using Rafty.Infrastructure;
using Rafty.Log;

namespace Ocelot.DependencyInjection
{
public class OcelotAdministrationBuilder : IOcelotAdministrationBuilder
{
private readonly IServiceCollection _services;
private readonly IConfiguration _configurationRoot;

public OcelotAdministrationBuilder(IServiceCollection services, IConfiguration configurationRoot)
{
_configurationRoot = configurationRoot;
_services = services;
}

public IOcelotAdministrationBuilder AddRafty()
{
var settings = new InMemorySettings(4000, 5000, 100, 5000);
_services.AddSingleton<ILog, SqlLiteLog>();
_services.AddSingleton<IFiniteStateMachine, OcelotFiniteStateMachine>();
_services.AddSingleton<ISettings>(settings);
_services.AddSingleton<IPeersProvider, FilePeersProvider>();
_services.AddSingleton<INode, Node>();
_services.Configure<FilePeers>(_configurationRoot);
return this;
}
}
}
Loading

0 comments on commit 065a013

Please sign in to comment.