-
Notifications
You must be signed in to change notification settings - Fork 457
Warn if .azurefunctions folder does not exist #10967
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 26 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
335a2d7
Initial changes
surgupta-msft 151b54c
Adding comment
surgupta-msft 3df08a5
Improving log and adding test
surgupta-msft dbb9557
cleanup utility
surgupta-msft 2ad8032
build fix
surgupta-msft 1815d68
Method cleanup
surgupta-msft 7b042ba
minor fix
surgupta-msft 12db36b
updating release notes
surgupta-msft 4693c8d
Merge with main
surgupta-msft 80e2bd8
Addresisng PR feedback
surgupta-msft cd0441f
Fixing tests
surgupta-msft d4bb19c
Tests fixing
surgupta-msft 3afb581
Tests
surgupta-msft fcc57b7
Tests fixing
surgupta-msft 0375667
minor
surgupta-msft 63d5e1e
Adding check log avoid logging in placeholder mode
surgupta-msft 958da5a
updating if check
surgupta-msft 3d334a2
Merge branch 'dev' into surgupta/innerbuild-warn
surgupta-msft a00805e
Test project build fix
surgupta-msft 6c98fb7
Fixing eventId
surgupta-msft 97d4db1
Merge with dev
surgupta-msft f8c9b97
Adding hosting service to validate function app
surgupta-msft fbe2b87
release notes fix
surgupta-msft ed21374
Adding tests
surgupta-msft f3674e3
Adding additional tests
surgupta-msft 6cadba0
PR cleanup
surgupta-msft eca58e4
Addressing PR feedback
surgupta-msft 88f0aed
Rebase with main
surgupta-msft 780b151
Adding e2e test
surgupta-msft f64b801
Updating E2E test
surgupta-msft 1374a3c
Merge with main
surgupta-msft d152e72
Adding placeholder check before creating timer
surgupta-msft 0bfc12d
Conditionally register the validation service
surgupta-msft 108d1a7
Improving logging message based on PR feedback
surgupta-msft a4facb2
Fixing tests
surgupta-msft 824fce5
Added logic to check valid zip
surgupta-msft 63f8cd1
Fixing tests
surgupta-msft fb16548
Rebasing with dev
surgupta-msft 10d1ea2
Tests cleanup
surgupta-msft 50d995f
Addressed feedback on a test app
surgupta-msft 4834166
Clean up in tests
surgupta-msft 2369091
Minor cleanup
surgupta-msft 17986cd
Class visibility update
surgupta-msft ff21cb3
Including exception in the trace log
surgupta-msft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
### Release notes | ||
|
||
<!-- Please add your release notes in the following format: | ||
- My change description (#PR) | ||
--> | ||
- Improved memory metrics reporting using CGroup data for Linux consumption (#10968) | ||
- Memory allocation optimizations in `RpcWorkerConfigFactory.AddProviders` (#10959) | ||
- Fixing GrpcWorkerChannel concurrency bug (#10998) | ||
- Avoid circular dependency when resolving LinuxContainerLegionMetricsPublisher. (#10991) | ||
- Add 'unix' to the list of runtimes kept when importing PowerShell worker for Linux builds | ||
- Update PowerShell 7.4 worker to 4.0.4206 | ||
- Update Python Worker Version to [4.37.0](https://github.com/Azure/azure-functions-python-worker/releases/tag/4.37.0) | ||
- Add runtime and process metrics. (#11034) | ||
- Add `win-arm64` and `linux-arm64` to the list of PowerShell runtimes; added filter for `osx` RIDs (includes `osx-x64` and `osx-arm64`) (#11013) | ||
- Disable Diagnostic Events when Table Storage is not accessible (#10996) | ||
### Release notes | ||
|
||
<!-- Please add your release notes in the following format: | ||
- My change description (#PR) | ||
--> | ||
- Improved memory metrics reporting using CGroup data for Linux consumption (#10968) | ||
- Memory allocation optimizations in `RpcWorkerConfigFactory.AddProviders` (#10959) | ||
- Fixing GrpcWorkerChannel concurrency bug (#10998) | ||
- Avoid circular dependency when resolving LinuxContainerLegionMetricsPublisher. (#10991) | ||
- Add 'unix' to the list of runtimes kept when importing PowerShell worker for Linux builds | ||
- Update PowerShell 7.4 worker to 4.0.4206 | ||
- Update Python Worker Version to [4.37.0](https://github.com/Azure/azure-functions-python-worker/releases/tag/4.37.0) | ||
- Add runtime and process metrics. (#11034) | ||
- Add `win-arm64` and `linux-arm64` to the list of PowerShell runtimes; added filter for `osx` RIDs (includes `osx-x64` and `osx-arm64`) (#11013) | ||
- Disable Diagnostic Events when Table Storage is not accessible (#10996) | ||
- Warn if .azurefunctions folder does not exist (#10967) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.IO; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.WebJobs.Script.Diagnostics.Extensions; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Microsoft.Azure.WebJobs.Script.Host | ||
{ | ||
public sealed class FunctionAppValidationService : IHostedService | ||
surgupta-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
private readonly IEnvironment _environment; | ||
private readonly ILogger<FunctionAppValidationService> _logger; | ||
private readonly IOptions<ScriptJobHostOptions> _scriptOptions; | ||
private readonly TimeSpan _initializationDelay = TimeSpan.FromSeconds(10); | ||
|
||
public FunctionAppValidationService( | ||
surgupta-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ILogger<FunctionAppValidationService> logger, | ||
IOptions<ScriptJobHostOptions> scriptOptions, | ||
IEnvironment environment) | ||
{ | ||
_scriptOptions = scriptOptions ?? throw new ArgumentNullException(nameof(scriptOptions)); | ||
_logger = logger ?? throw new ArgumentNullException(nameof(logger)); | ||
_environment = environment ?? throw new ArgumentNullException(nameof(environment)); | ||
} | ||
|
||
public async Task StartAsync(CancellationToken cancellationToken) | ||
{ | ||
// Adding a delay to ensure that this validation does not impact the cold start performance | ||
surgupta-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_ = Task.Delay(_initializationDelay, cancellationToken).ContinueWith(t => Validate()); | ||
surgupta-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
await Task.CompletedTask; | ||
} | ||
|
||
public Task StopAsync(CancellationToken cancellationToken) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
|
||
internal void Validate() | ||
{ | ||
if (!_environment.IsPlaceholderModeEnabled() && | ||
!_scriptOptions.Value.IsDefaultHostConfig && | ||
Utility.IsDotnetIsolatedApp(environment: _environment) && | ||
!Directory.Exists(Path.Combine(_scriptOptions.Value.RootScriptPath, ScriptConstants.AzureFunctionsSystemDirectoryName))) | ||
surgupta-msft marked this conversation as resolved.
Show resolved
Hide resolved
surgupta-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
_logger.NoAzureFunctionsFolder(); | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
test/WebJobs.Script.Tests/Description/FunctionAppValidationServiceTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.WebJobs.Script.Description; | ||
using Microsoft.Azure.WebJobs.Script.Host; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
using Microsoft.WebJobs.Script.Tests; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace Microsoft.Azure.WebJobs.Script.Tests | ||
{ | ||
public class FunctionAppValidationServiceTests | ||
{ | ||
private readonly ILogger<FunctionAppValidationService> _testLogger; | ||
private readonly Mock<IOptions<ScriptJobHostOptions>> _scriptOptionsMock; | ||
private readonly ScriptJobHostOptions _scriptJobHostOptions; | ||
private readonly TestLoggerProvider _testLoggerProvider; | ||
private readonly TimeSpan _initializationDelay = TimeSpan.FromSeconds(11); | ||
|
||
public FunctionAppValidationServiceTests() | ||
{ | ||
_scriptOptionsMock = new Mock<IOptions<ScriptJobHostOptions>>(); | ||
|
||
_scriptJobHostOptions = new ScriptJobHostOptions | ||
{ | ||
RootScriptPath = "test-root-path", | ||
IsDefaultHostConfig = false | ||
}; | ||
|
||
_scriptOptionsMock.Setup(o => o.Value).Returns(_scriptJobHostOptions); | ||
|
||
_testLoggerProvider = new TestLoggerProvider(); | ||
LoggerFactory factory = new LoggerFactory(); | ||
factory.AddProvider(_testLoggerProvider); | ||
_testLogger = factory.CreateLogger<FunctionAppValidationService>(); | ||
} | ||
|
||
[Fact] | ||
public async Task StartAsync_NotDotnetIsolatedApp_DoesNotLogError() | ||
{ | ||
_testLoggerProvider.ClearAllLogMessages(); | ||
|
||
var service = new FunctionAppValidationService( | ||
_testLogger, | ||
_scriptOptionsMock.Object, | ||
new TestEnvironment()); | ||
|
||
// Act | ||
await service.StartAsync(CancellationToken.None); | ||
surgupta-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
//Assert | ||
var traces = _testLoggerProvider.GetAllLogMessages(); | ||
var traceMessage = traces.FirstOrDefault(val => val.EventId.Name.Equals("NoAzureFunctionsFolder")); | ||
|
||
Assert.Null(traceMessage); | ||
} | ||
|
||
[Fact] | ||
public async Task StartAsync_PlaceholderMode_DoesNotLogError() | ||
{ | ||
_testLoggerProvider.ClearAllLogMessages(); | ||
|
||
var environment = new TestEnvironment(); | ||
environment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsitePlaceholderMode, "1"); | ||
|
||
var service = new FunctionAppValidationService( | ||
_testLogger, | ||
_scriptOptionsMock.Object, | ||
environment); | ||
|
||
// Act | ||
await service.StartAsync(CancellationToken.None); | ||
|
||
//Assert | ||
var traces = _testLoggerProvider.GetAllLogMessages(); | ||
var traceMessage = traces.FirstOrDefault(val => val.EventId.Name.Equals("NoAzureFunctionsFolder")); | ||
|
||
Assert.Null(traceMessage); | ||
} | ||
|
||
[Fact] | ||
public async Task StartAsync_NewAppWithNoPayload_DoesNotLogError() | ||
{ | ||
_testLoggerProvider.ClearAllLogMessages(); | ||
|
||
var environment = new TestEnvironment(); | ||
environment.SetEnvironmentVariable(EnvironmentSettingNames.FunctionWorkerRuntime, "dotnet-isolated"); | ||
|
||
var scriptOptionsMock = new Mock<IOptions<ScriptJobHostOptions>>(); | ||
|
||
var scriptJobHostOptions = new ScriptJobHostOptions | ||
{ | ||
RootScriptPath = "test-root-path", | ||
IsDefaultHostConfig = true | ||
}; | ||
|
||
scriptOptionsMock.Setup(o => o.Value).Returns(scriptJobHostOptions); | ||
|
||
var service = new FunctionAppValidationService( | ||
_testLogger, | ||
scriptOptionsMock.Object, | ||
environment); | ||
|
||
// Act | ||
await service.StartAsync(CancellationToken.None); | ||
|
||
//Assert | ||
var traces = _testLoggerProvider.GetAllLogMessages(); | ||
var traceMessage = traces.FirstOrDefault(val => val.EventId.Name.Equals("NoAzureFunctionsFolder")); | ||
|
||
Assert.Null(traceMessage); | ||
} | ||
|
||
[Fact] | ||
public async Task StartAsync_NoAzureFunctionsFolder_LogsWarning() | ||
{ | ||
_testLoggerProvider.ClearAllLogMessages(); | ||
|
||
// Arrange | ||
var functionMetadataList = ImmutableArray.Create(new FunctionMetadata()); | ||
|
||
var environment = new TestEnvironment(); | ||
environment.SetEnvironmentVariable(EnvironmentSettingNames.FunctionWorkerRuntime, "dotnet-isolated"); | ||
|
||
var service = new FunctionAppValidationService( | ||
_testLogger, | ||
_scriptOptionsMock.Object, | ||
environment); | ||
|
||
// Act | ||
await service.StartAsync(CancellationToken.None); | ||
|
||
await Task.Delay(_initializationDelay); | ||
surgupta-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
//Assert | ||
var traces = _testLoggerProvider.GetAllLogMessages(); | ||
var traceMessage = traces.FirstOrDefault(val => val.EventId.Name.Equals("NoAzureFunctionsFolder")); | ||
|
||
Assert.NotNull(traceMessage); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.