SlideShare a Scribd company logo
1 of 33
Download to read offline
#PitchOnline presents:
#PitchOnline presents:
Massimo Bonanni
Paranormal Trainer, with the head in the Cloud and all the REST in microservices!
massimo.bonanni@microsoft.com
@massimobonanni
Scifoni Ivano Fabio Mannis Francesco Del Re Matteo Riccardi Valerio Benedetti
The art of Azure Functions (unit) testing and monitoring!
The issue….
If you want to use Azure
Functions as components
of your Enterprise
solutions, you must test
and monitor them!!!
What are Azure Functions
Author functions in
C#, F#, Node.JS, Java,
Powershell, and more
Code
Events
React to timers, HTTP
, or
events from your favorite
Azure services, with more
on the way
Outputs
Send results to an
ever-growing collection
of services
The art of Azure Functions (unit) testing and monitoring!
What is a Unit Test
In a unit test you invoke a piece of your code with a
set of parameters and you checks the correctness its
behavior.
In a unit test you must substitute all your external
reference with a mock or stub.
Mock is for the software what a dummy is for a car
crash test (you don’t test a car with a human being
inside…I Hope!!)
The art of Azure Functions (unit) testing and monitoring!
Azure Functions Dependencies
You should implement your Azure Functions to allow you to
use mock/stub for all external reference!
Your
Function
Trigger
Binding
Binding
Binding
Binding
Your Service
Your Service
Your Service
Your Service
Logger
(infrastructure)
The art of Azure Functions (unit) testing and monitoring!
Azure Function … untestable!!
The art of Azure Functions (unit) testing and monitoring!
Azure Function … trigger!!
Trigger
You can mock it
because the trigger
payload is a POCO
class
The art of Azure Functions (unit) testing and monitoring!
Azure Function … bindings!!
Binding
You can mock it because
the binding payload is
an interface
The art of Azure Functions (unit) testing and monitoring!
Azure Function … logger!!
Logger
(infrastructural objects)
You can mock it because
the logger is an interface
The art of Azure Functions (unit) testing and monitoring!
Azure Function … your service!!
External service
You cannot substitute it
with your mock because it
is created inside the Azure
Function and you haven’t a
way to substitute it
The art of Azure Functions (unit) testing and monitoring!
Make your Azure Function testable!!!
The solution of your problem is: Dependency Injection !!
Azure Functions Runtime is based on .NET Core.
Azure Functions support the same ASP.NET Core
Dependency Injection!!!
Using Dependency Injection you provide a way to substitute
your Services with a mock!
The art of Azure Functions (unit) testing and monitoring!
Azure Function … testable!!
Constructor Injection
You can choose what kind of
actual service you want to use
when you instantiate the
function.
In a test you can substitute it
with a mock!!
The art of Azure Functions (unit) testing and monitoring!
Azure Function … how to use mock!!
Mock
Create a mock to use in the
test!!
The art of Azure Functions (unit) testing and monitoring!
DEMO
Azure Functions
Unit Testing
The art of Azure Functions (unit) testing and monitoring!
Monitoring Azure Functions
Once you deploy your Azure Functions on Azure, you need to monitor them to check when something
goes wrong.
The signature of an Azure Function Run method provides the instance of ILogger that you can use to log
information about your code.
Using ILogger, you can collect information from your code execution to monitor and triage errors and
exceptions.
The art of Azure Functions (unit) testing and monitoring!
Azure Functions Monitor
Azure Functions provide out-of-the-box monitor feature.
For each Function, you can have info about every function execution.
The art of Azure Functions (unit) testing and monitoring!
Azure Functions and Application Insight
The Azure Functions platform offers built-in integration with Azure
Application Insights.
Put the Application Insights instrumentation key in the function app
settings.
The art of Azure Functions (unit) testing and monitoring!
Configure monitoring
Logging is configured in host.json file.
Logger default level
Logger level for all the functions in
Function App
Logger level for a specific function
in Function App
Logger category for .NET runtime
components invoked by the host
The art of Azure Functions (unit) testing and monitoring!
Custom Metrics
Azure Function SDK
provides you extension
methods to log custom
metrics.
The art of Azure Functions (unit) testing and monitoring!
Pricing
Azure Functions consumption plan is billed based on per-second
resource consumption and executions
The art of Azure Functions (unit) testing and monitoring!
Pricing
Azure Functions consumption plan is billed based on per-second
resource consumption and executions
If your function use 1GB of
memory and its duration is 1
second, you pay €0.000014
each time the function runs.
The art of Azure Functions (unit) testing and monitoring!
Pricing
Azure Functions consumption plan is billed based on per-second
resource consumption and executions If your function runs 1 million
times every month, you pay
€0.169 each month.
The art of Azure Functions (unit) testing and monitoring!
Pricing - Example
You have a function:
• It runs every second
• Its duration is 1 second
• It uses 512 MB of memory
The art of Azure Functions (unit) testing and monitoring!
Resource Consumption Billing Calculation
• It runs every second
• Its duration is 1 second
• It uses 512 MB of memory
Executions 2,592,000
Resource Consumption Total 2,592,000 x 1 sec = 2,592,000 sec
Total GB-s 2,592,000 x 0.5 GB = 1,296,000 GB-s
Total billable consumption 1,296,000 – 400,000 = 896,000 GB-s
Total cost 896,000 x 0.000014€ = 12.54 €
The art of Azure Functions (unit) testing and monitoring!
Executions billing calculation
• It runs every second
• Its duration is 1 second
• It uses 512 MB of memory
Billable Monthly Executions 2,592,000 – 1,000,000 = 1,592,000
Total cost 1.592 x 0.169 € = 0.269 €
The art of Azure Functions (unit) testing and monitoring!
Total Monthly Cost
• It runs every second
• Its duration is 1 second
• It uses 512 MB of memory
Monthly resource consumption cost 12.540 €
Monthly executions cost 0.269 €
Total monthly cost 12.809 €
The art of Azure Functions (unit) testing and monitoring!
DEMO
Azure Functions
Monitoring
The art of Azure Functions (unit) testing and monitoring!
Takeaway
Write an Azure Functions is simple!
Testing Azure Functions is simple!
Monitoring Azure Functions is simple!
…. then ….
Photo by Aaron Burden on Unsplash
Massimo Bonanni
Azure Technical Trainer @ Microsoft
massimo.bonanni@microsoft.com
@massimobonanni
Connect with me on LinkedIn
linkedin.com/in/massimobonanni/
http://bit.ly/MasteringServerless
References
Azure Functions Documentation
https://docs.microsoft.com/en-US/azure/azure-functions/
Azure Functions Code Samples
https://azure.microsoft.com/en-us/resources/samples/?service=functions&sort=0
Azure Updates
https://azure.microsoft.com/en-us/roadmap/?category=compute
Azure Friday – Build Serverless APIs with Azure Functions
https://azure.microsoft.com/en-us/resources/videos/azure-friday-build-serverless-apis-with-azure-functions/
GitHub Demo
https://github.com/massimobonanni/AzureFunctionsSamples
The art of Azure Functions (unit) testing and monitoring!
Thank You!
Our Socials

