fixes
This commit is contained in:
Родитель
4ebf67ae69
Коммит
c8f3c91905
|
@ -23,8 +23,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "templates", "templates", "{
|
|||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{C0537983-2503-4D70-B831-27614DB29F81}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Diagnostics.Logger", "src\Diagnostics.Logger\Diagnostics.Logger.csproj", "{1C472832-6663-4EED-9D45-627B534E55E7}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -107,18 +105,6 @@ Global
|
|||
{CFD34079-6A40-4938-8840-4325B504ACFA}.Release|x64.Build.0 = Release|Any CPU
|
||||
{CFD34079-6A40-4938-8840-4325B504ACFA}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{CFD34079-6A40-4938-8840-4325B504ACFA}.Release|x86.Build.0 = Release|Any CPU
|
||||
{1C472832-6663-4EED-9D45-627B534E55E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1C472832-6663-4EED-9D45-627B534E55E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1C472832-6663-4EED-9D45-627B534E55E7}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{1C472832-6663-4EED-9D45-627B534E55E7}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{1C472832-6663-4EED-9D45-627B534E55E7}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{1C472832-6663-4EED-9D45-627B534E55E7}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{1C472832-6663-4EED-9D45-627B534E55E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1C472832-6663-4EED-9D45-627B534E55E7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1C472832-6663-4EED-9D45-627B534E55E7}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{1C472832-6663-4EED-9D45-627B534E55E7}.Release|x64.Build.0 = Release|Any CPU
|
||||
{1C472832-6663-4EED-9D45-627B534E55E7}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{1C472832-6663-4EED-9D45-627B534E55E7}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -130,7 +116,6 @@ Global
|
|||
{0080F318-4A06-40E3-BCA6-5C61978CBFE6} = {0F59F43E-D06C-4A0F-8D38-9538BA58FC6A}
|
||||
{F23F3EDA-2CD2-4F7B-B605-13DF4A8A632F} = {0F59F43E-D06C-4A0F-8D38-9538BA58FC6A}
|
||||
{CFD34079-6A40-4938-8840-4325B504ACFA} = {C0537983-2503-4D70-B831-27614DB29F81}
|
||||
{1C472832-6663-4EED-9D45-627B534E55E7} = {0F59F43E-D06C-4A0F-8D38-9538BA58FC6A}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {B4A19BFB-9A33-49E2-98AD-955E9472EFAD}
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Diagnostics.DataProviders\Diagnostics.DataProviders.csproj" />
|
||||
<ProjectReference Include="..\Diagnostics.Logger\Diagnostics.Logger.csproj" />
|
||||
<ProjectReference Include="..\Diagnostics.ModelsAndUtils\Diagnostics.ModelsAndUtils.csproj" />
|
||||
<ProjectReference Include="..\Diagnostics.Scripts\Diagnostics.Scripts.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -1,97 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Diagnostics.Logger;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace Diagnostics.CompilerHost
|
||||
{
|
||||
// You may need to install the Microsoft.AspNetCore.Http.Abstractions package into your project
|
||||
public class CompilerRequestMiddleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
private readonly string _apiLoggerKey = "CompilerHost_ApiLogger";
|
||||
|
||||
public CompilerRequestMiddleware(RequestDelegate next)
|
||||
{
|
||||
_next = next;
|
||||
}
|
||||
|
||||
public async Task Invoke(HttpContext httpContext)
|
||||
{
|
||||
BeginRequest_Handle(httpContext);
|
||||
|
||||
try
|
||||
{
|
||||
await _next(httpContext);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (!httpContext.Response.HasStarted)
|
||||
{
|
||||
httpContext.Response.Clear();
|
||||
httpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
|
||||
}
|
||||
|
||||
LogException(httpContext, ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
EndRequest_Handle(httpContext);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private void BeginRequest_Handle(HttpContext httpContext)
|
||||
{
|
||||
var logger = new ApiMetricsLogger(httpContext);
|
||||
httpContext.Items.Add(_apiLoggerKey, logger);
|
||||
}
|
||||
|
||||
private void EndRequest_Handle(HttpContext httpContext)
|
||||
{
|
||||
ApiMetricsLogger logger = (ApiMetricsLogger)httpContext.Items[_apiLoggerKey];
|
||||
if (logger == null)
|
||||
{
|
||||
logger = new ApiMetricsLogger(httpContext);
|
||||
}
|
||||
|
||||
logger.LogCompilerHostAPIMetrics(httpContext);
|
||||
}
|
||||
|
||||
private void LogException(HttpContext context, Exception ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
ApiMetricsLogger logger = (ApiMetricsLogger)context.Items[_apiLoggerKey];
|
||||
if (logger == null)
|
||||
{
|
||||
logger = new ApiMetricsLogger(context);
|
||||
}
|
||||
|
||||
logger.LogCompilerHostUnhandledException(context, ex);
|
||||
}
|
||||
catch (Exception logEx)
|
||||
{
|
||||
DiagnosticsETWProvider.Instance.LogCompilerHostUnhandledException(
|
||||
string.Empty,
|
||||
"LogException_CompilerRequestMiddleware",
|
||||
logEx.GetType().ToString(),
|
||||
logEx.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Extension method used to add the middleware to the HTTP request pipeline.
|
||||
public static class CompilerRequestMiddlewareExtensions
|
||||
{
|
||||
public static IApplicationBuilder UseCompilerRequestMiddleware(this IApplicationBuilder builder)
|
||||
{
|
||||
return builder.UseMiddleware<CompilerRequestMiddleware>();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -34,7 +34,6 @@ namespace Diagnostics.CompilerHost
|
|||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
|
||||
app.UseCompilerRequestMiddleware();
|
||||
app.UseMvc();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,12 @@
|
|||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="Models\**" />
|
||||
<EmbeddedResource Remove="Models\**" />
|
||||
<None Remove="Models\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.0.0" />
|
||||
|
@ -12,10 +18,6 @@
|
|||
<PackageReference Include="Microsoft.Win32.Registry" Version="4.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Models\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Diagnostics.ModelsAndUtils\Diagnostics.ModelsAndUtils.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -1,183 +0,0 @@
|
|||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Diagnostics.Logger
|
||||
{
|
||||
public class ApiMetricsLogger
|
||||
{
|
||||
private string _requestId;
|
||||
private string _address;
|
||||
private string _verb;
|
||||
private DateTime _startTime;
|
||||
private DateTime _endTime;
|
||||
private long _latencyInMs;
|
||||
private string _subscriptionId;
|
||||
private string _resourceGroupName;
|
||||
private string _resourceName;
|
||||
|
||||
public ApiMetricsLogger(HttpContext context)
|
||||
{
|
||||
StartMetricCapture(context);
|
||||
}
|
||||
|
||||
private void StartMetricCapture(HttpContext context)
|
||||
{
|
||||
if (context.Request.Headers.TryGetValue(HeaderConstants.RequestIdHeaderName, out StringValues values))
|
||||
{
|
||||
_requestId = values.ToString();
|
||||
}
|
||||
|
||||
_startTime = DateTime.UtcNow;
|
||||
_verb = context.Request.Method;
|
||||
_address = context.Request.Path.ToString();
|
||||
|
||||
ParseFromAddress(context);
|
||||
}
|
||||
|
||||
private void ParseFromAddress(HttpContext httpContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (String.IsNullOrWhiteSpace(httpContext.Request.Path.ToString()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var parts = httpContext.Request.Path.ToString().ToLowerInvariant().Split('?')[0].Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var cursor = ((IEnumerable<string>)parts).GetEnumerator();
|
||||
while (cursor.MoveNext())
|
||||
{
|
||||
if (String.Equals(cursor.Current, "subscriptions", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!cursor.MoveNext())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_subscriptionId = cursor.Current;
|
||||
|
||||
if (!cursor.MoveNext())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (String.Equals(cursor.Current, "resourceGroups", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (!cursor.MoveNext())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_resourceGroupName = cursor.Current;
|
||||
|
||||
if (!cursor.MoveNext() || !String.Equals(cursor.Current, "providers", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!cursor.MoveNext() || !String.Equals(cursor.Current, "Microsoft.Web", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (cursor.MoveNext() && String.Equals(cursor.Current, "sites", StringComparison.OrdinalIgnoreCase) || String.Equals(cursor.Current, "hostingEnvironments", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (!cursor.MoveNext())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_resourceName = cursor.Current;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignore error
|
||||
}
|
||||
}
|
||||
|
||||
public void LogRuntimeHostAPIMetrics(HttpContext context)
|
||||
{
|
||||
if (context == null) return;
|
||||
|
||||
_endTime = DateTime.UtcNow;
|
||||
_latencyInMs = Convert.ToInt64((_endTime - _startTime).TotalMilliseconds);
|
||||
|
||||
DiagnosticsETWProvider.Instance.LogRuntimeHostAPISummary(
|
||||
_requestId ?? string.Empty,
|
||||
_subscriptionId ?? string.Empty,
|
||||
_resourceGroupName ?? string.Empty,
|
||||
_resourceName ?? string.Empty,
|
||||
_address ?? string.Empty,
|
||||
_verb ?? string.Empty,
|
||||
string.Empty,
|
||||
context.Response.StatusCode,
|
||||
_latencyInMs,
|
||||
_startTime.ToString("HH:mm:ss.fff"),
|
||||
_endTime.ToString("HH:mm:ss.fff")
|
||||
);
|
||||
}
|
||||
|
||||
public void LogCompilerHostAPIMetrics(HttpContext context)
|
||||
{
|
||||
if (context == null) return;
|
||||
|
||||
_endTime = DateTime.UtcNow;
|
||||
_latencyInMs = Convert.ToInt64((_endTime - _startTime).TotalMilliseconds);
|
||||
|
||||
DiagnosticsETWProvider.Instance.LogCompilerHostAPISummary(
|
||||
_requestId ?? string.Empty,
|
||||
_address ?? string.Empty,
|
||||
_verb ?? string.Empty,
|
||||
context.Response.StatusCode,
|
||||
_latencyInMs,
|
||||
_startTime.ToString("HH:mm:ss.fff"),
|
||||
_endTime.ToString("HH:mm:ss.fff")
|
||||
);
|
||||
}
|
||||
|
||||
public void LogRuntimeHostUnhandledException(HttpContext context, Exception ex)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DiagnosticsETWProvider.Instance.LogRuntimeHostUnhandledException(
|
||||
_requestId ?? string.Empty,
|
||||
_address ?? string.Empty,
|
||||
_subscriptionId ?? string.Empty,
|
||||
_resourceGroupName ?? string.Empty,
|
||||
_resourceName ?? string.Empty,
|
||||
ex != null ? ex.GetType().ToString() : string.Empty,
|
||||
ex != null ? ex.ToString() : string.Empty
|
||||
);
|
||||
}
|
||||
|
||||
public void LogCompilerHostUnhandledException(HttpContext context, Exception ex)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DiagnosticsETWProvider.Instance.LogCompilerHostUnhandledException(
|
||||
_requestId ?? string.Empty,
|
||||
_address ?? string.Empty,
|
||||
ex != null ? ex.GetType().ToString() : string.Empty,
|
||||
ex != null ? ex.ToString() : string.Empty
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Diagnostics.Logger
|
||||
{
|
||||
public class HeaderConstants
|
||||
{
|
||||
public const string RequestIdHeaderName = "x-ms-request-id";
|
||||
public const string EtagHeaderName = "ETag";
|
||||
public const string IfMatchHeaderName = "If-Match";
|
||||
public const string IfNoneMatchHeaderName = "If-None-Match";
|
||||
public const string UserAgentHeaderName = "User-Agent";
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="Class1.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="2.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.AspNetCore.Http.Abstractions">
|
||||
<HintPath>C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.http.abstractions\2.0.1\lib\netstandard2.0\Microsoft.AspNetCore.Http.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -1,89 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Text;
|
||||
|
||||
namespace Diagnostics.Logger
|
||||
{
|
||||
[EventSource(Name = "Microsoft-Azure-AppService-Diagnostics")]
|
||||
public sealed class DiagnosticsETWProvider : DiagnosticsEventSourceBase
|
||||
{
|
||||
public static DiagnosticsETWProvider Instance = new DiagnosticsETWProvider();
|
||||
|
||||
#region Compile Host Events (ID Range : 1000 - 1999)
|
||||
|
||||
[Event(1000, Level = EventLevel.Informational, Channel = EventChannel.Admin)]
|
||||
public void LogCompilerHostStartup(string Message)
|
||||
{
|
||||
WriteDiagnosticsEvent(1000, Message);
|
||||
}
|
||||
|
||||
[Event(1001, Level = EventLevel.Error, Channel = EventChannel.Admin)]
|
||||
public void LogCompilerHostUnhandledException(string RequestId, string Source, string ExceptionType, string ExceptionDetails)
|
||||
{
|
||||
WriteDiagnosticsEvent(1001,
|
||||
RequestId,
|
||||
Source,
|
||||
ExceptionType,
|
||||
ExceptionDetails);
|
||||
}
|
||||
|
||||
[Event(1002, Level = EventLevel.Informational, Channel = EventChannel.Admin)]
|
||||
public void LogCompilerHostAPISummary(string RequestId, string Address, string Verb, int StatusCode, long LatencyInMilliseconds, string StartTime, string EndTime)
|
||||
{
|
||||
WriteDiagnosticsEvent(1002,
|
||||
RequestId,
|
||||
Address,
|
||||
Verb,
|
||||
StatusCode,
|
||||
LatencyInMilliseconds,
|
||||
StartTime,
|
||||
EndTime);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Runtime Host Events (ID Range : 2000 - 2999)
|
||||
|
||||
[Event(2000, Level = EventLevel.Informational, Channel = EventChannel.Admin)]
|
||||
public void LogRuntimeHostStartup(string Message)
|
||||
{
|
||||
WriteDiagnosticsEvent(2000, Message);
|
||||
}
|
||||
|
||||
[Event(2001, Level = EventLevel.Error, Channel = EventChannel.Admin)]
|
||||
public void LogRuntimeHostUnhandledException(string RequestId, string Source, string SubscriptionId, string ResourceGroup, string Resource, string ExceptionType, string ExceptionDetails)
|
||||
{
|
||||
WriteDiagnosticsEvent(2001,
|
||||
RequestId,
|
||||
Source,
|
||||
SubscriptionId,
|
||||
ResourceGroup,
|
||||
Resource,
|
||||
ExceptionType,
|
||||
ExceptionDetails);
|
||||
}
|
||||
|
||||
[Event(2002, Level = EventLevel.Informational, Channel = EventChannel.Admin)]
|
||||
public void LogRuntimeHostAPISummary(string RequestId, string SubscriptionId, string ResourceGroup, string Resource, string Address, string Verb, string OperationName, int StatusCode, long LatencyInMilliseconds, string StartTime, string EndTime)
|
||||
{
|
||||
WriteDiagnosticsEvent(2002,
|
||||
RequestId,
|
||||
SubscriptionId,
|
||||
ResourceGroup,
|
||||
Resource,
|
||||
Address,
|
||||
Verb,
|
||||
OperationName,
|
||||
StatusCode,
|
||||
LatencyInMilliseconds,
|
||||
StartTime,
|
||||
EndTime);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Data Provider Events (ID Range : 3000 - 3999)
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Text;
|
||||
|
||||
namespace Diagnostics.Logger
|
||||
{
|
||||
public abstract class DiagnosticsEventSourceBase : EventSource
|
||||
{
|
||||
[NonEvent]
|
||||
protected void WriteDiagnosticsEvent(int eventId, params object[] args)
|
||||
{
|
||||
WriteEvent(eventId, args);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,7 +13,7 @@ namespace Diagnostics.ModelsAndUtils
|
|||
public string EndTime;
|
||||
|
||||
public string TimeGrain;
|
||||
|
||||
|
||||
public OperationContext(SiteResource resource, string startTimeStr, string endTimeStr, string timeGrain = "5")
|
||||
{
|
||||
Resource = resource;
|
||||
|
|
|
@ -8,22 +8,13 @@ namespace Diagnostics.ModelsAndUtils
|
|||
public class ScriptHelper
|
||||
{
|
||||
public static ImmutableArray<string> GetFrameworkReferences() => ImmutableArray.Create(
|
||||
"System",
|
||||
"System.Data",
|
||||
"System.IO",
|
||||
"System.Linq",
|
||||
"Diagnostics.DataProviders",
|
||||
"Diagnostics.ModelsAndUtils"
|
||||
);
|
||||
|
||||
public static ImmutableArray<string> GetFrameworkImports() => ImmutableArray.Create(
|
||||
"System",
|
||||
"System.Collections",
|
||||
"System.Collections.Concurrent",
|
||||
"System.Collections.Generic",
|
||||
"System.Data",
|
||||
"System.IO",
|
||||
"System.Linq",
|
||||
"System.Threading.Tasks",
|
||||
"Diagnostics.DataProviders",
|
||||
"Diagnostics.ModelsAndUtils"
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Diagnostics.DataProviders\Diagnostics.DataProviders.csproj" />
|
||||
<ProjectReference Include="..\Diagnostics.Logger\Diagnostics.Logger.csproj" />
|
||||
<ProjectReference Include="..\Diagnostics.ModelsAndUtils\Diagnostics.ModelsAndUtils.csproj" />
|
||||
<ProjectReference Include="..\Diagnostics.Scripts\Diagnostics.Scripts.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -1,111 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Diagnostics.Logger;
|
||||
using Diagnostics.RuntimeHost.Utilities;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
|
||||
namespace Diagnostics.RuntimeHost
|
||||
{
|
||||
// You may need to install the Microsoft.AspNetCore.Http.Abstractions package into your project
|
||||
public class DiagnosticsRequestMiddleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
|
||||
public DiagnosticsRequestMiddleware(RequestDelegate next)
|
||||
{
|
||||
_next = next;
|
||||
}
|
||||
|
||||
public async Task Invoke(HttpContext httpContext)
|
||||
{
|
||||
GenerateMissingRequestHeaders(ref httpContext);
|
||||
BeginRequest_Handle(httpContext);
|
||||
|
||||
try
|
||||
{
|
||||
await _next(httpContext);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (!httpContext.Response.HasStarted)
|
||||
{
|
||||
httpContext.Response.Clear();
|
||||
httpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
|
||||
}
|
||||
|
||||
LogException(httpContext, ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
EndRequest_Handle(httpContext);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private void BeginRequest_Handle(HttpContext httpContext)
|
||||
{
|
||||
var logger = new ApiMetricsLogger(httpContext);
|
||||
httpContext.Items.Add(HostConstants.ApiLoggerKey, logger);
|
||||
}
|
||||
|
||||
private void EndRequest_Handle(HttpContext httpContext)
|
||||
{
|
||||
ApiMetricsLogger logger = (ApiMetricsLogger)httpContext.Items[HostConstants.ApiLoggerKey];
|
||||
if(logger == null)
|
||||
{
|
||||
logger = new ApiMetricsLogger(httpContext);
|
||||
}
|
||||
|
||||
logger.LogRuntimeHostAPIMetrics(httpContext);
|
||||
}
|
||||
|
||||
private void LogException(HttpContext context, Exception ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
ApiMetricsLogger logger = (ApiMetricsLogger)context.Items[HostConstants.ApiLoggerKey];
|
||||
if (logger == null)
|
||||
{
|
||||
logger = new ApiMetricsLogger(context);
|
||||
}
|
||||
|
||||
logger.LogRuntimeHostUnhandledException(context, ex);
|
||||
}
|
||||
catch (Exception logEx)
|
||||
{
|
||||
DiagnosticsETWProvider.Instance.LogRuntimeHostUnhandledException(
|
||||
string.Empty,
|
||||
"LogException_DiagnosticsRequestMiddleware",
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
logEx.GetType().ToString(),
|
||||
logEx.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private void GenerateMissingRequestHeaders(ref HttpContext httpContext)
|
||||
{
|
||||
if (!httpContext.Request.Headers.TryGetValue(HeaderConstants.RequestIdHeaderName, out StringValues values)
|
||||
|| values == default(StringValues) || !values.Any() || string.IsNullOrWhiteSpace(values.First()))
|
||||
{
|
||||
httpContext.Request.Headers[HeaderConstants.RequestIdHeaderName] = Guid.NewGuid().ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Extension method used to add the middleware to the HTTP request pipeline.
|
||||
public static class RequestMiddlewareExtensions
|
||||
{
|
||||
public static IApplicationBuilder UseDiagnosticsRequestMiddleware(this IApplicationBuilder builder)
|
||||
{
|
||||
return builder.UseMiddleware<DiagnosticsRequestMiddleware>();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
using Diagnostics.Logger;
|
||||
using Diagnostics.RuntimeHost.Utilities;
|
||||
using Diagnostics.RuntimeHost.Utilities;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Win32;
|
||||
|
@ -67,7 +66,7 @@ namespace Diagnostics.RuntimeHost.Services
|
|||
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, AppendQueryStringParams(url));
|
||||
if (!string.IsNullOrWhiteSpace(etag))
|
||||
{
|
||||
request.Headers.Add(HeaderConstants.IfNoneMatchHeaderName, etag);
|
||||
request.Headers.Add("If-None-Match", etag);
|
||||
}
|
||||
|
||||
return Get(request);
|
||||
|
@ -146,7 +145,7 @@ namespace Diagnostics.RuntimeHost.Services
|
|||
};
|
||||
|
||||
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
_httpClient.DefaultRequestHeaders.Add(HeaderConstants.UserAgentHeaderName, _userName);
|
||||
_httpClient.DefaultRequestHeaders.Add("User-Agent", _userName);
|
||||
}
|
||||
|
||||
private string AppendQueryStringParams(string url)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using Diagnostics.Logger;
|
||||
using Diagnostics.RuntimeHost.Utilities;
|
||||
using Diagnostics.RuntimeHost.Utilities;
|
||||
using Diagnostics.Scripts;
|
||||
using Diagnostics.Scripts.Models;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
|
@ -27,6 +26,7 @@ namespace Diagnostics.RuntimeHost.Services.SourceWatcher
|
|||
private string _lastModifiedMarkerName;
|
||||
private string _deleteMarkerName;
|
||||
private string _cacheIdFileName;
|
||||
private string _etagHeaderName;
|
||||
|
||||
private string _destinationCsxPath;
|
||||
private int _pollingIntervalInSeconds;
|
||||
|
@ -41,6 +41,7 @@ namespace Diagnostics.RuntimeHost.Services.SourceWatcher
|
|||
_lastModifiedMarkerName = "_lastModified.marker";
|
||||
_deleteMarkerName = "_delete.marker";
|
||||
_cacheIdFileName = "cacheId.txt";
|
||||
_etagHeaderName = "ETag";
|
||||
LoadConfigurations();
|
||||
Start();
|
||||
}
|
||||
|
@ -83,7 +84,7 @@ namespace Diagnostics.RuntimeHost.Services.SourceWatcher
|
|||
return;
|
||||
}
|
||||
|
||||
string githubRootContentETag = GetHeaderValue(response, HeaderConstants.EtagHeaderName).Replace("W/", string.Empty);
|
||||
string githubRootContentETag = GetHeaderValue(response, _etagHeaderName).Replace("W/", string.Empty);
|
||||
GithubEntry[] githubDirectories = await response.Content.ReadAsAsyncCustom<GithubEntry[]>();
|
||||
|
||||
foreach (GithubEntry gitHubDir in githubDirectories)
|
||||
|
|
|
@ -54,7 +54,6 @@ namespace Diagnostics.RuntimeHost
|
|||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
|
||||
app.UseDiagnosticsRequestMiddleware();
|
||||
app.UseMvc();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,6 @@ namespace Diagnostics.RuntimeHost.Utilities
|
|||
{
|
||||
internal const int WatcherDefaultPollingIntervalInSeconds = 5 * 60;
|
||||
|
||||
internal const string ApiLoggerKey = "API_LOGGER";
|
||||
|
||||
// These Configurations probably should be in Data Providers
|
||||
|
||||
public static TimeSpan KustoDataRetentionPeriod = TimeSpan.FromDays(-30);
|
||||
|
|
|
@ -13,16 +13,16 @@
|
|||
}
|
||||
},
|
||||
"CompilerHost": {
|
||||
"CompilerHostBinaryLocation": "E:\\git\\Azure-WebApps-Support-Center\\src\\Diagnostics.CompilerHost\\bin\\Debug\\netcoreapp2.0",
|
||||
"CompilerHostBinaryLocation": "",
|
||||
"CompilerHostPort": "7000",
|
||||
"PollingIntervalInSeconds": "60",
|
||||
"ProcessMemoryThresholdInMB": "300"
|
||||
},
|
||||
"SourceWatcher": {
|
||||
"WatcherType": "0",
|
||||
"WatcherType": "1",
|
||||
"PollingIntervalInSeconds" : "10",
|
||||
"Local": {
|
||||
"LocalScriptsPath": "D:\\CSX\\hawfor"
|
||||
"LocalScriptsPath": ""
|
||||
},
|
||||
"Github": {
|
||||
"DestinationScriptsPath": "",
|
||||
|
@ -33,11 +33,10 @@
|
|||
}
|
||||
},
|
||||
"Kusto": {
|
||||
"ClientId": "9633e90a-48cc-4b8c-be36-5d751fa9e66a",
|
||||
"AppKey": "Ddwc9tZDflIgKWQtu5uK6WuvfBxZW8zY1U9OnD3tOqk=",
|
||||
"DBName": "wawsprod",
|
||||
"KustoRegionGroupings": "BAY:MWH:MSFTBAY,BLU:BN1:YQ1:MSFTBLU,CH1:CQ1:CY4:DM1:SN1:YT1,AM2,DB3:MSFTDB3,*",
|
||||
"KustoClusterNameGroupings": "wawswus,wawseus,wawscus,wawsweu,wawsneu,wawseas"
|
||||
|
||||
"ClientId": "",
|
||||
"AppKey": "",
|
||||
"DBName": "",
|
||||
"KustoRegionGroupings": "",
|
||||
"KustoClusterNameGroupings": ""
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче