Skip to content
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

Add YARP Telemetry instrumentation #501

Merged
merged 19 commits into from
Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions src/ReverseProxy/Abstractions/Telemetry/IOperationContext.cs

This file was deleted.

52 changes: 0 additions & 52 deletions src/ReverseProxy/Abstractions/Telemetry/IOperationLogger.cs

This file was deleted.

28 changes: 0 additions & 28 deletions src/ReverseProxy/Abstractions/Time/IMonotonicTimer.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.ReverseProxy.Abstractions.Telemetry;
using Microsoft.ReverseProxy.Abstractions.Time;
using Microsoft.ReverseProxy.RuntimeModel;
using Microsoft.ReverseProxy.Service;
using Microsoft.ReverseProxy.Service.Config;
Expand All @@ -15,21 +13,13 @@
using Microsoft.ReverseProxy.Service.Proxy.Infrastructure;
using Microsoft.ReverseProxy.Service.Routing;
using Microsoft.ReverseProxy.Service.SessionAffinity;
using Microsoft.ReverseProxy.Telemetry;
using Microsoft.ReverseProxy.Utilities;
using System.Linq;

namespace Microsoft.ReverseProxy.Configuration.DependencyInjection
{
internal static class IReverseProxyBuilderExtensions
{
public static IReverseProxyBuilder AddTelemetryShims(this IReverseProxyBuilder builder)
{
// NOTE: Consumers of ReverseProxy are expected to replace these with their own classes
builder.Services.TryAddSingleton(typeof(IOperationLogger<>), typeof(TextOperationLogger<>));
return builder;
}

public static IReverseProxyBuilder AddConfigBuilder(this IReverseProxyBuilder builder)
{
builder.Services.TryAddSingleton<IConfigValidator, ConfigValidator>();
Expand All @@ -43,7 +33,6 @@ public static IReverseProxyBuilder AddRuntimeStateManagers(this IReverseProxyBui
builder.Services.TryAddSingleton<IDestinationManagerFactory, DestinationManagerFactory>();
builder.Services.TryAddSingleton<IClusterManager, ClusterManager>();
builder.Services.TryAddSingleton<IRouteManager, RouteManager>();
builder.Services.TryAddSingleton<IUptimeClock, UptimeClock>();
builder.Services.TryAddSingleton<ITimerFactory, TimerFactory>();
return builder;
}
Expand All @@ -64,13 +53,6 @@ public static IReverseProxyBuilder AddProxy(this IReverseProxyBuilder builder)
return builder;
}

public static IReverseProxyBuilder AddBackgroundWorkers(this IReverseProxyBuilder builder)
{
builder.Services.TryAddSingleton<IMonotonicTimer, MonotonicTimer>();

return builder;
}

public static IReverseProxyBuilder AddSessionAffinityProvider(this IReverseProxyBuilder builder)
{
builder.Services.TryAddEnumerable(new[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.ReverseProxy.Configuration.DependencyInjection;
using Microsoft.ReverseProxy.Service;
using Microsoft.ReverseProxy.Service.Proxy;
using Microsoft.ReverseProxy.Utilities;

namespace Microsoft.Extensions.DependencyInjection
{
Expand All @@ -23,6 +24,7 @@ public static class ReverseProxyServiceCollectionExtensions
/// </summary>
public static IServiceCollection AddHttpProxy(this IServiceCollection services)
{
services.TryAddSingleton<IClock, Clock>();
services.TryAddSingleton<IHttpProxy, HttpProxy>();
return services;
}
Expand All @@ -34,15 +36,13 @@ public static IReverseProxyBuilder AddReverseProxy(this IServiceCollection servi
{
var builder = new ReverseProxyBuilder(services);
builder
.AddTelemetryShims()
.AddConfigBuilder()
.AddRuntimeStateManagers()
.AddConfigManager()
.AddSessionAffinityProvider()
.AddActiveHealthChecks()
.AddPassiveHealthCheck()
.AddProxy()
.AddBackgroundWorkers();
.AddProxy();

services.AddDataProtection();
services.AddAuthorization();
Expand Down
1 change: 1 addition & 0 deletions src/ReverseProxy/Microsoft.ReverseProxy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<TargetFrameworks>net5.0;netcoreapp3.1</TargetFrameworks>
<OutputType>Library</OutputType>
<RootNamespace>Microsoft.ReverseProxy</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EventSource 😢

</PropertyGroup>

<ItemGroup>
Expand Down
13 changes: 4 additions & 9 deletions src/ReverseProxy/Middleware/ProxyInvokerMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
// Licensed under the MIT License.

using System;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Microsoft.ReverseProxy.Abstractions.Telemetry;
using Microsoft.ReverseProxy.Service.Proxy;
using Microsoft.ReverseProxy.Telemetry;
using Microsoft.ReverseProxy.Utilities;

namespace Microsoft.ReverseProxy.Middleware
Expand All @@ -21,19 +19,16 @@ internal class ProxyInvokerMiddleware
private readonly IRandomFactory _randomFactory;
private readonly RequestDelegate _next; // Unused, this middleware is always terminal
private readonly ILogger _logger;
private readonly IOperationLogger<ProxyInvokerMiddleware> _operationLogger;
private readonly IHttpProxy _httpProxy;

public ProxyInvokerMiddleware(
RequestDelegate next,
ILogger<ProxyInvokerMiddleware> logger,
IOperationLogger<ProxyInvokerMiddleware> operationLogger,
IHttpProxy httpProxy,
IRandomFactory randomFactory)
{
_next = next ?? throw new ArgumentNullException(nameof(next));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_operationLogger = operationLogger ?? throw new ArgumentNullException(nameof(operationLogger));
_httpProxy = httpProxy ?? throw new ArgumentNullException(nameof(httpProxy));
_randomFactory = randomFactory ?? throw new ArgumentNullException(nameof(randomFactory));
}
Expand Down Expand Up @@ -85,9 +80,9 @@ public async Task Invoke(HttpContext context)
cluster.ConcurrencyCounter.Increment();
destination.ConcurrencyCounter.Increment();

await _operationLogger.ExecuteAsync(
Tratcher marked this conversation as resolved.
Show resolved Hide resolved
"ReverseProxy.Proxy",
() => _httpProxy.ProxyAsync(context, destinationConfig.Address, reverseProxyFeature.ClusterConfig.HttpClient, proxyOptions));
ProxyTelemetry.Log.ProxyInvoke(cluster.ClusterId, routeConfig.Route.RouteId, destination.DestinationId);

await _httpProxy.ProxyAsync(context, destinationConfig.Address, reverseProxyFeature.ClusterConfig.HttpClient, proxyOptions);
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.ReverseProxy.Abstractions;
using Microsoft.ReverseProxy.Abstractions.Telemetry;
using Microsoft.ReverseProxy.RuntimeModel;
using Microsoft.ReverseProxy.Service.Management;
using Microsoft.ReverseProxy.Utilities;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Runtime.ExceptionServices;
using System.Threading;
Expand Down
Loading