-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Add disable HTTP metrics endpoint metadata #56036
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.AspNetCore.Http.Metadata; | ||
|
||
/// <summary> | ||
/// A marker interface which can be used to identify metadata that disables HTTP request duration metrics. | ||
/// </summary> | ||
public interface IDisableHttpMetricsMetadata | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the flag interface for? Relatedly, if there's only one concrete implementation, can we just use that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using interfaces for endpoint metadata is the normal pattern. The only implementation is an attribute. Internally, builder methods that add this metadata to the endpoint just add the attribute. |
||
{ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Diagnostics; | ||
using Microsoft.AspNetCore.Http.Metadata; | ||
|
||
namespace Microsoft.AspNetCore.Http; | ||
|
||
/// <summary> | ||
/// Specifies that HTTP request duration metrics is disabled for an endpoint. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)] | ||
JamesNK marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[DebuggerDisplay("{ToString(),nq}")] | ||
public sealed class DisableHttpMetricsAttribute : Attribute, IDisableHttpMetricsMetadata | ||
{ | ||
/// <inheritdoc/> | ||
public override string ToString() | ||
{ | ||
return "DisableHttpMetrics"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.AspNetCore.Http; | ||
|
||
namespace Microsoft.AspNetCore.Builder; | ||
|
||
/// <summary> | ||
/// HTTP metrics extension methods for <see cref="IEndpointConventionBuilder"/>. | ||
/// </summary> | ||
public static class HttpMetricsEndpointConventionBuilderExtensions | ||
{ | ||
private static readonly DisableHttpMetricsAttribute _disableHttpMetricsAttribute = new DisableHttpMetricsAttribute(); | ||
|
||
/// <summary> | ||
/// Specifies that HTTP request duration metrics is disabled for an endpoint. | ||
/// </summary> | ||
/// <typeparam name="TBuilder">The type of endpoint convention builder.</typeparam> | ||
/// <param name="builder">The endpoint convention builder.</param> | ||
/// <returns>The original convention builder parameter.</returns> | ||
public static TBuilder DisableHttpMetrics<TBuilder>(this TBuilder builder) where TBuilder : IEndpointConventionBuilder | ||
{ | ||
builder.Add(b => b.Metadata.Add(_disableHttpMetricsAttribute)); | ||
return builder; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
#nullable enable | ||
Microsoft.AspNetCore.Http.HttpValidationProblemDetails.HttpValidationProblemDetails(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, string![]!>>! errors) -> void (forwarded, contained in Microsoft.AspNetCore.Http.Abstractions) | ||
Microsoft.AspNetCore.Builder.HttpMetricsEndpointConventionBuilderExtensions | ||
Microsoft.AspNetCore.Http.DisableHttpMetricsAttribute | ||
Microsoft.AspNetCore.Http.DisableHttpMetricsAttribute.DisableHttpMetricsAttribute() -> void | ||
override Microsoft.AspNetCore.Http.DisableHttpMetricsAttribute.ToString() -> string! | ||
static Microsoft.AspNetCore.Builder.HttpMetricsEndpointConventionBuilderExtensions.DisableHttpMetrics<TBuilder>(this TBuilder builder) -> TBuilder |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Http.Metadata; | ||
|
||
namespace Microsoft.AspNetCore.Http.Extensions.Tests; | ||
|
||
public partial class HttpMetricsEndpointConventionBuilderExtensionsTests | ||
{ | ||
[Fact] | ||
public void DisableHttpMetrics_AddsMetadata() | ||
{ | ||
var builder = new TestEndointConventionBuilder(); | ||
builder.DisableHttpMetrics(); | ||
|
||
Assert.IsAssignableFrom<IDisableHttpMetricsMetadata>(Assert.Single(builder.Metadata)); | ||
} | ||
|
||
private sealed class TestEndointConventionBuilder : EndpointBuilder, IEndpointConventionBuilder | ||
{ | ||
public void Add(Action<EndpointBuilder> convention) | ||
{ | ||
convention(this); | ||
} | ||
|
||
public override Endpoint Build() => throw new NotImplementedException(); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.