diff --git a/src/Microsoft.Diagnostics.Monitoring.Options/AuthenticationOptions.cs b/src/Microsoft.Diagnostics.Monitoring.Options/AuthenticationOptions.cs index 776080b8ca7..8b2b8567588 100644 --- a/src/Microsoft.Diagnostics.Monitoring.Options/AuthenticationOptions.cs +++ b/src/Microsoft.Diagnostics.Monitoring.Options/AuthenticationOptions.cs @@ -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; } } } diff --git a/src/Microsoft.Diagnostics.Monitoring.Options/AzureAdOptions.cs b/src/Microsoft.Diagnostics.Monitoring.Options/AzureAdOptions.cs index a696a70bdd2..b40304057e1 100644 --- a/src/Microsoft.Diagnostics.Monitoring.Options/AzureAdOptions.cs +++ b/src/Microsoft.Diagnostics.Monitoring.Options/AzureAdOptions.cs @@ -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; } } diff --git a/src/Microsoft.Diagnostics.Monitoring.Options/CollectionRuleMetadata.cs b/src/Microsoft.Diagnostics.Monitoring.Options/CollectionRuleMetadata.cs index b8f93b77ded..8b22ceac2be 100644 --- a/src/Microsoft.Diagnostics.Monitoring.Options/CollectionRuleMetadata.cs +++ b/src/Microsoft.Diagnostics.Monitoring.Options/CollectionRuleMetadata.cs @@ -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; } } } diff --git a/src/Microsoft.Diagnostics.Monitoring.Options/CorsConfigurationOptions.cs b/src/Microsoft.Diagnostics.Monitoring.Options/CorsConfigurationOptions.cs index 3d0973cdc07..86398d68b90 100644 --- a/src/Microsoft.Diagnostics.Monitoring.Options/CorsConfigurationOptions.cs +++ b/src/Microsoft.Diagnostics.Monitoring.Options/CorsConfigurationOptions.cs @@ -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(';'); } } diff --git a/src/Microsoft.Diagnostics.Monitoring.Options/DiagnosticPortOptions.cs b/src/Microsoft.Diagnostics.Monitoring.Options/DiagnosticPortOptions.cs index 24f71cbf722..cb6d4431ca4 100644 --- a/src/Microsoft.Diagnostics.Monitoring.Options/DiagnosticPortOptions.cs +++ b/src/Microsoft.Diagnostics.Monitoring.Options/DiagnosticPortOptions.cs @@ -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), diff --git a/src/Microsoft.Diagnostics.Monitoring.Options/DotnetMonitorDebugOptions.cs b/src/Microsoft.Diagnostics.Monitoring.Options/DotnetMonitorDebugOptions.cs index f0ed54fb1af..b8ca50a529e 100644 --- a/src/Microsoft.Diagnostics.Monitoring.Options/DotnetMonitorDebugOptions.cs +++ b/src/Microsoft.Diagnostics.Monitoring.Options/DotnetMonitorDebugOptions.cs @@ -9,6 +9,6 @@ namespace Microsoft.Diagnostics.Monitoring.Options /// internal sealed class DotnetMonitorDebugOptions { - public ExceptionsDebugOptions Exceptions { get; set; } + public ExceptionsDebugOptions? Exceptions { get; set; } } } diff --git a/src/Microsoft.Diagnostics.Monitoring.Options/EgressOptions.cs b/src/Microsoft.Diagnostics.Monitoring.Options/EgressOptions.cs index 2120c2e0335..b0b07ca343e 100644 --- a/src/Microsoft.Diagnostics.Monitoring.Options/EgressOptions.cs +++ b/src/Microsoft.Diagnostics.Monitoring.Options/EgressOptions.cs @@ -13,11 +13,11 @@ internal sealed class EgressOptions [Display( ResourceType = typeof(OptionsDisplayStrings), Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_EgressOptions_FileSystem))] - public IDictionary FileSystem { get; set; } + public IDictionary? FileSystem { get; set; } [Display( ResourceType = typeof(OptionsDisplayStrings), Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_EgressOptions_Properties))] - public IDictionary Properties { get; set; } + public IDictionary? Properties { get; set; } } } diff --git a/src/Microsoft.Diagnostics.Monitoring.Options/ExceptionsConfiguration.cs b/src/Microsoft.Diagnostics.Monitoring.Options/ExceptionsConfiguration.cs index e47bb3953cd..8a44b0c7ae1 100644 --- a/src/Microsoft.Diagnostics.Monitoring.Options/ExceptionsConfiguration.cs +++ b/src/Microsoft.Diagnostics.Monitoring.Options/ExceptionsConfiguration.cs @@ -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. /// [JsonPropertyName("include")] - public List Include { get; set; } = new(); + public List? Include { get; set; } = new(); /// /// 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. /// [JsonPropertyName("exclude")] - public List Exclude { get; set; } = new(); + public List? Exclude { get; set; } = new(); } - public sealed class ExceptionFilter : IMethodDescription + 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; } } } diff --git a/src/Microsoft.Diagnostics.Monitoring.Options/ExceptionsOptions.cs b/src/Microsoft.Diagnostics.Monitoring.Options/ExceptionsOptions.cs index ed638f0c0a0..547c125916f 100644 --- a/src/Microsoft.Diagnostics.Monitoring.Options/ExceptionsOptions.cs +++ b/src/Microsoft.Diagnostics.Monitoring.Options/ExceptionsOptions.cs @@ -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; } } } diff --git a/src/Microsoft.Diagnostics.Monitoring.Options/FileSystemEgressProviderOptions.cs b/src/Microsoft.Diagnostics.Monitoring.Options/FileSystemEgressProviderOptions.cs index d6ceffc2673..0caee405036 100644 --- a/src/Microsoft.Diagnostics.Monitoring.Options/FileSystemEgressProviderOptions.cs +++ b/src/Microsoft.Diagnostics.Monitoring.Options/FileSystemEgressProviderOptions.cs @@ -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), diff --git a/src/Microsoft.Diagnostics.Monitoring.Options/GlobalCounterOptions.cs b/src/Microsoft.Diagnostics.Monitoring.Options/GlobalCounterOptions.cs index ccb83017e09..c360b5184d1 100644 --- a/src/Microsoft.Diagnostics.Monitoring.Options/GlobalCounterOptions.cs +++ b/src/Microsoft.Diagnostics.Monitoring.Options/GlobalCounterOptions.cs @@ -39,7 +39,7 @@ public partial class GlobalCounterOptions [Display( ResourceType = typeof(OptionsDisplayStrings), Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_GlobalCounterOptions_Providers))] - public System.Collections.Generic.IDictionary Providers { get; set; } = new Dictionary(StringComparer.OrdinalIgnoreCase); + public System.Collections.Generic.IDictionary? Providers { get; set; } = new Dictionary(StringComparer.OrdinalIgnoreCase); } public class GlobalProviderOptions @@ -53,15 +53,19 @@ partial class GlobalCounterOptions : IValidatableObject public IEnumerable Validate(ValidationContext validationContext) { var results = new List(); - var providerResults = new List(); - 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(); + 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)))); + } } } @@ -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(); } } diff --git a/src/Microsoft.Diagnostics.Monitoring.Options/InProcessFeaturesOptions.cs b/src/Microsoft.Diagnostics.Monitoring.Options/InProcessFeaturesOptions.cs index 63be112f872..0d7dadbd92f 100644 --- a/src/Microsoft.Diagnostics.Monitoring.Options/InProcessFeaturesOptions.cs +++ b/src/Microsoft.Diagnostics.Monitoring.Options/InProcessFeaturesOptions.cs @@ -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; } } } diff --git a/src/Microsoft.Diagnostics.Monitoring.Options/MetricsOptions.cs b/src/Microsoft.Diagnostics.Monitoring.Options/MetricsOptions.cs index a3bb75c6246..1450284480e 100644 --- a/src/Microsoft.Diagnostics.Monitoring.Options/MetricsOptions.cs +++ b/src/Microsoft.Diagnostics.Monitoring.Options/MetricsOptions.cs @@ -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), @@ -43,12 +43,12 @@ public class MetricsOptions [Display( ResourceType = typeof(OptionsDisplayStrings), Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_MetricsOptions_Providers))] - public List Providers { get; set; } = new List(0); + public List? Providers { get; set; } = new List(0); [Display( ResourceType = typeof(OptionsDisplayStrings), Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_MetricsOptions_Meters))] - public List Meters { get; set; } = new List(0); + public List? Meters { get; set; } = new List(0); } public class MetricProvider @@ -57,12 +57,12 @@ 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 CounterNames { get; set; } = new List(0); + public List? CounterNames { get; set; } = new List(0); } public class MeterConfiguration @@ -70,11 +70,11 @@ 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 InstrumentNames { get; set; } = new List(0); + public List? InstrumentNames { get; set; } = new List(0); } } diff --git a/src/Microsoft.Diagnostics.Monitoring.Options/Microsoft.Diagnostics.Monitoring.Options.csproj b/src/Microsoft.Diagnostics.Monitoring.Options/Microsoft.Diagnostics.Monitoring.Options.csproj index 14275961c91..f11b2d63e0e 100644 --- a/src/Microsoft.Diagnostics.Monitoring.Options/Microsoft.Diagnostics.Monitoring.Options.csproj +++ b/src/Microsoft.Diagnostics.Monitoring.Options/Microsoft.Diagnostics.Monitoring.Options.csproj @@ -8,6 +8,7 @@ $(TestTargetFrameworks) true Library + enable diff --git a/src/Microsoft.Diagnostics.Monitoring.Options/MonitorApiKeyOptions.cs b/src/Microsoft.Diagnostics.Monitoring.Options/MonitorApiKeyOptions.cs index 8f54cce9111..d37c2c6449d 100644 --- a/src/Microsoft.Diagnostics.Monitoring.Options/MonitorApiKeyOptions.cs +++ b/src/Microsoft.Diagnostics.Monitoring.Options/MonitorApiKeyOptions.cs @@ -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; } } } diff --git a/src/Microsoft.Diagnostics.Monitoring.Options/ProcessFilterOptions.cs b/src/Microsoft.Diagnostics.Monitoring.Options/ProcessFilterOptions.cs index 572de62c486..cc6f88ab22b 100644 --- a/src/Microsoft.Diagnostics.Monitoring.Options/ProcessFilterOptions.cs +++ b/src/Microsoft.Diagnostics.Monitoring.Options/ProcessFilterOptions.cs @@ -41,7 +41,7 @@ public sealed class ProcessFilterOptions [Display( ResourceType = typeof(OptionsDisplayStrings), Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_ProcessFilterOptions_Filters))] - public List Filters { get; set; } = new List(0); + public List? Filters { get; set; } = new List(0); } public sealed partial class ProcessFilterDescriptor @@ -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), @@ -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 diff --git a/src/Microsoft.Diagnostics.Monitoring.Options/StorageOptions.cs b/src/Microsoft.Diagnostics.Monitoring.Options/StorageOptions.cs index aaf9240cbbc..39c925fee41 100644 --- a/src/Microsoft.Diagnostics.Monitoring.Options/StorageOptions.cs +++ b/src/Microsoft.Diagnostics.Monitoring.Options/StorageOptions.cs @@ -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; } } } diff --git a/src/Microsoft.Diagnostics.Monitoring.WebApi/Controllers/DiagController.cs b/src/Microsoft.Diagnostics.Monitoring.WebApi/Controllers/DiagController.cs index 60bea0b1635..ea42067a86b 100644 --- a/src/Microsoft.Diagnostics.Monitoring.WebApi/Controllers/DiagController.cs +++ b/src/Microsoft.Diagnostics.Monitoring.WebApi/Controllers/DiagController.cs @@ -500,7 +500,7 @@ public ActionResult 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() { @@ -653,7 +653,7 @@ public Task CaptureStacks( }, processKey, Utilities.ArtifactType_Stacks); } - private string GetDiagnosticPortName() + private string? GetDiagnosticPortName() { return _diagnosticPortOptions.Value.EndpointName; } diff --git a/src/Microsoft.Diagnostics.Monitoring.WebApi/DiagProcessFilter.cs b/src/Microsoft.Diagnostics.Monitoring.WebApi/DiagProcessFilter.cs index 09159e22762..3a417960008 100644 --- a/src/Microsoft.Diagnostics.Monitoring.WebApi/DiagProcessFilter.cs +++ b/src/Microsoft.Diagnostics.Monitoring.WebApi/DiagProcessFilter.cs @@ -36,13 +36,17 @@ public static DiagProcessFilter FromConfiguration(ProcessFilterOptions options) return FromConfiguration(options.Filters); } - public static DiagProcessFilter FromConfiguration(IEnumerable filters) + public static DiagProcessFilter FromConfiguration(IEnumerable? filters) { var filter = new DiagProcessFilter(); - foreach (ProcessFilterDescriptor processFilter in filters) + if (filters != null) { - filter.Filters.Add(TransformDescriptor(processFilter)); + foreach (ProcessFilterDescriptor processFilter in filters) + { + filter.Filters.Add(TransformDescriptor(processFilter)); + } } + return filter; } @@ -96,23 +100,24 @@ private static DiagProcessFilterEntry TransformDescriptor(ProcessFilterDescripto }; } + string filterValue = processFilterDescriptor.Value!; // Guaranteed not to be null by ProcessFilterDescriptor.Validate. switch (processFilterDescriptor.Key) { case ProcessFilterKey.ProcessId: - return new DiagProcessFilterEntry { Criteria = DiagProcessFilterCriteria.ProcessId, MatchType = DiagProcessFilterMatchType.Exact, Value = processFilterDescriptor.Value }; + return new DiagProcessFilterEntry { Criteria = DiagProcessFilterCriteria.ProcessId, MatchType = DiagProcessFilterMatchType.Exact, Value = filterValue }; case ProcessFilterKey.ProcessName: return new DiagProcessFilterEntry { Criteria = DiagProcessFilterCriteria.ProcessName, MatchType = (processFilterDescriptor.MatchType == ProcessFilterType.Exact) ? DiagProcessFilterMatchType.Exact : DiagProcessFilterMatchType.Contains, - Value = processFilterDescriptor.Value + Value = filterValue }; case ProcessFilterKey.CommandLine: return new DiagProcessFilterEntry { Criteria = DiagProcessFilterCriteria.CommandLine, MatchType = (processFilterDescriptor.MatchType == ProcessFilterType.Exact) ? DiagProcessFilterMatchType.Exact : DiagProcessFilterMatchType.Contains, - Value = processFilterDescriptor.Value + Value = filterValue }; default: throw new ArgumentException( diff --git a/src/Microsoft.Diagnostics.Monitoring.WebApi/DumpService.cs b/src/Microsoft.Diagnostics.Monitoring.WebApi/DumpService.cs index 337ff58c6a6..358ee7745d7 100644 --- a/src/Microsoft.Diagnostics.Monitoring.WebApi/DumpService.cs +++ b/src/Microsoft.Diagnostics.Monitoring.WebApi/DumpService.cs @@ -36,7 +36,8 @@ public async Task DumpAsync(IEndpointInfo endpointInfo, Models.DumpType throw new ArgumentNullException(nameof(endpointInfo)); } - string dumpTempFolder = _storageOptions.CurrentValue.DumpTempFolder; + // Guaranteed to not be null by StoragePostConfigureOptions.PostConfigure. + string dumpTempFolder = _storageOptions.CurrentValue.DumpTempFolder!; // Ensure folder exists before issue command. if (!Directory.Exists(dumpTempFolder)) diff --git a/src/Microsoft.Diagnostics.Monitoring.WebApi/Exceptions/ExceptionsSettingsFactory.cs b/src/Microsoft.Diagnostics.Monitoring.WebApi/Exceptions/ExceptionsSettingsFactory.cs index 465f1bce77d..55a6ff5b25c 100644 --- a/src/Microsoft.Diagnostics.Monitoring.WebApi/Exceptions/ExceptionsSettingsFactory.cs +++ b/src/Microsoft.Diagnostics.Monitoring.WebApi/Exceptions/ExceptionsSettingsFactory.cs @@ -19,14 +19,20 @@ public static ExceptionsConfigurationSettings ConvertExceptionsConfiguration(Exc return configurationSettings; } - foreach (var filter in configuration.Include) + if (configuration.Include != null) { - configurationSettings.Include.Add(ConvertExceptionFilter(filter)); + foreach (var filter in configuration.Include) + { + configurationSettings.Include.Add(ConvertExceptionFilter(filter)); + } } - foreach (var filter in configuration.Exclude) + if (configuration.Exclude != null) { - configurationSettings.Exclude.Add(ConvertExceptionFilter(filter)); + foreach (var filter in configuration.Exclude) + { + configurationSettings.Exclude.Add(ConvertExceptionFilter(filter)); + } } return configurationSettings; diff --git a/src/Microsoft.Diagnostics.Monitoring.WebApi/Metrics/MetricsSettingsFactory.cs b/src/Microsoft.Diagnostics.Monitoring.WebApi/Metrics/MetricsSettingsFactory.cs index 06cbe409fa4..3deb2d8d3dc 100644 --- a/src/Microsoft.Diagnostics.Monitoring.WebApi/Metrics/MetricsSettingsFactory.cs +++ b/src/Microsoft.Diagnostics.Monitoring.WebApi/Metrics/MetricsSettingsFactory.cs @@ -54,7 +54,7 @@ public static MetricsPipelineSettings CreateSettings(GlobalCounterOptions counte private static MetricsPipelineSettings CreateSettings(bool includeDefaults, int durationSeconds, float counterInterval, - IDictionary intervalMap, + IDictionary? intervalMap, int maxHistograms, int maxTimeSeries, Func> createCounterGroups) @@ -68,12 +68,15 @@ private static MetricsPipelineSettings CreateSettings(bool includeDefaults, eventPipeCounterGroups.Add(new EventPipeCounterGroup { ProviderName = MonitoringSourceConfiguration.GrpcAspNetCoreServer, Type = CounterGroupType.EventCounter }); } - foreach (EventPipeCounterGroup counterGroup in eventPipeCounterGroups) + if (intervalMap != null) { - if (intervalMap.TryGetValue(counterGroup.ProviderName, out GlobalProviderOptions? providerInterval)) + foreach (EventPipeCounterGroup counterGroup in eventPipeCounterGroups) { - Debug.Assert(counterGroup.IntervalSeconds == null, "Unexpected value for provider interval"); - counterGroup.IntervalSeconds = providerInterval.IntervalSeconds; + if (intervalMap.TryGetValue(counterGroup.ProviderName, out GlobalProviderOptions? providerInterval)) + { + Debug.Assert(counterGroup.IntervalSeconds == null, "Unexpected value for provider interval"); + counterGroup.IntervalSeconds = providerInterval.IntervalSeconds; + } } } @@ -87,7 +90,7 @@ private static MetricsPipelineSettings CreateSettings(bool includeDefaults, }; } - private static List ConvertCounterGroups(IList providers, IList meters) + private static List ConvertCounterGroups(IList? providers, IList? meters) { List counterGroups = new(); diff --git a/src/Microsoft.Diagnostics.Monitoring.WebApi/ProfilerChannel.cs b/src/Microsoft.Diagnostics.Monitoring.WebApi/ProfilerChannel.cs index ce07974f9e1..ddbd9d40bb5 100644 --- a/src/Microsoft.Diagnostics.Monitoring.WebApi/ProfilerChannel.cs +++ b/src/Microsoft.Diagnostics.Monitoring.WebApi/ProfilerChannel.cs @@ -119,8 +119,8 @@ private static async Task ReceiveStatusMessageAsync(Socket socket, Cancella private string ComputeChannelPath(IEndpointInfo endpointInfo) { - string defaultSharedPath = _storageOptions.CurrentValue.DefaultSharedPath; - if (string.IsNullOrEmpty(_storageOptions.CurrentValue.DefaultSharedPath)) + string? defaultSharedPath = _storageOptions.CurrentValue.DefaultSharedPath; + if (string.IsNullOrEmpty(defaultSharedPath)) { //Note this fallback does not work well for sidecar scenarios. defaultSharedPath = Path.GetTempPath();