Skip to content

Commit

Permalink
v3.14.1 Hotfix - Add feature flag for FunctionExecutionCount logging …
Browse files Browse the repository at this point in the history
…Linux AppService (#8760)

* HOTFIXv3 - Introduce feature flag to Execution Logger. Opt-in for FunctionExecutionCount  (#8754)

* Update FEC feature flag

* Fixed build issues

* Alphabetize using

* Comment test related code

* Clean code - lilian feedback

* syntax

* Update tests

Co-authored-by: Cooper Link <[email protected]>

* Update build version to 3.14.2

Co-authored-by: Cooper Link <[email protected]>
  • Loading branch information
CooperLink and Cooper Link authored Sep 16, 2022
1 parent cc189e9 commit 65a3d5a
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 26 deletions.
2 changes: 1 addition & 1 deletion build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<LangVersion>latest</LangVersion>
<MajorVersion>3</MajorVersion>
<MinorVersion>14</MinorVersion>
<PatchVersion>1</PatchVersion>
<PatchVersion>2</PatchVersion>
<VersionPrefix>$(MajorVersion).$(MinorVersion).$(PatchVersion)</VersionPrefix>
<Version Condition=" '$(BuildNumber)' != '' ">$(VersionPrefix)-$(BuildNumber)</Version>
<Version Condition=" '$(Version)' == '' ">$(VersionPrefix)</Version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using Microsoft.Azure.WebJobs.Script.Config;
using Microsoft.Extensions.Logging;

namespace Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics
Expand Down Expand Up @@ -68,8 +69,15 @@ public override void LogFunctionExecutionEvent(string executionId, string siteNa
{
var logger = _loggerFactory.GetOrCreate(FunctionsExecutionEventsCategory);
string currentUtcTime = DateTime.UtcNow.ToString();
string log = string.Join(",", executionId, siteName, concurrency.ToString(), functionName, invocationId, executionStage, executionTimeSpan.ToString(), success.ToString(), currentUtcTime);
WriteEvent(logger, log);
if (FeatureFlags.IsEnabled(ScriptConstants.FeatureFlagEnableLinuxEPExecutionCount))
{
string log = string.Join(",", executionId, siteName, concurrency.ToString(), functionName, invocationId, executionStage, executionTimeSpan.ToString(), success.ToString(), currentUtcTime);
WriteEvent(logger, log);
}
else
{
WriteEvent(logger, currentUtcTime);
}
}

private static void WriteEvent(LinuxAppServiceFileLogger logger, string evt)
Expand Down
1 change: 1 addition & 0 deletions src/WebJobs.Script/ScriptConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public static class ScriptConstants
public const string FeatureFlagDisableAspNetCoreGrpc = "DisableAspNetCoreGrpc";
public const string FeatureFlagEnableWorkerIndexing = "EnableWorkerIndexing";
public const string FeatureFlagEnableMultiLanguageWorker = "EnableMultiLanguageWorker";
public const string FeatureFlagEnableLinuxEPExecutionCount = "EnableLinuxFEC";

public const string AdminJwtValidAudienceFormat = "https://{0}.azurewebsites.net/azurefunctions";
public const string AdminJwtValidIssuerFormat = "https://{0}.scm.azurewebsites.net";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.Extensions.Logging;
using Moq;
using Xunit;
using static Microsoft.Azure.WebJobs.Script.ScriptConstants;

namespace Microsoft.Azure.WebJobs.Script.Tests.Diagnostics
{
Expand Down Expand Up @@ -178,28 +179,47 @@ public void ParseAzureMonitoringEvents(LogLevel level, string resourceId, string
[Theory]
[MemberData(nameof(LinuxEventGeneratorTestData.GetFunctionExecutionEvents), MemberType = typeof(LinuxEventGeneratorTestData))]
public void ParseFunctionExecutionEvents(string executionId, string siteName, int concurrency, string functionName, string invocationId,
string executionStage, long executionTimeSpan, bool success)
string executionStage, long executionTimeSpan, bool success, bool featureFlagEnabled)
{
_generator.LogFunctionExecutionEvent(executionId, siteName, concurrency, functionName, invocationId, executionStage, executionTimeSpan, success);
string evt = _loggers[LinuxEventGenerator.FunctionsExecutionEventsCategory].Events.Single();

Regex regex = new Regex(LinuxAppServiceEventGenerator.ExecutionEventRegex);
var match = regex.Match(evt);

Assert.True(match.Success);
Assert.Equal(10, match.Groups.Count);

var groupMatches = match.Groups.Cast<Group>().Select(p => p.Value).Skip(1).ToArray();
Assert.Collection(groupMatches,
p => Assert.Equal(executionId, p),
p => Assert.Equal(siteName, p),
p => Assert.Equal(concurrency.ToString(), p),
p => Assert.Equal(functionName, p),
p => Assert.Equal(invocationId, p),
p => Assert.Equal(executionStage, p),
p => Assert.Equal(executionTimeSpan.ToString(), p),
p => Assert.True(Convert.ToBoolean(p)),
p => Assert.True(DateTime.TryParse(p, out DateTime dt)));
TestScopedEnvironmentVariable featureFlags = null;
try
{
if (featureFlagEnabled)
{
featureFlags = new TestScopedEnvironmentVariable(EnvironmentSettingNames.AzureWebJobsFeatureFlags, FeatureFlagEnableLinuxEPExecutionCount);
}
_generator.LogFunctionExecutionEvent(executionId, siteName, concurrency, functionName, invocationId, executionStage, executionTimeSpan, success);
string evt = _loggers[LinuxEventGenerator.FunctionsExecutionEventsCategory].Events.Single();

if (featureFlagEnabled)
{
Regex regex = new Regex(LinuxAppServiceEventGenerator.ExecutionEventRegex);
var match = regex.Match(evt);

Assert.True(match.Success);
Assert.Equal(10, match.Groups.Count);

var groupMatches = match.Groups.Cast<Group>().Select(p => p.Value).Skip(1).ToArray();
Assert.Collection(groupMatches,
p => Assert.Equal(executionId, p),
p => Assert.Equal(siteName, p),
p => Assert.Equal(concurrency.ToString(), p),
p => Assert.Equal(functionName, p),
p => Assert.Equal(invocationId, p),
p => Assert.Equal(executionStage, p),
p => Assert.Equal(executionTimeSpan.ToString(), p),
p => Assert.True(Convert.ToBoolean(p)),
p => Assert.True(DateTime.TryParse(p, out DateTime dt)));
}
else
{
Assert.True(DateTime.TryParse(evt, out DateTime dt));
}
}
finally
{
featureFlags?.Dispose();
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public static IEnumerable<object[]> GetAzureMonitorEvents()

public static IEnumerable<object[]> GetFunctionExecutionEvents()
{
yield return new object[] { "testexecution", "testSite", 1, "testFunction", "testInvocation", "testStage", 1, true };
yield return new object[] { "testexecution", "testSite", 1, "testFunction", "testInvocation", "testStage", 1, true, true };
yield return new object[] { "testexecution", "testSite", 1, "testFunction", "testInvocation", "testStage", 1, true, false };
}
}
}

0 comments on commit 65a3d5a

Please sign in to comment.