More Related Content

What's hot

Servicehost Customization
Servicehost CustomizationServicehost Customization
Servicehost CustomizationEyal Vardi
 
Testing a Service Fabric solution and live happy!!
Testing a Service Fabric solution and live happy!!Testing a Service Fabric solution and live happy!!
Testing a Service Fabric solution and live happy!!Massimo Bonanni
 
Xmas Serverless Transformation: when the elf doesn’t scale!
Xmas Serverless Transformation: when the elf doesn’t scale!Xmas Serverless Transformation: when the elf doesn’t scale!
Xmas Serverless Transformation: when the elf doesn’t scale!Massimo Bonanni
 
Discovering the Service Fabric's actor model
Discovering the Service Fabric's actor modelDiscovering the Service Fabric's actor model
Discovering the Service Fabric's actor modelMassimo Bonanni
 
Windows iot barone
Windows iot baroneWindows iot barone
Windows iot baroneDotNetCampus
 
Discovering the Service Fabric's actor model
Discovering the Service Fabric's actor modelDiscovering the Service Fabric's actor model
Discovering the Service Fabric's actor modelMassimo Bonanni
 
Integrating consumers IoT devices into Business Workflow
Integrating consumers IoT devices into Business WorkflowIntegrating consumers IoT devices into Business Workflow
Integrating consumers IoT devices into Business WorkflowYakov Fain
 
Angular 4 for Java Developers
Angular 4 for Java DevelopersAngular 4 for Java Developers
Angular 4 for Java DevelopersYakov Fain
 
