We recently tried out the premium plan for our azure functions and we are noticing a lot of requests for 'admin/warmup'. My guess is that it is part of the premium plan for keeping the function workers alive, but I couldn't find any documentation on this. Anybody knows if this is the case?
That's correct!
Here's a snippet from Azure Functions HostController
[HttpGet]
[HttpPost]
[Route("admin/warmup")]
[Authorize(Policy = PolicyNames.AdminAuthLevelOrInternal)]
[RequiresRunningHost]
public async Task<IActionResult> Warmup([FromServices] IScriptJobHost scriptHost)
{
await scriptHost.TryInvokeWarmupAsync();
return Ok();
}
The changes are made recently and the docs aren't updated with that yet. You can validate the same with this git commit:
https://github.com/Azure/azure-functions-host/commit/30405116a72e90ab17e77d2c39787d2e7f6f9570
Related
How is it that we can't access RetryContext on the ExecutionContext on a Azure Function?
try
{
//my code here....
}
catch (Exception ex)
{
if (executionContext.RetryContext?.RetryCount)
}
The RetryContext property is not there? WTF?!
Please check the below steps if it helps to fix the issue:
In .NET 6 Azure Functions (v4), RetryContext is available as part of FunctionContext/ExecutionContext as given in this MS Doc.
It can be accessible using the Namespace Microsoft.Azure.Functions.Worker.
The Same Property RetryContext is part of the ExecutionContext when it comes to non-dotnet languages as given in the GitHub Repos of Azure Functions Host Retry Context include proposal.
I'm still trying to learn about Azure Functions and best practices, but as I understand there are two ways to separate logic by http verb (GET, POST, etc.). Is there a standard or best practice that would prefer either of the two below methods? And more importantly, is there a cost difference between the two methods when running in Azure, assuming the underlying logic stays the same?
Method A:
public static class Function1
{
[FunctionName("Function1")]
public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req)
{
if (req.Method == HttpMethods.Get)
{
// do stuff here
}
else if (req.Method == HttpMethods.Post)
{
// do stuff here
}
}
}
Method B:
public static class GetFunction
{
[FunctionName("GetFunction")]
public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req)
{
// do stuff here
}
}
public static class PostFunction
{
[FunctionName("PostFunction")]
public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req)
{
// do stuff here
}
}
In short the answer to your question about pricing is, IT will be the same for both. It will be equal to the time your logic runs. You should use Consumption plan. If you are looking for cost savings. Microsoft says
"
Azure Functions consumption plan is billed based on per-second resource consumption and executions. Consumption plan pricing includes a monthly free grant of 1 million requests and 400,000 GB-s of resource consumption per month per subscription in pay-as-you-go pricing across all function apps in that subscription."
Here is a link to more details.
https://azure.microsoft.com/en-us/pricing/details/functions/
As far as your second question is concerned. IMO you should use separate functions for get and post. In this way you can separate the endpoints and handle both calls differently. But this kind a breaks the RESTful API practice. So its give and take. :)
You had asked if there is a standard or best practice for using GET or POST. Generally, in REST world, you use GET if you are fetching a resource and POST when you want to create a new resource. So, it basically depends on what you are trying to achieve using the Function. Found a similar questions here > https://stackoverflow.com/a/504993/5344880 and When do you use POST and when do you use GET?
Regarding the pricing, it is based on the number of executions and memory and not by logic. This link will provide more details https://azure.microsoft.com/en-in/pricing/details/functions/ Please do note that there is hard timeout of 10 minutes for Azure Functions
Hope this helps.
I'm working on exploring the following 2 features of Azure App Configuration in Azure Function's Http Trigger
Externalizing the App Settings
Feature Flags
Below is how i'm getting the reference of the configuration
So, when I use _configuration["SomeAppSettingKey"], I'm able to retrieve the value. So, I'm able to achieve #1 feature mentioned above.
My Question is, How do we retrieve the Feature Flag information? I have tried the below ways.
I would appreciate if someone could help me in understanding how to retrieve it in Azure Functions (I'm using V3)? A Sample code or any reference to documentation would be helpful.
Thanks.
Update1:
I can deserialize the json content as shown below. But, is this is the right approach?
Where FeatureManager is a class that I have defined as shown below.
all you need is to call UseFeatureFlags() function as part of AddAzureAppConfiguration to let the App Configuration provider know you want to use feature flags. An example can be found following the link below. It uses the FunctionsStartup and dependency injection (DI) of Azure Functions. An instance of a feature manager is put into the DI.
https://github.com/Azure/AppConfiguration/blob/master/examples/DotNetCore/AzureFunction/FunctionApp/Startup.cs
The link below shows how you can obtain the instance of IFeatureManagerSnapshot from DI and use it as part of your Azure Functions call.
https://github.com/Azure/AppConfiguration/blob/master/examples/DotNetCore/AzureFunction/FunctionApp/ShowBetaFeature.cs
Deserialize JSON is not a good idea, every time you will add new key you need to modify your class.
private static IConfiguration Configuration { set; get; }
static Function1()
{
var builder = new ConfigurationBuilder();
builder.AddAzureAppConfiguration(Environment.GetEnvironmentVariable("ConnectionString"));
Configuration = builder.Build();
}
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string keyName = "TestApp:Settings:Message";
string message = Configuration[keyName];
return message != null
? (ActionResult)new OkObjectResult(message)
: new BadRequestObjectResult($"Please create a key-value with the key '{keyName}' in App Configuration.");
}
I have a series of Azure Functions, and I'd like to keep track of them by the InovcationId. In Application Insights, the InvocationId is called the operation_Id.
What I'm trying to do is set the operation_Id to be the same across several different Azure Functions.
I can read this property inside the Azure Function when I pass in ExecutionContext by following this answer, but I can't seem to alter it. Is there some way to change this value from inside the Azure Function?
public static class TestOperationId
{
[FunctionName("TestOperationId")]
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req,
ILogger log,
ExecutionContext exeCtx
)
{
var input = await req.Content.ReadAsStringAsync();
log.Info(input);
exeCtx.InvocationId = Guid.Parse(input);
return req.CreateResponse(HttpStatusCode.OK);
}
}
The definition for the InvocationId field is defined as
Provides the invocation ID, uniquely identifying the current invocation
Azure Functions doesn't provide changing this, as it would mean that code could override the platform's methods to detect unique invocations of Functions, which would interfere with things like Billing and Metrics for the platform.
It sounds like what you really want is cross-function correlation. There is work being done with the Application Insights team to help support this, but in the meantime, you can see solutions that others are currently utilizing, like here.
In Visual Studio 2017 with the latest update, for azure functions template, I want something where I can initialize like program.cs in webjobs template.
I am trying to create a new subscription with new namespace Manager when application initializes so that I can listen to one service bus topic.
Is there a way to do that? If yes then how?
If you intend to create a subscription that this Function will be triggered on, there is no need to do that manually. Function App will create the subscription based on your binding at deployment time.
For other scenarios (e.g. timer-triggered function), you can do the initialization in a static constructor:
public static class MyFunction1
{
static MyFunction1()
{
var namespaceManager = NamespaceManager.CreateFromConnectionString(connString);
if (!namespaceManager.SubscriptionExists("topic1", "subscription1"))
{
namespaceManager.CreateSubscription("topic1", "subscription1");
}
}
[FunctionName("MyFunction1")]
public static void Run(
// ...
}
Static constructor will run at the time of the first function call.
for azure functions template, I want something where I can initialize like program.cs in webjobs template.
As far as I know, Azure functions do not have good support for this right now. You can find a similar question:
Question:
I have a C# function and want to know if there is any Initialization point. I have dependency injection containers that need initialization
and want to know where to do that.
Mathew's reply
We don't have a good story for this right now. Please see open issue
here in our repo where this is discussed.