MicrosoftDocs / azure-docs

Open source documentation of Microsoft Azure
https://docs.microsoft.com/azure
Creative Commons Attribution 4.0 International
10.2k stars 21.34k forks source link

How to disable a function when running in Container on AKS? #83932

Open miqm opened 2 years ago

miqm commented 2 years ago

Hello,

Can you provide details how to disable particular function (how to format the environment variable I guess) when running Functions Host in Container outside App Service i.e. on AKS? Or if it cannot be done, please add to considerations that this is not possible.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

KranthiPakala-MSFT commented 2 years ago

Thank you for reaching out. At this time we are reviewing the ask and will provide an update as appropriate

miqm commented 2 years ago

Hello, any update on this?

gabr1elt-arc commented 2 years ago

Functions running in containers seem to ignore the disable setting. Is there any setting that can fix this?

gabr1elt-arc commented 2 years ago

I guess this works in a pinch: https://docs.microsoft.com/en-us/azure/azure-functions/functions-host-json#functions but it would be way easier to implement with a setting.

miqm commented 1 year ago

I found the solution, but it would be nice to be documented on the page.

option 1: use allow list - mainly specify list of functions you want to load by setting environment variables

AzureFunctionsJobHost__functions__0 = "function1_name"
AzureFunctionsJobHost__functions__1 = "function2_name"

Plus to disable a particular loaded function use single underscore instead the dot as specified on the docs:

AzureWebJobs_function1_name_Disabled: 1

A bit of background: The code responsible for loading functions uses asp.net configuration mechanism which is hierarchical and the delimiter there is two (2) underscores:v https://github.com/Azure/azure-functions-host/blob/2a1327f4c142f4226256262635fd4b70bcc969c0/src/WebJobs.Script/Host/FunctionMetadataManager.cs#L96-L106 as described here: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-7.0#non-prefixed-environment-variables:~:text=The%20%3A%20separator,by%20a%20%3A

But the code responsible for disabling particular function uses own implementation: https://github.com/Azure/azure-webjobs-sdk/blob/eb19c9ec01bb29391934720f93c7dc416a9f1715/src/Microsoft.Azure.WebJobs.Host/Listeners/HostListenerFactory.cs#L150-L159

It would be good to add to this page note that on linux self-hosting we need to use underscore instead dot in environment variables.

This is done by the app service seamlessly and we can observe envs with _ in Kudu. But anyway - #KranthiPakala-MSFT -please update the docs with the solution.