Skip to content

Call AddMetrics inside AddRouting #50168

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

Merged
merged 1 commit into from
Aug 30, 2023
Merged

Conversation

JamesNK
Copy link
Member

@JamesNK JamesNK commented Aug 17, 2023

Routing now uses metrics. The meter and counters are created using IMeterFactory. IMeterFactory is a new type and an implementation is registered by calling AddMetrics(). AddMetrics() is called by host builders.

However, this breaks if someone creates an app without using a host builder. They will get an error that IMeterFactory can't be resolved. Orchard Core doesn't use one of our built-in host builders and runs into this problem: https://github.com/OrchardCMS/OrchardCore/blob/fa03f92536de065c87f780ae27b277cce6d2d656/src/OrchardCore/OrchardCore/Modules/Extensions/ServiceCollectionExtensions.cs#L92. This is probably a rare situation.

Fix this issue by calling AddMetrics() inside AddRouting() so an IMeterFactory is always present. If the host already added metrics then the extra add inside routing doesn't have any impact.

@JamesNK JamesNK requested a review from javiercn as a code owner August 17, 2023 23:23
@ghost ghost added the area-runtime label Aug 17, 2023
var services = new ServiceCollection();
services.AddLogging();
services.AddOptions();
services.AddSingleton<DiagnosticListener>(s => new DiagnosticListener("Test"));
Copy link
Member Author

@JamesNK JamesNK Aug 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sebastienros UseRouting requires DiagnosticListener in DI, but I don't see that in OC source code. I'm confused how it worked before.

@JamesNK
Copy link
Member Author

JamesNK commented Aug 18, 2023

@Tratcher Multiple calls to AddMetrics has uncovered a problem with some changes you made to AddMetrics when implementing configuration: dotnet/runtime#90779

@JamesNK
Copy link
Member Author

JamesNK commented Aug 18, 2023

Blocked on dotnet/runtime#90779, which causes test failures in ASP.NET Core.

Microsoft.AspNetCore.Mvc.MvcServiceCollectionExtensionsTest.AddMvc_Twice_DoesNotAddDuplicates

Found multiple instances of  registered as Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.Extensions.DependencyInjection.MetricsServiceExtensions+NoOpOptions]
Expected: True
Actual:   False

We might struggle to get both fixes into rc1 on time.

@JamesNK JamesNK added the blocked The work on this issue is blocked due to some dependency label Aug 18, 2023
@Tratcher
Copy link
Member

This PR doesn't seem critical for RC1, it's an uncommon issue with an easy workaround. I'll look into the other issue today.

@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 25, 2023
@JamesNK JamesNK force-pushed the jamesnk/routing-addmetrics branch from 79ec039 to ff64647 Compare August 28, 2023 23:58
@JamesNK JamesNK changed the base branch from main to release/8.0 August 28, 2023 23:59
@JamesNK JamesNK removed the blocked The work on this issue is blocked due to some dependency label Aug 29, 2023
@JamesNK JamesNK added this to the 8.0-rc2 milestone Aug 29, 2023
Copy link
Member

@joperezr joperezr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @JamesNK!

@JamesNK JamesNK merged commit 23bd3b3 into release/8.0 Aug 30, 2023
@JamesNK JamesNK deleted the jamesnk/routing-addmetrics branch August 30, 2023 00:47
@ghost ghost modified the milestone: 8.0-rc2 Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions area-routing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants