Skip to content

Commit

Permalink
Revert "Use single instance of WebhostMetricsLogger"
Browse files Browse the repository at this point in the history
This reverts commit e9d2df3.
  • Loading branch information
yojagad committed Oct 3, 2019
1 parent bbb8762 commit 5400db5
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private static ExpectedDependencyBuilder CreateExpectedDependencies()
expected.ExpectNone<IEventGenerator>();

expected.Expect<ILoggerFactory, ScriptLoggerFactory>();
expected.ExpectInstance<IMetricsLogger, WebHostMetricsLogger>();
expected.Expect<IMetricsLogger, WebHostMetricsLogger>();

expected.Expect<IWebJobsExceptionHandler, WebScriptHostExceptionHandler>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ public static void AddWebJobsScriptHost(this IServiceCollection services, IConfi
services.AddTransient<VirtualFileSystem>();
services.AddTransient<VirtualFileSystemMiddleware>();

// Logging and diagnostics
services.AddSingleton<IMetricsLogger, WebHostMetricsLogger>();

// Secret management
services.TryAddSingleton<ISecretManagerProvider, DefaultSecretManagerProvider>();

Expand Down
8 changes: 1 addition & 7 deletions src/WebJobs.Script.WebHost/WebScriptHostBuilderExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,7 @@ public static IHostBuilder AddWebScriptHost(this IHostBuilder builder, IServiceP
}

// Logging and diagnostics
// Get WebHostMetricsLogger registered at webhost
IMetricsLogger metricsLogger = rootServiceProvider.GetService<IMetricsLogger>();
if (metricsLogger != null)
{
services.AddSingleton(metricsLogger);
}

services.AddSingleton<IMetricsLogger, WebHostMetricsLogger>();
services.AddSingleton<IEventCollectorProvider, FunctionInstanceLogCollectorProvider>();

// Hosted services
Expand Down
3 changes: 0 additions & 3 deletions src/WebJobs.Script/ScriptHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,7 @@ public static IHostBuilder AddScriptHostCore(this IHostBuilder builder, ScriptAp
services.AddSingleton<ITypeLocator, ScriptTypeLocator>();
services.AddSingleton<ScriptSettingsManager>();
services.AddTransient<IExtensionsManager, ExtensionsManager>();

// Fallback option if webhost is not present.
services.TryAddSingleton<IMetricsLogger, MetricsLogger>();

services.TryAddSingleton<IScriptJobHostEnvironment, ConsoleScriptJobHostEnvironment>();
services.AddTransient<IExtensionBundleContentProvider, ExtensionBundleContentProvider>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ private RunDependencies CreateDependencies(Action<IServiceCollection> configureS
compilationServiceFactory.Setup(f => f.CreateService(DotNetScriptTypes.CSharp, It.IsAny<IFunctionMetadataResolver>()))
.Returns(compilationService.Object);

var metricsLogger = new MetricsLogger();

var hostBuilder = new HostBuilder()
.ConfigureDefaultTestWebScriptHost(o =>
{
Expand All @@ -459,7 +461,7 @@ private RunDependencies CreateDependencies(Action<IServiceCollection> configureS
CompilationServiceFactory = compilationServiceFactory,
LoggerProvider = loggerProvider,
LoggerFactory = loggerFactory,
MetricsLogger = new TestMetricsLogger(),
MetricsLogger = metricsLogger
};
}

Expand Down Expand Up @@ -493,7 +495,7 @@ private class RunDependencies

public ILoggerFactory LoggerFactory { get; set; }

public IMetricsLogger MetricsLogger { get; set; }
public MetricsLogger MetricsLogger { get; set; }
}
}
}

0 comments on commit 5400db5

Please sign in to comment.