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

[DO NOT REVIEW] [Nullable Context] Enable on dotnet-monitor #6941

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4e1979a
Enable nullable context for options
schmittjoseph Jul 1, 2024
75cb74a
Enable nullability context
schmittjoseph Jul 1, 2024
678291f
Remove placeholder
schmittjoseph Jul 1, 2024
8ba4691
Spelling
schmittjoseph Jul 1, 2024
f08aefb
Fix build
schmittjoseph Jul 1, 2024
7da8781
Fix build
schmittjoseph Jul 1, 2024
014c52f
Remove comments
schmittjoseph Jul 1, 2024
ca3e898
Fix GetOrigins
schmittjoseph Jul 1, 2024
d69f805
Merge branch 'nullability/options-project' into nullability/tool
schmittjoseph Jul 1, 2024
364042b
Merge branch 'nullability/options' into nullability/tool
schmittjoseph Jul 1, 2024
8b400c9
Port dotnet-monitor tool
schmittjoseph Jul 2, 2024
1e2ac9a
Fix endpoint info
schmittjoseph Jul 2, 2024
0d254a7
Fix tests
schmittjoseph Jul 2, 2024
2194680
Port logger
schmittjoseph Jul 2, 2024
fbf5ca2
Fix build
schmittjoseph Jul 2, 2024
63f0fdb
Fix test
schmittjoseph Jul 2, 2024
e912ca5
PR feedback
schmittjoseph Jul 2, 2024
bd9f95e
PR feedback
schmittjoseph Jul 2, 2024
30fe914
Merge branch 'nullability/options-project' into nullability/options
schmittjoseph Jul 2, 2024
01d4e70
Merge branch 'nullability/options' into nullability/tool
schmittjoseph Jul 2, 2024
c8102ba
Reconcile merge
schmittjoseph Jul 2, 2024
ac3b6b8
Standardize schema
schmittjoseph Jul 3, 2024
65a5fd4
Merge remote-tracking branch 'upstream/main' into nullability/tool
schmittjoseph Jul 3, 2024
c855da0
Fixes
schmittjoseph Jul 3, 2024
c12dfd7
Merge branch 'nullability/fix-schema' into nullability/tool
schmittjoseph Jul 3, 2024
4f2b9b6
Fixes
schmittjoseph Jul 3, 2024
00a3868
Merge remote-tracking branch 'upstream/main' into nullability/tool
schmittjoseph Jul 3, 2024
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 @@ -13,6 +13,6 @@ public class CorsConfigurationOptions
[Required]
public string AllowedOrigins { get; set; } = string.Empty;

