Skip to content

Commit d2dddf9

Browse files
committed
Merge branch 'master' into dev
2 parents e6a5b26 + 8d619f4 commit d2dddf9

File tree

6 files changed

+77
-12
lines changed

6 files changed

+77
-12
lines changed

src/WebJobs.Script.WebHost/Diagnostics/LinuxContainerEventGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private void ConsoleWriter(string evt)
104104

105105
public override void LogAzureMonitorDiagnosticLogEvent(LogLevel level, string resourceId, string operationName, string category, string regionName, string properties)
106106
{
107-
_writeEvent($"{ScriptConstants.LinuxAzureMonitorEventStreamName} {(int)ToEventLevel(level)},{resourceId},{operationName},{category},{regionName},{NormalizeString(properties)},{_containerName},{TenantId},{DateTime.UtcNow.ToString()}");
107+
// _writeEvent($"{ScriptConstants.LinuxAzureMonitorEventStreamName} {(int)ToEventLevel(level)},{resourceId},{operationName},{category},{regionName},{NormalizeString(properties)},{_containerName},{TenantId},{DateTime.UtcNow.ToString()}");
108108
}
109109
}
110110
}

src/WebJobs.Script/Description/DotNet/FunctionAssemblyLoadContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ private static bool IsMinorMatchOrLowerPolicyEvaluator(AssemblyName requestedAss
154154
{
155155
AssemblyName runtimeAssemblyName = AssemblyNameCache.GetName(runtimeAssembly);
156156

157-
return requestedAssembly.Version.Major == runtimeAssemblyName.Version.Major &&
158-
requestedAssembly.Version.Minor <= runtimeAssemblyName.Version.Minor;
157+
return requestedAssembly.Version == null || (requestedAssembly.Version.Major == runtimeAssemblyName.Version.Major &&
158+
requestedAssembly.Version.Minor <= runtimeAssemblyName.Version.Minor);
159159
}
160160

161161
private bool IsRuntimeAssembly(AssemblyName assemblyName)

src/WebJobs.Script/Host/ScriptHost.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,16 @@ public async Task InitializeAsync(CancellationToken cancellationToken = default)
280280
{
281281
string runtimeStack = _workerRuntime;
282282

283-
// Appending the runtime version is currently only enabled for linux consumption. This will be eventually enabled for
284-
// Windows Consumption as well.
285-
string runtimeVersion = _environment.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeVersionSettingName);
286-
287-
if (!string.IsNullOrEmpty(runtimeVersion))
283+
if (!string.IsNullOrEmpty(_environment.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName)))
288284
{
289-
runtimeStack = string.Concat(runtimeStack, "-", runtimeVersion);
285+
// Appending the runtime version is currently only enabled for linux consumption. This will be eventually enabled for
286+
// Windows Consumption as well.
287+
string runtimeVersion = _environment.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeVersionSettingName);
288+
289+
if (!string.IsNullOrEmpty(runtimeVersion))
290+
{
291+
runtimeStack = string.Concat(runtimeStack, "-", runtimeVersion);
292+
}
290293
}
291294

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

test/WebJobs.Script.Tests/Description/DotNet/FunctionAssemblyLoadContextTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public class FunctionAssemblyLoadContextTests
2828
[InlineData("Microsoft.Azure.WebJobs.Script, Version=3.0.0.0")]
2929
[InlineData("Microsoft.Azure.WebJobs.Script.Grpc, Version=3.0.0.0")]
3030
[InlineData("Microsoft.Azure.WebJobs.Script.WebHost, Version=3.0.0.0")]
31-
[InlineData("Microsoft.Azure.WebSites.DataProtection, Version=0.0.0.0")]
32-
[InlineData("System.IO, Version=0.0.0.0")] // System.*
31+
[InlineData("Microsoft.Azure.WebSites.DataProtection")]
32+
[InlineData("System.IO")] // System.*
3333
public void RuntimeAssemblies_AreLoadedInDefaultContext(string assemblyName)
3434
{
3535
var functionContext = new FunctionAssemblyLoadContext(AppContext.BaseDirectory);

test/WebJobs.Script.Tests/Diagnostics/LinuxContainerEventGeneratorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public void ToEventLevel_ReturnsExpectedValue(LogLevel logLevel, EventLevel even
193193
Assert.Equal(eventLevel, LinuxEventGenerator.ToEventLevel(logLevel));
194194
}
195195

196-
[Theory]
196+
[Theory(Skip = "https://github.com/Azure/azure-functions-host/issues/5636")]
197197
[MemberData(nameof(LinuxEventGeneratorTestData.GetAzureMonitorEvents), MemberType = typeof(LinuxEventGeneratorTestData))]
198198
public void ParseAzureMonitoringEvents(LogLevel level, string resourceId, string operationName, string category, string regionName, string properties)
199199
{

test/WebJobs.Script.Tests/ScriptHostTests.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Microsoft.Azure.WebJobs.Script.Config;
1616
using Microsoft.Azure.WebJobs.Script.Configuration;
1717
using Microsoft.Azure.WebJobs.Script.Description;
18+
using Microsoft.Azure.WebJobs.Script.Diagnostics;
1819
using Microsoft.Azure.WebJobs.Script.Eventing;
1920
using Microsoft.Azure.WebJobs.Script.Workers.Rpc;
2021
using Microsoft.Extensions.Configuration;
@@ -433,6 +434,67 @@ public async Task Initialize_WithLatestSiteExtensionVersion_LogsWarning()
433434
}
434435
}
435436

