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] Enable on Microsoft.Diagnostics.Monitoring.Options #6933

Merged
Merged
Show file tree
Hide file tree
Changes from 6 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 @@ -11,11 +11,11 @@ internal sealed partial class AuthenticationOptions
[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_AuthenticationOptions_MonitorApiKey))]
public MonitorApiKeyOptions MonitorApiKey { get; set; }
public MonitorApiKeyOptions? MonitorApiKey { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_AuthenticationOptions_AzureAd))]
public AzureAdOptions AzureAd { get; set; }
public AzureAdOptions? AzureAd { get; set; }
}
}
10 changes: 5 additions & 5 deletions src/Microsoft.Diagnostics.Monitoring.Options/AzureAdOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@ internal sealed partial class AzureAdOptions
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_AzureAdOptions_Instance))]
[DefaultValue(AzureAdOptionsDefaults.DefaultInstance)]
public Uri Instance { get; set; }
public Uri? Instance { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_AzureAdOptions_TenantId))]
[DefaultValue(AzureAdOptionsDefaults.DefaultTenantId)]
public string TenantId { get; set; }
public string? TenantId { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_AzureAdOptions_ClientId))]
[Required]
public string ClientId { get; set; }
public string ClientId { get; set; } = string.Empty;

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_AzureAdOptions_AppIdUri))]
public Uri AppIdUri { get; set; }
public Uri? AppIdUri { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_AzureAdOptions_RequiredRole))]
[Required]
public string RequiredRole { get; set; }
public string RequiredRole { get; set; } = string.Empty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ namespace Microsoft.Diagnostics.Monitoring.WebApi
{
internal class CollectionRuleMetadata
{
public string CollectionRuleName { get; set; }
public string CollectionRuleName { get; set; } = string.Empty;

public int ActionListIndex { get; set; }

public string ActionName { get; set; }
public string? ActionName { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class CorsConfigurationOptions
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_CorsConfiguration_AllowedOrigins))]
[Required]
public string AllowedOrigins { get; set; }
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 @@ -17,7 +17,7 @@ public class DiagnosticPortOptions
[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_DiagnosticPortOptions_EndpointName))]
public string EndpointName { get; set; }
public string? EndpointName { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ namespace Microsoft.Diagnostics.Monitoring.Options
/// </summary>
internal sealed class DotnetMonitorDebugOptions
{
public ExceptionsDebugOptions Exceptions { get; set; }
public ExceptionsDebugOptions? Exceptions { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ internal sealed class EgressOptions
[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_EgressOptions_FileSystem))]
public IDictionary<string, FileSystemEgressProviderOptions> FileSystem { get; set; }
public IDictionary<string, FileSystemEgressProviderOptions>? FileSystem { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_EgressOptions_Properties))]
public IDictionary<string, string> Properties { get; set; }
public IDictionary<string, string>? Properties { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,28 @@ public sealed class ExceptionsConfiguration
/// Each configuration is a logical OR, so if any of the configurations match, the exception is shown.
/// </summary>
[JsonPropertyName("include")]
public List<ExceptionFilter> Include { get; set; } = new();
public List<ExceptionFilter>? Include { get; set; } = new();

/// <summary>
/// The list of exception configurations that determine which exceptions should be shown.
/// Each configuration is a logical OR, so if any of the configurations match, the exception isn't shown.
/// </summary>
[JsonPropertyName("exclude")]
public List<ExceptionFilter> Exclude { get; set; } = new();
public List<ExceptionFilter>? Exclude { get; set; } = new();
}

