Skip to content

Commit 1c0a2ef

Browse files
authored
removing call to Configure() for FunctionsHostingConfigOptions (#9891)
1 parent 937267a commit 1c0a2ef

File tree

4 files changed

+190
-42
lines changed

4 files changed

+190
-42
lines changed

src/WebJobs.Script.WebHost/WebHostServiceCollectionExtensions.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,7 @@ public static void AddWebJobsScriptHost(this IServiceCollection services, IConfi
208208
services.ConfigureOptionsWithChangeTokenSource<HttpBodyControlOptions, HttpBodyControlOptionsSetup, SpecializationChangeTokenSource<HttpBodyControlOptions>>();
209209
services.ConfigureOptions<FlexConsumptionMetricsPublisherOptionsSetup>();
210210
services.ConfigureOptions<ConsoleLoggingOptionsSetup>();
211-
services.ConfigureOptions<FunctionsHostingConfigOptionsSetup>();
212-
if (configuration != null)
213-
{
214-
services.Configure<FunctionsHostingConfigOptions>(configuration.GetSection(ScriptConstants.FunctionsHostingConfigSectionName));
215-
}
211+
services.AddHostingConfigOptions(configuration);
216212

217213
services.TryAddSingleton<IDependencyValidator, DependencyValidator>();
218214
services.TryAddSingleton<IJobHostMiddlewarePipeline>(s => DefaultMiddlewarePipeline.Empty);
@@ -221,6 +217,18 @@ public static void AddWebJobsScriptHost(this IServiceCollection services, IConfi
221217
services.AddAzureBlobStorageProvider();
222218
}
223219

220+
internal static void AddHostingConfigOptions(this IServiceCollection services, IConfiguration configuration)
221+
{
222+
services.ConfigureOptions<FunctionsHostingConfigOptionsSetup>();
223+
224+
if (configuration != null)
225+
{
226+
// Refresh IOptionsMonitor<FunctionsHostingConfigOptions> when the config section changes
227+
var configSection = configuration.GetSection(ScriptConstants.FunctionsHostingConfigSectionName);
228+
services.AddSingleton<IOptionsChangeTokenSource<FunctionsHostingConfigOptions>>(new ConfigurationChangeTokenSource<FunctionsHostingConfigOptions>(configSection));
229+
}
230+
}
231+
224232
private static void AddStandbyServices(this IServiceCollection services)
225233
{
226234
services.AddSingleton<IOptionsChangeTokenSource<StandbyOptions>, StandbyChangeTokenSource>();

src/WebJobs.Script/Config/FunctionsHostingConfigOptions.cs

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public FunctionsHostingConfigOptions()
2424
/// <summary>
2525
/// Gets a value indicating whether worker concurrency feature is enabled in the hosting config.
2626
/// </summary>
27-
public bool FunctionsWorkerDynamicConcurrencyEnabled
27+
internal bool FunctionsWorkerDynamicConcurrencyEnabled
2828
{
2929
get
3030
{
@@ -35,7 +35,7 @@ public bool FunctionsWorkerDynamicConcurrencyEnabled
3535
/// <summary>
3636
/// Gets a value indicating whether worker indexing feature is enabled in the hosting config.
3737
/// </summary>
38-
public bool WorkerIndexingEnabled
38+
internal bool WorkerIndexingEnabled
3939
{
4040
get
4141
{
@@ -46,11 +46,11 @@ public bool WorkerIndexingEnabled
4646
/// <summary>
4747
/// Gets or Sets a value indicating whether the host should shutdown webhost worker channels during shutdown.
4848
/// </summary>
49-
public bool ShutdownWebhostWorkerChannelsOnHostShutdown
49+
internal bool ShutdownWebhostWorkerChannelsOnHostShutdown
5050
{
5151
get
5252
{
53-
return GetFeatureOrDefault(RpcWorkerConstants.ShutdownWebhostWorkerChannelsOnHostShutdown, "1") == "1";
53+
return GetFeatureAsBooleanOrDefault(RpcWorkerConstants.ShutdownWebhostWorkerChannelsOnHostShutdown, true);
5454
}
5555

5656
set
@@ -62,11 +62,11 @@ public bool ShutdownWebhostWorkerChannelsOnHostShutdown
6262
/// <summary>
6363
/// Gets or sets a value indicating whether SWT tokens should be accepted.
6464
/// </summary>
65-
public bool SwtAuthenticationEnabled
65+
internal bool SwtAuthenticationEnabled
6666
{
6767
get
6868
{
69-
return GetFeatureOrDefault(ScriptConstants.HostingConfigSwtAuthenticationEnabled, "1") == "1";
69+
return GetFeatureAsBooleanOrDefault(ScriptConstants.HostingConfigSwtAuthenticationEnabled, true);
7070
}
7171

7272
set
@@ -78,11 +78,11 @@ public bool SwtAuthenticationEnabled
7878
/// <summary>
7979
/// Gets or sets a value indicating whether SWT tokens should be sent on outgoing requests.
8080
/// </summary>
81-
public bool SwtIssuerEnabled
81+
internal bool SwtIssuerEnabled
8282
{
8383
get
8484
{
85-
return GetFeatureOrDefault(ScriptConstants.HostingConfigSwtIssuerEnabled, "1") == "1";
85+
return GetFeatureAsBooleanOrDefault(ScriptConstants.HostingConfigSwtIssuerEnabled, true);
8686
}
8787

8888
set
@@ -94,7 +94,7 @@ public bool SwtIssuerEnabled
9494
/// <summary>
9595
/// Gets a string delimited by '|' that contains the name of the apps with worker indexing disabled.
9696
/// </summary>
97-
public string WorkerIndexingDisabledApps
97+
internal string WorkerIndexingDisabledApps
9898
{
9999
get
100100
{
@@ -105,7 +105,7 @@ public string WorkerIndexingDisabledApps
105105
/// <summary>
106106
/// Gets a value indicating whether Linux Log Backoff is disabled in the hosting config.
107107
/// </summary>
108-
public bool DisableLinuxAppServiceLogBackoff
108+
internal bool DisableLinuxAppServiceLogBackoff
109109
{
110110
get
111111
{
@@ -116,7 +116,7 @@ public bool DisableLinuxAppServiceLogBackoff
116116
/// <summary>
117117
/// Gets or sets a value indicating whether Linux AppService/EP Detailed Execution Event is disabled in the hosting config.
118118
/// </summary>
119-
public bool DisableLinuxAppServiceExecutionDetails
119+
internal bool DisableLinuxAppServiceExecutionDetails
120120
{
121121
get
122122
{
@@ -129,11 +129,11 @@ public bool DisableLinuxAppServiceExecutionDetails
129129
}
130130
}
131131

132-
public bool EnableOrderedInvocationMessages
132+
internal bool EnableOrderedInvocationMessages
133133
{
134134
get
135135
{
136-
return GetFeature(ScriptConstants.FeatureFlagEnableOrderedInvocationmessages) == "1";
136+
return GetFeatureAsBooleanOrDefault(ScriptConstants.FeatureFlagEnableOrderedInvocationmessages, false);
137137
}
138138

139139
set
@@ -145,7 +145,7 @@ public bool EnableOrderedInvocationMessages
145145
/// <summary>
146146
/// Gets the highest version of extension bundle v3 supported.
147147
/// </summary>
148-
public string MaximumBundleV3Version
148+
internal string MaximumBundleV3Version
149149
{
150150
get
151151
{
@@ -156,7 +156,7 @@ public string MaximumBundleV3Version
156156
/// <summary>
157157
/// Gets the highest version of extension bundle v4 supported.
158158
/// </summary>
159-
public string MaximumBundleV4Version
159+
internal string MaximumBundleV4Version
160160
{
161161
get
162162
{
@@ -167,15 +167,15 @@ public string MaximumBundleV4Version
167167
/// <summary>
168168
/// Gets a value indicating whether the host should revert the worker shutdown behavior in the WebHostWorkerChannelManager.
169169
/// </summary>
170-
public bool RevertWorkerShutdownBehavior
170+
internal bool RevertWorkerShutdownBehavior
171171
{
172172
get
173173
{
174174
return GetFeature(RpcWorkerConstants.RevertWorkerShutdownBehavior) == "1";
175175
}
176176
}
177177

178-
public bool ThrowOnMissingFunctionsWorkerRuntime
178+
internal bool ThrowOnMissingFunctionsWorkerRuntime
179179
{
180180
get
181181
{
@@ -207,5 +207,35 @@ public string GetFeatureOrDefault(string name, string defaultValue)
207207
{
208208
return GetFeature(name) ?? defaultValue;
209209
}
210+
211+
/// <summary>
212+
/// Gets a feature by name and attempts to parse it into a boolean.
213+
/// Returns "True, False" or ints as booleans. Returns True for any non-zero integer.
214+
/// If none of those (or empty), returns default.
215+
/// </summary>
216+
/// <param name="name">Feature name.</param>
217+
/// <param name="defaultValue">The default value to return if the feature value cannot be parsed into a boolean.</param>
218+
/// <returns>Boolean value if parse-able from hosting configuration. Otherwise, the defaultValue.</returns>
219+
internal bool GetFeatureAsBooleanOrDefault(string name, bool defaultValue)
220+
{
221+
string featureValue = GetFeature(name);
222+
223+
if (string.IsNullOrWhiteSpace(featureValue))
224+
{
225+
return defaultValue;
226+
}
227+
228+
if (bool.TryParse(featureValue, out bool parsedBool))
229+
{
230+
return parsedBool;
231+
}
232+
233+
if (int.TryParse(featureValue, out int parsedInt))
234+
{
235+
return parsedInt != 0;
236+
}
237+
238+
return defaultValue;
239+
}
210240
}
211-
}
241+
}

test/WebJobs.Script.Tests.Integration/WebHostEndToEnd/SamplesEndToEndTests_Node_MultipleProcessesNoBundle.cs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@
66
using System.Diagnostics;
77
using System.IO;
88
using System.Linq;
9-
using System.Net;
10-
using System.Net.Http;
11-
using System.Net.Http.Headers;
129
using System.Threading;
1310
using System.Threading.Tasks;
14-
using Microsoft.Azure.WebJobs.Script.Config;
1511
using Microsoft.Azure.WebJobs.Script.Workers.Rpc;
1612
using Microsoft.Extensions.DependencyInjection;
1713
using Microsoft.WebJobs.Script.Tests;
@@ -23,35 +19,31 @@ namespace Microsoft.Azure.WebJobs.Script.Tests.EndToEnd
2319
[Trait(TestTraits.Group, TestTraits.SamplesEndToEnd)]
2420
public class SamplesEndToEndTests_Node_MultipleProcessesNoBundle : IClassFixture<SamplesEndToEndTests_Node_MultipleProcessesNoBundle.MultiplepleProcessesTestFixtureNoBundles>
2521
{
26-
private readonly ScriptSettingsManager _settingsManager;
27-
private MultiplepleProcessesTestFixtureNoBundles _fixture;
28-
private IEnumerable<int> _nodeProcessesBeforeTestStarted;
22+
private readonly MultiplepleProcessesTestFixtureNoBundles _fixture;
2923

3024
public SamplesEndToEndTests_Node_MultipleProcessesNoBundle(MultiplepleProcessesTestFixtureNoBundles fixture)
3125
{
3226
_fixture = fixture;
33-
_nodeProcessesBeforeTestStarted = fixture.NodeProcessesBeforeTestStarted;
34-
_settingsManager = ScriptSettingsManager.Instance;
3527
}
3628

3729
[Fact]
3830
public async Task NodeProcessNoBundleConfigured_Different_AfterHostRestart()
3931
{
4032
await SamplesTestHelpers.InvokeAndValidateHttpTrigger(_fixture, "HttpTrigger");
41-
IEnumerable<int> nodeProcessesBeforeHostRestart = Process.GetProcessesByName("node").Select(p => p.Id);
33+
IEnumerable<int> nodeProcessesBeforeHostRestart = Process.GetProcessesByName("node").Select(p => p.Id).ToArray();
4234
// Trigger a restart
4335
await _fixture.Host.RestartAsync(CancellationToken.None);
4436

4537
await SamplesTestHelpers.InvokeAndValidateHttpTrigger(_fixture, "HttpTrigger");
4638

4739
// Wait for all the 3 process to start
48-
await Task.Delay(TimeSpan.FromMinutes(1));
49-
50-
IEnumerable<int> nodeProcessesAfter = Process.GetProcessesByName("node").Select(p => p.Id);
51-
52-
// Verify node process is different after host restart
53-
var result = nodeProcessesAfter.Where(pId1 => !nodeProcessesBeforeHostRestart.Any(pId2 => pId2 == pId1) && !_fixture.NodeProcessesBeforeTestStarted.Any(pId3 => pId3 == pId1));
54-
Assert.Equal(3, result.Count());
40+
await TestHelpers.Await(() =>
41+
{
42+
IEnumerable<int> nodeProcessesAfter = Process.GetProcessesByName("node").Select(p => p.Id);
43+
// Verify node process is different after host restart
44+
var result = nodeProcessesAfter.Where(pId1 => !nodeProcessesBeforeHostRestart.Any(pId2 => pId2 == pId1) && !_fixture.NodeProcessesBeforeTestStarted.Any(pId3 => pId3 == pId1));
45+
return result.Count() == 3;
46+
});
5547
}
5648

5749
public class MultiplepleProcessesTestFixtureNoBundles : EndToEndTestFixture

0 commit comments

Comments
 (0)