437+
[Theory]
438+
[InlineData("dotnet", "", "", "dotnet")]
439+
[InlineData("dotnet", "", "~2", "dotnet-~2")]
440+
[InlineData("python", "~2", "", "python")]
441+
[InlineData("python", "~2", "3.6", "python-3.6")]
442+
[InlineData("python", "~3", "3.7", "python-3.7")]
443+
[InlineData("node", "~3", "~8", "node-~8")]
444+
[InlineData("node", "~2", "~8", "node-~8")]
445+
[InlineData("powershell", "~2", "", "powershell")]
446+
[InlineData("powershell", "~2", "~7", "powershell-~7")]
447+
[InlineData("java", "~3", "", "java")]
448+
public async Task Initialize_WithRuntimeAndWorkerVersion_ReportRuntimeToMetricsTable(
449+
string functionsWorkerRuntime,
450+
string functionsExtensionVersion,
451+
string functionsWorkerRuntimeVersion,
452+
string expectedRuntimeStack)
453+
{
454+
try
455+
{
456+
using (var tempDirectory = new TempDirectory())
457+
{
458+
string rootPath = Path.Combine(tempDirectory.Path, Guid.NewGuid().ToString());
459+
Directory.CreateDirectory(rootPath);
460+
var metricsLogger = new TestMetricsLogger();
461+
var environment = new TestEnvironment();
462+
463+
environment.SetEnvironmentVariable(
464+
RpcWorkerConstants.FunctionWorkerRuntimeSettingName, functionsWorkerRuntime);
465+
environment.SetEnvironmentVariable(
466+
EnvironmentSettingNames.FunctionsExtensionVersion, functionsExtensionVersion);
467+
environment.SetEnvironmentVariable(
468+
RpcWorkerConstants.FunctionWorkerRuntimeVersionSettingName, functionsWorkerRuntimeVersion);
469+
470+
IHost host = new HostBuilder()
471+
.ConfigureServices(s =>
472+
{
473+
s.AddSingleton<IEnvironment>(environment);
474+
})
475+
.ConfigureDefaultTestWebScriptHost(
476+
null,
477+
o =>
478+
{
479+
o.ScriptPath = rootPath;
480+
},
481+
false,
482+
s =>
483+
{
484+
s.AddSingleton<IMetricsLogger>(metricsLogger);
485+
})
486+
.Build();
487+
var scriptHost = host.GetScriptHost();
488+
await scriptHost.InitializeAsync();
489+
Assert.Single(metricsLogger.LoggedEvents, e => e.Equals($"host.startup.runtime.language.{expectedRuntimeStack}"));
490+
}
491+
}
492+
finally
493+
{
494+
EnvironmentExtensions.BaseDirectory = null;
495+
}
496+
}
497+
436498
// TODO: Newer TODO - ApplyConfiguration no longer exists. Validate logic (moved to HostJsonFileConfigurationSource)
437499
// TODO: Move this test into a new WebJobsCoreScriptBindingProvider class since
438500
// the functionality moved. Also add tests for the ServiceBus config, etc.

0 commit comments

Comments
 (0)