Skip to content
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

Add AddMetricsConsumer helper to TelemetryConsumption #1899

Merged
merged 1 commit into from Oct 19, 2022

Conversation

MihaZupan
Copy link
Member

I am writing networking telemetry docs and it bothered me that we have very convenient helpers for ITelemetryConsumer*s, but nothing for IMetricsConsumer<T>.

So while you can write code like this for events:

services.AddTelemetryConsumer<MyTelemetryConsumer>();

you have to write this for metrics:

services.AddSingleton<IMetricsConsumer<SocketsMetrics>, MetricsConsumer>();
services.AddTelemetryListeners();

or even this if you implement multiple interfaces:

services.AddSingleton<MetricsConsumer>();
services.AddSingleton(services => (IMetricsConsumer<ForwarderMetrics>)services.GetRequiredService<MetricsConsumer>());
services.AddSingleton(services => (IMetricsConsumer<KestrelMetrics>)services.GetRequiredService<MetricsConsumer>());
services.AddSingleton(services => (IMetricsConsumer<SocketsMetrics>)services.GetRequiredService<MetricsConsumer>());
services.AddTelemetryListeners();

This PR adds AddMetricsConsumer helpers that do the same for metrics as AddTelemetryConsumer does for events.

@MihaZupan MihaZupan added this to the YARP 2.0.0 milestone Oct 17, 2022
@@ -98,7 +98,7 @@ private void EnableEventSource(EventSource eventSource)
return;
}

var eventLevel = enableEvents ? EventLevel.Verbose : EventLevel.Critical;
var eventLevel = enableEvents ? EventLevel.Informational : EventLevel.Critical;
Copy link
Member

Choose a reason for hiding this comment

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

?

Copy link
Member Author

Choose a reason for hiding this comment

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

This doesn't change anything currently, but it can make a significant difference if we ever add debug/trace events to the existing EventSources.
Since this library only knows about the current (informational) events, it would only waste CPU on more verbose events.

If we ever want to consume more verbose events with this library, we will adjust this flag as needed.

@MihaZupan MihaZupan merged commit 6b4195a into microsoft:main Oct 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants