Skip to content

Commit bcbf3c1

Browse files
authored
Switched memory usage reporting to use CGroup metrics by default for Linux consumption (#11114)
* Removed feature flag driven metric reporting code. * Add release notes.
1 parent 534a66e commit bcbf3c1

File tree

6 files changed

+3
-66
lines changed

6 files changed

+3
-66
lines changed

release_notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@
1717
- Improvements to coldstart pipeline (#11102).
1818
- Update Python Worker Version to [4.38.0](https://github.com/Azure/azure-functions-python-worker/releases/tag/4.38.0)
1919
- Only start the Diagnostic Events flush logs timer when events are present, preventing unnecessary flush attempts (#11100).
20+
- Switched memory usage reporting to use CGroup metrics by default for Linux consumption (#11114)

src/WebJobs.Script.WebHost/Metrics/LinuxContainerLegionMetricsPublisher.cs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public sealed class LinuxContainerLegionMetricsPublisher : IMetricsPublisher, ID
2424
private readonly TimeSpan _timerStartDelay = TimeSpan.FromSeconds(2);
2525
private readonly IOptionsMonitor<StandbyOptions> _standbyOptions;
2626
private readonly IDisposable _standbyOptionsOnChangeListener;
27-
private readonly IDisposable _hostingConfigOptionsOnChangeListener;
2827
private readonly IEnvironment _environment;
2928
private readonly ILogger _logger;
3029
private readonly IServiceProvider _serviceProvider;
@@ -37,7 +36,6 @@ public sealed class LinuxContainerLegionMetricsPublisher : IMetricsPublisher, ID
3736
private Timer _processMonitorTimer;
3837
private Timer _metricsPublisherTimer;
3938
private bool _initialized = false;
40-
private bool _isCGroupMemoryMetricsEnabled = false;
4139

4240
public LinuxContainerLegionMetricsPublisher(IEnvironment environment, IOptionsMonitor<StandbyOptions> standbyOptions,
4341
IOptions<LinuxConsumptionLegionMetricsPublisherOptions> options, ILogger<LinuxContainerLegionMetricsPublisher> logger,
@@ -72,21 +70,10 @@ public LinuxContainerLegionMetricsPublisher(IEnvironment environment, IOptionsMo
7270
{
7371
Start();
7472
}
75-
76-
_hostingConfigOptionsOnChangeListener = _hostingConfigOptions.OnChange(OnHostingConfigOptionsChanged);
7773
}
7874

7975
private IMetricsLogger MetricsLogger => _metricsLogger ??= _serviceProvider.GetRequiredService<IMetricsLogger>();
8076

81-
private void OnHostingConfigOptionsChanged(FunctionsHostingConfigOptions newOptions)
82-
{
83-
if (newOptions.IsCGroupMemoryMetricsEnabled != _isCGroupMemoryMetricsEnabled)
84-
{
85-
_logger.LogInformation("CGroup memory metrics enabled: {Enabled}", newOptions.IsCGroupMemoryMetricsEnabled);
86-
_isCGroupMemoryMetricsEnabled = newOptions.IsCGroupMemoryMetricsEnabled;
87-
}
88-
}
89-
9077
public void Initialize()
9178
{
9279
_process = Process.GetCurrentProcess();
@@ -189,16 +176,7 @@ private void OnProcessMonitorTimer(object state)
189176
{
190177
try
191178
{
192-
long memoryUsageInBytes;
193-
if (_hostingConfigOptions.CurrentValue.IsCGroupMemoryMetricsEnabled)
194-
{
195-
memoryUsageInBytes = CgroupMemoryUsageHelper.GetMemoryUsageInBytes(_logger);
196-
}
197-
else
198-
{
199-
_process.Refresh();
200-
memoryUsageInBytes = _process.WorkingSet64;
201-
}
179+
long memoryUsageInBytes = CgroupMemoryUsageHelper.GetMemoryUsageInBytes(_logger);
202180

203181
if (memoryUsageInBytes != 0)
204182
{
@@ -258,7 +236,6 @@ public void Dispose()
258236

259237
_metricsTracker.OnDiagnosticEvent -= OnMetricsDiagnosticEvent;
260238
_standbyOptionsOnChangeListener?.Dispose();
261-
_hostingConfigOptionsOnChangeListener?.Dispose();
262239
}
263240

264241
internal class Metrics

src/WebJobs.Script.WebHost/Metrics/LinuxContainerMetricsPublisher.cs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public sealed class LinuxContainerMetricsPublisher : IMetricsPublisher, IDisposa
3838
private readonly TimeSpan _timerStartDelay = TimeSpan.FromSeconds(2);
3939
private readonly IOptionsMonitor<StandbyOptions> _standbyOptions;
4040
private readonly IDisposable _standbyOptionsOnChangeListener;
41-
private readonly IDisposable _hostingConfigOptionsOnChangeListener;
4241
private readonly string _requestUri;
4342
private readonly IEnvironment _environment;
4443
private readonly IOptionsMonitor<FunctionsHostingConfigOptions> _hostingConfigOptions;
@@ -66,7 +65,6 @@ public sealed class LinuxContainerMetricsPublisher : IMetricsPublisher, IDisposa
6665
private int _errorCount = 0;
6766
private string _stampName;
6867
private bool _initialized = false;
69-
private bool _isCGroupMemoryMetricsEnabled = false;
7068

7169
public LinuxContainerMetricsPublisher(IEnvironment environment, IOptionsMonitor<StandbyOptions> standbyOptions, ILogger<LinuxContainerMetricsPublisher> logger, HostNameProvider hostNameProvider, IOptionsMonitor<FunctionsHostingConfigOptions> functionsHostingConfigOptions, HttpClient httpClient = null)
7270
{
@@ -95,17 +93,6 @@ public LinuxContainerMetricsPublisher(IEnvironment environment, IOptionsMonitor<
9593
{
9694
Start();
9795
}
98-
99-
_hostingConfigOptionsOnChangeListener = _hostingConfigOptions.OnChange(OnHostingConfigOptionsChanged);
100-
}
101-
102-
private void OnHostingConfigOptionsChanged(FunctionsHostingConfigOptions newOptions)
103-
{
104-
if (newOptions.IsCGroupMemoryMetricsEnabled != _isCGroupMemoryMetricsEnabled)
105-
{
106-
_logger.LogInformation("CGroup memory metrics enabled: {Enabled}", newOptions.IsCGroupMemoryMetricsEnabled);
107-
_isCGroupMemoryMetricsEnabled = newOptions.IsCGroupMemoryMetricsEnabled;
108-
}
10996
}
11097

11198
private void OnStandbyOptionsChange()
@@ -278,16 +265,7 @@ private void OnProcessMonitorTimer(object state)
278265
{
279266
try
280267
{
281-
long memoryUsageInBytes;
282-
if (_hostingConfigOptions.CurrentValue.IsCGroupMemoryMetricsEnabled)
283-
{
284-
memoryUsageInBytes = CgroupMemoryUsageHelper.GetMemoryUsageInBytes(_logger);
285-
}
286-
else
287-
{
288-
_process.Refresh();
289-
memoryUsageInBytes = _process.WorkingSet64;
290-
}
268+
long memoryUsageInBytes = CgroupMemoryUsageHelper.GetMemoryUsageInBytes(_logger);
291269

292270
if (memoryUsageInBytes != 0)
293271
{
@@ -339,7 +317,6 @@ public void OnFunctionCompleted(string functionName, string invocationId)
339317
public void Dispose()
340318
{
341319
_standbyOptionsOnChangeListener?.Dispose();
342-
_hostingConfigOptionsOnChangeListener?.Dispose();
343320
_processMonitorTimer?.Dispose();
344321
_metricsPublisherTimer?.Dispose();
345322
_httpClient?.Dispose();

src/WebJobs.Script/Config/FunctionsHostingConfigOptions.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,6 @@ internal bool SwtIssuerEnabled
7878
}
7979
}
8080

81-
/// <summary>
82-
/// Gets or sets a value indicating whether to use cgroup memory metrics for reporting memory usage.
83-
/// </summary>
84-
internal bool IsCGroupMemoryMetricsEnabled
85-
{
86-
get
87-
{
88-
return GetFeatureAsBooleanOrDefault(ScriptConstants.FeatureFlagEnableCGroupMemoryMetrics, false);
89-
}
90-
91-
set
92-
{
93-
_features[ScriptConstants.FeatureFlagEnableCGroupMemoryMetrics] = value ? "1" : "0";
94-
}
95-
}
96-
9781
/// <summary>
9882
/// Gets or sets a string delimited by '|' that contains a list of admin APIs that are allowed to
9983
/// be invoked internally by platform components.

src/WebJobs.Script/ScriptConstants.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ public static class ScriptConstants
142142
public const string FeatureFlagDisableOrderedInvocationMessages = "DisableOrderedInvocationMessages";
143143
public const string FeatureFlagEnableAzureMonitorTimeIsoFormat = "EnableAzureMonitorTimeIsoFormat";
144144
public const string FeatureFlagEnableTestDataSuppression = "EnableTestDataSuppression";
145-
public const string FeatureFlagEnableCGroupMemoryMetrics = "EnableCGroupMemoryMetrics";
146145
public const string HostingConfigDisableLinuxAppServiceDetailedExecutionEvents = "DisableLinuxExecutionDetails";
147146
public const string HostingConfigDisableLinuxAppServiceExecutionEventLogBackoff = "DisableLinuxLogBackoff";
148147
public const string FeatureFlagEnableLegacyDurableVersionCheck = "EnableLegacyDurableVersionCheck";

test/WebJobs.Script.Tests/Configuration/FunctionsHostingConfigOptionsTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ public static IEnumerable<object[]> PropertyValues
7676
yield return [nameof(FunctionsHostingConfigOptions.IsDotNetInProcDisabled), "DotNetInProcDisabled=0", false];
7777

7878
yield return [nameof(FunctionsHostingConfigOptions.IsTestDataSuppressionEnabled), "EnableTestDataSuppression=1", true];
79-
yield return [nameof(FunctionsHostingConfigOptions.IsCGroupMemoryMetricsEnabled), "EnableCGroupMemoryMetrics=1", true];
8079

8180
#pragma warning restore SA1011 // Closing square brackets should be spaced correctly
8281
#pragma warning restore SA1010 // Opening square brackets should be spaced correctly

0 commit comments

Comments
 (0)