diff --git a/src/Microsoft.Diagnostics.Monitoring.WebApi/Controllers/ControllerExtensions.cs b/src/Microsoft.Diagnostics.Monitoring.WebApi/Controllers/ControllerExtensions.cs index e595b1a5d87..86cdf7c4ec0 100644 --- a/src/Microsoft.Diagnostics.Monitoring.WebApi/Controllers/ControllerExtensions.cs +++ b/src/Microsoft.Diagnostics.Monitoring.WebApi/Controllers/ControllerExtensions.cs @@ -17,6 +17,15 @@ namespace Microsoft.Diagnostics.Monitoring.WebApi.Controllers { internal static class ControllerExtensions { + public static ActionResult FeatureNotEnabled(this ControllerBase controller, string featureName) + { + return new BadRequestObjectResult(new ProblemDetails() + { + Detail = string.Format(Strings.Message_FeatureNotEnabled, featureName), + Status = StatusCodes.Status400BadRequest + }); + } + public static ActionResult NotAcceptable(this ControllerBase controller) { return new StatusCodeResult((int)HttpStatusCode.NotAcceptable); diff --git a/src/Microsoft.Diagnostics.Monitoring.WebApi/Controllers/DiagController.cs b/src/Microsoft.Diagnostics.Monitoring.WebApi/Controllers/DiagController.cs index db2fbfbb865..988f547da60 100644 --- a/src/Microsoft.Diagnostics.Monitoring.WebApi/Controllers/DiagController.cs +++ b/src/Microsoft.Diagnostics.Monitoring.WebApi/Controllers/DiagController.cs @@ -584,7 +584,7 @@ public async Task CaptureParameters( { if (!_parameterCapturingOptions.Value.GetEnabled()) { - return NotFound(); + return this.FeatureNotEnabled(Strings.FeatureName_ParameterCapturing); } ProcessKey? processKey = Utilities.GetProcessKey(pid, uid, name); @@ -617,7 +617,7 @@ public Task CaptureStacks( { if (!_callStacksOptions.Value.GetEnabled()) { - return Task.FromResult(NotFound()); + return Task.FromResult(this.FeatureNotEnabled(Strings.FeatureName_CallStacks)); } ProcessKey? processKey = Utilities.GetProcessKey(pid, uid, name); diff --git a/src/Microsoft.Diagnostics.Monitoring.WebApi/Controllers/ExceptionsController.cs b/src/Microsoft.Diagnostics.Monitoring.WebApi/Controllers/ExceptionsController.cs index 0f634f36e95..30a644ba45f 100644 --- a/src/Microsoft.Diagnostics.Monitoring.WebApi/Controllers/ExceptionsController.cs +++ b/src/Microsoft.Diagnostics.Monitoring.WebApi/Controllers/ExceptionsController.cs @@ -6,7 +6,6 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Diagnostics.Monitoring.Options; using Microsoft.Diagnostics.Monitoring.WebApi.Exceptions; -using Microsoft.Diagnostics.Monitoring.WebApi.Models; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -64,7 +63,7 @@ public Task GetExceptions( { if (!_options.Value.GetEnabled()) { - return Task.FromResult(NotFound()); + return Task.FromResult(this.FeatureNotEnabled(Strings.FeatureName_Exceptions)); } ProcessKey? processKey = Utilities.GetProcessKey(pid, uid, name); diff --git a/src/Microsoft.Diagnostics.Monitoring.WebApi/Strings.Designer.cs b/src/Microsoft.Diagnostics.Monitoring.WebApi/Strings.Designer.cs index 350dfdf3791..04bc00e1768 100644 --- a/src/Microsoft.Diagnostics.Monitoring.WebApi/Strings.Designer.cs +++ b/src/Microsoft.Diagnostics.Monitoring.WebApi/Strings.Designer.cs @@ -276,6 +276,33 @@ internal static string ErrorMessage_ValueNotString { } } + /// + /// Looks up a localized string similar to Call Stacks. + /// + internal static string FeatureName_CallStacks { + get { + return ResourceManager.GetString("FeatureName_CallStacks", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Exceptions. + /// + internal static string FeatureName_Exceptions { + get { + return ResourceManager.GetString("FeatureName_Exceptions", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Parameter Capturing. + /// + internal static string FeatureName_ParameterCapturing { + get { + return ResourceManager.GetString("FeatureName_ParameterCapturing", resourceCulture); + } + } + /// /// Looks up a localized string similar to The counter {0} ended and is no longer receiving metrics.. /// @@ -492,6 +519,15 @@ internal static string Message_CollectionRuleStateReason_Throttled { } } + /// + /// Looks up a localized string similar to The '{0}' feature is not enabled.. + /// + internal static string Message_FeatureNotEnabled { + get { + return ResourceManager.GetString("Message_FeatureNotEnabled", resourceCulture); + } + } + /// /// Looks up a localized string similar to Finished generating in-process artifact. /// diff --git a/src/Microsoft.Diagnostics.Monitoring.WebApi/Strings.resx b/src/Microsoft.Diagnostics.Monitoring.WebApi/Strings.resx index 23213385dbc..3c0ed672c57 100644 --- a/src/Microsoft.Diagnostics.Monitoring.WebApi/Strings.resx +++ b/src/Microsoft.Diagnostics.Monitoring.WebApi/Strings.resx @@ -213,6 +213,15 @@ Value must be of type string. Gets a string similar to "Value must be of type string.". + + Call Stacks + + + Exceptions + + + Parameter Capturing + The counter {0} ended and is no longer receiving metrics. @@ -314,6 +323,9 @@ This collection rule is temporarily throttled because the ActionCountLimit has been reached within the ActionCountSlidingWindowDuration. + + The '{0}' feature is not enabled. + Finished generating in-process artifact diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests/StacksTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests/StacksTests.cs index cfbdd66b39c..dc211ce2950 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests/StacksTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests/StacksTests.cs @@ -247,8 +247,8 @@ public Task TestInProcessFeaturesEnabledCallStacksDisabled(Architecture targetAr { int processId = await runner.ProcessIdTask; - ApiStatusCodeException ex = await Assert.ThrowsAsync(() => client.CaptureStacksAsync(processId, WebApi.StackFormat.Json)); - Assert.Equal(HttpStatusCode.NotFound, ex.StatusCode); + ValidationProblemDetailsException ex = await Assert.ThrowsAsync(() => client.CaptureStacksAsync(processId, WebApi.StackFormat.Json)); + Assert.Equal(HttpStatusCode.BadRequest, ex.StatusCode); await runner.SendCommandAsync(TestAppScenarios.Stacks.Commands.Continue); }, @@ -279,8 +279,8 @@ public Task TestInProcessFeaturesDisabledCallStacksEnabled(Architecture targetAr { int processId = await runner.ProcessIdTask; - ApiStatusCodeException ex = await Assert.ThrowsAsync(() => client.CaptureStacksAsync(processId, WebApi.StackFormat.Json)); - Assert.Equal(HttpStatusCode.NotFound, ex.StatusCode); + ValidationProblemDetailsException ex = await Assert.ThrowsAsync(() => client.CaptureStacksAsync(processId, WebApi.StackFormat.Json)); + Assert.Equal(HttpStatusCode.BadRequest, ex.StatusCode); await runner.SendCommandAsync(TestAppScenarios.Stacks.Commands.Continue); }, diff --git a/src/Tools/dotnet-monitor/Experimental/ExperimentalStartupLogger.cs b/src/Tools/dotnet-monitor/Experimental/ExperimentalStartupLogger.cs index a66b10aa1aa..0a69300b6d5 100644 --- a/src/Tools/dotnet-monitor/Experimental/ExperimentalStartupLogger.cs +++ b/src/Tools/dotnet-monitor/Experimental/ExperimentalStartupLogger.cs @@ -23,7 +23,7 @@ public void Log() { if (_parameterCapturingOptions.GetEnabled()) { - _logger.ExperimentalFeatureEnabled(Strings.FeatureName_ParameterCapturing); + _logger.ExperimentalFeatureEnabled(Microsoft.Diagnostics.Monitoring.WebApi.Strings.FeatureName_ParameterCapturing); } // Experimental features should log a warning when they are activated e.g. diff --git a/src/Tools/dotnet-monitor/Strings.Designer.cs b/src/Tools/dotnet-monitor/Strings.Designer.cs index 8c27890e6d8..f78a5abf928 100644 --- a/src/Tools/dotnet-monitor/Strings.Designer.cs +++ b/src/Tools/dotnet-monitor/Strings.Designer.cs @@ -592,33 +592,6 @@ internal static string ErrorMessage_UnknownTriggerType { } } - /// - /// Looks up a localized string similar to Call Stacks. - /// - internal static string FeatureName_CallStacks { - get { - return ResourceManager.GetString("FeatureName_CallStacks", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Exceptions. - /// - internal static string FeatureName_Exceptions { - get { - return ResourceManager.GetString("FeatureName_Exceptions", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Parameter Capturing. - /// - internal static string FeatureName_ParameterCapturing { - get { - return ResourceManager.GetString("FeatureName_ParameterCapturing", resourceCulture); - } - } - /// /// Looks up a localized string similar to Monitor logs and metrics in a .NET application send the results to a chosen destination.. /// diff --git a/src/Tools/dotnet-monitor/Strings.resx b/src/Tools/dotnet-monitor/Strings.resx index a1e52979aa9..b5a53b94af6 100644 --- a/src/Tools/dotnet-monitor/Strings.resx +++ b/src/Tools/dotnet-monitor/Strings.resx @@ -377,12 +377,6 @@ '{0}' is not a known trigger type. {0} = The type of trigger that is unknown. - - Call Stacks - - - Exceptions - Monitor logs and metrics in a .NET application send the results to a chosen destination. Gets the string to display in help that explains what the 'collect' command does. @@ -913,9 +907,6 @@ 0. providerName: The name of the provider that failed validation. 1. errorMessage: The validation failure message - - Parameter Capturing - Unable to find hosting startup assembly at determined path.