Reactive Thinking in Java with RxJava2
Reactive Thinking in Java with RxJava2Reactive Thinking in Java with RxJava2
Reactive Thinking in Java with RxJava2Yakov Fain
 
Angular2 Development for Java developers
Angular2 Development for Java developersAngular2 Development for Java developers
Angular2 Development for Java developersYakov Fain
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScriptYakov Fain
 
Building a Lightning App with Angular Material Design
Building a Lightning App with Angular Material DesignBuilding a Lightning App with Angular Material Design
Building a Lightning App with Angular Material DesignSalesforce Developers
 
Asp.Net Ajax Component Development
Asp.Net Ajax Component DevelopmentAsp.Net Ajax Component Development
Asp.Net Ajax Component DevelopmentChui-Wen Chiu
 
Advanced Spring Boot with Consul
Advanced Spring Boot with ConsulAdvanced Spring Boot with Consul
Advanced Spring Boot with ConsulVMware Tanzu
 
Deep dive into azure durable functions
Deep dive into azure durable functionsDeep dive into azure durable functions
Deep dive into azure durable functionsAhmed Elharouny
 
Phonegap android angualr material design
Phonegap android angualr material designPhonegap android angualr material design
Phonegap android angualr material designSrinadh Kanugala
 

What's hot (20)

Servicehost Customization
Servicehost CustomizationServicehost Customization
Servicehost Customization
 
Testing a Service Fabric solution and live happy!!
Testing a Service Fabric solution and live happy!!Testing a Service Fabric solution and live happy!!
Testing a Service Fabric solution and live happy!!
 
Xmas Serverless Transformation: when the elf doesn’t scale!
Xmas Serverless Transformation: when the elf doesn’t scale!Xmas Serverless Transformation: when the elf doesn’t scale!
Xmas Serverless Transformation: when the elf doesn’t scale!
 
Introducing to Azure Functions
Introducing to Azure FunctionsIntroducing to Azure Functions
Introducing to Azure Functions
 
Discovering the Service Fabric's actor model
Discovering the Service Fabric's actor modelDiscovering the Service Fabric's actor model
Discovering the Service Fabric's actor model
 
Linq
LinqLinq
Linq
 
Azure functions
Azure functionsAzure functions
Azure functions
 
Windows iot barone
Windows iot baroneWindows iot barone
Windows iot barone
 
Discovering the Service Fabric's actor model
Discovering the Service Fabric's actor modelDiscovering the Service Fabric's actor model
Discovering the Service Fabric's actor model
 
Grails with swagger
Grails with swaggerGrails with swagger
Grails with swagger
 
Integrating consumers IoT devices into Business Workflow
Integrating consumers IoT devices into Business WorkflowIntegrating consumers IoT devices into Business Workflow
Integrating consumers IoT devices into Business Workflow
 
Angular 4 for Java Developers
Angular 4 for Java DevelopersAngular 4 for Java Developers
Angular 4 for Java Developers
 
Reactive Thinking in Java with RxJava2
Reactive Thinking in Java with RxJava2Reactive Thinking in Java with RxJava2
Reactive Thinking in Java with RxJava2
 
Angular2 Development for Java developers
Angular2 Development for Java developersAngular2 Development for Java developers
Angular2 Development for Java developers
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
 
Building a Lightning App with Angular Material Design
Building a Lightning App with Angular Material DesignBuilding a Lightning App with Angular Material Design
Building a Lightning App with Angular Material Design
 
Asp.Net Ajax Component Development
Asp.Net Ajax Component DevelopmentAsp.Net Ajax Component Development
Asp.Net Ajax Component Development
 
Advanced Spring Boot with Consul
Advanced Spring Boot with ConsulAdvanced Spring Boot with Consul
Advanced Spring Boot with Consul
 
Deep dive into azure durable functions
Deep dive into azure durable functionsDeep dive into azure durable functions
Deep dive into azure durable functions
 
Phonegap android angualr material design
Phonegap android angualr material designPhonegap android angualr material design
Phonegap android angualr material design
 

Similar to The art of Azure Functions (unit) testing and monitoring

Serverless Computing with Azure
Serverless Computing with AzureServerless Computing with Azure
Serverless Computing with AzureAnalben Mehta
 
Azure Functions.pptx
Azure Functions.pptxAzure Functions.pptx
Azure Functions.pptxYachikaKamra
 
