Skip to content

Commit 6093315

Browse files
CooperLinkCooper Link
andauthored
HOTFIXv4 - Introduce feature flag to Execution Logger. Opt-in for Fun… (#8759)
* HOTFIXv4 - Introduce feature flag to Execution Logger. Opt-in for FunctionExecutionCount (#8755) * v4 feature flag FEC * remove build issues * Update using dir order * Comment test related code * Update log statement lilian feedback * whitespace * Remove whitespace * Add failing tests * Update with working tests * Dispose of env * Whitespace Co-authored-by: Cooper Link <[email protected]> * Update to version 4.11.3 Co-authored-by: Cooper Link <[email protected]>
1 parent a781311 commit 6093315

File tree

5 files changed

+55
-25
lines changed

5 files changed

+55
-25
lines changed

build/common.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<LangVersion>latest</LangVersion>
66
<MajorVersion>4</MajorVersion>
77
<MinorVersion>11</MinorVersion>
8-
<PatchVersion>2</PatchVersion>
8+
<PatchVersion>3</PatchVersion>
99
<BuildNumber Condition="'$(BuildNumber)' == '' ">0</BuildNumber>
1010
<PreviewVersion></PreviewVersion>
1111

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

44
using System;
5+
using Microsoft.Azure.WebJobs.Script.Config;
56
using Microsoft.Extensions.Logging;
67

78
namespace Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics
@@ -68,8 +69,15 @@ public override void LogFunctionExecutionEvent(string executionId, string siteNa
6869
{
6970
var logger = _loggerFactory.GetOrCreate(FunctionsExecutionEventsCategory);
7071
string currentUtcTime = DateTime.UtcNow.ToString();
71-
string log = string.Join(",", executionId, siteName, concurrency.ToString(), functionName, invocationId, executionStage, executionTimeSpan.ToString(), success.ToString(), currentUtcTime);
72-
WriteEvent(logger, log);
72+
if (FeatureFlags.IsEnabled(ScriptConstants.FeatureFlagEnableLinuxEPExecutionCount))
73+
{
74+
string log = string.Join(",", executionId, siteName, concurrency.ToString(), functionName, invocationId, executionStage, executionTimeSpan.ToString(), success.ToString(), currentUtcTime);
75+
WriteEvent(logger, log);
76+
}
77+
else
78+
{
79+
WriteEvent(logger, currentUtcTime);
80+
}
7381
}
7482

7583
private static void WriteEvent(LinuxAppServiceFileLogger logger, string evt)

src/WebJobs.Script/ScriptConstants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public static class ScriptConstants
113113
public const string FeatureFlagEnableWorkerIndexing = "EnableWorkerIndexing";
114114
public const string FeatureFlagEnableDebugTracing = "EnableDebugTracing";
115115
public const string FeatureFlagEnableMultiLanguageWorker = "EnableMultiLanguageWorker";
116+
public const string FeatureFlagEnableLinuxEPExecutionCount = "EnableLinuxFEC";
116117

117118
public const string AdminJwtValidAudienceFormat = "https://{0}.azurewebsites.net/azurefunctions";
118119
public const string AdminJwtValidIssuerFormat = "https://{0}.scm.azurewebsites.net";

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

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Microsoft.Extensions.Logging;
1212
using Moq;
1313
using Xunit;
14+
using static Microsoft.Azure.WebJobs.Script.ScriptConstants;
1415

1516
namespace Microsoft.Azure.WebJobs.Script.Tests.Diagnostics
1617
{
@@ -178,28 +179,47 @@ public void ParseAzureMonitoringEvents(LogLevel level, string resourceId, string
178179
[Theory]
179180
[MemberData(nameof(LinuxEventGeneratorTestData.GetFunctionExecutionEvents), MemberType = typeof(LinuxEventGeneratorTestData))]
180181
public void ParseFunctionExecutionEvents(string executionId, string siteName, int concurrency, string functionName, string invocationId,
181-
string executionStage, long executionTimeSpan, bool success)
182+
string executionStage, long executionTimeSpan, bool success, bool featureFlagEnabled)
182183
{
183-
_generator.LogFunctionExecutionEvent(executionId, siteName, concurrency, functionName, invocationId, executionStage, executionTimeSpan, success);
184-
string evt = _loggers[LinuxEventGenerator.FunctionsExecutionEventsCategory].Events.Single();
185-
186-
Regex regex = new Regex(LinuxAppServiceEventGenerator.ExecutionEventRegex);
187-
var match = regex.Match(evt);
188-
189-
Assert.True(match.Success);
190-
Assert.Equal(10, match.Groups.Count);
191-
192-
var groupMatches = match.Groups.Cast<Group>().Select(p => p.Value).Skip(1).ToArray();
193-
Assert.Collection(groupMatches,
194-
p => Assert.Equal(executionId, p),
195-
p => Assert.Equal(siteName, p),
196-
p => Assert.Equal(concurrency.ToString(), p),
197-
p => Assert.Equal(functionName, p),
198-
p => Assert.Equal(invocationId, p),
199-
p => Assert.Equal(executionStage, p),
200-
p => Assert.Equal(executionTimeSpan.ToString(), p),
201-
p => Assert.True(Convert.ToBoolean(p)),
202-
p => Assert.True(DateTime.TryParse(p, out DateTime dt)));
184+
TestScopedEnvironmentVariable featureFlags = null;
185+
try
186+
{
187+
if (featureFlagEnabled)
188+
{
189+
featureFlags = new TestScopedEnvironmentVariable(EnvironmentSettingNames.AzureWebJobsFeatureFlags, FeatureFlagEnableLinuxEPExecutionCount);
190+
}
191+
_generator.LogFunctionExecutionEvent(executionId, siteName, concurrency, functionName, invocationId, executionStage, executionTimeSpan, success);
192+
string evt = _loggers[LinuxEventGenerator.FunctionsExecutionEventsCategory].Events.Single();
193+
194+
if (featureFlagEnabled)
195+
{
196+
Regex regex = new Regex(LinuxAppServiceEventGenerator.ExecutionEventRegex);
197+
var match = regex.Match(evt);
198+
199+
Assert.True(match.Success);
200+
Assert.Equal(10, match.Groups.Count);
201+
202+
var groupMatches = match.Groups.Cast<Group>().Select(p => p.Value).Skip(1).ToArray();
203+
Assert.Collection(groupMatches,
204+
p => Assert.Equal(executionId, p),
205+
p => Assert.Equal(siteName, p),
206+
p => Assert.Equal(concurrency.ToString(), p),
207+
p => Assert.Equal(functionName, p),
208+
p => Assert.Equal(invocationId, p),
209+
p => Assert.Equal(executionStage, p),
210+
p => Assert.Equal(executionTimeSpan.ToString(), p),
211+
p => Assert.True(Convert.ToBoolean(p)),
212+
p => Assert.True(DateTime.TryParse(p, out DateTime dt)));
213+
}
214+
else
215+
{
216+
Assert.True(DateTime.TryParse(evt, out DateTime dt));
217+
}
218+
}
219+
finally
220+
{
221+
featureFlags?.Dispose();
222+
}
203223
}
204224
}
205225
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public static IEnumerable<object[]> GetAzureMonitorEvents()
3535

3636
public static IEnumerable<object[]> GetFunctionExecutionEvents()
3737
{
38-
yield return new object[] { "testexecution", "testSite", 1, "testFunction", "testInvocation", "testStage", 1, true };
38+
yield return new object[] { "testexecution", "testSite", 1, "testFunction", "testInvocation", "testStage", 1, true, true };
39+
yield return new object[] { "testexecution", "testSite", 1, "testFunction", "testInvocation", "testStage", 1, true, false };
3940
}
4041
}
4142
}

0 commit comments

Comments
 (0)