This repository has been archived by the owner on Oct 20, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 681
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1303 from oliverw/dev
dev v70
- Loading branch information
Showing
60 changed files
with
9,811 additions
and
8,342 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/Miningcore/Api/Middlewares/ApiRequestMetricsMiddleware.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System.Diagnostics; | ||
using Microsoft.AspNetCore.Http; | ||
using Miningcore.Extensions; | ||
using Miningcore.Messaging; | ||
using Miningcore.Notifications.Messages; | ||
|
||
namespace Miningcore.Api.Middlewares; | ||
|
||
/// <summary> | ||
/// Publishes telemetry data of API request execution times | ||
/// </summary> | ||
public class ApiRequestMetricsMiddleware | ||
{ | ||
public ApiRequestMetricsMiddleware(RequestDelegate next, IMessageBus messageBus) | ||
{ | ||
this.next = next; | ||
this.messageBus = messageBus; | ||
} | ||
|
||
private readonly RequestDelegate next; | ||
private readonly IMessageBus messageBus; | ||
|
||
public async Task Invoke(HttpContext context) | ||
{ | ||
if(context.Request?.Path.StartsWithSegments("/api") == true) | ||
{ | ||
var sw = Stopwatch.StartNew(); | ||
|
||
try | ||
{ | ||
await next.Invoke(context); | ||
|
||
messageBus.SendTelemetry(context.Request.Path, TelemetryCategory.ApiRequest, null, sw.Elapsed, true); | ||
} | ||
|
||
catch | ||
{ | ||
messageBus.SendTelemetry(context.Request.Path, TelemetryCategory.ApiRequest, null, sw.Elapsed, false); | ||
throw; | ||
} | ||
} | ||
|
||
else | ||
await next.Invoke(context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.