-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mark 404, 403, 401, 429 as successful Drop request durations for websockets
- Loading branch information
1 parent
53fa62c
commit 9a7b1e7
Showing
14 changed files
with
169 additions
and
22 deletions.
There are no files selected for viewing
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,7 @@ | ||
namespace GuildWarsPartySearch.Server.Attributes; | ||
|
||
[AttributeUsage(AttributeTargets.Class)] | ||
public sealed class OptionsNameAttribute : Attribute | ||
{ | ||
public string? Name { get; set; } | ||
} |
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
28 changes: 28 additions & 0 deletions
28
GuildWarsPartySearch/Extensions/WebApplicationBuilderExtensions.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,28 @@ | ||
using GuildWarsPartySearch.Server.Attributes; | ||
using System.Core.Extensions; | ||
using System.Extensions; | ||
|
||
namespace GuildWarsPartySearch.Server.Extensions; | ||
|
||
public static class WebApplicationBuilderExtensions | ||
{ | ||
public static WebApplicationBuilder ConfigureExtended<TOptions>(this WebApplicationBuilder builder) | ||
where TOptions : class, new() | ||
{ | ||
builder.ThrowIfNull() | ||
.Services.Configure<TOptions>(builder.Configuration.GetSection(GetOptionsName<TOptions>())); | ||
return builder; | ||
} | ||
|
||
private static string GetOptionsName<TOptions>() | ||
{ | ||
var maybeAttribute = typeof(TOptions).GetCustomAttributes(false).OfType<OptionsNameAttribute>().FirstOrDefault(); | ||
if (maybeAttribute is not null && | ||
maybeAttribute.Name?.IsNullOrWhiteSpace() is false) | ||
{ | ||
return maybeAttribute.Name; | ||
} | ||
|
||
return typeof(TOptions).Name; | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,8 +1,15 @@ | ||
namespace GuildWarsPartySearch.Server.Options; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace GuildWarsPartySearch.Server.Options; | ||
|
||
public sealed class ContentOptions : IAzureBlobStorageOptions | ||
{ | ||
[JsonPropertyName(nameof(UpdateFrequency))] | ||
public TimeSpan UpdateFrequency { get; set; } = TimeSpan.FromMinutes(5); | ||
|
||
[JsonPropertyName(nameof(StagingFolder))] | ||
public string StagingFolder { get; set; } = "Content"; | ||
|
||
[JsonPropertyName(nameof(ContainerName))] | ||
public string ContainerName { get; set; } = default!; | ||
} |
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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
namespace GuildWarsPartySearch.Server.Options; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace GuildWarsPartySearch.Server.Options; | ||
|
||
public sealed class EnvironmentOptions | ||
{ | ||
[JsonPropertyName(nameof(Name))] | ||
public string? Name { get; init; } | ||
} |
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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
namespace GuildWarsPartySearch.Server.Options; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace GuildWarsPartySearch.Server.Options; | ||
|
||
public class PartySearchTableOptions : IAzureTableStorageOptions | ||
{ | ||
[JsonPropertyName(nameof(TableName))] | ||
public string TableName { get; set; } = default!; | ||
} |
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 |
---|---|---|
@@ -1,18 +1,18 @@ | ||
using Newtonsoft.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace GuildWarsPartySearch.Server.Options; | ||
|
||
public sealed class ServerOptions | ||
{ | ||
[JsonProperty(nameof(Certificate))] | ||
[JsonPropertyName(nameof(Certificate))] | ||
public string? Certificate { get; set; } | ||
|
||
[JsonProperty(nameof(ApiKey))] | ||
[JsonPropertyName(nameof(ApiKey))] | ||
public string? ApiKey { get; set; } | ||
|
||
[JsonProperty(nameof(InactivityTimeout))] | ||
[JsonPropertyName(nameof(InactivityTimeout))] | ||
public TimeSpan? InactivityTimeout { get; set; } | ||
|
||
[JsonProperty(nameof(HeartbeatFrequency))] | ||
[JsonPropertyName(nameof(HeartbeatFrequency))] | ||
public TimeSpan? HeartbeatFrequency { get; set; } | ||
} |
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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
using Newtonsoft.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace GuildWarsPartySearch.Server.Options; | ||
|
||
public sealed class StorageAccountOptions | ||
{ | ||
[JsonProperty(nameof(TableName))] | ||
[JsonPropertyName(nameof(TableName))] | ||
public string? TableName { get; set; } | ||
|
||
[JsonProperty(nameof(ConnectionString))] | ||
[JsonPropertyName(nameof(ConnectionString))] | ||
public string? ConnectionString { get; set; } | ||
|
||
[JsonProperty(nameof(ContainerName))] | ||
[JsonPropertyName(nameof(ContainerName))] | ||
public string? ContainerName { get; set; } | ||
} |
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,9 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace GuildWarsPartySearch.Server.Options; | ||
|
||
public sealed class TelemetryOptions | ||
{ | ||
[JsonPropertyName(nameof(SuccessfulStatusCodes))] | ||
public List<int>? SuccessfulStatusCodes { get; set; } | ||
} |
39 changes: 39 additions & 0 deletions
39
GuildWarsPartySearch/Telemetry/Mark4xxAsSuccessfulTelemetryInitializer.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,39 @@ | ||
using GuildWarsPartySearch.Server.Options; | ||
using Microsoft.ApplicationInsights.Channel; | ||
using Microsoft.ApplicationInsights.DataContracts; | ||
using Microsoft.ApplicationInsights.Extensibility; | ||
using Microsoft.Extensions.Options; | ||
using System.Core.Extensions; | ||
|
||
namespace GuildWarsPartySearch.Server.Telemetry; | ||
|
||
public sealed class Mark4xxAsSuccessfulTelemetryInitializer : ITelemetryInitializer | ||
{ | ||
private readonly TelemetryOptions telemetryOptions; | ||
|
||
public Mark4xxAsSuccessfulTelemetryInitializer( | ||
IOptions<TelemetryOptions> options) | ||
{ | ||
this.telemetryOptions = options.ThrowIfNull().Value; | ||
} | ||
|
||
public void Initialize(ITelemetry telemetry) | ||
{ | ||
if (telemetry is not RequestTelemetry requestTelemetry) | ||
{ | ||
return; | ||
} | ||
|
||
if (!int.TryParse(requestTelemetry.ResponseCode, out var statusCode)) | ||
{ | ||
return; | ||
} | ||
|
||
if (this.telemetryOptions.SuccessfulStatusCodes?.Contains(statusCode) is true) | ||
{ | ||
requestTelemetry.Success = true; | ||
} | ||
|
||
return; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
GuildWarsPartySearch/Telemetry/WebSocketTelemetryProcessor.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,31 @@ | ||
using Microsoft.ApplicationInsights.Channel; | ||
using Microsoft.ApplicationInsights.DataContracts; | ||
using Microsoft.ApplicationInsights.Extensibility; | ||
using System.Core.Extensions; | ||
|
||
namespace GuildWarsPartySearch.Server.Telemetry; | ||
|
||
public sealed class WebSocketTelemetryProcessor : ITelemetryProcessor | ||
{ | ||
private readonly ITelemetryProcessor next; | ||
|
||
public WebSocketTelemetryProcessor(ITelemetryProcessor next) | ||
{ | ||
this.next = next.ThrowIfNull(); | ||
} | ||
|
||
public void Process(ITelemetry item) | ||
{ | ||
if (item is not RequestTelemetry request) | ||
{ | ||
return; | ||
} | ||
|
||
if (request.Url.Scheme is "ws" or "wss") | ||
{ | ||
request.Duration = TimeSpan.Zero; | ||
} | ||
|
||
this.next.Process(item); | ||
} | ||
} |