Skip to content

Commit a7688d6

Browse files
authored
Adding "isDefaultHostConfig" to host json WellKnownHostJsonProperties (#11133)
1 parent 9d6da71 commit a7688d6

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

src/WebJobs.Script/Config/HostJsonFileConfigurationSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class HostJsonFileConfigurationProvider : ConfigurationProvider
5252
"version", "functionTimeout", "retry", "functions", "http", "watchDirectories", "watchFiles", "queues", "serviceBus",
5353
"eventHub", "singleton", "logging", "aggregator", "healthMonitor", "extensionBundle", "managedDependencies",
5454
"customHandler", "httpWorker", "extensions", "concurrency", "telemetryMode", ConfigurationSectionNames.SendCanceledInvocationsToWorker,
55-
ConfigurationSectionNames.MetadataProviderTimeout
55+
ConfigurationSectionNames.MetadataProviderTimeout, "isDefaultHostConfig"
5656
};
5757

5858
private readonly HostJsonFileConfigurationSource _configurationSource;

test/WebJobs.Script.Tests/Configuration/HostJsonFileConfigurationSourceTests.cs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public HostJsonFileConfigurationSourceTests()
4949
}
5050

5151
[Fact]
52-
public void MissingHostJson_CreatesHostJson_withDefaultExtensionBundleId()
52+
public void MissingHostJson_GeneratesExpectedDefaultConfigFile()
5353
{
5454
Assert.False(File.Exists(_hostJsonFile));
5555
TestMetricsLogger testMetricsLogger = new TestMetricsLogger();
@@ -58,14 +58,17 @@ public void MissingHostJson_CreatesHostJson_withDefaultExtensionBundleId()
5858

5959
AreExpectedMetricsGenerated(testMetricsLogger);
6060

61+
// verify actual file content
6162
Assert.Equal(_hostJsonWithBundles, File.ReadAllText(_hostJsonFile));
6263

63-
var log = _loggerProvider.GetAllLogMessages().Single(l => l.FormattedMessage == "No host configuration file found. Creating a default host.json file.");
64-
Assert.Equal(LogLevel.Information, log.Level);
64+
// verify log messages
65+
var logs = _loggerProvider.GetAllLogMessages();
66+
Assert.Single(logs.Where(l => l.Level == LogLevel.Information && l.FormattedMessage == "No host configuration file found. Creating a default host.json file."));
67+
VerifySanitizedHostConfigLog(logs, ScriptConstants.DefaultExtensionBundleId, ScriptConstants.DefaultExtensionBundleVersion);
6568
}
6669

6770
[Fact]
68-
public void MissingHostJson_CreatesHostJson_withWorkFlowExtensionBundleId()
71+
public void MissingHostJson_WorkflowApp_GeneratesExpectedDefaultConfigFile()
6972
{
7073
var environment = new TestEnvironment(new Dictionary<string, string>
7174
{
@@ -79,10 +82,13 @@ public void MissingHostJson_CreatesHostJson_withWorkFlowExtensionBundleId()
7982

8083
AreExpectedMetricsGenerated(testMetricsLogger);
8184

85+
// verify actual file content
8286
Assert.Equal(_hostJsonWithWorkFlowBundle, File.ReadAllText(_hostJsonFile));
8387

84-
var log = _loggerProvider.GetAllLogMessages().Single(l => l.FormattedMessage == "No host configuration file found. Creating a default host.json file.");
85-
Assert.Equal(LogLevel.Information, log.Level);
88+
// verify log messages
89+
var logs = _loggerProvider.GetAllLogMessages();
90+
Assert.Single(logs.Where(l => l.Level == LogLevel.Information && l.FormattedMessage == "No host configuration file found. Creating a default host.json file."));
91+
VerifySanitizedHostConfigLog(logs, ScriptConstants.WorkFlowExtensionBundleId, ScriptConstants.LogicAppDefaultExtensionBundleVersion);
8692
}
8793

8894
[Theory]
@@ -279,5 +285,21 @@ private bool AreExpectedMetricsGenerated(TestMetricsLogger metricsLogger)
279285
&& metricsLogger.EventsBegan.Contains(MetricEventNames.LoadHostConfiguration) && metricsLogger.EventsEnded.Contains(MetricEventNames.LoadHostConfiguration)
280286
&& metricsLogger.EventsBegan.Contains(MetricEventNames.InitializeHostConfiguration) && metricsLogger.EventsEnded.Contains(MetricEventNames.InitializeHostConfiguration);
281287
}
288+
289+
private static void VerifySanitizedHostConfigLog(IList<LogMessage> logs, string expectedBundleId, string expectedBundleVersionSpec)
290+
{
291+
var hostJsonLog = logs.Single(p => p.EventId.Name == "HostConfigRead");
292+
Assert.Equal(LogLevel.Information, hostJsonLog.Level);
293+
string sanitizedJson = (string)hostJsonLog.State.ToDictionary()["sanitizedJson"];
294+
var jo = JObject.Parse(sanitizedJson);
295+
296+
Assert.Equal(3, jo.Count);
297+
Assert.Equal("2.0", jo["version"]);
298+
Assert.Equal(true, jo["isDefaultHostConfig"]);
299+
300+
var bundleConfig = jo["extensionBundle"];
301+
Assert.Equal(expectedBundleId, bundleConfig["id"]);
302+
Assert.Equal(expectedBundleVersionSpec, bundleConfig["version"]);
303+
}
282304
}
283305
}

0 commit comments

Comments
 (0)