public sealed class ExceptionFilter : IMethodDescription
schmittjoseph marked this conversation as resolved.
Show resolved Hide resolved
public sealed class ExceptionFilter
{
[JsonPropertyName("exceptionType")]
public string ExceptionType { get; set; }
public string? ExceptionType { get; set; }

public string ModuleName { get; set; }
[JsonPropertyName("moduleName")]
public string? ModuleName { get; set; }

public string TypeName { get; set; }
[JsonPropertyName("typeName")]
public string? TypeName { get; set; }

public string MethodName { get; set; }
[JsonPropertyName("methodName")]
public string? MethodName { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ internal sealed class ExceptionsOptions :
[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_ExceptionsOptions_CollectionFilters))]
public ExceptionsConfiguration CollectionFilters { get; set; }
public ExceptionsConfiguration? CollectionFilters { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ internal sealed class FileSystemEgressProviderOptions
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_FileSystemEgressProviderOptions_DirectoryPath))]
[Required]
public string DirectoryPath { get; set; }
public string DirectoryPath { get; set; } = string.Empty;

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_FileSystemEgressProviderOptions_IntermediateDirectoryPath))]
public string IntermediateDirectoryPath { get; set; }
public string? IntermediateDirectoryPath { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public partial class GlobalCounterOptions
[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_GlobalCounterOptions_Providers))]
public System.Collections.Generic.IDictionary<string, GlobalProviderOptions> Providers { get; set; } = new Dictionary<string, GlobalProviderOptions>(StringComparer.OrdinalIgnoreCase);
public System.Collections.Generic.IDictionary<string, GlobalProviderOptions>? Providers { get; set; } = new Dictionary<string, GlobalProviderOptions>(StringComparer.OrdinalIgnoreCase);
}

public class GlobalProviderOptions
Expand All @@ -53,15 +53,19 @@ partial class GlobalCounterOptions : IValidatableObject
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
var results = new List<ValidationResult>();
var providerResults = new List<ValidationResult>();
foreach ((string provider, GlobalProviderOptions options) in Providers)

if (Providers != null)
{
providerResults.Clear();
if (!Validator.TryValidateObject(options, new ValidationContext(options), providerResults, true))
var providerResults = new List<ValidationResult>();
foreach ((string provider, GlobalProviderOptions options) in Providers)
{
// We prefix the validation error with the provider.
results.AddRange(providerResults.Select(r => new ValidationResult(
string.Format(CultureInfo.CurrentCulture, OptionsDisplayStrings.ErrorMessage_NestedProviderValidationError, provider, r.ErrorMessage))));
providerResults.Clear();
if (!Validator.TryValidateObject(options, new ValidationContext(options), providerResults, true))
{
// We prefix the validation error with the provider.
results.AddRange(providerResults.Select(r => new ValidationResult(
string.Format(CultureInfo.CurrentCulture, OptionsDisplayStrings.ErrorMessage_NestedProviderValidationError, provider, r.ErrorMessage))));
}
}
}

Expand All @@ -81,6 +85,6 @@ public static int GetMaxTimeSeries(this GlobalCounterOptions options) =>
options.MaxTimeSeries.GetValueOrDefault(GlobalCounterOptionsDefaults.MaxTimeSeries);

public static float GetProviderSpecificInterval(this GlobalCounterOptions options, string providerName) =>
options.Providers.TryGetValue(providerName, out GlobalProviderOptions providerOptions) ? providerOptions.IntervalSeconds ?? options.GetIntervalSeconds() : options.GetIntervalSeconds();
options.Providers?.TryGetValue(providerName, out GlobalProviderOptions? providerOptions) == true ? providerOptions.IntervalSeconds ?? options.GetIntervalSeconds() : options.GetIntervalSeconds();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ internal sealed class InProcessFeaturesOptions
[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_InProcessFeaturesOptions_CallStacks))]
public CallStacksOptions CallStacks { get; set; }
public CallStacksOptions? CallStacks { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_InProcessFeaturesOptions_Exceptions))]
public ExceptionsOptions Exceptions { get; set; }
public ExceptionsOptions? Exceptions { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_InProcessFeaturesOptions_ParameterCapturing))]
[Experimental]
public ParameterCapturingOptions ParameterCapturing { get; set; }
public ParameterCapturingOptions? ParameterCapturing { get; set; }
}
}
14 changes: 7 additions & 7 deletions src/Microsoft.Diagnostics.Monitoring.Options/MetricsOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class MetricsOptions
[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_MetricsOptions_Endpoints))]
public string Endpoints { get; set; }
public string? Endpoints { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Expand All @@ -43,12 +43,12 @@ public class MetricsOptions
[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_MetricsOptions_Providers))]
public List<MetricProvider> Providers { get; set; } = new List<MetricProvider>(0);
public List<MetricProvider>? Providers { get; set; } = new List<MetricProvider>(0);

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_MetricsOptions_Meters))]
public List<MeterConfiguration> Meters { get; set; } = new List<MeterConfiguration>(0);
public List<MeterConfiguration>? Meters { get; set; } = new List<MeterConfiguration>(0);
}