Serverless API with Azure Functions
Serverless API with Azure FunctionsServerless API with Azure Functions
Serverless API with Azure FunctionsAnalben Mehta
 
Getting Started with Serverless Architectures using Azure Functions
Getting Started with Serverless Architectures using Azure FunctionsGetting Started with Serverless Architectures using Azure Functions
Getting Started with Serverless Architectures using Azure FunctionsMarc Duiker
 
Massimo Bonanni - Workflow as code with Azure Durable Functions - Codemotion ...
Massimo Bonanni - Workflow as code with Azure Durable Functions - Codemotion ...Massimo Bonanni - Workflow as code with Azure Durable Functions - Codemotion ...
Massimo Bonanni - Workflow as code with Azure Durable Functions - Codemotion ...Codemotion
 
Serverless Development with Azure Durable Functions in .Net by Jonah Andersson
Serverless Development with Azure Durable Functions in .Net by Jonah AnderssonServerless Development with Azure Durable Functions in .Net by Jonah Andersson
Serverless Development with Azure Durable Functions in .Net by Jonah AnderssonJonah Andersson
 
Guidelines to understand durable functions with .net core, c# and stateful se...
Guidelines to understand durable functions with .net core, c# and stateful se...Guidelines to understand durable functions with .net core, c# and stateful se...
Guidelines to understand durable functions with .net core, c# and stateful se...Concetto Labs
 
Serverless on Azure with Functions
Serverless on Azure with FunctionsServerless on Azure with Functions
Serverless on Azure with FunctionsChristos Matskas
 
SharePoint meetup Speaking Deck - Knowing the formula
SharePoint meetup Speaking Deck -  Knowing the formulaSharePoint meetup Speaking Deck -  Knowing the formula
SharePoint meetup Speaking Deck - Knowing the formulaKenneth Cooper
 
Building stateful serverless orchestrations with Azure Durable Azure Function...
Building stateful serverless orchestrations with Azure Durable Azure Function...Building stateful serverless orchestrations with Azure Durable Azure Function...
Building stateful serverless orchestrations with Azure Durable Azure Function...Callon Campbell
 
Anti Patterns and Mistakes Using Serverless (ServerlessConf SF - 08 2018)
Anti Patterns and Mistakes Using Serverless (ServerlessConf SF - 08 2018)Anti Patterns and Mistakes Using Serverless (ServerlessConf SF - 08 2018)
Anti Patterns and Mistakes Using Serverless (ServerlessConf SF - 08 2018)Yochay Kiriaty
 
Durable Azure Functions
Durable Azure FunctionsDurable Azure Functions
Durable Azure FunctionsPushkar Saraf
 
Workflow as code with Azure Durable Functions
Workflow as code with Azure Durable FunctionsWorkflow as code with Azure Durable Functions
Workflow as code with Azure Durable FunctionsMassimo Bonanni
 
Building API in the cloud using Azure Functions
Building API in the cloud using Azure FunctionsBuilding API in the cloud using Azure Functions
Building API in the cloud using Azure FunctionsAleksandar Bozinovski
 
Building scalable applications with angular js
Building scalable applications with angular jsBuilding scalable applications with angular js
Building scalable applications with angular jsAndrew Alpert
 
4 Integrating azure monitor with power bi and power automate
4 Integrating azure monitor with power bi and power automate4 Integrating azure monitor with power bi and power automate
4 Integrating azure monitor with power bi and power automateKumton Suttiraksiri
 

Similar to The art of Azure Functions (unit) testing and monitoring (20)

Azure Functions - Introduction
Azure Functions - IntroductionAzure Functions - Introduction
Azure Functions - Introduction
 
Serverless Computing with Azure
Serverless Computing with AzureServerless Computing with Azure
Serverless Computing with Azure
 
Azure Functions.pptx
Azure Functions.pptxAzure Functions.pptx
Azure Functions.pptx
 
Serverless API with Azure Functions
Serverless API with Azure FunctionsServerless API with Azure Functions
Serverless API with Azure Functions
 
Getting Started with Serverless Architectures using Azure Functions
Getting Started with Serverless Architectures using Azure FunctionsGetting Started with Serverless Architectures using Azure Functions
Getting Started with Serverless Architectures using Azure Functions
 
slides.pptx
slides.pptxslides.pptx
slides.pptx
 
