Azure Function with Service Control (Heartbeat & Metrics)

What is the teams advise on using Heartbeats and Metrics when running in an Azure Functions, assuming function are not running continually.

I have a NServicebus Azure Function that’s being triggered every 15min. It also has Heartbeat and Metrics enabled and it seems to be up continuously (which is logic if youre sending an heartbeat every 20sec). But this conflicts with the benefit of not running your function all the time.

Should I disable Heartbeat? I’m ok with that, but I still would like to recieive Metrics when it’s running. Is there a best practice configurating this, so that my function is not running constant?

Hi Remy,

The Heartbeats plugin and Metrics plugin do both have background processes that run while the endpoint is active but neither of them should affect the lifecycle of the function host. The function host will be shutdown if there has been no triggered functions in the timeframe defined by the functionTimeout. Even if one of the plugins is still running in the background, the process will be shut down if that timeout is reached.

Having said that, the heartbeats plugin is designed for endpoints that are “always on” and I wouldn’t recommend using it for endpoints hosted in Azure Functions.

The metrics plugin should work with Azure Functions but we haven’t specifically tested that combination. The plugin collects metric data about each message and sends a message with that data when its internal buffers are full or when a specific interval has passed (depending on which comes first).

Are there specific metrics that you are interested in that are missing from the built-in metrics that Azure Functions provides?

-Mike

Good to know that heartbeat and metrics are background processes and will not affect the lifecycle of the function host.

Are there specific metrics that you are interested in that are missing from the built-in metrics that Azure Functions provides?
No, I’m not missing any metrics. I use ServicePulse to monitor, and my understanding is that the following line is feeding these metrics to ServicePulse (through ServiceControl):
endpointConfiguration.EnableMetrics().SendMetricDataToServiceControl()

So therefore, I want this to be enabled when the Azure function is being triggered/running.

You are correct that the highlighted configuration sends data that shows up in ServicePulse.

Please let us know if you run into any issues with it.

Hi Mike,

Thanks for that info. I assume this is still the case. The heartbeats plugin is designed for endpoints that are “always on” and not recommended for endpoints hosted in Azure Functions. Correct?

Best regards,
Sam

Hi Sam,

It depends. I had a schedule azure function that runs every 15min and I enable the heartbeat plugin. It was sending every 20sec a heartbeat and keep doing that ongoing. That was the reason for my question.

Because of the answer of Mike, my assumption then is that the ongoing heartbeat that I got, is because the function doesn’t have enough time between 15min to scale down. In my case having an ongoing heartbeat is ok.

I now changed to my own App Plan, which means it is always up (and the heartbeat is ongoing).