From 11856725edf8399f0ebda6084cab3d8f249bdd8d Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Wed, 3 Nov 2021 07:00:09 +0100 Subject: [PATCH 1/4] feat: Provide custom metrics for Application Insights Signed-off-by: Tom Kerkhove --- .../.gitignore | 264 ++++++++++++++++++ ...pplicationInsightsCustomMetricsFunction.cs | 54 ++++ ...nsightsWithClassicCustomMetricsFunction.cs | 25 ++ ...ightsWithWorkspaceCustomMetricsFunction.cs | 25 ++ ...omitor.DataGeneration.CustomMetrics.csproj | 23 ++ .../Properties/serviceDependencies.json | 11 + .../Properties/serviceDependencies.local.json | 11 + .../Startup.cs | 38 +++ .../host.json | 11 + src/Promitor.DataGeneration.sln | 25 ++ 10 files changed, 487 insertions(+) create mode 100644 src/Promitor.DataGeneration.CustomMetrics/.gitignore create mode 100644 src/Promitor.DataGeneration.CustomMetrics/ApplicationInsightsCustomMetricsFunction.cs create mode 100644 src/Promitor.DataGeneration.CustomMetrics/ApplicationInsightsWithClassicCustomMetricsFunction.cs create mode 100644 src/Promitor.DataGeneration.CustomMetrics/ApplicationInsightsWithWorkspaceCustomMetricsFunction.cs create mode 100644 src/Promitor.DataGeneration.CustomMetrics/Promitor.DataGeneration.CustomMetrics.csproj create mode 100644 src/Promitor.DataGeneration.CustomMetrics/Properties/serviceDependencies.json create mode 100644 src/Promitor.DataGeneration.CustomMetrics/Properties/serviceDependencies.local.json create mode 100644 src/Promitor.DataGeneration.CustomMetrics/Startup.cs create mode 100644 src/Promitor.DataGeneration.CustomMetrics/host.json create mode 100644 src/Promitor.DataGeneration.sln diff --git a/src/Promitor.DataGeneration.CustomMetrics/.gitignore b/src/Promitor.DataGeneration.CustomMetrics/.gitignore new file mode 100644 index 0000000..ff5b00c --- /dev/null +++ b/src/Promitor.DataGeneration.CustomMetrics/.gitignore @@ -0,0 +1,264 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# Azure Functions localsettings file +local.settings.json + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +project.fragment.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +#*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc \ No newline at end of file diff --git a/src/Promitor.DataGeneration.CustomMetrics/ApplicationInsightsCustomMetricsFunction.cs b/src/Promitor.DataGeneration.CustomMetrics/ApplicationInsightsCustomMetricsFunction.cs new file mode 100644 index 0000000..250434e --- /dev/null +++ b/src/Promitor.DataGeneration.CustomMetrics/ApplicationInsightsCustomMetricsFunction.cs @@ -0,0 +1,54 @@ +using System; +using Microsoft.Azure.WebJobs; +using Microsoft.Azure.WebJobs.Host; +using Microsoft.Extensions.Logging; + +namespace Promitor.DataGeneration.CustomMetrics +{ + public class ApplicationInsightsCustomMetricsFunction + { + public ILogger Logger { get; } + private readonly Random _randomizer = new Random(); + private const string OrdersCreatedMetricName = "Orders Created"; + + private readonly List _tenants = new List{ "Contoso", "Fabrikam", "Promito" }; + + internal ApplicationInsightsCustomMetricsFunction(string configurationKeyName, IConfiguration configuration) + { + var instrumentationKey = configuration.GetValue(configurationKeyName); + var loggerConfiguration = new LoggerConfiguration() + .MinimumLevel.Debug() + .MinimumLevel.Override("Microsoft", LogEventLevel.Information) + .Enrich.FromLogContext() + .Enrich.WithComponentName("Promitor Automation") + .Enrich.WithVersion() + .WriteTo.Console() + .WriteTo.AzureApplicationInsights(instrumentationKey); + + Logger = loggerConfiguration.CreateLogger(); + } + + public void SimulateNewOrdersCreated() + { + foreach (var tenant in _tenants) + { + SimulateNewOrdersCreated(tenant); + } + } + + private void SimulateNewOrdersCreated(string tenantName) + { + // Annotate with contextual information + var contextInformation = new Dictionary + { + {"Tenant", tenantName} + }; + + // Generate order amount + var orderAmount = _randomizer.Next(100, 1337); + + // Log metric + Logger.LogMetric(OrdersCreatedMetricName, orderAmount, contextualInformation); + } + } +} diff --git a/src/Promitor.DataGeneration.CustomMetrics/ApplicationInsightsWithClassicCustomMetricsFunction.cs b/src/Promitor.DataGeneration.CustomMetrics/ApplicationInsightsWithClassicCustomMetricsFunction.cs new file mode 100644 index 0000000..bff6cb3 --- /dev/null +++ b/src/Promitor.DataGeneration.CustomMetrics/ApplicationInsightsWithClassicCustomMetricsFunction.cs @@ -0,0 +1,25 @@ +using System; +using Microsoft.Azure.WebJobs; +using Microsoft.Azure.WebJobs.Host; +using Microsoft.Extensions.Logging; + +namespace Promitor.DataGeneration.CustomMetrics +{ + public class ApplicationInsightsWithClassicCustomMetricsFunction : ApplicationInsightsCustomMetricsFunction + { + public ApplicationInsightsWithClassicCustomMetricsFunction(IConfiguration configuration) + : base("APPLICATIONINSIGHTS_CLASSIC_INSTRUMENTATIONKEY", configuration) + { + } + + [FunctionName("custom-metrics-application-insights-classic")] + public void Run([TimerTrigger("0 */5 * * * *")]TimerInfo timerInfo) + { + Logger.LogVerbose("Simulating new orders for classic Azure Application Insights"); + + SimulateNewOrdersCreated(); + + Logger.LogVerbose("New orders simulated for classic Azure Application Insights"); + } + } +} diff --git a/src/Promitor.DataGeneration.CustomMetrics/ApplicationInsightsWithWorkspaceCustomMetricsFunction.cs b/src/Promitor.DataGeneration.CustomMetrics/ApplicationInsightsWithWorkspaceCustomMetricsFunction.cs new file mode 100644 index 0000000..32b4943 --- /dev/null +++ b/src/Promitor.DataGeneration.CustomMetrics/ApplicationInsightsWithWorkspaceCustomMetricsFunction.cs @@ -0,0 +1,25 @@ +using System; +using Microsoft.Azure.WebJobs; +using Microsoft.Azure.WebJobs.Host; +using Microsoft.Extensions.Logging; + +namespace Promitor.DataGeneration.CustomMetrics +{ + public class ApplicationInsightsWithWorkspaceCustomMetricsFunction : ApplicationInsightsCustomMetricsFunction + { + public ApplicationInsightsWithWorkspaceCustomMetricsFunction(IConfiguration configuration) + : base("APPLICATIONINSIGHTS_WORKSPACE_INSTRUMENTATIONKEY", configuration) + { + } + + [FunctionName("custom-metrics-application-insights-workspace")] + public void Run([TimerTrigger("0 */5 * * * *")]TimerInfo timerInfo) + { + Logger.LogVerbose("Simulating new orders for workspace-based Azure Application Insights"); + + SimulateNewOrdersCreated(); + + Logger.LogVerbose("New orders simulated for workspace-based Azure Application Insights"); + } + } +} diff --git a/src/Promitor.DataGeneration.CustomMetrics/Promitor.DataGeneration.CustomMetrics.csproj b/src/Promitor.DataGeneration.CustomMetrics/Promitor.DataGeneration.CustomMetrics.csproj new file mode 100644 index 0000000..9a71688 --- /dev/null +++ b/src/Promitor.DataGeneration.CustomMetrics/Promitor.DataGeneration.CustomMetrics.csproj @@ -0,0 +1,23 @@ + + + netcoreapp3.1 + v3 + + + + + + + + + + + + PreserveNewest + + + PreserveNewest + Never + + + diff --git a/src/Promitor.DataGeneration.CustomMetrics/Properties/serviceDependencies.json b/src/Promitor.DataGeneration.CustomMetrics/Properties/serviceDependencies.json new file mode 100644 index 0000000..df4dcc9 --- /dev/null +++ b/src/Promitor.DataGeneration.CustomMetrics/Properties/serviceDependencies.json @@ -0,0 +1,11 @@ +{ + "dependencies": { + "appInsights1": { + "type": "appInsights" + }, + "storage1": { + "type": "storage", + "connectionId": "AzureWebJobsStorage" + } + } +} \ No newline at end of file diff --git a/src/Promitor.DataGeneration.CustomMetrics/Properties/serviceDependencies.local.json b/src/Promitor.DataGeneration.CustomMetrics/Properties/serviceDependencies.local.json new file mode 100644 index 0000000..b804a28 --- /dev/null +++ b/src/Promitor.DataGeneration.CustomMetrics/Properties/serviceDependencies.local.json @@ -0,0 +1,11 @@ +{ + "dependencies": { + "appInsights1": { + "type": "appInsights.sdk" + }, + "storage1": { + "type": "storage.emulator", + "connectionId": "AzureWebJobsStorage" + } + } +} \ No newline at end of file diff --git a/src/Promitor.DataGeneration.CustomMetrics/Startup.cs b/src/Promitor.DataGeneration.CustomMetrics/Startup.cs new file mode 100644 index 0000000..b344d06 --- /dev/null +++ b/src/Promitor.DataGeneration.CustomMetrics/Startup.cs @@ -0,0 +1,38 @@ +using AzureAutoscalingToolbox.Samples.StatefulAppInstances; +using Microsoft.Azure.Functions.Extensions.DependencyInjection; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Serilog; +using Serilog.Configuration; +using Serilog.Events; + +[assembly: FunctionsStartup(typeof(Startup))] +namespace AzureAutoscalingToolbox.Samples.StatefulAppInstances +{ + public class Startup : FunctionsStartup + { + // This method gets called by the runtime. Use this method to configure the app configuration. + public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder) + { + builder.ConfigurationBuilder.AddEnvironmentVariables(); + } + + // This method gets called by the runtime. Use this method to add services to the container. + // For more information on how to configure your application, visit https://docs.microsoft.com/en-us/azure/azure-functions/functions-dotnet-dependency-injection + public override void Configure(IFunctionsHostBuilder builder) + { + builder.ConfigureSecretStore(stores => + { + stores.AddEnvironmentVariables(); + }); + + builder.Services.AddLogging(logging => + { + logging.ClearProvidersExceptFunctionProviders() + .AddSerilog(configuration.CreateLogger(), dispose: true); + }); + } + } +} diff --git a/src/Promitor.DataGeneration.CustomMetrics/host.json b/src/Promitor.DataGeneration.CustomMetrics/host.json new file mode 100644 index 0000000..beb2e40 --- /dev/null +++ b/src/Promitor.DataGeneration.CustomMetrics/host.json @@ -0,0 +1,11 @@ +{ + "version": "2.0", + "logging": { + "applicationInsights": { + "samplingSettings": { + "isEnabled": true, + "excludedTypes": "Request" + } + } + } +} \ No newline at end of file diff --git a/src/Promitor.DataGeneration.sln b/src/Promitor.DataGeneration.sln new file mode 100644 index 0000000..441896e --- /dev/null +++ b/src/Promitor.DataGeneration.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31423.177 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Promitor.DataGeneration.CustomMetrics", "Promitor.DataGeneration.CustomMetrics\Promitor.DataGeneration.CustomMetrics.csproj", "{698B2B13-13D5-4FA0-B3D2-DB4B51F8ECAE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {698B2B13-13D5-4FA0-B3D2-DB4B51F8ECAE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {698B2B13-13D5-4FA0-B3D2-DB4B51F8ECAE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {698B2B13-13D5-4FA0-B3D2-DB4B51F8ECAE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {698B2B13-13D5-4FA0-B3D2-DB4B51F8ECAE}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {33C9024E-D44A-4442-8193-D1F2400B9F22} + EndGlobalSection +EndGlobal From c447c5fa159ced9c78b87e8e137958f71d93f533 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Sat, 6 Nov 2021 19:37:26 +0100 Subject: [PATCH 2/4] Provide README Signed-off-by: Tom Kerkhove --- README.md | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2a91941..8a67be9 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,32 @@ -# GitHub Template -GitHub template for all my future GitHub repos +# Promitor - Data Generation + +Automation to generate data in Azure to run automated tests against for Promitor. + +![Logo](https://raw.githubusercontent.com/promitor/governance/main/logos/promitor-small.png) + +## Support + +Learn more about our support options [here](https://github.com/tomkerkhove/promitor/blob/master/SUPPORT.md). + +[![Carlo Garcia-Mier](https://raw.githubusercontent.com/tomkerkhove/promitor/master//media/supporters/CarloGarcia.jpg)](https://github.com/CarloGarcia) +[![Jorge Turrado Ferrero](https://raw.githubusercontent.com/tomkerkhove/promitor/master//media/supporters/JorTurFer.jpg)](https://github.com/JorTurFer) +[![Karl Ots](https://raw.githubusercontent.com/tomkerkhove/promitor/master//media/supporters/karlgots.jpg)](https://github.com/karlgots) +[![Loc Mai](https://raw.githubusercontent.com/tomkerkhove/promitor/master//media/supporters/locmai.jpg)](https://github.com/locmai) +[![Lovelace Engineering](https://raw.githubusercontent.com/tomkerkhove/promitor/master//media/supporters/LovelaceEngineering.png)](https://github.com/LovelaceEngineering) +[![Nills Franssens](https://raw.githubusercontent.com/tomkerkhove/promitor/master//media/supporters/nillsf.jpg)](https://github.com/NillsF) +[![Richard Simpson](https://raw.githubusercontent.com/tomkerkhove/promitor/master//media/supporters/RichiCoder1.jpg)](https://github.com/RichiCoder1) +[![Sam Vanhoutte](https://raw.githubusercontent.com/tomkerkhove/promitor/master//media/supporters/samvanhoutte.png)](https://github.com/samvanhoutte) + +## Donate + +Promitor is fully OSS and built free-of-charge, however, if you appreciate my work +you can do a small donation. + +[![Donate](https://img.shields.io/badge/Donate%20via-GitHub-blue.svg?style=flat-square)](https://github.com/sponsors/promitor) + +## License Information + +This is licensed under The MIT License (MIT). Which means that you can use, copy, +modify, merge, publish, distribute, sublicense, and/or sell copies of the web +application. But you always need to state that Tom Kerkhove is the original author +of this web application. From 0dd8b8a284521fac5ae3c56cc7a371139640af41 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Sat, 6 Nov 2021 19:47:48 +0100 Subject: [PATCH 3/4] Provide sponsor overview Signed-off-by: Tom Kerkhove --- README.md | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/README.md b/README.md index 8a67be9..889ea6e 100644 --- a/README.md +++ b/README.md @@ -8,14 +8,7 @@ Automation to generate data in Azure to run automated tests against for Promitor Learn more about our support options [here](https://github.com/tomkerkhove/promitor/blob/master/SUPPORT.md). -[![Carlo Garcia-Mier](https://raw.githubusercontent.com/tomkerkhove/promitor/master//media/supporters/CarloGarcia.jpg)](https://github.com/CarloGarcia) -[![Jorge Turrado Ferrero](https://raw.githubusercontent.com/tomkerkhove/promitor/master//media/supporters/JorTurFer.jpg)](https://github.com/JorTurFer) -[![Karl Ots](https://raw.githubusercontent.com/tomkerkhove/promitor/master//media/supporters/karlgots.jpg)](https://github.com/karlgots) -[![Loc Mai](https://raw.githubusercontent.com/tomkerkhove/promitor/master//media/supporters/locmai.jpg)](https://github.com/locmai) -[![Lovelace Engineering](https://raw.githubusercontent.com/tomkerkhove/promitor/master//media/supporters/LovelaceEngineering.png)](https://github.com/LovelaceEngineering) -[![Nills Franssens](https://raw.githubusercontent.com/tomkerkhove/promitor/master//media/supporters/nillsf.jpg)](https://github.com/NillsF) -[![Richard Simpson](https://raw.githubusercontent.com/tomkerkhove/promitor/master//media/supporters/RichiCoder1.jpg)](https://github.com/RichiCoder1) -[![Sam Vanhoutte](https://raw.githubusercontent.com/tomkerkhove/promitor/master//media/supporters/samvanhoutte.png)](https://github.com/samvanhoutte) +![Sponsors](https://raw.githubusercontent.com/promitor/governance/main/media/sponsor-overview.png) ## Donate From 0fe8b07b352d5451984e2cbacdb014ba14d72be1 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Sat, 6 Nov 2021 19:58:19 +0100 Subject: [PATCH 4/4] Cleanup Signed-off-by: Tom Kerkhove --- .../ApplicationInsightsCustomMetricsFunction.cs | 16 +++++++++++----- ...onInsightsWithClassicCustomMetricsFunction.cs | 7 +++---- ...InsightsWithWorkspaceCustomMetricsFunction.cs | 7 +++---- .../Promitor.DataGeneration.CustomMetrics.csproj | 3 +++ .../Properties/serviceDependencies.json | 11 ----------- .../Properties/serviceDependencies.local.json | 11 ----------- .../Startup.cs | 12 ++++-------- 7 files changed, 24 insertions(+), 43 deletions(-) delete mode 100644 src/Promitor.DataGeneration.CustomMetrics/Properties/serviceDependencies.json delete mode 100644 src/Promitor.DataGeneration.CustomMetrics/Properties/serviceDependencies.local.json diff --git a/src/Promitor.DataGeneration.CustomMetrics/ApplicationInsightsCustomMetricsFunction.cs b/src/Promitor.DataGeneration.CustomMetrics/ApplicationInsightsCustomMetricsFunction.cs index 250434e..a55aa81 100644 --- a/src/Promitor.DataGeneration.CustomMetrics/ApplicationInsightsCustomMetricsFunction.cs +++ b/src/Promitor.DataGeneration.CustomMetrics/ApplicationInsightsCustomMetricsFunction.cs @@ -1,13 +1,17 @@ using System; -using Microsoft.Azure.WebJobs; -using Microsoft.Azure.WebJobs.Host; +using System.Collections.Generic; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using Serilog; +using Serilog.Configuration; +using Serilog.Events; +using Serilog.Extensions.Logging; namespace Promitor.DataGeneration.CustomMetrics { public class ApplicationInsightsCustomMetricsFunction { - public ILogger Logger { get; } + public ILogger Logger { get; } private readonly Random _randomizer = new Random(); private const string OrdersCreatedMetricName = "Orders Created"; @@ -25,7 +29,9 @@ internal ApplicationInsightsCustomMetricsFunction(string configurationKeyName, I .WriteTo.Console() .WriteTo.AzureApplicationInsights(instrumentationKey); - Logger = loggerConfiguration.CreateLogger(); + var serilogLogger = loggerConfiguration.CreateLogger(); + Logger = new SerilogLoggerFactory(serilogLogger) + .CreateLogger(); } public void SimulateNewOrdersCreated() @@ -39,7 +45,7 @@ public void SimulateNewOrdersCreated() private void SimulateNewOrdersCreated(string tenantName) { // Annotate with contextual information - var contextInformation = new Dictionary + var contextualInformation = new Dictionary { {"Tenant", tenantName} }; diff --git a/src/Promitor.DataGeneration.CustomMetrics/ApplicationInsightsWithClassicCustomMetricsFunction.cs b/src/Promitor.DataGeneration.CustomMetrics/ApplicationInsightsWithClassicCustomMetricsFunction.cs index bff6cb3..2ab95f3 100644 --- a/src/Promitor.DataGeneration.CustomMetrics/ApplicationInsightsWithClassicCustomMetricsFunction.cs +++ b/src/Promitor.DataGeneration.CustomMetrics/ApplicationInsightsWithClassicCustomMetricsFunction.cs @@ -1,6 +1,5 @@ -using System; using Microsoft.Azure.WebJobs; -using Microsoft.Azure.WebJobs.Host; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; namespace Promitor.DataGeneration.CustomMetrics @@ -15,11 +14,11 @@ public ApplicationInsightsWithClassicCustomMetricsFunction(IConfiguration config [FunctionName("custom-metrics-application-insights-classic")] public void Run([TimerTrigger("0 */5 * * * *")]TimerInfo timerInfo) { - Logger.LogVerbose("Simulating new orders for classic Azure Application Insights"); + Logger.LogInformation("Simulating new orders for classic Azure Application Insights"); SimulateNewOrdersCreated(); - Logger.LogVerbose("New orders simulated for classic Azure Application Insights"); + Logger.LogInformation("New orders simulated for classic Azure Application Insights"); } } } diff --git a/src/Promitor.DataGeneration.CustomMetrics/ApplicationInsightsWithWorkspaceCustomMetricsFunction.cs b/src/Promitor.DataGeneration.CustomMetrics/ApplicationInsightsWithWorkspaceCustomMetricsFunction.cs index 32b4943..c636b01 100644 --- a/src/Promitor.DataGeneration.CustomMetrics/ApplicationInsightsWithWorkspaceCustomMetricsFunction.cs +++ b/src/Promitor.DataGeneration.CustomMetrics/ApplicationInsightsWithWorkspaceCustomMetricsFunction.cs @@ -1,6 +1,5 @@ -using System; using Microsoft.Azure.WebJobs; -using Microsoft.Azure.WebJobs.Host; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; namespace Promitor.DataGeneration.CustomMetrics @@ -15,11 +14,11 @@ public ApplicationInsightsWithWorkspaceCustomMetricsFunction(IConfiguration conf [FunctionName("custom-metrics-application-insights-workspace")] public void Run([TimerTrigger("0 */5 * * * *")]TimerInfo timerInfo) { - Logger.LogVerbose("Simulating new orders for workspace-based Azure Application Insights"); + Logger.LogInformation("Simulating new orders for workspace-based Azure Application Insights"); SimulateNewOrdersCreated(); - Logger.LogVerbose("New orders simulated for workspace-based Azure Application Insights"); + Logger.LogInformation("New orders simulated for workspace-based Azure Application Insights"); } } } diff --git a/src/Promitor.DataGeneration.CustomMetrics/Promitor.DataGeneration.CustomMetrics.csproj b/src/Promitor.DataGeneration.CustomMetrics/Promitor.DataGeneration.CustomMetrics.csproj index 9a71688..7dd4a09 100644 --- a/src/Promitor.DataGeneration.CustomMetrics/Promitor.DataGeneration.CustomMetrics.csproj +++ b/src/Promitor.DataGeneration.CustomMetrics/Promitor.DataGeneration.CustomMetrics.csproj @@ -20,4 +20,7 @@ Never + + + diff --git a/src/Promitor.DataGeneration.CustomMetrics/Properties/serviceDependencies.json b/src/Promitor.DataGeneration.CustomMetrics/Properties/serviceDependencies.json deleted file mode 100644 index df4dcc9..0000000 --- a/src/Promitor.DataGeneration.CustomMetrics/Properties/serviceDependencies.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "dependencies": { - "appInsights1": { - "type": "appInsights" - }, - "storage1": { - "type": "storage", - "connectionId": "AzureWebJobsStorage" - } - } -} \ No newline at end of file diff --git a/src/Promitor.DataGeneration.CustomMetrics/Properties/serviceDependencies.local.json b/src/Promitor.DataGeneration.CustomMetrics/Properties/serviceDependencies.local.json deleted file mode 100644 index b804a28..0000000 --- a/src/Promitor.DataGeneration.CustomMetrics/Properties/serviceDependencies.local.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "dependencies": { - "appInsights1": { - "type": "appInsights.sdk" - }, - "storage1": { - "type": "storage.emulator", - "connectionId": "AzureWebJobsStorage" - } - } -} \ No newline at end of file diff --git a/src/Promitor.DataGeneration.CustomMetrics/Startup.cs b/src/Promitor.DataGeneration.CustomMetrics/Startup.cs index b344d06..fd1c26d 100644 --- a/src/Promitor.DataGeneration.CustomMetrics/Startup.cs +++ b/src/Promitor.DataGeneration.CustomMetrics/Startup.cs @@ -1,15 +1,12 @@ -using AzureAutoscalingToolbox.Samples.StatefulAppInstances; -using Microsoft.Azure.Functions.Extensions.DependencyInjection; +using Microsoft.Azure.Functions.Extensions.DependencyInjection; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; -using Serilog; -using Serilog.Configuration; -using Serilog.Events; +using Promitor.DataGeneration.CustomMetrics; [assembly: FunctionsStartup(typeof(Startup))] -namespace AzureAutoscalingToolbox.Samples.StatefulAppInstances +namespace Promitor.DataGeneration.CustomMetrics { public class Startup : FunctionsStartup { @@ -30,8 +27,7 @@ public override void Configure(IFunctionsHostBuilder builder) builder.Services.AddLogging(logging => { - logging.ClearProvidersExceptFunctionProviders() - .AddSerilog(configuration.CreateLogger(), dispose: true); + logging.ClearProvidersExceptFunctionProviders(); }); } }