Durable functions
Durable functionsDurable functions
Durable functions
 
Save Azure Cost
Save Azure CostSave Azure Cost
Save Azure Cost
 
Massimo Bonanni - Workflow as code with Azure Durable Functions - Codemotion ...
Massimo Bonanni - Workflow as code with Azure Durable Functions - Codemotion ...Massimo Bonanni - Workflow as code with Azure Durable Functions - Codemotion ...
Massimo Bonanni - Workflow as code with Azure Durable Functions - Codemotion ...
 
Serverless Development with Azure Durable Functions in .Net by Jonah Andersson
Serverless Development with Azure Durable Functions in .Net by Jonah AnderssonServerless Development with Azure Durable Functions in .Net by Jonah Andersson
Serverless Development with Azure Durable Functions in .Net by Jonah Andersson
 
Guidelines to understand durable functions with .net core, c# and stateful se...
Guidelines to understand durable functions with .net core, c# and stateful se...Guidelines to understand durable functions with .net core, c# and stateful se...
Guidelines to understand durable functions with .net core, c# and stateful se...
 
Serverless on Azure with Functions
Serverless on Azure with FunctionsServerless on Azure with Functions
Serverless on Azure with Functions
 
SharePoint meetup Speaking Deck - Knowing the formula
SharePoint meetup Speaking Deck -  Knowing the formulaSharePoint meetup Speaking Deck -  Knowing the formula
SharePoint meetup Speaking Deck - Knowing the formula
 
Building stateful serverless orchestrations with Azure Durable Azure Function...
Building stateful serverless orchestrations with Azure Durable Azure Function...Building stateful serverless orchestrations with Azure Durable Azure Function...
Building stateful serverless orchestrations with Azure Durable Azure Function...
 
Anti Patterns and Mistakes Using Serverless (ServerlessConf SF - 08 2018)
Anti Patterns and Mistakes Using Serverless (ServerlessConf SF - 08 2018)Anti Patterns and Mistakes Using Serverless (ServerlessConf SF - 08 2018)
Anti Patterns and Mistakes Using Serverless (ServerlessConf SF - 08 2018)
 
Durable Azure Functions
Durable Azure FunctionsDurable Azure Functions
Durable Azure Functions
 
Workflow as code with Azure Durable Functions
Workflow as code with Azure Durable FunctionsWorkflow as code with Azure Durable Functions
Workflow as code with Azure Durable Functions
 
Building API in the cloud using Azure Functions
Building API in the cloud using Azure FunctionsBuilding API in the cloud using Azure Functions
Building API in the cloud using Azure Functions
 
Building scalable applications with angular js
Building scalable applications with angular jsBuilding scalable applications with angular js
Building scalable applications with angular js
 
4 Integrating azure monitor with power bi and power automate
4 Integrating azure monitor with power bi and power automate4 Integrating azure monitor with power bi and power automate
4 Integrating azure monitor with power bi and power automate
 

More from Massimo Bonanni

Architetture Serverless con SQL Server e Azure Functions
Architetture Serverless con SQL Server e Azure FunctionsArchitetture Serverless con SQL Server e Azure Functions
Architetture Serverless con SQL Server e Azure FunctionsMassimo Bonanni
 
