From fa05c3fb760ec4aab9492072055db27c22f2b0ef Mon Sep 17 00:00:00 2001 From: Joel Verhagen Date: Wed, 8 Apr 2020 11:56:29 -0700 Subject: [PATCH] Add build hook for closed-source assemblies (#763) Activate assembly modules and add more base configuration types to DI Consider 4XX as successfully for telemetry purposes Add KnownOperation for the V3 search endpoint Progress on https://github.com/NuGet/Engineering/issues/3020 --- sign.thirdparty.props | 1 + .../NuGet.Services.Metadata.Catalog.csproj | 4 +-- src/Ng/Ng.csproj | 8 ++--- ...ervices.Metadata.Catalog.Monitoring.csproj | 2 +- .../App_Start/WebApiConfig.cs | 33 +++++++++++++++++-- .../NuGet.Services.SearchService.csproj | 26 ++------------- src/NuGet.Services.SearchService/Web.config | 6 +++- tests/CatalogTests/CatalogTests.csproj | 2 +- tests/NgTests/NgTests.csproj | 4 +-- ...ervices.AzureSearch.FunctionalTests.csproj | 2 +- 10 files changed, 50 insertions(+), 38 deletions(-) diff --git a/sign.thirdparty.props b/sign.thirdparty.props index d80a59cbb..09a954a98 100644 --- a/sign.thirdparty.props +++ b/sign.thirdparty.props @@ -4,6 +4,7 @@ + diff --git a/src/Catalog/NuGet.Services.Metadata.Catalog.csproj b/src/Catalog/NuGet.Services.Metadata.Catalog.csproj index 5e7e990a9..d73f674ae 100644 --- a/src/Catalog/NuGet.Services.Metadata.Catalog.csproj +++ b/src/Catalog/NuGet.Services.Metadata.Catalog.csproj @@ -292,7 +292,7 @@ 4.4.5-dev-3612899 - 2.74.0 + 2.75.0 1.0.6 @@ -309,7 +309,7 @@ all - 2.74.0 + 2.75.0 9.3.3 diff --git a/src/Ng/Ng.csproj b/src/Ng/Ng.csproj index bf8c69d21..ca454022b 100644 --- a/src/Ng/Ng.csproj +++ b/src/Ng/Ng.csproj @@ -164,16 +164,16 @@ all - 2.74.0 + 2.75.0 - 2.74.0 + 2.75.0 - 2.74.0 + 2.75.0 - 2.74.0 + 2.75.0 4.0.0 diff --git a/src/NuGet.Services.Metadata.Catalog.Monitoring/NuGet.Services.Metadata.Catalog.Monitoring.csproj b/src/NuGet.Services.Metadata.Catalog.Monitoring/NuGet.Services.Metadata.Catalog.Monitoring.csproj index 9b33b21d3..00ab42bfb 100644 --- a/src/NuGet.Services.Metadata.Catalog.Monitoring/NuGet.Services.Metadata.Catalog.Monitoring.csproj +++ b/src/NuGet.Services.Metadata.Catalog.Monitoring/NuGet.Services.Metadata.Catalog.Monitoring.csproj @@ -172,7 +172,7 @@ all - 2.74.0 + 2.75.0 diff --git a/src/NuGet.Services.SearchService/App_Start/WebApiConfig.cs b/src/NuGet.Services.SearchService/App_Start/WebApiConfig.cs index 94ed96efe..42b43ecdb 100644 --- a/src/NuGet.Services.SearchService/App_Start/WebApiConfig.cs +++ b/src/NuGet.Services.SearchService/App_Start/WebApiConfig.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Net.Http; using System.Reflection; using System.Threading; using System.Threading.Tasks; @@ -142,6 +143,8 @@ private static AutofacWebApiDependencyResolver GetDependencyResolver(HttpConfigu var services = new ServiceCollection(); services.AddSingleton(configuration.SecretReaderFactory); + services.AddSingleton(applicationInsightsConfiguration.TelemetryConfiguration); + services.AddSingleton(configuration.Root); services.Add(ServiceDescriptor.Scoped(typeof(IOptionsSnapshot<>), typeof(NonCachingOptionsSnapshot<>))); services.Configure(configuration.Root.GetSection(ConfigurationSectionName)); services.Configure(configuration.Root.GetSection(ConfigurationSectionName)); @@ -150,6 +153,7 @@ private static AutofacWebApiDependencyResolver GetDependencyResolver(HttpConfigu services.AddTransient(); var builder = new ContainerBuilder(); + builder.RegisterAssemblyModules(typeof(WebApiConfig).Assembly); builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); builder.RegisterWebApiFilterProvider(config); builder.RegisterWebApiModelBinderProvider(); @@ -174,10 +178,30 @@ private static ApplicationInsightsConfiguration InitializeApplicationInsights(Re var heartbeatIntervalSeconds = configuration.Root.GetValue("ApplicationInsights_HeartbeatIntervalSeconds", 60); var applicationInsightsConfiguration = ApplicationInsights.Initialize( - instrumentationKey, - TimeSpan.FromSeconds(heartbeatIntervalSeconds)); + instrumentationKey, + TimeSpan.FromSeconds(heartbeatIntervalSeconds)); applicationInsightsConfiguration.TelemetryConfiguration.TelemetryInitializers.Add(new AzureWebAppTelemetryInitializer()); + applicationInsightsConfiguration.TelemetryConfiguration.TelemetryInitializers.Add(new KnownOperationNameEnricher(new[] + { + GetOperationName(HttpMethod.Get, nameof(SearchController.AutocompleteAsync)), + GetOperationName(HttpMethod.Get, nameof(SearchController.IndexAsync)), + GetOperationName(HttpMethod.Get, nameof(SearchController.GetStatusAsync)), + GetOperationName(HttpMethod.Get, nameof(SearchController.V2SearchAsync)), + GetOperationName(HttpMethod.Get, nameof(SearchController.V3SearchAsync)), + })); + + applicationInsightsConfiguration.TelemetryConfiguration.TelemetryProcessorChainBuilder.Use(next => + { + var processor = new RequestTelemetryProcessor(next); + + processor.SuccessfulResponseCodes.Add(400); + processor.SuccessfulResponseCodes.Add(403); + processor.SuccessfulResponseCodes.Add(404); + processor.SuccessfulResponseCodes.Add(405); + + return processor; + }); RegisterApplicationInsightsTelemetryModules(applicationInsightsConfiguration.TelemetryConfiguration); @@ -318,6 +342,11 @@ private static string GetControllerName() where T : ApiController throw new ArgumentException($"The controller type name must end with '{ControllerSuffix}'."); } + private static string GetOperationName(HttpMethod verb, string actionName) where T : ApiController + { + return $"{verb} {GetControllerName()}/{actionName}"; + } + private class RefreshableConfiguration { public IRefreshableSecretReaderFactory SecretReaderFactory { get; set; } diff --git a/src/NuGet.Services.SearchService/NuGet.Services.SearchService.csproj b/src/NuGet.Services.SearchService/NuGet.Services.SearchService.csproj index 98487d8f0..e8502fdb2 100644 --- a/src/NuGet.Services.SearchService/NuGet.Services.SearchService.csproj +++ b/src/NuGet.Services.SearchService/NuGet.Services.SearchService.csproj @@ -1,5 +1,6 @@  + Debug AnyCPU @@ -114,31 +115,8 @@ none - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/src/NuGet.Services.SearchService/Web.config b/src/NuGet.Services.SearchService/Web.config index c26b3dff6..7e81f8d8a 100644 --- a/src/NuGet.Services.SearchService/Web.config +++ b/src/NuGet.Services.SearchService/Web.config @@ -6,7 +6,7 @@ - + @@ -23,6 +23,10 @@ + + + + diff --git a/tests/CatalogTests/CatalogTests.csproj b/tests/CatalogTests/CatalogTests.csproj index b75dd8720..e6944c82d 100644 --- a/tests/CatalogTests/CatalogTests.csproj +++ b/tests/CatalogTests/CatalogTests.csproj @@ -337,7 +337,7 @@ 4.10.1 - 2.74.0 + 2.75.0 2.4.1 diff --git a/tests/NgTests/NgTests.csproj b/tests/NgTests/NgTests.csproj index b36e5807d..86dfafc0b 100644 --- a/tests/NgTests/NgTests.csproj +++ b/tests/NgTests/NgTests.csproj @@ -190,10 +190,10 @@ 4.10.1 - 2.74.0 + 2.75.0 - 2.74.0 + 2.75.0 2.4.1 diff --git a/tests/NuGet.Services.AzureSearch.FunctionalTests/NuGet.Services.AzureSearch.FunctionalTests.csproj b/tests/NuGet.Services.AzureSearch.FunctionalTests/NuGet.Services.AzureSearch.FunctionalTests.csproj index 641fff887..471e82c58 100644 --- a/tests/NuGet.Services.AzureSearch.FunctionalTests/NuGet.Services.AzureSearch.FunctionalTests.csproj +++ b/tests/NuGet.Services.AzureSearch.FunctionalTests/NuGet.Services.AzureSearch.FunctionalTests.csproj @@ -76,7 +76,7 @@ 2.2.0 - 2.74.0 + 2.75.0 5.0.0-preview1.5707