Skip to content

Commit

Permalink
Fix runtime version telemetry logging (Azure#5680)
Browse files Browse the repository at this point in the history
  • Loading branch information
divyagandhisethi authored Feb 21, 2020
1 parent 999f47e commit 8d619f4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 47 deletions.
1 change: 0 additions & 1 deletion src/WebJobs.Script/Environment/EnvironmentSettingNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public static class EnvironmentSettingNames
public const string AppInsightsConnectionString = "APPLICATIONINSIGHTS_CONNECTION_STRING";
public const string AppInsightsQuickPulseAuthApiKey = "APPINSIGHTS_QUICKPULSEAUTHAPIKEY";
public const string FunctionsExtensionVersion = "FUNCTIONS_EXTENSION_VERSION";
public const string WebsiteNodeDefaultVersion = "WEBSITE_NODE_DEFAULT_VERSION";
public const string ContainerName = "CONTAINER_NAME";
public const string WebSiteHomeStampName = "WEBSITE_HOME_STAMPNAME";
public const string WebSiteStampDeploymentId = "WEBSITE_STAMP_DEPLOYMENT_ID";
Expand Down
46 changes: 14 additions & 32 deletions src/WebJobs.Script/Host/ScriptHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,20 @@ public async Task InitializeAsync(CancellationToken cancellationToken = default)

if (!_environment.IsPlaceholderModeEnabled())
{
// Appending the runtime version is currently only enabled for linux consumption.
// This will be eventually enabled for Windows Consumption as well.
string runtimeStack = GetPreciseRuntimeStack(_workerRuntime);
string runtimeStack = _workerRuntime;

if (!string.IsNullOrEmpty(_environment.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName)))
{
// Appending the runtime version is currently only enabled for linux consumption. This will be eventually enabled for
// Windows Consumption as well.
string runtimeVersion = _environment.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeVersionSettingName);

if (!string.IsNullOrEmpty(runtimeVersion))
{
runtimeStack = string.Concat(runtimeStack, "-", runtimeVersion);
}
}

_metricsLogger.LogEvent(string.Format(MetricEventNames.HostStartupRuntimeLanguage, runtimeStack));
}

Expand All @@ -292,35 +303,6 @@ public async Task InitializeAsync(CancellationToken cancellationToken = default)
}
}

/// <summary>
/// Appends specific functions worker runtime version after runtime stack
/// </summary>
/// <returns>A string contains specific runtime stack (e.g. python-3.6, dotnet-~2) or single stack</returns>
private string GetPreciseRuntimeStack(string runtime)
{
string runtimeStack = runtime?.ToLower() ?? string.Empty;
string preciseRuntime = string.Empty;
switch (runtimeStack)
{
case "dotnet":
// Get Dotnet version from FUNCTIONS_EXTENSION_VERSION
preciseRuntime = $"dotnet-{_environment.GetEnvironmentVariable(EnvironmentSettingNames.FunctionsExtensionVersion)}";
break;
case "node":
// Get Node version from WEBSITE_NODE_DEFAULT_VERSION
preciseRuntime = $"node-{_environment.GetEnvironmentVariable(EnvironmentSettingNames.WebsiteNodeDefaultVersion)}";
break;
case "python":
preciseRuntime = $"python-{_environment.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeVersionSettingName)}";
break;
default:
// PowerShell, Java only has single version
preciseRuntime = runtimeStack;
break;
}
return preciseRuntime.TrimEnd('-');
}

private async Task LogInitializationAsync()
{
// If the host id is explicitly set, emit a warning that this could cause issues and shouldn't be done
Expand Down
24 changes: 10 additions & 14 deletions test/WebJobs.Script.Tests/ScriptHostTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,21 +406,19 @@ public async Task Initialize_WithLatestSiteExtensionVersion_LogsWarning()
}

[Theory]
[InlineData("dotnet", "", "", "", "dotnet")]
[InlineData("dotnet", "~2", "", "", "dotnet-~2")]
[InlineData("python", "~2", "", "", "python")]
[InlineData("python", "~2", "", "3.6", "python-3.6")]
[InlineData("python", "~3", "~8", "3.7", "python-3.7")]
[InlineData("node", "~3", "", "3.6", "node")]
[InlineData("node", "~2", "~8", "3.6", "node-~8")]
[InlineData("powershell", "~2", "", "", "powershell")]
[InlineData("powershell", "~2", "~10", "3.6", "powershell")]
[InlineData("java", "~3", "", "", "java")]
[InlineData("java", "~3", "~8", "3.6", "java")]
[InlineData("dotnet", "", "", "dotnet")]
[InlineData("dotnet", "", "~2", "dotnet-~2")]
[InlineData("python", "~2", "", "python")]
[InlineData("python", "~2", "3.6", "python-3.6")]
[InlineData("python", "~3", "3.7", "python-3.7")]
[InlineData("node", "~3", "~8", "node-~8")]
[InlineData("node", "~2", "~8", "node-~8")]
[InlineData("powershell", "~2", "", "powershell")]
[InlineData("powershell", "~2", "~7", "powershell-~7")]
[InlineData("java", "~3", "", "java")]
public async Task Initialize_WithRuntimeAndWorkerVersion_ReportRuntimeToMetricsTable(
string functionsWorkerRuntime,
string functionsExtensionVersion,
string websiteNodeDefaultVersion,
string functionsWorkerRuntimeVersion,
string expectedRuntimeStack)
{
Expand All @@ -437,8 +435,6 @@ public async Task Initialize_WithRuntimeAndWorkerVersion_ReportRuntimeToMetricsT
RpcWorkerConstants.FunctionWorkerRuntimeSettingName, functionsWorkerRuntime);
environment.SetEnvironmentVariable(
EnvironmentSettingNames.FunctionsExtensionVersion, functionsExtensionVersion);
environment.SetEnvironmentVariable(
EnvironmentSettingNames.WebsiteNodeDefaultVersion, websiteNodeDefaultVersion);
environment.SetEnvironmentVariable(
RpcWorkerConstants.FunctionWorkerRuntimeVersionSettingName, functionsWorkerRuntimeVersion);

Expand Down

0 comments on commit 8d619f4

Please sign in to comment.