Skip to content

Commit eefe40a

Browse files
Derive host Id from hostName for Linux consumption (#5507)
1 parent 2990a47 commit eefe40a

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/WebJobs.Script/Host/ScriptHostIdProvider.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ internal static string GetDefaultHostId(IEnvironment environment, ScriptApplicat
4848
}
4949
else if (environment.IsLinuxConsumption())
5050
{
51-
// The hostid is derived from the unique container name for Linux consumption.
52-
hostId = environment.GetEnvironmentVariable(EnvironmentSettingNames.ContainerName);
51+
// The hostid is derived from the hostname for Linux consumption.
52+
string hostName = environment.GetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteHostName);
53+
hostId = hostName?.Replace(".azurewebsites.net", string.Empty);
5354
}
5455
else
5556
{

test/WebJobs.Script.Tests.Integration/Host/StandbyManager/StandbyManagerE2ETests_Linux.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public async Task StandbyModeE2E_LinuxContainer()
3838
{
3939
{ EnvironmentSettingNames.AzureWebsitePlaceholderMode, "1" },
4040
{ EnvironmentSettingNames.ContainerName, containerName },
41+
{ EnvironmentSettingNames.AzureWebsiteHostName, "testapp.azurewebsites.net" },
4142
{ EnvironmentSettingNames.AzureWebsiteName, "TestApp" },
4243
{ EnvironmentSettingNames.ContainerEncryptionKey, encryptionKey },
4344
{ EnvironmentSettingNames.AzureWebsiteContainerReady, null },
@@ -97,7 +98,7 @@ public async Task StandbyModeE2E_LinuxContainer()
9798
response = await _httpClient.SendAsync(request);
9899
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
99100

100-
string hostId = containerName.ToLowerInvariant();
101+
string hostId = "testapp";
101102

102103
// verify the expected logs
103104
var logLines = _loggerProvider.GetAllLogMessages().Where(p => p.FormattedMessage != null).Select(p => p.FormattedMessage).ToArray();

test/WebJobs.Script.Tests/ScriptHostIdProviderTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public async Task GetHostIdAsync_WithConfigurationHostId_ReturnsConfigurationHos
4040
[InlineData("TEST-FUNCTIONS--", "123123", "test-functions")]
4141
[InlineData("TEST-FUNCTIONS-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "123123", "test-functions-xxxxxxxxxxxxxxxxx")]
4242
[InlineData("TEST-FUNCTIONS-XXXXXXXXXXXXXXXX-XXXX", "123123", "test-functions-xxxxxxxxxxxxxxxx")] /* 32nd character is a '-' */
43-
[InlineData("TEST-FUNCTIONS-XXXXXXXXXXXXXXXX-XXXX", null, "f6c34226-637100850484032865")] // Linux consumption scenario where host id will be derived from the container name.
43+
[InlineData("TEST-FUNCTIONS-XXXXXXXXXXXXXXXX-XXXX", null, "testsite")] // Linux consumption scenario where host id will be derived from the host name.
4444
[InlineData(null, "123123", null)]
4545
public void GetDefaultHostId_AzureHost_ReturnsExpectedResult(string siteName, string azureWebsiteInstanceId, string expected)
4646
{
@@ -52,7 +52,8 @@ public void GetDefaultHostId_AzureHost_ReturnsExpectedResult(string siteName, st
5252
var environment = new TestEnvironment();
5353
environment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteInstanceId, azureWebsiteInstanceId);
5454
environment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteName, siteName);
55-
environment.SetEnvironmentVariable(EnvironmentSettingNames.ContainerName, "F6C34226-637100850484032865");
55+
environment.SetEnvironmentVariable(EnvironmentSettingNames.ContainerName, "testContainer");
56+
environment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteHostName, "testsite.azurewebsites.net");
5657
string hostId = ScriptHostIdProvider.GetDefaultHostId(environment, options);
5758
Assert.Equal(expected, hostId);
5859
}

0 commit comments

Comments
 (0)