Tutto quello che avreste voluto sapere sull'API Management (e non avete mai o...
Tutto quello che avreste voluto sapere sull'API Management (e non avete mai o...Tutto quello che avreste voluto sapere sull'API Management (e non avete mai o...
Tutto quello che avreste voluto sapere sull'API Management (e non avete mai o...Massimo Bonanni
 
Everything you always wanted to know about API Management (but were afraid to...
Everything you always wanted to know about API Management (but were afraid to...Everything you always wanted to know about API Management (but were afraid to...
Everything you always wanted to know about API Management (but were afraid to...Massimo Bonanni
 
Welcome Azure Functions 2. 0
Welcome Azure Functions 2. 0Welcome Azure Functions 2. 0
Welcome Azure Functions 2. 0Massimo Bonanni
 
Soluzioni IoT con le tecnologie Microsoft
Soluzioni IoT con le tecnologie MicrosoftSoluzioni IoT con le tecnologie Microsoft
Soluzioni IoT con le tecnologie MicrosoftMassimo Bonanni
 
Project Gesture & Real Sense: il potere nelle mani!!
Project Gesture & Real Sense: il potere nelle mani!!Project Gesture & Real Sense: il potere nelle mani!!
Project Gesture & Real Sense: il potere nelle mani!!Massimo Bonanni
 
Project Gesture & RealSense: gestures in a simple way!!
Project Gesture & RealSense: gestures in a simple way!!Project Gesture & RealSense: gestures in a simple way!!
Project Gesture & RealSense: gestures in a simple way!!Massimo Bonanni
 
Project Prague & RealSense: il potere nelle mani!!
Project Prague & RealSense: il potere nelle mani!!Project Prague & RealSense: il potere nelle mani!!
Project Prague & RealSense: il potere nelle mani!!Massimo Bonanni
 
L'approccio ai microservizi secondo Service Fabric
L'approccio ai microservizi secondo Service FabricL'approccio ai microservizi secondo Service Fabric
L'approccio ai microservizi secondo Service FabricMassimo Bonanni
 
The Microservices world in. NET Core and. NET framework
The Microservices world in. NET Core and. NET frameworkThe Microservices world in. NET Core and. NET framework
The Microservices world in. NET Core and. NET frameworkMassimo Bonanni
 
Microservices architecture & Service Fabric
Microservices architecture & Service FabricMicroservices architecture & Service Fabric
Microservices architecture & Service FabricMassimo Bonanni
 
Introduzione allo sviluppo UWP per xBox
Introduzione allo sviluppo UWP per xBoxIntroduzione allo sviluppo UWP per xBox
Introduzione allo sviluppo UWP per xBoxMassimo Bonanni
 
Cognitive Services & LUIS
Cognitive Services & LUISCognitive Services & LUIS
Cognitive Services & LUISMassimo Bonanni
 
Service Fabric: la potenza dei micro servizi
Service Fabric:  la potenza dei micro serviziService Fabric:  la potenza dei micro servizi
Service Fabric: la potenza dei micro serviziMassimo Bonanni
 
Automated UI testing for iOs and Android mobile apps
Automated UI testing for iOs and Android mobile appsAutomated UI testing for iOs and Android mobile apps
Automated UI testing for iOs and Android mobile appsMassimo Bonanni
 
Soluzioni IoT con le tecnologie Microsoft
Soluzioni IoT con le tecnologie MicrosoftSoluzioni IoT con le tecnologie Microsoft
Soluzioni IoT con le tecnologie MicrosoftMassimo Bonanni
 

More from Massimo Bonanni (17)

Architetture Serverless con SQL Server e Azure Functions
Architetture Serverless con SQL Server e Azure FunctionsArchitetture Serverless con SQL Server e Azure Functions
Architetture Serverless con SQL Server e Azure Functions
 
Tutto quello che avreste voluto sapere sull'API Management (e non avete mai o...
Tutto quello che avreste voluto sapere sull'API Management (e non avete mai o...Tutto quello che avreste voluto sapere sull'API Management (e non avete mai o...
Tutto quello che avreste voluto sapere sull'API Management (e non avete mai o...
 
Everything you always wanted to know about API Management (but were afraid to...
Everything you always wanted to know about API Management (but were afraid to...Everything you always wanted to know about API Management (but were afraid to...
Everything you always wanted to know about API Management (but were afraid to...
 
Welcome Azure Functions 2. 0
Welcome Azure Functions 2. 0Welcome Azure Functions 2. 0
Welcome Azure Functions 2. 0
 
Soluzioni IoT con le tecnologie Microsoft
Soluzioni IoT con le tecnologie MicrosoftSoluzioni IoT con le tecnologie Microsoft
Soluzioni IoT con le tecnologie Microsoft
 
Project Gesture & Real Sense: il potere nelle mani!!
Project Gesture & Real Sense: il potere nelle mani!!Project Gesture & Real Sense: il potere nelle mani!!
Project Gesture & Real Sense: il potere nelle mani!!
 
Project Gesture & RealSense: gestures in a simple way!!
Project Gesture & RealSense: gestures in a simple way!!Project Gesture & RealSense: gestures in a simple way!!
Project Gesture & RealSense: gestures in a simple way!!
 
Project Prague & RealSense: il potere nelle mani!!
Project Prague & RealSense: il potere nelle mani!!Project Prague & RealSense: il potere nelle mani!!
Project Prague & RealSense: il potere nelle mani!!
 
L'approccio ai microservizi secondo Service Fabric
L'approccio ai microservizi secondo Service FabricL'approccio ai microservizi secondo Service Fabric
L'approccio ai microservizi secondo Service Fabric
 
The Microservices world in. NET Core and. NET framework
The Microservices world in. NET Core and. NET frameworkThe Microservices world in. NET Core and. NET framework
The Microservices world in. NET Core and. NET framework
 
Microservices architecture & Service Fabric
Microservices architecture & Service FabricMicroservices architecture & Service Fabric
Microservices architecture & Service Fabric
 
Introduzione allo sviluppo UWP per xBox
Introduzione allo sviluppo UWP per xBoxIntroduzione allo sviluppo UWP per xBox
Introduzione allo sviluppo UWP per xBox
 
Cognitive Services & LUIS
Cognitive Services & LUISCognitive Services & LUIS
Cognitive Services & LUIS
 
Service Fabric: la potenza dei micro servizi
Service Fabric:  la potenza dei micro serviziService Fabric:  la potenza dei micro servizi
Service Fabric: la potenza dei micro servizi
 
Automated UI testing for iOs and Android mobile apps
Automated UI testing for iOs and Android mobile appsAutomated UI testing for iOs and Android mobile apps
Automated UI testing for iOs and Android mobile apps
 
Soluzioni IoT con le tecnologie Microsoft
Soluzioni IoT con le tecnologie MicrosoftSoluzioni IoT con le tecnologie Microsoft
Soluzioni IoT con le tecnologie Microsoft
 
Xamarin Test Cloud
Xamarin Test CloudXamarin Test Cloud
Xamarin Test Cloud
 

Recently uploaded

"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 

Recently uploaded (20)

"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

The art of Azure Functions (unit) testing and monitoring

  • 1. #PitchOnline presents: #PitchOnline presents: Massimo Bonanni Paranormal Trainer, with the head in the Cloud and all the REST in microservices! massimo.bonanni@microsoft.com @massimobonanni
  • 2. Scifoni Ivano Fabio Mannis Francesco Del Re Matteo Riccardi Valerio Benedetti The art of Azure Functions (unit) testing and monitoring!
  • 3. The issue…. If you want to use Azure Functions as components of your Enterprise solutions, you must test and monitor them!!!
  • 4. What are Azure Functions Author functions in C#, F#, Node.JS, Java, Powershell, and more Code Events React to timers, HTTP , or events from your favorite Azure services, with more on the way Outputs Send results to an ever-growing collection of services The art of Azure Functions (unit) testing and monitoring!
  • 5. What is a Unit Test In a unit test you invoke a piece of your code with a set of parameters and you checks the correctness its behavior. In a unit test you must substitute all your external reference with a mock or stub. Mock is for the software what a dummy is for a car crash test (you don’t test a car with a human being inside…I Hope!!) The art of Azure Functions (unit) testing and monitoring!
  • 6. Azure Functions Dependencies You should implement your Azure Functions to allow you to use mock/stub for all external reference! Your Function Trigger Binding Binding Binding Binding Your Service Your Service Your Service Your Service Logger (infrastructure) The art of Azure Functions (unit) testing and monitoring!
  • 7. Azure Function … untestable!! The art of Azure Functions (unit) testing and monitoring!
  • 8. Azure Function … trigger!! Trigger You can mock it because the trigger payload is a POCO class The art of Azure Functions (unit) testing and monitoring!
  • 9. Azure Function … bindings!! Binding You can mock it because the binding payload is an interface The art of Azure Functions (unit) testing and monitoring!
  • 10. Azure Function … logger!! Logger (infrastructural objects) You can mock it because the logger is an interface The art of Azure Functions (unit) testing and monitoring!
  • 11. Azure Function … your service!! External service You cannot substitute it with your mock because it is created inside the Azure Function and you haven’t a way to substitute it The art of Azure Functions (unit) testing and monitoring!
  • 12. Make your Azure Function testable!!! The solution of your problem is: Dependency Injection !! Azure Functions Runtime is based on .NET Core. Azure Functions support the same ASP.NET Core Dependency Injection!!! Using Dependency Injection you provide a way to substitute your Services with a mock! The art of Azure Functions (unit) testing and monitoring!
  • 13. Azure Function … testable!! Constructor Injection You can choose what kind of actual service you want to use when you instantiate the function. In a test you can substitute it with a mock!! The art of Azure Functions (unit) testing and monitoring!
  • 14. Azure Function … how to use mock!! Mock Create a mock to use in the test!! The art of Azure Functions (unit) testing and monitoring!
  • 15. DEMO Azure Functions Unit Testing The art of Azure Functions (unit) testing and monitoring!
  • 16. Monitoring Azure Functions Once you deploy your Azure Functions on Azure, you need to monitor them to check when something goes wrong. The signature of an Azure Function Run method provides the instance of ILogger that you can use to log information about your code. Using ILogger, you can collect information from your code execution to monitor and triage errors and exceptions. The art of Azure Functions (unit) testing and monitoring!
  • 17. Azure Functions Monitor Azure Functions provide out-of-the-box monitor feature. For each Function, you can have info about every function execution. The art of Azure Functions (unit) testing and monitoring!
  • 18. Azure Functions and Application Insight The Azure Functions platform offers built-in integration with Azure Application Insights. Put the Application Insights instrumentation key in the function app settings. The art of Azure Functions (unit) testing and monitoring!
  • 19. Configure monitoring Logging is configured in host.json file. Logger default level Logger level for all the functions in Function App Logger level for a specific function in Function App Logger category for .NET runtime components invoked by the host The art of Azure Functions (unit) testing and monitoring!
  • 20. Custom Metrics Azure Function SDK provides you extension methods to log custom metrics. The art of Azure Functions (unit) testing and monitoring!
  • 21. Pricing Azure Functions consumption plan is billed based on per-second resource consumption and executions The art of Azure Functions (unit) testing and monitoring!
  • 22. Pricing Azure Functions consumption plan is billed based on per-second resource consumption and executions If your function use 1GB of memory and its duration is 1 second, you pay €0.000014 each time the function runs. The art of Azure Functions (unit) testing and monitoring!
  • 23. Pricing Azure Functions consumption plan is billed based on per-second resource consumption and executions If your function runs 1 million times every month, you pay €0.169 each month. The art of Azure Functions (unit) testing and monitoring!
  • 24. Pricing - Example You have a function: • It runs every second • Its duration is 1 second • It uses 512 MB of memory The art of Azure Functions (unit) testing and monitoring!
  • 25. Resource Consumption Billing Calculation • It runs every second • Its duration is 1 second • It uses 512 MB of memory Executions 2,592,000 Resource Consumption Total 2,592,000 x 1 sec = 2,592,000 sec Total GB-s 2,592,000 x 0.5 GB = 1,296,000 GB-s Total billable consumption 1,296,000 – 400,000 = 896,000 GB-s Total cost 896,000 x 0.000014€ = 12.54 € The art of Azure Functions (unit) testing and monitoring!
  • 26. Executions billing calculation • It runs every second • Its duration is 1 second • It uses 512 MB of memory Billable Monthly Executions 2,592,000 – 1,000,000 = 1,592,000 Total cost 1.592 x 0.169 € = 0.269 € The art of Azure Functions (unit) testing and monitoring!
  • 27. Total Monthly Cost • It runs every second • Its duration is 1 second • It uses 512 MB of memory Monthly resource consumption cost 12.540 € Monthly executions cost 0.269 € Total monthly cost 12.809 € The art of Azure Functions (unit) testing and monitoring!
  • 28. DEMO Azure Functions Monitoring The art of Azure Functions (unit) testing and monitoring!
  • 29. Takeaway Write an Azure Functions is simple! Testing Azure Functions is simple! Monitoring Azure Functions is simple! …. then …. Photo by Aaron Burden on Unsplash
  • 30.
  • 31. Massimo Bonanni Azure Technical Trainer @ Microsoft massimo.bonanni@microsoft.com @massimobonanni Connect with me on LinkedIn linkedin.com/in/massimobonanni/ http://bit.ly/MasteringServerless
  • 32. References Azure Functions Documentation https://docs.microsoft.com/en-US/azure/azure-functions/ Azure Functions Code Samples https://azure.microsoft.com/en-us/resources/samples/?service=functions&sort=0 Azure Updates https://azure.microsoft.com/en-us/roadmap/?category=compute Azure Friday – Build Serverless APIs with Azure Functions https://azure.microsoft.com/en-us/resources/videos/azure-friday-build-serverless-apis-with-azure-functions/ GitHub Demo https://github.com/massimobonanni/AzureFunctionsSamples The art of Azure Functions (unit) testing and monitoring!