Skip to content

Commit 7ce3e6f

Browse files
committed
Merge branch 'hostidconfigremoval' into dev
2 parents 7ea34e4 + dcb5d15 commit 7ce3e6f

File tree

16 files changed

+40
-40
lines changed

16 files changed

+40
-40
lines changed

schemas/json/host.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55
"type": "object",
66

77
"properties": {
8-
"id": {
9-
"description": "The unique ID for this job host. Can be a lower case GUID with dashes removed",
10-
"type": "string",
11-
"minLength": 1
12-
},
13-
148
"functions": {
159
"description": "The list of functions the host should load.",
1610
"type": "array",
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"version": "2.0",
3-
"id": "placeholder-host"
2+
"version": "2.0"
43
}

src/WebJobs.Script/Config/ConfigurationSectionNames.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ public static class ConfigurationSectionNames
1010
public const string Logging = "logging";
1111
public const string Aggregator = "aggregator";
1212
public const string HealthMonitor = "healthMonitor";
13+
public const string HostIdPath = WebHost + ":hostid";
1314
}
1415
}

src/WebJobs.Script/Config/HostJsonFileConfigurationSource.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ private class HostJsonFileConfigurationProvider : ConfigurationProvider
4444
{
4545
private static readonly string[] WellKnownHostJsonProperties = new[]
4646
{
47-
"version", "id", "functionTimeout", "functions", "http", "watchDirectories", "queues", "serviceBus",
47+
"version", "functionTimeout", "functions", "http", "watchDirectories", "queues", "serviceBus",
4848
"eventHub", "singleton", "logging", "aggregator", "healthMonitor"
4949
};
5050

@@ -166,13 +166,6 @@ private JObject LoadHostConfigurationFile()
166166
_logger.LogInformation(readingFileMessage);
167167
_logger.LogInformation(readFileMessage);
168168

169-
// TODO: DI (FACAVAL) Move this to a more appropriate place
170-
// If they set the host id in the JSON, emit a warning that this could cause issues and they shouldn't do it.
171-
if (hostConfigObject["id"] != null)
172-
{
173-
_logger.LogWarning("Host id explicitly set in the host.json. It is recommended that you remove the \"id\" property in your host.json.");
174-
}
175-
176169
// TODO: DI (FACAVAL) Move to setup
177170
//if (string.IsNullOrEmpty(_hostOptions.HostId))
178171
//{

src/WebJobs.Script/Host/ScriptHost.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using Microsoft.Azure.WebJobs.Host.Listeners;
2121
using Microsoft.Azure.WebJobs.Logging;
2222
using Microsoft.Azure.WebJobs.Script.Config;
23+
using Microsoft.Azure.WebJobs.Script.Configuration;
2324
using Microsoft.Azure.WebJobs.Script.Description;
2425
using Microsoft.Azure.WebJobs.Script.Diagnostics;
2526
using Microsoft.Azure.WebJobs.Script.Eventing;
@@ -51,6 +52,7 @@ public class ScriptHost : JobHost, IScriptJobHost
5152
private readonly Stopwatch _stopwatch = new Stopwatch();
5253
private readonly string _currentRuntimelanguage;
5354
private readonly IOptions<JobHostOptions> _hostOptions;
55+
private readonly IConfiguration _configuration;
5456
private readonly ScriptTypeLocator _typeLocator;
5557
private readonly IDebugStateProvider _debugManager;
5658
private readonly ICollection<IScriptBindingProvider> _bindingProviders;
@@ -101,6 +103,7 @@ public ScriptHost(IOptions<JobHostOptions> options,
101103

102104
_instanceId = Guid.NewGuid().ToString();
103105
_hostOptions = options;
106+
_configuration = configuration;
104107
_storageConnectionString = configuration.GetWebJobsConnectionString(ConnectionStringNames.Storage);
105108
_distributedLockManager = distributedLockManager;
106109
_functionMetadataManager = functionMetadataManager;
@@ -271,6 +274,12 @@ public async Task InitializeAsync()
271274

272275
private async Task LogInitializationAsync()
273276
{
277+
// If the host id is explicitly set, emit a warning that this could cause issues and shouldn't be done
278+
if (_configuration[ConfigurationSectionNames.HostIdPath] != null)
279+
{
280+
_logger.LogWarning("Host id explicitly set in configuration. This is not a recommended configuration and may lead to unexpected behavior.");
281+
}
282+
274283
string extensionVersion = _environment.GetEnvironmentVariable(EnvironmentSettingNames.FunctionsExtensionVersion);
275284
string hostId = await _hostIdProvider.GetHostIdAsync(CancellationToken.None);
276285
string message = $"Starting Host (HostId={hostId}, InstanceId={InstanceId}, Version={Version}, ProcessId={Process.GetCurrentProcess().Id}, AppDomainId={AppDomain.CurrentDomain.Id}, Debug={InDebugMode}, FunctionsExtensionVersion={extensionVersion})";

src/WebJobs.Script/Host/ScriptHostIdProvider.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.Threading;
88
using System.Threading.Tasks;
99
using Microsoft.Azure.WebJobs.Host.Executors;
10-
using Microsoft.Azure.WebJobs.Script.Config;
1110
using Microsoft.Azure.WebJobs.Script.Configuration;
1211
using Microsoft.Extensions.Configuration;
1312
using Microsoft.Extensions.Options;
@@ -16,7 +15,6 @@ namespace Microsoft.Azure.WebJobs.Script
1615
{
1716
public class ScriptHostIdProvider : IHostIdProvider
1817
{
19-
private const string HostIdPath = ConfigurationSectionNames.JobHost + ":id";
2018
private readonly IConfiguration _config;
2119
private readonly IEnvironment _environment;
2220
private readonly IOptionsMonitor<ScriptApplicationHostOptions> _options;
@@ -30,7 +28,7 @@ public ScriptHostIdProvider(IConfiguration config, IEnvironment environment, IOp
3028

3129
public Task<string> GetHostIdAsync(CancellationToken cancellationToken)
3230
{
33-
return Task.FromResult(_config[HostIdPath] ?? GetDefaultHostId(_environment, _options.CurrentValue));
31+
return Task.FromResult(_config[ConfigurationSectionNames.HostIdPath] ?? GetDefaultHostId(_environment, _options.CurrentValue));
3432
}
3533

3634
internal static string GetDefaultHostId(IEnvironment environment, ScriptApplicationHostOptions scriptOptions)
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"version": "2.0",
3-
"id": "function-tests-csharp"
2+
"version": "2.0"
43
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"version": "2.0",
3-
"id": "function-tests-dotnet-direct"
2+
"version": "2.0"
43
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"version": "2.0",
3-
"id": "function-tests-dotnet"
2+
"version": "2.0"
43
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"version": "2.0",
3-
"id": "function-tests-fsharp"
2+
"version": "2.0"
43
}

0 commit comments

Comments
 (0)