mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 01:58:15 +08:00
Feature/#246 (#252)
* failing test * failing test but needs real butterfly server running..need to fix that...also worked out ive broken tracing...yey * brought in butterfly source code so i can work out how to write acceptance tests for this... * fixed the bug but still need to fix tracing * tracing working again across services but need to make tracing hook into new Ocelot middleware as it still uses asp.net middleware * removed butterfly libs brought in for testing
This commit is contained in:
@ -11,11 +11,11 @@ namespace Ocelot.Configuration.Repository
|
||||
{
|
||||
public class ConsulFileConfigurationPoller : IDisposable
|
||||
{
|
||||
private IOcelotLogger _logger;
|
||||
private IFileConfigurationRepository _repo;
|
||||
private IFileConfigurationSetter _setter;
|
||||
private readonly IOcelotLogger _logger;
|
||||
private readonly IFileConfigurationRepository _repo;
|
||||
private readonly IFileConfigurationSetter _setter;
|
||||
private string _previousAsJson;
|
||||
private Timer _timer;
|
||||
private readonly Timer _timer;
|
||||
private bool _polling;
|
||||
|
||||
public ConsulFileConfigurationPoller(IOcelotLoggerFactory factory, IFileConfigurationRepository repo, IFileConfigurationSetter setter)
|
||||
@ -77,4 +77,4 @@ namespace Ocelot.Configuration.Repository
|
||||
_timer.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
using Butterfly.Client.Tracing;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Ocelot.Middleware.Multiplexer;
|
||||
|
||||
@ -146,10 +147,14 @@ namespace Ocelot.DependencyInjection
|
||||
|
||||
//these get picked out later and added to http request
|
||||
_provider = new DelegatingHandlerHandlerProvider();
|
||||
_services.TryAddSingleton<IDelegatingHandlerHandlerProvider>(_provider);
|
||||
_services.AddTransient<ITracingHandler, NoTracingHandler>();
|
||||
_services.TryAddSingleton<IDelegatingHandlerHandlerProvider>(_provider);
|
||||
_services.TryAddSingleton<IMultiplexer, Multiplexer>();
|
||||
_services.TryAddSingleton<IResponseAggregator, SimpleJsonResponseAggregator>();
|
||||
_services.AddSingleton<ITracingHandlerFactory, TracingHandlerFactory>();
|
||||
|
||||
// We add this here so that we can always inject something into the factory for IoC..
|
||||
_services.AddSingleton<IServiceTracer, FakeServiceTracer>();
|
||||
|
||||
}
|
||||
|
||||
public IOcelotAdministrationBuilder AddAdministration(string path, string secret)
|
||||
@ -192,7 +197,8 @@ namespace Ocelot.DependencyInjection
|
||||
|
||||
public IOcelotBuilder AddOpenTracing(Action<ButterflyOptions> settings)
|
||||
{
|
||||
_services.AddTransient<ITracingHandler, OcelotHttpTracingHandler>();
|
||||
// Earlier we add FakeServiceTracer and need to remove it here before we add butterfly
|
||||
_services.RemoveAll<IServiceTracer>();
|
||||
_services.AddButterfly(settings);
|
||||
return this;
|
||||
}
|
||||
|
@ -173,23 +173,34 @@
|
||||
var ocelotConfigurationRepository =
|
||||
(IOcelotConfigurationRepository) builder.ApplicationServices.GetService(
|
||||
typeof(IOcelotConfigurationRepository));
|
||||
|
||||
var ocelotConfigurationCreator =
|
||||
(IOcelotConfigurationCreator) builder.ApplicationServices.GetService(
|
||||
typeof(IOcelotConfigurationCreator));
|
||||
|
||||
var fileConfigFromConsul = await consulFileConfigRepo.Get();
|
||||
|
||||
if (fileConfigFromConsul.Data == null)
|
||||
{
|
||||
config = await setter.Set(fileConfig.Value);
|
||||
var hack = builder.ApplicationServices.GetService(typeof(ConsulFileConfigurationPoller));
|
||||
}
|
||||
else
|
||||
{
|
||||
var ocelotConfig = await ocelotConfigurationCreator.Create(fileConfigFromConsul.Data);
|
||||
|
||||
if(ocelotConfig.IsError)
|
||||
{
|
||||
return new ErrorResponse(ocelotConfig.Errors);
|
||||
}
|
||||
|
||||
config = await ocelotConfigurationRepository.AddOrReplace(ocelotConfig.Data);
|
||||
|
||||
if (config.IsError)
|
||||
{
|
||||
return new ErrorResponse(config.Errors);
|
||||
}
|
||||
|
||||
//todo - this starts the poller if it has been registered...please this is so bad.
|
||||
var hack = builder.ApplicationServices.GetService(typeof(ConsulFileConfigurationPoller));
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
<DebugSymbols>True</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Butterfly.Client.AspNetCore" Version="0.0.5" />
|
||||
<PackageReference Include="Butterfly.Client.AspNetCore" Version="0.0.8" />
|
||||
<PackageReference Include="FluentValidation" Version="7.2.1" />
|
||||
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="2.1.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
|
||||
|
@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.Logging;
|
||||
@ -8,17 +9,17 @@ namespace Ocelot.Requester
|
||||
{
|
||||
public class DelegatingHandlerHandlerProviderFactory : IDelegatingHandlerHandlerProviderFactory
|
||||
{
|
||||
private readonly ITracingHandler _tracingHandler;
|
||||
private readonly ITracingHandlerFactory _factory;
|
||||
private readonly IOcelotLoggerFactory _loggerFactory;
|
||||
private readonly IDelegatingHandlerHandlerProvider _allRoutesProvider;
|
||||
private readonly IQosProviderHouse _qosProviderHouse;
|
||||
|
||||
public DelegatingHandlerHandlerProviderFactory(IOcelotLoggerFactory loggerFactory,
|
||||
IDelegatingHandlerHandlerProvider allRoutesProvider,
|
||||
ITracingHandler tracingHandler,
|
||||
IDelegatingHandlerHandlerProvider allRoutesProvider,
|
||||
ITracingHandlerFactory factory,
|
||||
IQosProviderHouse qosProviderHouse)
|
||||
{
|
||||
_tracingHandler = tracingHandler;
|
||||
_factory = factory;
|
||||
_loggerFactory = loggerFactory;
|
||||
_allRoutesProvider = allRoutesProvider;
|
||||
_qosProviderHouse = qosProviderHouse;
|
||||
@ -37,7 +38,7 @@ namespace Ocelot.Requester
|
||||
|
||||
if (request.HttpHandlerOptions.UseTracing)
|
||||
{
|
||||
provider.Add(() => (DelegatingHandler)_tracingHandler);
|
||||
provider.Add(() => (DelegatingHandler)_factory.Get());
|
||||
}
|
||||
|
||||
if (request.IsQos)
|
||||
|
@ -26,8 +26,10 @@ namespace Ocelot.Requester
|
||||
{
|
||||
var provider = _house.Get(request);
|
||||
|
||||
var handlers = provider.Data.Get();
|
||||
|
||||
//todo handle error
|
||||
provider.Data.Get()
|
||||
handlers
|
||||
.Select(handler => handler)
|
||||
.Reverse()
|
||||
.ToList()
|
||||
|
7
src/Ocelot/Requester/ITracingHandlerFactory.cs
Normal file
7
src/Ocelot/Requester/ITracingHandlerFactory.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace Ocelot.Requester
|
||||
{
|
||||
public interface ITracingHandlerFactory
|
||||
{
|
||||
ITracingHandler Get();
|
||||
}
|
||||
}
|
@ -12,11 +12,6 @@ namespace Ocelot.Requester
|
||||
{
|
||||
}
|
||||
|
||||
public class NoTracingHandler : DelegatingHandler, ITracingHandler
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class OcelotHttpTracingHandler : DelegatingHandler, ITracingHandler
|
||||
{
|
||||
private readonly IServiceTracer _tracer;
|
||||
|
32
src/Ocelot/Requester/TracingHandlerFactory.cs
Normal file
32
src/Ocelot/Requester/TracingHandlerFactory.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using Butterfly.Client.Tracing;
|
||||
using Butterfly.OpenTracing;
|
||||
|
||||
namespace Ocelot.Requester
|
||||
{
|
||||
public class TracingHandlerFactory : ITracingHandlerFactory
|
||||
{
|
||||
private readonly IServiceTracer _tracer;
|
||||
|
||||
public TracingHandlerFactory(IServiceTracer tracer)
|
||||
{
|
||||
_tracer = tracer;
|
||||
}
|
||||
|
||||
public ITracingHandler Get()
|
||||
{
|
||||
return new OcelotHttpTracingHandler(_tracer);
|
||||
}
|
||||
}
|
||||
|
||||
public class FakeServiceTracer : IServiceTracer
|
||||
{
|
||||
public ITracer Tracer { get; }
|
||||
public string ServiceName { get; }
|
||||
public string Environment { get; }
|
||||
public string Identity { get; }
|
||||
public ISpan Start(ISpanBuilder spanBuilder)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user