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

[Nullable Context] Microsoft.Diagnostics.Monitoring.WebApi fixes #6931

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ public partial class DiagController : DiagnosticsControllerBase
{
private const TraceProfile DefaultTraceProfiles = TraceProfile.Cpu | TraceProfile.Http | TraceProfile.Metrics | TraceProfile.GcCollect;

#nullable disable
private readonly IOptions<DiagnosticPortOptions> _diagnosticPortOptions;
#nullable restore
private readonly IOptions<CallStacksOptions> _callStacksOptions;
private readonly IOptions<ParameterCapturingOptions> _parameterCapturingOptions;
private readonly IOptionsMonitor<GlobalCounterOptions> _counterOptions;
Expand All @@ -54,7 +52,7 @@ public partial class DiagController : DiagnosticsControllerBase
public DiagController(IServiceProvider serviceProvider, ILogger<DiagController> logger)
: base(serviceProvider.GetRequiredService<IDiagnosticServices>(), serviceProvider.GetRequiredService<IEgressOperationStore>(), logger)
{
_diagnosticPortOptions = serviceProvider.GetService<IOptions<DiagnosticPortOptions>>();
_diagnosticPortOptions = serviceProvider.GetRequiredService<IOptions<DiagnosticPortOptions>>();
_callStacksOptions = serviceProvider.GetRequiredService<IOptions<CallStacksOptions>>();
_parameterCapturingOptions = serviceProvider.GetRequiredService<IOptions<ParameterCapturingOptions>>();
_counterOptions = serviceProvider.GetRequiredService<IOptionsMonitor<GlobalCounterOptions>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@ public class MetricsController : ControllerBase
private const string ArtifactType_Metrics = "metrics";

private readonly ILogger<MetricsController> _logger;
#nullable disable
private readonly MetricsStoreService _metricsStore;
#nullable restore
private readonly MetricsOptions _metricsOptions;

public MetricsController(ILogger<MetricsController> logger,
IServiceProvider serviceProvider,
IOptions<MetricsOptions> metricsOptions)
{
_logger = logger;
_metricsStore = serviceProvider.GetService<MetricsStoreService>();
_metricsStore = serviceProvider.GetRequiredService<MetricsStoreService>();
_metricsOptions = metricsOptions.Value;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable disable

using System.Threading;
using System.Threading.Tasks;

Expand All @@ -22,15 +20,15 @@ internal static class TaskCompletionSourceExtensions
/// </remarks>
public static async Task<T> WithCancellation<T>(this TaskCompletionSource<T> source, CancellationToken token)
{
using (token.Register(source => ((TaskCompletionSource<T>)source).TrySetCanceled(token), source))
using (token.Register(() => source.TrySetCanceled(token)))
{
return await source.Task.ConfigureAwait(false);
}
}

public static async Task WithCancellation(this TaskCompletionSource source, CancellationToken token)
{
using (token.Register(source => ((TaskCompletionSource)source).TrySetCanceled(token), source))
using (token.Register(() => source.TrySetCanceled(token)))
{
await source.Task.ConfigureAwait(false);
}
Expand Down