case 4670 miniprofiler removal entirely keywords profile profiler mini metrics this is the commit for ayanova 8 duplicating this
This commit is contained in:
@@ -15,7 +15,7 @@ using Newtonsoft.Json.Linq;
|
|||||||
using Sockeye.Models;
|
using Sockeye.Models;
|
||||||
using Sockeye.Api.ControllerHelpers;
|
using Sockeye.Api.ControllerHelpers;
|
||||||
using Sockeye.Biz;
|
using Sockeye.Biz;
|
||||||
//using StackExchange.Profiling;
|
|
||||||
|
|
||||||
namespace Sockeye.Api.Controllers
|
namespace Sockeye.Api.Controllers
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ using Sockeye.Util;
|
|||||||
using Sockeye.Generator;
|
using Sockeye.Generator;
|
||||||
using Sockeye.Biz;
|
using Sockeye.Biz;
|
||||||
using NLog.Extensions.Logging;
|
using NLog.Extensions.Logging;
|
||||||
using StackExchange.Profiling;
|
|
||||||
using Asp.Versioning.ApiExplorer;
|
using Asp.Versioning.ApiExplorer;
|
||||||
using Asp.Versioning;
|
using Asp.Versioning;
|
||||||
|
|
||||||
@@ -57,24 +56,6 @@ namespace Sockeye
|
|||||||
_newLog.LogDebug("Health");
|
_newLog.LogDebug("Health");
|
||||||
services.AddHealthChecks().AddDbContextCheck<AyContext>(); ;
|
services.AddHealthChecks().AddDbContextCheck<AyContext>(); ;
|
||||||
|
|
||||||
_newLog.LogDebug("Profiler");
|
|
||||||
//https://dotnetthoughts.net/using-miniprofiler-in-aspnetcore-webapi/
|
|
||||||
services.AddMemoryCache();
|
|
||||||
services.AddMiniProfiler(options =>
|
|
||||||
{
|
|
||||||
options.RouteBasePath = "/profiler";
|
|
||||||
//in testing only ignorepaths was reliable and worked and docs say it prevents any profiling at all
|
|
||||||
options.IgnorePath("/auth").IgnorePath("/user").IgnorePath("/docs").IgnorePath("/cust").IgnorePath("/notify/hello").IgnorePath("/notify/new-count");
|
|
||||||
options.ResultsAuthorize = request =>
|
|
||||||
{
|
|
||||||
if (request.HttpContext.Items["AY_PROFILER_ALLOWED"] != null)
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
}).AddEntityFramework();
|
|
||||||
|
|
||||||
|
|
||||||
//Server state service for shutting people out of api
|
//Server state service for shutting people out of api
|
||||||
_newLog.LogDebug("ServerState service");
|
_newLog.LogDebug("ServerState service");
|
||||||
services.AddSingleton(new Sockeye.Api.ControllerHelpers.ApiServerState());
|
services.AddSingleton(new Sockeye.Api.ControllerHelpers.ApiServerState());
|
||||||
@@ -416,55 +397,6 @@ namespace Sockeye
|
|||||||
{
|
{
|
||||||
if (!context.User.Identity.IsAuthenticated)
|
if (!context.User.Identity.IsAuthenticated)
|
||||||
{
|
{
|
||||||
#region Profiler workaround
|
|
||||||
//Is this a profiler route? If so we're going to use the dl token to authorize
|
|
||||||
if (context.Request.Path.Value.StartsWith("/profiler/results"))
|
|
||||||
{
|
|
||||||
//someone is requesting the profiler
|
|
||||||
//check for a dl token "t" and rehydrate user if found
|
|
||||||
//Note that the profiler UI triggers it's own requests to to get the token
|
|
||||||
//we need to check the referer which was the first page of profile
|
|
||||||
|
|
||||||
string token = string.Empty;
|
|
||||||
//is the token in the request?
|
|
||||||
if (context.Request.Query.ContainsKey("t"))
|
|
||||||
{
|
|
||||||
token = context.Request.Query["t"].ToString();
|
|
||||||
}
|
|
||||||
else if (context.Request.Headers["Referer"].Count > 0)
|
|
||||||
{//Maybe it's in the referer
|
|
||||||
//try to split it on the ?
|
|
||||||
string[] stuff = context.Request.Headers["Referer"].ToString().Split('?');
|
|
||||||
if (stuff.Count() > 1)
|
|
||||||
{
|
|
||||||
var q = Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(stuff[1]);
|
|
||||||
if (q.ContainsKey("t"))
|
|
||||||
{
|
|
||||||
token = q["t"].ToString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(token))
|
|
||||||
{
|
|
||||||
using (AyContext ct = ServiceProviderProvider.DBContext)
|
|
||||||
{
|
|
||||||
var u = ct.User.AsNoTracking().SingleOrDefault(z => z.DlKey == token.ToString() && z.Active == true);
|
|
||||||
if (u != null)
|
|
||||||
{
|
|
||||||
//this is necessary because they might have an expired JWT but this would just keep on working without a date check
|
|
||||||
//the default is the same timespan as the jwt so it's all good
|
|
||||||
var utcNow = new DateTimeOffset(DateTime.Now.ToUniversalTime(), TimeSpan.Zero);
|
|
||||||
if (u.DlKeyExpire > utcNow.DateTime)
|
|
||||||
{
|
|
||||||
if (Sockeye.Api.ControllerHelpers.Authorized.HasReadFullRole(u.Roles, SockType.ServerMetrics))
|
|
||||||
context.Request.HttpContext.Items["AY_PROFILER_ALLOWED"] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion profiler workaround
|
|
||||||
|
|
||||||
context.Request.HttpContext.Items["AY_ROLES"] = 0;
|
context.Request.HttpContext.Items["AY_ROLES"] = 0;
|
||||||
await next.Invoke();
|
await next.Invoke();
|
||||||
@@ -551,10 +483,6 @@ namespace Sockeye
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
_newLog.LogDebug("Profiler");
|
|
||||||
app.UseMiniProfiler();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
_newLog.LogDebug("Endpoints pipeline");
|
_newLog.LogDebug("Endpoints pipeline");
|
||||||
app.UseEndpoints(endpoints =>
|
app.UseEndpoints(endpoints =>
|
||||||
|
|||||||
@@ -34,8 +34,6 @@
|
|||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="10.0.12" />
|
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="10.0.12" />
|
||||||
<PackageReference Include="MiniProfiler.AspNetCore.Mvc" Version="4.5.4" />
|
|
||||||
<PackageReference Include="MiniProfiler.EntityFrameworkCore" Version="4.5.4" />
|
|
||||||
<PackageReference Include="NLog" Version="6.2.1" />
|
<PackageReference Include="NLog" Version="6.2.1" />
|
||||||
<PackageReference Include="NLog.Web.AspNetCore" Version="6.2.1" />
|
<PackageReference Include="NLog.Web.AspNetCore" Version="6.2.1" />
|
||||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.3" />
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.3" />
|
||||||
|
|||||||
Reference in New Issue
Block a user