public string[]? GetOrigins() => AllowedOrigins?.Split(';');
public string[] GetOrigins() => AllowedOrigins.Split(';');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Microsoft.Diagnostics.Monitoring.Options
{
internal static class ExceptionsDebugOptionsExtensions
{
public static bool GetIncludeMonitorExceptions(this ExceptionsDebugOptions options)
public static bool GetIncludeMonitorExceptions(this ExceptionsDebugOptions? options)
{
return (options?.IncludeMonitorExceptions).GetValueOrDefault(ExceptionsDebugOptionsDefaults.IncludeMonitorExceptions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ public Task<ActionResult<Dictionary<string, CollectionRuleDescription>>> GetColl
[HttpGet("collectionrules/{collectionRuleName}", Name = nameof(GetCollectionRuleDetailedDescription))]
[ProducesWithProblemDetails(ContentTypes.ApplicationJson)]
[ProducesResponseType(typeof(CollectionRuleDetailedDescription), StatusCodes.Status200OK)]
public Task<ActionResult<CollectionRuleDetailedDescription>> GetCollectionRuleDetailedDescription(
public Task<ActionResult<CollectionRuleDetailedDescription?>> GetCollectionRuleDetailedDescription(
string collectionRuleName,
[FromQuery]
int? pid = null,
Expand All @@ -556,7 +556,7 @@ public Task<ActionResult<CollectionRuleDetailedDescription>> GetCollectionRuleDe
[FromQuery]
string? name = null)
{
return InvokeForProcess<CollectionRuleDetailedDescription>(processInfo =>
return InvokeForProcess<CollectionRuleDetailedDescription?>(processInfo =>
{
return _collectionRuleService.GetCollectionRuleDetailedDescription(collectionRuleName, processInfo.EndpointInfo);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public bool MatchFilter(IProcessInfo processInfo)
return false;
}

private bool Compare(string value)
private bool Compare(string? value)
{
if (MatchType == DiagProcessFilterMatchType.Exact)
{
Expand All @@ -174,12 +174,12 @@ private bool Compare(string value)
return false;
}

private bool ExactCompare(string value)
private bool ExactCompare(string? value)
{
return string.Equals(Value, value, StringComparison.OrdinalIgnoreCase);
}

private bool ContainsCompare(string value)
private bool ContainsCompare(string? value)
{
return value?.IndexOf(Value, StringComparison.OrdinalIgnoreCase) > -1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Microsoft.Diagnostics.Monitoring.WebApi.Exceptions
{
internal record class ExceptionInstance(ulong Id, string TypeName, string ModuleName, string Message, DateTime Timestamp, CallStack CallStack, ulong[] InnerExceptionIds, string ActivityId, ActivityIdFormat ActivityIdFormat)
internal record class ExceptionInstance(ulong Id, string TypeName, string ModuleName, string Message, DateTime Timestamp, CallStack? CallStack, ulong[] InnerExceptionIds, string ActivityId, ActivityIdFormat ActivityIdFormat)
: IExceptionInstance
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.Diagnostics.Monitoring.WebApi.Exceptions
/// </summary>
internal static class ExceptionsSettingsFactory
{
public static ExceptionsConfigurationSettings ConvertExceptionsConfiguration(ExceptionsConfiguration configuration)
public static ExceptionsConfigurationSettings ConvertExceptionsConfiguration(ExceptionsConfiguration? configuration)
{
ExceptionsConfigurationSettings configurationSettings = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ internal interface ICollectionRuleService : IHostedService, IAsyncDisposable
{
Dictionary<string, CollectionRuleDescription> GetCollectionRulesDescriptions(IEndpointInfo endpointInfo);

CollectionRuleDetailedDescription GetCollectionRuleDetailedDescription(string collectionRuleName, IEndpointInfo endpointInfo);
CollectionRuleDetailedDescription? GetCollectionRuleDetailedDescription(string collectionRuleName, IEndpointInfo endpointInfo);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public interface IProcessInfo
{
IEndpointInfo EndpointInfo { get; }

string CommandLine { get; }
string? CommandLine { get; }

public string OperatingSystem { get; }
public string? OperatingSystem { get; }

public string ProcessArchitecture { get; }
public string? ProcessArchitecture { get; }

string ProcessName { get; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ IArtifactOperation Create(
TimeSpan duration,
string providerName,
string eventName,
IDictionary<string, string> payloadFilter);
IDictionary<string, string>? payloadFilter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Moq;
using System;
using System.Reflection;
using System.Threading;
Expand All @@ -30,6 +31,16 @@ public sealed class ActionListExecutorTests

private const string DefaultRuleName = nameof(ActionListExecutorTests);

private static Microsoft.Diagnostics.Monitoring.WebApi.IProcessInfo CreateTestProcess()
{
Mock<Microsoft.Diagnostics.Monitoring.WebApi.IProcessInfo> mockProcessInfo = new();
mockProcessInfo
.Setup(p => p.EndpointInfo)
.Returns(Mock.Of<Microsoft.Diagnostics.Monitoring.WebApi.IEndpointInfo>);

return mockProcessInfo.Object;
}

public ActionListExecutorTests(ITestOutputHelper outputHelper)
{
_outputHelper = outputHelper;
Expand All @@ -54,7 +65,7 @@ await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions =>
ILogger<CollectionRuleService> logger = host.Services.GetRequiredService<ILogger<CollectionRuleService>>();
TimeProvider timeProvider = host.Services.GetRequiredService<TimeProvider>();

CollectionRuleContext context = new(DefaultRuleName, ruleOptions, null, logger, timeProvider);
CollectionRuleContext context = new(DefaultRuleName, ruleOptions, CreateTestProcess(), logger, timeProvider);

int callbackCount = 0;
Action startCallback = () => callbackCount++;
Expand Down Expand Up @@ -95,7 +106,7 @@ await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions =>
ILogger<CollectionRuleService> logger = host.Services.GetRequiredService<ILogger<CollectionRuleService>>();
TimeProvider timeProvider = host.Services.GetRequiredService<TimeProvider>();

CollectionRuleContext context = new(DefaultRuleName, ruleOptions, null, logger, timeProvider);
CollectionRuleContext context = new(DefaultRuleName, ruleOptions, CreateTestProcess(), logger, timeProvider);

int callbackCount = 0;
Action startCallback = () => callbackCount++;
Expand Down Expand Up @@ -141,7 +152,7 @@ await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions =>
ILogger<CollectionRuleService> logger = host.Services.GetRequiredService<ILogger<CollectionRuleService>>();
TimeProvider timeProvider = host.Services.GetRequiredService<TimeProvider>();

CollectionRuleContext context = new(DefaultRuleName, ruleOptions, null, logger, timeProvider);
CollectionRuleContext context = new(DefaultRuleName, ruleOptions, CreateTestProcess(), logger, timeProvider);

int callbackCount = 0;
Action startCallback = () => callbackCount++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<Compile Include="..\..\Tools\dotnet-monitor\LoggingEventIds.cs" Link="LoggingEventIds.cs" />
<Compile Include="..\..\Tools\dotnet-monitor\OutputFormat.cs" Link="Options\OutputFormat.cs" />
<Compile Include="..\..\Tools\dotnet-monitor\RootOptions.cs" Link="Options\RootOptions.cs" />
<Compile Include="..\..\Tools\dotnet-monitor\ConvertUtils.cs" Link="ConvertUtils.cs" />
<Compile Include="..\Microsoft.Diagnostics.Monitoring.Tool.UnitTestCommon\ExecuteActionTestHelper.cs" Link="ExecuteActionTestHelper.cs" />
<Compile Include="..\Microsoft.Diagnostics.Monitoring.Tool.UnitTestCommon\Options\CollectionRuleOptionsExtensions.cs" Link="Options\CollectionRuleOptionsExtensions.cs" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions =>
ILogger<CollectionRuleService> logger = host.Services.GetRequiredService<ILogger<CollectionRuleService>>();
TimeProvider timeProvider = host.Services.GetRequiredService<TimeProvider>();

CollectionRuleContext context = new(DefaultRuleName, ruleOptions, null, logger, timeProvider);
Guid instanceId = Guid.NewGuid();
CollectionRuleContext context = new(DefaultRuleName, ruleOptions, new TestProcessInfo(instanceId), logger, timeProvider);

int callbackCount = 0;
Action startCallback = () => callbackCount++;
Expand Down Expand Up @@ -200,7 +201,8 @@ await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions =>
ILogger<CollectionRuleService> logger = host.Services.GetRequiredService<ILogger<CollectionRuleService>>();
TimeProvider timeProvider = host.Services.GetRequiredService<TimeProvider>();

CollectionRuleContext context = new(DefaultRuleName, ruleOptions, null, logger, timeProvider);
Guid instanceId = Guid.NewGuid();
CollectionRuleContext context = new(DefaultRuleName, ruleOptions, new TestProcessInfo(instanceId), logger, timeProvider);

ActionOptionsDependencyAnalyzer analyzer = ActionOptionsDependencyAnalyzer.Create(context);
analyzer.GetActionDependencies(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public void FoundExtension_Failure()
HostBuilderSettings settings = new()
{
SharedConfigDirectory = sharedConfigDir.FullName,
UserConfigDirectory = userConfigDir.FullName
UserConfigDirectory = userConfigDir.FullName,
ContentRootDirectory = AppContext.BaseDirectory
};

IHost host = TestHostHelper.CreateHost(_outputHelper, rootOptions => { }, host => { }, settings: settings);
Expand All @@ -61,7 +62,8 @@ public void FoundExtensionFile_Success(ConfigDirectory configDirectory)
HostBuilderSettings settings = new()
{
SharedConfigDirectory = sharedConfigDir.FullName,
UserConfigDirectory = userConfigDir.FullName
UserConfigDirectory = userConfigDir.FullName,
ContentRootDirectory = AppContext.BaseDirectory
};

IEgressExtension extension = FindEgressExtension(configDirectory, settings);
Expand Down Expand Up @@ -96,7 +98,8 @@ private async Task<EgressArtifactResult> GetExtensionResponse(bool shouldSucceed
HostBuilderSettings settings = new()
{
SharedConfigDirectory = sharedConfigDir.FullName,
UserConfigDirectory = userConfigDir.FullName
UserConfigDirectory = userConfigDir.FullName,
ContentRootDirectory = AppContext.BaseDirectory
};

EgressExtension extension = (EgressExtension)FindEgressExtension(ConfigDirectory.UserConfigDirectory, settings);
Expand Down
6 changes: 3 additions & 3 deletions src/Tools/dotnet-monitor/ActivityExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Microsoft.Diagnostics.Tools.Monitor
{
internal static class ActivityExtensions
{
public static string GetSpanId(this Activity activity)
public static string? GetSpanId(this Activity activity)
{
switch (activity.IdFormat)
{
Expand All @@ -19,7 +19,7 @@ public static string GetSpanId(this Activity activity)
return string.Empty;
}

public static string GetParentId(this Activity activity)
public static string? GetParentId(this Activity activity)
{
switch (activity.IdFormat)
{
Expand All @@ -31,7 +31,7 @@ public static string GetParentId(this Activity activity)
return string.Empty;
}

public static string GetTraceId(this Activity activity)
public static string? GetTraceId(this Activity activity)
{
switch (activity.IdFormat)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Tools/dotnet-monitor/AddressListenResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void Listen(KestrelServerOptions options, IEnumerable<string> defaultUrls
/// </summary>
private bool Listen(KestrelServerOptions options, string url, bool isAuthEnabled)
{
BindingAddress address = null;
BindingAddress? address = null;
try
{
address = BindingAddress.Parse(url);
Expand All @@ -95,7 +95,7 @@ private bool Listen(KestrelServerOptions options, string url, bool isAuthEnabled
{
options.ListenLocalhost(address.Port, configureListenOptions);
}
else if (IPAddress.TryParse(address.Host, out IPAddress ipAddress))
else if (IPAddress.TryParse(address.Host, out IPAddress? ipAddress))
{
options.Listen(ipAddress, address.Port, configureListenOptions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ public AddressListenResultsStartupLogger(
_logger = logger;
_server = server;

#nullable disable
_applicationStartedRegistration = lifetime.ApplicationStarted.Register(
l => ((AddressListenResultsStartupLogger)l).OnStarted(),
this);
#nullable restore
}

public void Dispose()
Expand All @@ -52,6 +54,7 @@ public void Log()
}
}

#nullable disable
private void OnStarted()
{
IServerAddressesFeature serverAddresses = _server.Features.Get<IServerAddressesFeature>();
Expand All @@ -69,5 +72,6 @@ private void OnStarted()
_logger.BoundMetricsAddress(metricAddress);
}
}
#nullable restore
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal sealed class JwtBearerChangeTokenSource :
IDisposable
{
private readonly IOptionsMonitor<MonitorApiKeyConfiguration> _optionsMonitor;
private readonly IDisposable _changeRegistration;
private readonly IDisposable? _changeRegistration;

private ConfigurationReloadToken _reloadToken = new ConfigurationReloadToken();

Expand All @@ -42,7 +42,7 @@ public IChangeToken GetChangeToken()

public void Dispose()
{
_changeRegistration.Dispose();
_changeRegistration?.Dispose();
}

private void OnReload(MonitorApiKeyConfiguration options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public JwtBearerPostConfigure(
_apiKeyConfig = apiKeyConfig;
}

public void PostConfigure(string name, JwtBearerOptions options)
public void PostConfigure(string? name, JwtBearerOptions options)
{
MonitorApiKeyConfiguration configSnapshot = _apiKeyConfig.CurrentValue;
if (!configSnapshot.Configured || configSnapshot.ValidationErrors.Any())
if (!configSnapshot.Configured || configSnapshot.ValidationErrors?.Any() == true)
{
#if NET8_0_OR_GREATER
// https://github.com/aspnet/Announcements/issues/508
Expand All @@ -37,7 +37,9 @@ public void PostConfigure(string name, JwtBearerOptions options)
return;
}

#nullable disable
options.ConfigureApiKeyTokenValidation(configSnapshot.PublicKey, configSnapshot.Issuer);
#nullable restore
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ namespace Microsoft.Diagnostics.Tools.Monitor.Auth.ApiKey
{
internal sealed class MonitorApiKeyAuthConfigurator : IAuthenticationConfigurator
{
private readonly GeneratedJwtKey _pinnedJwtKey;
private readonly GeneratedJwtKey? _pinnedJwtKey;
private readonly bool _enableNegotiation;


public MonitorApiKeyAuthConfigurator(GeneratedJwtKey pinnedJwtKey = null)
public MonitorApiKeyAuthConfigurator(GeneratedJwtKey? pinnedJwtKey = null)
{
_pinnedJwtKey = pinnedJwtKey;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal sealed class MonitorApiKeyChangeTokenSource :
IDisposable
{
private readonly IOptionsMonitor<MonitorApiKeyOptions> _optionsMonitor;
private readonly IDisposable _changeRegistration;
private readonly IDisposable? _changeRegistration;

private ConfigurationReloadToken _reloadToken = new ConfigurationReloadToken();

Expand All @@ -37,7 +37,7 @@ public IChangeToken GetChangeToken()

public void Dispose()
{
_changeRegistration.Dispose();
_changeRegistration?.Dispose();
}

private void OnReload(MonitorApiKeyOptions options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ namespace Microsoft.Diagnostics.Tools.Monitor.Auth.ApiKey
internal class MonitorApiKeyConfiguration : AuthenticationSchemeOptions
{
public bool Configured { get; set; }
public string Subject { get; set; }
public SecurityKey PublicKey { get; set; }
public IEnumerable<ValidationResult> ValidationErrors { get; set; }
public string Issuer { get; set; }
public string? Subject { get; set; }
public SecurityKey? PublicKey { get; set; }
public IEnumerable<ValidationResult>? ValidationErrors { get; set; }
public string? Issuer { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class MonitorApiKeyConfigurationObserver :
private readonly ILogger<MonitorApiKeyConfigurationObserver> _logger;
private readonly IOptionsMonitor<MonitorApiKeyConfiguration> _options;

private IDisposable _changeRegistration;
private IDisposable? _changeRegistration;

public MonitorApiKeyConfigurationObserver(
ILogger<MonitorApiKeyConfigurationObserver> logger,
Expand Down
Loading
Loading