public class MetricProvider
Expand All @@ -57,24 +57,24 @@ public class MetricProvider
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_MetricProvider_ProviderName))]
[Required]
public string ProviderName { get; set; }
public string ProviderName { get; set; } = string.Empty;

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_MetricProvider_CounterNames))]
public List<string> CounterNames { get; set; } = new List<string>(0);
public List<string>? CounterNames { get; set; } = new List<string>(0);
}

public class MeterConfiguration
{
[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_MeterConfiguration_MeterName))]
public string MeterName { get; set; }
public string? MeterName { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_MeterConfiguration_InstrumentNames))]
public List<string> InstrumentNames { get; set; } = new List<string>(0);
public List<string>? InstrumentNames { get; set; } = new List<string>(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<TargetFrameworks>$(TestTargetFrameworks)</TargetFrameworks>
<IsShippingAssembly>true</IsShippingAssembly>
<OutputType>Library</OutputType>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ internal sealed class MonitorApiKeyOptions
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_MonitorApiKeyOptions_Subject))]
[Required]
public string Subject { get; set; }
public string Subject { get; set; } = string.Empty;

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_MonitorApiKeyOptions_PublicKey))]
[RegularExpression("[0-9a-zA-Z_-]+")]
[Required]
public string PublicKey { get; set; }
public string PublicKey { get; set; } = string.Empty;

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_MonitorApiKeyOptions_Issuer))]
public string Issuer { get; set; }
public string? Issuer { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public sealed class ProcessFilterOptions
[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_ProcessFilterOptions_Filters))]
public List<ProcessFilterDescriptor> Filters { get; set; } = new List<ProcessFilterDescriptor>(0);
public List<ProcessFilterDescriptor>? Filters { get; set; } = new List<ProcessFilterDescriptor>(0);
}

public sealed partial class ProcessFilterDescriptor
Expand All @@ -54,7 +54,7 @@ public sealed partial class ProcessFilterDescriptor
[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_ProcessFilterDescriptor_Value))]
public string Value { get; set; }
public string? Value { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Expand All @@ -65,17 +65,17 @@ public sealed partial class ProcessFilterDescriptor
[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_ProcessFilterDescriptor_ProcessName))]
public string ProcessName { get; set; }
public string? ProcessName { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_ProcessFilterDescriptor_ProcessId))]
public string ProcessId { get; set; }
public string? ProcessId { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_ProcessFilterDescriptor_CommandLine))]
public string CommandLine { get; set; }
public string? CommandLine { get; set; }
}

partial class ProcessFilterDescriptor : IValidatableObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ public class StorageOptions
[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_StorageOptions_DefaultSharedPath))]
public string DefaultSharedPath { get; set; }
public string? DefaultSharedPath { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_StorageOptions_DumpTempFolder))]
public string DumpTempFolder { get; set; }
public string? DumpTempFolder { get; set; }

[Experimental]
[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_StorageOptions_SharedLibraryPath))]
public string SharedLibraryPath { get; set; }
public string? SharedLibraryPath { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ public ActionResult<DotnetMonitorInfo> GetInfo()
string? version = Assembly.GetExecutingAssembly().GetInformationalVersionString();
string runtimeVersion = Environment.Version.ToString();
DiagnosticPortConnectionMode diagnosticPortMode = _diagnosticPortOptions.Value.GetConnectionMode();
string diagnosticPortName = GetDiagnosticPortName();
string? diagnosticPortName = GetDiagnosticPortName();

DotnetMonitorInfo dotnetMonitorInfo = new()
{
Expand Down Expand Up @@ -653,7 +653,7 @@ public Task<ActionResult> CaptureStacks(
}, processKey, Utilities.ArtifactType_Stacks);
}

private string GetDiagnosticPortName()
private string? GetDiagnosticPortName()
{
return _diagnosticPortOptions.Value.EndpointName;
}
Expand Down
Loading
Loading