Skip to content

Commit

Permalink
Merge pull request #47 from furkandeveloper/feature/http
Browse files Browse the repository at this point in the history
🔀 Feature/http
  • Loading branch information
furkandeveloper authored Nov 11, 2020
2 parents 2f91666 + 775cbb4 commit fec1f77
Show file tree
Hide file tree
Showing 31 changed files with 352 additions and 85 deletions.
9 changes: 1 addition & 8 deletions EasyProfiler.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{9AE5BFB8-BA7
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EasyProfiler.SQLServer", "src\EasyProfiler.SQLServer\EasyProfiler.SQLServer.csproj", "{A6CF2E31-7D4C-465A-9E3D-72DD012C26C3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EasyProfiler.Entities", "src\EasyProfiler.Entities\EasyProfiler.Entities.csproj", "{7EA52047-90A2-48E3-A1E6-48A56B4B8E0A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A6E015BB-C6E2-4EBF-BDE1-421F601B63FB}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
Expand All @@ -23,7 +21,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EasyProfiler.Core", "src\Ea
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EasyProfiler.MariaDb", "src\EasyProfiler.MariaDb\EasyProfiler.MariaDb.csproj", "{7D777586-91E5-4826-91AC-4ED0C9C30B13}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyProfiler.PostgreSQL", "src\EasyProfiler.PostgreSQL\EasyProfiler.PostgreSQL.csproj", "{FCC42610-B106-443B-9CDD-6DB922D47139}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EasyProfiler.PostgreSQL", "src\EasyProfiler.PostgreSQL\EasyProfiler.PostgreSQL.csproj", "{FCC42610-B106-443B-9CDD-6DB922D47139}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -35,10 +33,6 @@ Global
{A6CF2E31-7D4C-465A-9E3D-72DD012C26C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A6CF2E31-7D4C-465A-9E3D-72DD012C26C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A6CF2E31-7D4C-465A-9E3D-72DD012C26C3}.Release|Any CPU.Build.0 = Release|Any CPU
{7EA52047-90A2-48E3-A1E6-48A56B4B8E0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7EA52047-90A2-48E3-A1E6-48A56B4B8E0A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7EA52047-90A2-48E3-A1E6-48A56B4B8E0A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7EA52047-90A2-48E3-A1E6-48A56B4B8E0A}.Release|Any CPU.Build.0 = Release|Any CPU
{E08FD8E2-2D4F-4DA2-A668-E7A3E84B8DE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E08FD8E2-2D4F-4DA2-A668-E7A3E84B8DE9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E08FD8E2-2D4F-4DA2-A668-E7A3E84B8DE9}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -61,7 +55,6 @@ Global
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{A6CF2E31-7D4C-465A-9E3D-72DD012C26C3} = {9AE5BFB8-BA7B-4939-934E-B28220564041}
{7EA52047-90A2-48E3-A1E6-48A56B4B8E0A} = {9AE5BFB8-BA7B-4939-934E-B28220564041}
{E08FD8E2-2D4F-4DA2-A668-E7A3E84B8DE9} = {E7EE1DF1-9E6C-4B2B-9847-3C03030EFF6E}
{5900675D-AC82-4F00-A90E-486AA22F8FDF} = {9AE5BFB8-BA7B-4939-934E-B28220564041}
{7D777586-91E5-4826-91AC-4ED0C9C30B13} = {9AE5BFB8-BA7B-4939-934E-B28220564041}
Expand Down
15 changes: 15 additions & 0 deletions samples/EasyProfiler.Web/Controllers/DefaultController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,20 @@ public async Task<IActionResult> AdvancedFilterForEasyProfilerAsync([FromQuery]
{
return Ok(await baseService.AdvancedFilterAsync(model));
}

/// <summary>
/// Find slowest endpoint.
/// </summary>
/// <param name="baseService">
/// EasyProfilerBaseService
/// </param>
/// <returns>
/// List of SlowestEndpointResponseModel.
/// </returns>
[HttpGet("SlowestEndpoint")]
public async Task<IActionResult> SlowestEndpointAsync([FromServices] IEasyProfilerBaseService<ProfilerDbContext> baseService)
{
return Ok(await baseService.GetSlowestEndpointsAsync());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using EasyProfiler.Core.Helpers.AdvancedQuery;
using EasyProfiler.Entities;
using EasyProfiler.Core.Entities;
using EasyProfiler.Core.Helpers.AdvancedQuery;
using EasyProfiler.Core.Helpers.Responses;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

Expand All @@ -13,5 +15,7 @@ public interface IEasyProfilerBaseService<TDbContext> where TDbContext : DbConte
Task InsertAsync(Profiler profiler);

Task<List<Profiler>> AdvancedFilterAsync(AdvancedFilterModel advancedFilterModel);

Task<List<SlowestEndpointResponseModel>> GetSlowestEndpointsAsync();
}
}
16 changes: 15 additions & 1 deletion src/EasyProfiler.Core/Concrete/EasyProfilerBaseManager.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using AutoFilterer.Extensions;
using EasyProfiler.Core.Abstractions;
using EasyProfiler.Core.Entities;
using EasyProfiler.Core.Helpers.AdvancedQuery;
using EasyProfiler.Entities;
using EasyProfiler.Core.Helpers.Responses;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -25,6 +27,18 @@ public async Task<List<Profiler>> AdvancedFilterAsync(AdvancedFilterModel advanc
return await dbContext.Set<Profiler>().ApplyFilter(advancedFilterModel).ToListAsync();
}

public async Task<List<SlowestEndpointResponseModel>> GetSlowestEndpointsAsync()
{
var data = await dbContext.Set<Profiler>().Where(x => !string.IsNullOrEmpty(x.RequestUrl) && x.RequestUrl != "/")
.GroupBy(g => g.RequestUrl).Select(s => new SlowestEndpointResponseModel
{
RequestUrl = s.Key,
Count = s.Count(),
AvarageDurationTime = new TimeSpan(s.Sum(a => a.Duration) / s.Count())
}).ToListAsync();
return data.OrderByDescending(x=>x.AvarageDurationTime).ToList();
}

public async Task InsertAsync(Profiler profiler)
{
var entity = dbContext.Entry(profiler);
Expand Down
14 changes: 8 additions & 6 deletions src/EasyProfiler.Core/EasyProfiler.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@
<PackageIcon>easyProfilerSQLServer.png</PackageIcon>
<RepositoryUrl>https://github.com/furkandeveloper/EasyProfiler</RepositoryUrl>
<PackageTags>sql-server, profiler, query-profiler,query-analyzer</PackageTags>
<PackageReleaseNotes>Added base service.</PackageReleaseNotes>
<Version>1.1.0</Version>
<PackageReleaseNotes>
*♻️ Move Profiler entity from EasyProfiler.Entites to EasyProfiler.Core
*✨ Add RequestUrl feature.
*✨ Add SlowestEndpoint feature.
</PackageReleaseNotes>
<Version>1.2.0</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoFilterer" Version="2.1.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.8" />
</ItemGroup>

<ItemGroup>
Expand All @@ -21,9 +27,5 @@
<PackagePath></PackagePath>
</None>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\EasyProfiler.Entities\EasyProfiler.Entities.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;

namespace EasyProfiler.Entities
namespace EasyProfiler.Core.Entities
{
/// <summary>
/// Base Entity.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;

namespace EasyProfiler.Entities
namespace EasyProfiler.Core.Entities
{
/// <summary>
/// Profiler entity.
Expand All @@ -11,6 +11,8 @@ public class Profiler : BaseEntity
{
public string Query { get; set; }

public TimeSpan Duration { get; set; }
public long Duration { get; set; }

public string RequestUrl { get; set; } = "/";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@ public AdvancedFilterModel()
public string Query { get; set; }

/// <summary>
/// Query duration.
/// Request Url
/// </summary>
public Range<TimeSpan> Duration { get; set; }
[ToLowerContainsComparison]
public string RequestUrl { get; set; }

/// <summary>
/// Duration.
/// </summary>
public Range<long> Duration { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Collections.Generic;
using System.Text;

namespace EasyProfiler.Entities
namespace EasyProfiler.Core.Helpers.Generators
{
/// <summary>
/// Guid value generator for primary key.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace EasyProfiler.Core.Helpers.Responses
{
public class SlowestEndpointResponseModel
{
public string RequestUrl { get; set; }

public int Count { get; set; }

public TimeSpan AvarageDurationTime { get; set; }
}
}
24 changes: 0 additions & 24 deletions src/EasyProfiler.Entities/EasyProfiler.Entities.csproj

This file was deleted.

Binary file removed src/EasyProfiler.Entities/easyProfilerSQLServer.png
Binary file not shown.
6 changes: 3 additions & 3 deletions src/EasyProfiler.MariaDb/Context/ProfilerDbContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using EasyProfiler.Entities;
using EasyProfiler.Core.Entities;
using EasyProfiler.Core.Helpers.Generators;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

Expand Down Expand Up @@ -40,8 +41,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

entity
.Property(p => p.Duration)
.HasColumnType("bigint")
.HasConversion(new TimeSpanToTicksConverter());
.HasColumnType("bigint");
});
base.OnModelCreating(modelBuilder);
}
Expand Down
11 changes: 7 additions & 4 deletions src/EasyProfiler.MariaDb/EasyProfiler.MariaDb.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<Description>This repo, provides query profiler for EF Core.</Description>
<PackageTags>mariadb, profiler, query-profiler,query-analyzer</PackageTags>
<PackageReleaseNotes>Move service layer EasyProfiler.MariaDb to EasyProfiler.Core</PackageReleaseNotes>
<PackageReleaseNotes>
*♻️ Move Profiler entity from EasyProfiler.Entites to EasyProfiler.Core
*✨ Add RequestUrl feature.
*✨ Add SlowestEndpoint feature.
</PackageReleaseNotes>
<PackageIcon>easyProfilerMariaDb.png</PackageIcon>
<RepositoryUrl>https://github.com/furkandeveloper/EasyProfiler</RepositoryUrl>
<Authors>furkandeveloper</Authors>
<Version>1.1.0</Version>
<Version>1.2.0</Version>
</PropertyGroup>

<ItemGroup>
Expand All @@ -24,7 +28,6 @@

<ItemGroup>
<ProjectReference Include="..\EasyProfiler.Core\EasyProfiler.Core.csproj" />
<ProjectReference Include="..\EasyProfiler.Entities\EasyProfiler.Entities.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Data.Common;
using System.Threading.Tasks;
using EasyProfiler.Core.Abstractions;
using EasyProfiler.Core.Entities;
using EasyProfiler.MariaDb.Context;
using Microsoft.EntityFrameworkCore.Diagnostics;

Expand All @@ -17,10 +18,10 @@ public EasyProfilerInterceptors(IEasyProfilerBaseService<ProfilerDbContext> base

public override InterceptionResult DataReaderDisposing(DbCommand command, DataReaderDisposingEventData eventData, InterceptionResult result)
{
Task.Run(() => baseService.InsertAsync(new Entities.Profiler()
Task.Run(() => baseService.InsertAsync(new Profiler()
{
Query = command.CommandText,
Duration = eventData.Duration
Duration = eventData.Duration.Ticks
}));
return base.DataReaderDisposing(command, eventData, result);
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Migrations;

namespace EasyProfiler.MariaDb.Migrations
{
public partial class AddRequestUrl : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "RequestUrl",
table: "Profilers",
nullable: true);
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "RequestUrl",
table: "Profilers");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.IsRequired()
.HasColumnType("longtext CHARACTER SET utf8mb4");

b.Property<string>("RequestUrl")
.HasColumnType("longtext CHARACTER SET utf8mb4");

b.HasKey("Id");

b.HasIndex("Duration");
Expand Down
Loading

0 comments on commit fec1f77

Please sign in to comment.