Maintenance mode for web availability tests in Application Insights

Search for a command to run...

No comments yet. Be the first to comment.
If you have been following my experiments for hosting and running Ghost on Azure, you might recall that I tried hosted it on Azure Web App for Containers first, using the Docker Compose for running a

I recently presented on a webinar hosted by the Turbo360 team and Michael Stephenson, the host of Azure on Air and FinOps on Azure podcasts. There, we discussed the most common mistakes in optimizing compute costs in Azure and how to avoid them, the ...

I’ve been watching the development of Radius, a new application hosting platform that originated in the Microsoft Azure Incubations team and later became a CNCF project, for a while, and I finally managed to dedicate some time to trying it in practic...

It has been some time since I wrote my Azure Policy Starter Guide, in which I briefly touched upon the challenges of testing custom Azure Policy definitions. Azure Policy testing still remains an open question for me, offering a lot of room for vario...

When optimizing cloud costs for large enterprise environments, it’s common to focus on compute-intensive cloud resources, such as virtual machines, clusters, and container-based workloads, as they are usually the primary cost driver and top contribut...

Many teams that host applications in Azure App Service set up the availability monitoring for their apps using Application Insights web tests, which can be basic URL ping checks and more advanced multi-step and performance ones. A common approach when creating such tests is configuring alerts to notify or trigger an action on some criteria, i.e., when the tests fail.

As a result, people responsible for keeping the application alive are aware when something goes wrong with it and can take remediation actions.
Also, it is common practice to put an application or service in operation into maintenance mode in a monitoring solution before making any changes to it or updating its components so as not to be woken up at 2 a.m. by false-positive alerts on your “pager.”
Regarding the Azure App Service applications, in my example, misleading notifications from the web test were triggered during the regular, continuous deployments from Azure DevOps pipelines. This was not good, as each time, the Ops had to verify with the Devs whether the issue was not fake.
Unfortunately, there is no such handy built-in maintenance mode for monitored items in Application Insights as, for example, in System Center Operations Manager, where you can suspend all alerting for a specific configuration item or a group of items for some period and not worry about putting them back on monitoring later.
To make it worse, there are even no PowerShell cmdlets yet to work with the web tests, specifically in Az 3.0.0:

Currently, one of the options to interact with ‘Microsoft.Insights/webtests’ resources is to use generic ‘Get-AzResource’ and ‘Set-AzResource’ PowerShell cmdlets. They might not be as convenient as specialized cmdlets, but they still do the job as you can manipulate resource properties.
For example, a script to disable all web tests in a specific resource group might look like the following:
To enable them back, you can modify the ‘Enabled’ property to ‘True’ and rerun the script.
Armed with these scripts, you can emulate the maintenance mode for your application in the deployment pipeline:

You can use the Azure PowerShell tasks to disable the tests before deployment and enable them back afterward.
Also, don’t forget to configure the run conditions for the enabling task so you have your monitoring turned on even if a previous task, e.g., a deployment, failed:

A sample YAML snippet for this:
Also, I didn’t want to use ARM REST APIs in my solution as their format usually makes the script logic hard to understand, and IMHO, it is a complete nightmare for future solution maintenance.
How do you monitor your apps in production and put them in maintenance mode? Share your experience in the comments!