Web Tests Thoughts
Khaled Hikmat
Software EngineerIf a Web App is deployed on Azure, both the App Insights and Web Apps offer a utility that can hammer the app's endpoints from different regions. While this functionality is quite nice and comes bundled in, it is considered an alert-based system and is slightly rudimentary as one cannot customize the test or get access to the full results easily. This post describes an alternative approach that uses Azure Functions or Service Fabric to implement a web test that can test and endpoint and report its test to PowerBI in real time.
What I really wanted to do is to conduct a web test for a duration of time from different regions against a new product's endpoints at launch time and immediately view the test results with executives.
#
Azure FunctionsBriefly, here is what I decided to do:
- Use PowerShell to provision resource groups in four different regions. Each resource group contains an Azure Function App that loads its source code from a code repository.
- Use source code changes to trigger updates to all the functions apps at the same time.
- Configure the Azure Functions App to test a Web URL or a collection. This test can be sophisticated because we have the full power of an Azure Function to conduct the test. In other words, the test can be running through a use case scenario as opposed to just posting to a URL, for example.
- Auto-trigger the Azure Functions by a timer (i.e. configurable) to repeat the test.
- Report the source (i.e region), duration, URL, date time and status code to a PowerBI real-time data set at the end of every test iteration.
- Create a real-time visualization to see, in real-time, the test results.
- Use PowerShell script to de-provision the resource groups when the test is no longer needed.
The source code can be found here.
#
Macro Architecture#
Azure Resource Group TemplateI downloaded an Azure Function template and modified it to suit my needs. The main thing in the template is that it defines the repository URL and branch from which the source code is to be imported and the definitions of the app strings:
Here is the entire template:
Here is the template parameters file:
#
PowerShell ScriptThe PowerShell script is the main driver that orchestrates the deployment and of the different Azure Functions to different resource groups. Here is the complete script:
Once you run the deployments, u will see something like this in your subscription resource groups:
#
PowerBI Real-Time DatasetUsing this nifty feature in PowerBI, I defined a real-time dataset that looks like this:
This gave me a URL that I can use from Azure Functions to pump data into this Real-time dataset. Also please note that I enbaled the historic data analysis
to allow me to report on the data and visualize it in real-time and beyond.
#
Azure Function Source CodeFinally, the Azure Function source code that conducts the test and reports to PowerBI:
#
Results VisualizationIf we deploy the Azure Functions and collect the results in PowerBI, we can get real-time results that look like this:
Hopefully this visualization helps executives to see a clear indication that the product launch is not that successful :-)
#
Service FabricI also wanted to mantion that Azure Service Fabric could also be used to conduct a web test from hammering the test site from multiple instances. Briefly, here is what I thought of doing:
- Create a Web Test Application Type. The Service Fabric app contains a single stateless service which does work on its RunAsync method.
- Use a PowerShell script to instantiate multiple tenants (or named applications): one for each region. Please note that the tenants simulate the different regions as they are all sitting in the same cluster!
- Update (i.e increase or decrease the number of the stateless service instances) each tenant (or named application) independently. This means that, unlike the Azure Functions, the system under-test can be hammered from multiple instances within the same tenant if need be.
- Write sophisticated tests within Service Fabric because the stateless service is doing it and the service can have a lot of configuration to govern that process.
- Report the source (i.e region), duration, URL, date time and status code to a PowerBI real-time data set at the end of every test iteration.
- Create a real-time visualization to see, in real-time, the test results.
- Use PowerShell script to de-provision the resource groups when the test is no longer needed.
I will publish the Service Fabric web test solution in a different blog post. For now, here is the macro architecture that I am thinking about: