From 16304fea59b91fc9a2b3b8c47ba0e5cfa0cd089d Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Wed, 25 Sep 2019 18:09:54 +0200 Subject: [PATCH 01/38] Build everything for .NET Core 3.0.0 Signed-off-by: Tom Kerkhove --- build/azure-devops/agents-scraper-release-official.yml | 2 +- build/azure-devops/agents-scraper-release-preview.yml | 2 +- build/azure-devops/scraper-ci.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build/azure-devops/agents-scraper-release-official.yml b/build/azure-devops/agents-scraper-release-official.yml index f20d73a97..df2d7c112 100644 --- a/build/azure-devops/agents-scraper-release-official.yml +++ b/build/azure-devops/agents-scraper-release-official.yml @@ -4,7 +4,7 @@ resources: trigger: none pr: none variables: - DotNet.SDK.Version: '2.2.402' + DotNet.SDK.Version: '3.0.100' Image.Name: 'tomkerkhove/promitor-agent-scraper' Image.TaggedName: '$(Image.Name):$(Image.Version)' Release.TagName: '$(Build.BuildNumber)' diff --git a/build/azure-devops/agents-scraper-release-preview.yml b/build/azure-devops/agents-scraper-release-preview.yml index 11f34147f..539d1b827 100644 --- a/build/azure-devops/agents-scraper-release-preview.yml +++ b/build/azure-devops/agents-scraper-release-preview.yml @@ -4,7 +4,7 @@ resources: trigger: none pr: none variables: - DotNet.SDK.Version: '2.2.402' + DotNet.SDK.Version: '3.0.100' Image.Name: 'tomkerkhove/promitor-agent-scraper' Image.TaggedName: '$(Image.Name):$(Image.Version)' Release.TagName: '$(Build.BuildNumber)' diff --git a/build/azure-devops/scraper-ci.yml b/build/azure-devops/scraper-ci.yml index fe35e2ad4..c506ed120 100644 --- a/build/azure-devops/scraper-ci.yml +++ b/build/azure-devops/scraper-ci.yml @@ -14,7 +14,7 @@ pr: - charts/promitor-agent-scraper/* - deploy/automation/docker-hub/ci/* # Add Docker Hub bot here to trigger it for testing sake variables: - DotNet.SDK.Version: '2.2.402' + DotNet.SDK.Version: '3.0.100' DotNet.Configuration: 'release' Image.Name: 'tomkerkhove/promitor-agent-scraper-ci' Image.TaggedName: '$(Image.Name):$(Build.BuildNumber)' From 5d0fc7c5c3c8427d44919f086e2d897efa13ad31 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Wed, 25 Sep 2019 18:10:09 +0200 Subject: [PATCH 02/38] Update everything to .NET Core 3.0.0 Signed-off-by: Tom Kerkhove --- .../Promitor.Core.Configuration.csproj | 10 +++++----- .../Promitor.Core.Scraping.csproj | 4 ++-- .../Promitor.Core.Telemetry.Metrics.csproj | 8 ++++---- .../Promitor.Core.Telemetry.csproj | 8 ++++---- src/Promitor.Core/Promitor.Core.csproj | 4 ++-- .../Promitor.Integrations.AzureMonitor.csproj | 4 ++-- .../Promitor.Integrations.AzureStorage.csproj | 6 +++--- src/Promitor.Scraper.Host/Dockerfile | 4 ++-- src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj | 5 ++--- .../Promitor.Scraper.Tests.Unit.csproj | 4 ++-- 10 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj b/src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj index 73a6c1a71..6df604069 100644 --- a/src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj +++ b/src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj @@ -1,8 +1,8 @@  - netcoreapp2.2 - 2.2.3 + netcoreapp3.0 + 3.0.0 @@ -14,9 +14,9 @@ - - - + + + diff --git a/src/Promitor.Core.Scraping/Promitor.Core.Scraping.csproj b/src/Promitor.Core.Scraping/Promitor.Core.Scraping.csproj index bd3d658d3..f94c2c823 100644 --- a/src/Promitor.Core.Scraping/Promitor.Core.Scraping.csproj +++ b/src/Promitor.Core.Scraping/Promitor.Core.Scraping.csproj @@ -1,8 +1,8 @@  - netcoreapp2.2 - 2.2.3 + netcoreapp3.0 + 3.0.0 diff --git a/src/Promitor.Core.Telemetry.Metrics/Promitor.Core.Telemetry.Metrics.csproj b/src/Promitor.Core.Telemetry.Metrics/Promitor.Core.Telemetry.Metrics.csproj index d69ddff72..cb2101b13 100644 --- a/src/Promitor.Core.Telemetry.Metrics/Promitor.Core.Telemetry.Metrics.csproj +++ b/src/Promitor.Core.Telemetry.Metrics/Promitor.Core.Telemetry.Metrics.csproj @@ -1,8 +1,8 @@ - netcoreapp2.2 - 2.2.3 + netcoreapp3.0 + 3.0.0 @@ -15,8 +15,8 @@ - - + + diff --git a/src/Promitor.Core.Telemetry/Promitor.Core.Telemetry.csproj b/src/Promitor.Core.Telemetry/Promitor.Core.Telemetry.csproj index 538d2a47b..a3281f75f 100644 --- a/src/Promitor.Core.Telemetry/Promitor.Core.Telemetry.csproj +++ b/src/Promitor.Core.Telemetry/Promitor.Core.Telemetry.csproj @@ -1,8 +1,8 @@ - netcoreapp2.2 - 2.2.3 + netcoreapp3.0 + 3.0.0 @@ -15,8 +15,8 @@ - - + + diff --git a/src/Promitor.Core/Promitor.Core.csproj b/src/Promitor.Core/Promitor.Core.csproj index e1db36e4b..3283c8623 100644 --- a/src/Promitor.Core/Promitor.Core.csproj +++ b/src/Promitor.Core/Promitor.Core.csproj @@ -1,8 +1,8 @@ - netcoreapp2.2 - 2.2.3 + netcoreapp3.0 + 3.0.0 diff --git a/src/Promitor.Integrations.AzureMonitor/Promitor.Integrations.AzureMonitor.csproj b/src/Promitor.Integrations.AzureMonitor/Promitor.Integrations.AzureMonitor.csproj index 091be8de8..8cccd9932 100644 --- a/src/Promitor.Integrations.AzureMonitor/Promitor.Integrations.AzureMonitor.csproj +++ b/src/Promitor.Integrations.AzureMonitor/Promitor.Integrations.AzureMonitor.csproj @@ -1,8 +1,8 @@  - netcoreapp2.2 - 2.2.3 + netcoreapp3.0 + 3.0.0 diff --git a/src/Promitor.Integrations.AzureStorage/Promitor.Integrations.AzureStorage.csproj b/src/Promitor.Integrations.AzureStorage/Promitor.Integrations.AzureStorage.csproj index 596b1a9d6..5d621c682 100644 --- a/src/Promitor.Integrations.AzureStorage/Promitor.Integrations.AzureStorage.csproj +++ b/src/Promitor.Integrations.AzureStorage/Promitor.Integrations.AzureStorage.csproj @@ -1,14 +1,14 @@  - netcoreapp2.2 - 2.2.3 + netcoreapp3.0 + 3.0.0 - + diff --git a/src/Promitor.Scraper.Host/Dockerfile b/src/Promitor.Scraper.Host/Dockerfile index 239a2cf19..1ee4772bb 100644 --- a/src/Promitor.Scraper.Host/Dockerfile +++ b/src/Promitor.Scraper.Host/Dockerfile @@ -1,4 +1,4 @@ -FROM mcr.microsoft.com/dotnet/core/sdk:2.2.402-alpine3.9 AS build +FROM mcr.microsoft.com/dotnet/core/sdk:3.0.100-alpine3.9 AS build WORKDIR /src COPY Promitor.Core/* Promitor.Core/ COPY Promitor.Core.Configuration/* Promitor.Core.Configuration/ @@ -10,7 +10,7 @@ COPY Promitor.Integrations.AzureStorage/* Promitor.Integrations.AzureStorage/ COPY Promitor.Scraper.Host/* Promitor.Scraper.Host/ RUN dotnet publish Promitor.Scraper.Host/Promitor.Scraper.Host.csproj --configuration release -o app -FROM mcr.microsoft.com/dotnet/core/aspnet:2.2.7-alpine3.9 as runtime +FROM mcr.microsoft.com/dotnet/core/aspnet:3.0.0-alpine3.9 as runtime WORKDIR /app COPY --from=build /src/Promitor.Scraper.Host/app . diff --git a/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj b/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj index f08face6b..bfccbcc78 100644 --- a/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj +++ b/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj @@ -1,9 +1,9 @@  - netcoreapp2.2 + netcoreapp3.0 ..\docker-compose.dcproj - 2.2.3 + 3.0.0 @@ -37,7 +37,6 @@ - diff --git a/src/Promitor.Scraper.Tests.Unit/Promitor.Scraper.Tests.Unit.csproj b/src/Promitor.Scraper.Tests.Unit/Promitor.Scraper.Tests.Unit.csproj index 47186b1c8..240a63e76 100644 --- a/src/Promitor.Scraper.Tests.Unit/Promitor.Scraper.Tests.Unit.csproj +++ b/src/Promitor.Scraper.Tests.Unit/Promitor.Scraper.Tests.Unit.csproj @@ -1,8 +1,8 @@  - netcoreapp2.2 - 2.2.3 + netcoreapp3.0 + 3.0.0 true From c0b59d1d5954d3b56cec3c29f9ca21d26574c575 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Mon, 30 Sep 2019 17:16:26 +0200 Subject: [PATCH 03/38] WIP Signed-off-by: Tom Kerkhove --- .../Promitor.Core.Configuration.csproj | 2 +- .../Promitor.Core.Telemetry.Metrics.csproj | 2 +- src/Promitor.Core.Telemetry/Promitor.Core.Telemetry.csproj | 2 +- .../Promitor.Integrations.AzureMonitor.csproj | 1 - .../Extensions/IServiceCollectionExtensions.cs | 1 - src/Promitor.Scraper.Host/Program.cs | 6 +++--- src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj | 1 - src/Promitor.Scraper.Host/Startup.cs | 1 - .../Promitor.Scraper.Tests.Unit.csproj | 2 +- 9 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj b/src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj index 6df604069..2f9e131b8 100644 --- a/src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj +++ b/src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj @@ -2,7 +2,7 @@ netcoreapp3.0 - 3.0.0 + 2.2.3 diff --git a/src/Promitor.Core.Telemetry.Metrics/Promitor.Core.Telemetry.Metrics.csproj b/src/Promitor.Core.Telemetry.Metrics/Promitor.Core.Telemetry.Metrics.csproj index cb2101b13..2dd28c10f 100644 --- a/src/Promitor.Core.Telemetry.Metrics/Promitor.Core.Telemetry.Metrics.csproj +++ b/src/Promitor.Core.Telemetry.Metrics/Promitor.Core.Telemetry.Metrics.csproj @@ -2,7 +2,7 @@ netcoreapp3.0 - 3.0.0 + 2.2.3 diff --git a/src/Promitor.Core.Telemetry/Promitor.Core.Telemetry.csproj b/src/Promitor.Core.Telemetry/Promitor.Core.Telemetry.csproj index a3281f75f..d2101935d 100644 --- a/src/Promitor.Core.Telemetry/Promitor.Core.Telemetry.csproj +++ b/src/Promitor.Core.Telemetry/Promitor.Core.Telemetry.csproj @@ -2,7 +2,7 @@ netcoreapp3.0 - 3.0.0 + 2.2.3 diff --git a/src/Promitor.Integrations.AzureMonitor/Promitor.Integrations.AzureMonitor.csproj b/src/Promitor.Integrations.AzureMonitor/Promitor.Integrations.AzureMonitor.csproj index 8cccd9932..927a8b42d 100644 --- a/src/Promitor.Integrations.AzureMonitor/Promitor.Integrations.AzureMonitor.csproj +++ b/src/Promitor.Integrations.AzureMonitor/Promitor.Integrations.AzureMonitor.csproj @@ -15,7 +15,6 @@ - diff --git a/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs b/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs index 983bb1415..4758ceabc 100644 --- a/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs +++ b/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs @@ -1,7 +1,6 @@ using System.IO; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.HealthChecks; diff --git a/src/Promitor.Scraper.Host/Program.cs b/src/Promitor.Scraper.Host/Program.cs index 82410ced1..fe4c60a18 100644 --- a/src/Promitor.Scraper.Host/Program.cs +++ b/src/Promitor.Scraper.Host/Program.cs @@ -1,8 +1,8 @@ using System; using System.IO; using Microsoft.AspNetCore; -using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; using Promitor.Core.Configuration.Model.Server; namespace Promitor.Scraper.Host @@ -22,13 +22,13 @@ private static void Welcome() Console.WriteLine(Constants.Texts.Welcome); } - public static IWebHost BuildWebHost(string[] args) + public static IHostBuilder BuildWebHost(string[] args) { var configuration = CreateConfiguration(); var httpPort = DetermineHttpPort(configuration); var endpointUrl = $"http://+:{httpPort}"; - return WebHost.CreateDefaultBuilder(args) + return Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder(args) .UseKestrel(kestrelServerOptions => { kestrelServerOptions.AddServerHeader = false; diff --git a/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj b/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj index d463ea3d9..161033b55 100644 --- a/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj +++ b/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj @@ -36,7 +36,6 @@ - diff --git a/src/Promitor.Scraper.Host/Startup.cs b/src/Promitor.Scraper.Host/Startup.cs index c99940f24..c6faae6d6 100644 --- a/src/Promitor.Scraper.Host/Startup.cs +++ b/src/Promitor.Scraper.Host/Startup.cs @@ -1,6 +1,5 @@ using AutoMapper; using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Promitor.Core.Configuration.Model.Prometheus; diff --git a/src/Promitor.Scraper.Tests.Unit/Promitor.Scraper.Tests.Unit.csproj b/src/Promitor.Scraper.Tests.Unit/Promitor.Scraper.Tests.Unit.csproj index 240a63e76..4e0dc82b2 100644 --- a/src/Promitor.Scraper.Tests.Unit/Promitor.Scraper.Tests.Unit.csproj +++ b/src/Promitor.Scraper.Tests.Unit/Promitor.Scraper.Tests.Unit.csproj @@ -2,7 +2,7 @@ netcoreapp3.0 - 3.0.0 + 2.2.3 true From a06cd46a828a504fa3d6e3413bb36a130411fb5f Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Wed, 25 Sep 2019 18:09:54 +0200 Subject: [PATCH 04/38] Build everything for .NET Core 3.0.0 Signed-off-by: Tom Kerkhove --- build/azure-devops/agents-scraper-release-official.yml | 2 +- build/azure-devops/agents-scraper-release-preview.yml | 2 +- build/azure-devops/scraper-ci.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build/azure-devops/agents-scraper-release-official.yml b/build/azure-devops/agents-scraper-release-official.yml index f20d73a97..df2d7c112 100644 --- a/build/azure-devops/agents-scraper-release-official.yml +++ b/build/azure-devops/agents-scraper-release-official.yml @@ -4,7 +4,7 @@ resources: trigger: none pr: none variables: - DotNet.SDK.Version: '2.2.402' + DotNet.SDK.Version: '3.0.100' Image.Name: 'tomkerkhove/promitor-agent-scraper' Image.TaggedName: '$(Image.Name):$(Image.Version)' Release.TagName: '$(Build.BuildNumber)' diff --git a/build/azure-devops/agents-scraper-release-preview.yml b/build/azure-devops/agents-scraper-release-preview.yml index 11f34147f..539d1b827 100644 --- a/build/azure-devops/agents-scraper-release-preview.yml +++ b/build/azure-devops/agents-scraper-release-preview.yml @@ -4,7 +4,7 @@ resources: trigger: none pr: none variables: - DotNet.SDK.Version: '2.2.402' + DotNet.SDK.Version: '3.0.100' Image.Name: 'tomkerkhove/promitor-agent-scraper' Image.TaggedName: '$(Image.Name):$(Image.Version)' Release.TagName: '$(Build.BuildNumber)' diff --git a/build/azure-devops/scraper-ci.yml b/build/azure-devops/scraper-ci.yml index bda9e1a06..77d9ae31a 100644 --- a/build/azure-devops/scraper-ci.yml +++ b/build/azure-devops/scraper-ci.yml @@ -14,7 +14,7 @@ pr: - charts/promitor-agent-scraper/* - deploy/automation/docker-hub/ci/* # Add Docker Hub bot here to trigger it for testing sake variables: - DotNet.SDK.Version: '2.2.402' + DotNet.SDK.Version: '3.0.100' DotNet.Configuration: 'release' Image.Name: 'tomkerkhove/promitor-agent-scraper-ci' Image.TaggedName: '$(Image.Name):$(Build.BuildNumber)' From f0978f7f30ae4fb342125372268c6b187727053d Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Wed, 25 Sep 2019 18:10:09 +0200 Subject: [PATCH 05/38] Update everything to .NET Core 3.0.0 Signed-off-by: Tom Kerkhove --- .../Promitor.Core.Configuration.csproj | 10 +++++----- .../Promitor.Core.Scraping.csproj | 4 ++-- .../Promitor.Core.Telemetry.Metrics.csproj | 8 ++++---- .../Promitor.Core.Telemetry.csproj | 8 ++++---- src/Promitor.Core/Promitor.Core.csproj | 4 ++-- .../Promitor.Integrations.AzureMonitor.csproj | 4 ++-- .../Promitor.Integrations.AzureStorage.csproj | 6 +++--- src/Promitor.Scraper.Host/Dockerfile | 4 ++-- src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj | 5 ++--- .../Promitor.Scraper.Tests.Unit.csproj | 4 ++-- 10 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj b/src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj index 73a6c1a71..6df604069 100644 --- a/src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj +++ b/src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj @@ -1,8 +1,8 @@  - netcoreapp2.2 - 2.2.3 + netcoreapp3.0 + 3.0.0 @@ -14,9 +14,9 @@ - - - + + + diff --git a/src/Promitor.Core.Scraping/Promitor.Core.Scraping.csproj b/src/Promitor.Core.Scraping/Promitor.Core.Scraping.csproj index ffae58b1e..60144d85e 100644 --- a/src/Promitor.Core.Scraping/Promitor.Core.Scraping.csproj +++ b/src/Promitor.Core.Scraping/Promitor.Core.Scraping.csproj @@ -1,8 +1,8 @@  - netcoreapp2.2 - 2.2.3 + netcoreapp3.0 + 3.0.0 diff --git a/src/Promitor.Core.Telemetry.Metrics/Promitor.Core.Telemetry.Metrics.csproj b/src/Promitor.Core.Telemetry.Metrics/Promitor.Core.Telemetry.Metrics.csproj index 865a0ae3f..df9f1cf6c 100644 --- a/src/Promitor.Core.Telemetry.Metrics/Promitor.Core.Telemetry.Metrics.csproj +++ b/src/Promitor.Core.Telemetry.Metrics/Promitor.Core.Telemetry.Metrics.csproj @@ -1,8 +1,8 @@ - netcoreapp2.2 - 2.2.3 + netcoreapp3.0 + 3.0.0 @@ -15,8 +15,8 @@ - - + + diff --git a/src/Promitor.Core.Telemetry/Promitor.Core.Telemetry.csproj b/src/Promitor.Core.Telemetry/Promitor.Core.Telemetry.csproj index 538d2a47b..a3281f75f 100644 --- a/src/Promitor.Core.Telemetry/Promitor.Core.Telemetry.csproj +++ b/src/Promitor.Core.Telemetry/Promitor.Core.Telemetry.csproj @@ -1,8 +1,8 @@ - netcoreapp2.2 - 2.2.3 + netcoreapp3.0 + 3.0.0 @@ -15,8 +15,8 @@ - - + + diff --git a/src/Promitor.Core/Promitor.Core.csproj b/src/Promitor.Core/Promitor.Core.csproj index 978f9e7fa..b260773f8 100644 --- a/src/Promitor.Core/Promitor.Core.csproj +++ b/src/Promitor.Core/Promitor.Core.csproj @@ -1,8 +1,8 @@ - netcoreapp2.2 - 2.2.3 + netcoreapp3.0 + 3.0.0 diff --git a/src/Promitor.Integrations.AzureMonitor/Promitor.Integrations.AzureMonitor.csproj b/src/Promitor.Integrations.AzureMonitor/Promitor.Integrations.AzureMonitor.csproj index 60ac78923..9e01677ac 100644 --- a/src/Promitor.Integrations.AzureMonitor/Promitor.Integrations.AzureMonitor.csproj +++ b/src/Promitor.Integrations.AzureMonitor/Promitor.Integrations.AzureMonitor.csproj @@ -1,8 +1,8 @@  - netcoreapp2.2 - 2.2.3 + netcoreapp3.0 + 3.0.0 diff --git a/src/Promitor.Integrations.AzureStorage/Promitor.Integrations.AzureStorage.csproj b/src/Promitor.Integrations.AzureStorage/Promitor.Integrations.AzureStorage.csproj index f329570a4..9a113d559 100644 --- a/src/Promitor.Integrations.AzureStorage/Promitor.Integrations.AzureStorage.csproj +++ b/src/Promitor.Integrations.AzureStorage/Promitor.Integrations.AzureStorage.csproj @@ -1,14 +1,14 @@  - netcoreapp2.2 - 2.2.3 + netcoreapp3.0 + 3.0.0 - + diff --git a/src/Promitor.Scraper.Host/Dockerfile b/src/Promitor.Scraper.Host/Dockerfile index 239a2cf19..1ee4772bb 100644 --- a/src/Promitor.Scraper.Host/Dockerfile +++ b/src/Promitor.Scraper.Host/Dockerfile @@ -1,4 +1,4 @@ -FROM mcr.microsoft.com/dotnet/core/sdk:2.2.402-alpine3.9 AS build +FROM mcr.microsoft.com/dotnet/core/sdk:3.0.100-alpine3.9 AS build WORKDIR /src COPY Promitor.Core/* Promitor.Core/ COPY Promitor.Core.Configuration/* Promitor.Core.Configuration/ @@ -10,7 +10,7 @@ COPY Promitor.Integrations.AzureStorage/* Promitor.Integrations.AzureStorage/ COPY Promitor.Scraper.Host/* Promitor.Scraper.Host/ RUN dotnet publish Promitor.Scraper.Host/Promitor.Scraper.Host.csproj --configuration release -o app -FROM mcr.microsoft.com/dotnet/core/aspnet:2.2.7-alpine3.9 as runtime +FROM mcr.microsoft.com/dotnet/core/aspnet:3.0.0-alpine3.9 as runtime WORKDIR /app COPY --from=build /src/Promitor.Scraper.Host/app . diff --git a/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj b/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj index e5504c0df..d463ea3d9 100644 --- a/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj +++ b/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj @@ -1,9 +1,9 @@  - netcoreapp2.2 + netcoreapp3.0 ..\docker-compose.dcproj - 2.2.3 + 3.0.0 @@ -37,7 +37,6 @@ - diff --git a/src/Promitor.Scraper.Tests.Unit/Promitor.Scraper.Tests.Unit.csproj b/src/Promitor.Scraper.Tests.Unit/Promitor.Scraper.Tests.Unit.csproj index 3ced81943..9070fa026 100644 --- a/src/Promitor.Scraper.Tests.Unit/Promitor.Scraper.Tests.Unit.csproj +++ b/src/Promitor.Scraper.Tests.Unit/Promitor.Scraper.Tests.Unit.csproj @@ -1,8 +1,8 @@  - netcoreapp2.2 - 2.2.3 + netcoreapp3.0 + 3.0.0 true From d7523011c259b0ee768c4c429cb48a4170c0346a Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Mon, 30 Sep 2019 17:16:26 +0200 Subject: [PATCH 06/38] WIP Signed-off-by: Tom Kerkhove --- .../Promitor.Core.Configuration.csproj | 2 +- .../Promitor.Core.Telemetry.Metrics.csproj | 2 +- src/Promitor.Core.Telemetry/Promitor.Core.Telemetry.csproj | 2 +- .../Promitor.Integrations.AzureMonitor.csproj | 1 - .../Extensions/IServiceCollectionExtensions.cs | 1 - src/Promitor.Scraper.Host/Program.cs | 6 +++--- src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj | 1 - src/Promitor.Scraper.Host/Startup.cs | 1 - .../Promitor.Scraper.Tests.Unit.csproj | 2 +- 9 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj b/src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj index 6df604069..2f9e131b8 100644 --- a/src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj +++ b/src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj @@ -2,7 +2,7 @@ netcoreapp3.0 - 3.0.0 + 2.2.3 diff --git a/src/Promitor.Core.Telemetry.Metrics/Promitor.Core.Telemetry.Metrics.csproj b/src/Promitor.Core.Telemetry.Metrics/Promitor.Core.Telemetry.Metrics.csproj index df9f1cf6c..b89d7e076 100644 --- a/src/Promitor.Core.Telemetry.Metrics/Promitor.Core.Telemetry.Metrics.csproj +++ b/src/Promitor.Core.Telemetry.Metrics/Promitor.Core.Telemetry.Metrics.csproj @@ -2,7 +2,7 @@ netcoreapp3.0 - 3.0.0 + 2.2.3 diff --git a/src/Promitor.Core.Telemetry/Promitor.Core.Telemetry.csproj b/src/Promitor.Core.Telemetry/Promitor.Core.Telemetry.csproj index a3281f75f..d2101935d 100644 --- a/src/Promitor.Core.Telemetry/Promitor.Core.Telemetry.csproj +++ b/src/Promitor.Core.Telemetry/Promitor.Core.Telemetry.csproj @@ -2,7 +2,7 @@ netcoreapp3.0 - 3.0.0 + 2.2.3 diff --git a/src/Promitor.Integrations.AzureMonitor/Promitor.Integrations.AzureMonitor.csproj b/src/Promitor.Integrations.AzureMonitor/Promitor.Integrations.AzureMonitor.csproj index 9e01677ac..fdfffeaac 100644 --- a/src/Promitor.Integrations.AzureMonitor/Promitor.Integrations.AzureMonitor.csproj +++ b/src/Promitor.Integrations.AzureMonitor/Promitor.Integrations.AzureMonitor.csproj @@ -15,7 +15,6 @@ - diff --git a/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs b/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs index 983bb1415..4758ceabc 100644 --- a/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs +++ b/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs @@ -1,7 +1,6 @@ using System.IO; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.HealthChecks; diff --git a/src/Promitor.Scraper.Host/Program.cs b/src/Promitor.Scraper.Host/Program.cs index 82410ced1..fe4c60a18 100644 --- a/src/Promitor.Scraper.Host/Program.cs +++ b/src/Promitor.Scraper.Host/Program.cs @@ -1,8 +1,8 @@ using System; using System.IO; using Microsoft.AspNetCore; -using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; using Promitor.Core.Configuration.Model.Server; namespace Promitor.Scraper.Host @@ -22,13 +22,13 @@ private static void Welcome() Console.WriteLine(Constants.Texts.Welcome); } - public static IWebHost BuildWebHost(string[] args) + public static IHostBuilder BuildWebHost(string[] args) { var configuration = CreateConfiguration(); var httpPort = DetermineHttpPort(configuration); var endpointUrl = $"http://+:{httpPort}"; - return WebHost.CreateDefaultBuilder(args) + return Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder(args) .UseKestrel(kestrelServerOptions => { kestrelServerOptions.AddServerHeader = false; diff --git a/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj b/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj index d463ea3d9..161033b55 100644 --- a/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj +++ b/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj @@ -36,7 +36,6 @@ - diff --git a/src/Promitor.Scraper.Host/Startup.cs b/src/Promitor.Scraper.Host/Startup.cs index c99940f24..c6faae6d6 100644 --- a/src/Promitor.Scraper.Host/Startup.cs +++ b/src/Promitor.Scraper.Host/Startup.cs @@ -1,6 +1,5 @@ using AutoMapper; using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Promitor.Core.Configuration.Model.Prometheus; diff --git a/src/Promitor.Scraper.Tests.Unit/Promitor.Scraper.Tests.Unit.csproj b/src/Promitor.Scraper.Tests.Unit/Promitor.Scraper.Tests.Unit.csproj index 9070fa026..748e1da16 100644 --- a/src/Promitor.Scraper.Tests.Unit/Promitor.Scraper.Tests.Unit.csproj +++ b/src/Promitor.Scraper.Tests.Unit/Promitor.Scraper.Tests.Unit.csproj @@ -2,7 +2,7 @@ netcoreapp3.0 - 3.0.0 + 2.2.3 true From 4763f2b18e523d912ed2884e9003d807454b8d00 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Fri, 11 Oct 2019 14:56:43 +0200 Subject: [PATCH 07/38] Update CronScheduler.AspNetCor Signed-off-by: Tom Kerkhove --- src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj b/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj index 161033b55..05c113d25 100644 --- a/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj +++ b/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj @@ -35,7 +35,7 @@ - + From 64c844fd8f71ced3e59dc8bc47a195e6f9869e2b Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Fri, 11 Oct 2019 15:31:28 +0200 Subject: [PATCH 08/38] Initial buildable version Signed-off-by: Tom Kerkhove --- src/Promitor.Core.Telemetry/Loggers/Logger.cs | 36 ------------------- .../Loggers/RuntimeLogger.cs | 14 -------- .../Loggers/ValidationLogger.cs | 14 -------- .../IServiceCollectionExtensions.cs | 15 ++++---- src/Promitor.Scraper.Host/Program.cs | 26 ++++++++------ .../Scheduling/MetricScrapingJob.cs | 2 +- src/Promitor.Scraper.Host/Startup.cs | 7 ++-- .../Validation/RuntimeValidator.cs | 3 +- 8 files changed, 29 insertions(+), 88 deletions(-) delete mode 100644 src/Promitor.Core.Telemetry/Loggers/Logger.cs delete mode 100644 src/Promitor.Core.Telemetry/Loggers/RuntimeLogger.cs delete mode 100644 src/Promitor.Core.Telemetry/Loggers/ValidationLogger.cs diff --git a/src/Promitor.Core.Telemetry/Loggers/Logger.cs b/src/Promitor.Core.Telemetry/Loggers/Logger.cs deleted file mode 100644 index 442191f1e..000000000 --- a/src/Promitor.Core.Telemetry/Loggers/Logger.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Console; -using Microsoft.Extensions.Options; -using Promitor.Core.Configuration.Model.Telemetry; - -#pragma warning disable 618 - -namespace Promitor.Core.Telemetry.Loggers -{ - public class Logger : ConsoleLogger - { - public Logger(string name, IOptionsMonitor configuration) : base(name, (loggerName, logLevel) => IsFilteringRequired(logLevel, configuration), includeScopes: true) - { - } - - public override void WriteMessage(LogLevel logLevel, string logName, int eventId, string message, Exception exception) - { - message = $"[{DateTimeOffset.UtcNow:u}] {message}"; - base.WriteMessage(logLevel, logName, eventId, message, exception); - } - - private static bool IsFilteringRequired(LogLevel usedLogLevel, IOptionsMonitor configuration) - { - var telemetryConfiguration = configuration.CurrentValue; - if (telemetryConfiguration?.ContainerLogs == null || telemetryConfiguration.ContainerLogs.IsEnabled == false) - { - return true; - } - - LogLevel minimalLogLevel = telemetryConfiguration.ContainerLogs?.Verbosity ?? telemetryConfiguration.DefaultVerbosity ?? LogLevel.Warning; - - return minimalLogLevel <= usedLogLevel; - } - } -} \ No newline at end of file diff --git a/src/Promitor.Core.Telemetry/Loggers/RuntimeLogger.cs b/src/Promitor.Core.Telemetry/Loggers/RuntimeLogger.cs deleted file mode 100644 index 170d1c13a..000000000 --- a/src/Promitor.Core.Telemetry/Loggers/RuntimeLogger.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Microsoft.Extensions.Options; -using Promitor.Core.Configuration.Model.Telemetry; - -#pragma warning disable 618 - -namespace Promitor.Core.Telemetry.Loggers -{ - public class RuntimeLogger : Logger - { - public RuntimeLogger(IOptionsMonitor configuration) : base("Runtime", configuration) - { - } - } -} \ No newline at end of file diff --git a/src/Promitor.Core.Telemetry/Loggers/ValidationLogger.cs b/src/Promitor.Core.Telemetry/Loggers/ValidationLogger.cs deleted file mode 100644 index 7550af5ab..000000000 --- a/src/Promitor.Core.Telemetry/Loggers/ValidationLogger.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Microsoft.Extensions.Options; -using Promitor.Core.Configuration.Model.Telemetry; - -#pragma warning disable 618 - -namespace Promitor.Core.Telemetry.Loggers -{ - public class ValidationLogger : Logger - { - public ValidationLogger(IOptionsMonitor configuration) : base("Validation", configuration) - { - } - } -} \ No newline at end of file diff --git a/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs b/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs index 4758ceabc..f6e6001ff 100644 --- a/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs +++ b/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs @@ -1,6 +1,8 @@ using System.IO; using System.Linq; +using System.Text.Json.Serialization; using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.HealthChecks; @@ -21,7 +23,6 @@ using Promitor.Core.Scraping.Prometheus.Interfaces; using Promitor.Core.Telemetry; using Promitor.Core.Telemetry.Interfaces; -using Promitor.Core.Telemetry.Loggers; using Promitor.Core.Telemetry.Metrics; using Promitor.Core.Telemetry.Metrics.Interfaces; using Promitor.Scraper.Host.Scheduling; @@ -72,12 +73,10 @@ public static IServiceCollection ScheduleMetricScraping(this IServiceCollection public static IServiceCollection DefineDependencies(this IServiceCollection services) { services.AddTransient(); - services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); services.AddTransient(); services.AddSingleton, V1Deserializer>(); @@ -111,11 +110,11 @@ public static IServiceCollection UseHealthChecks(this IServiceCollection service /// public static IServiceCollection UseWebApi(this IServiceCollection services) { - services.AddMvc() + services.AddControllers() .AddJsonOptions(jsonOptions => { - jsonOptions.SerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter()); - jsonOptions.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore; + jsonOptions.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); + jsonOptions.JsonSerializerOptions.IgnoreNullValues=true; }); return services; @@ -182,13 +181,13 @@ public static IServiceCollection UseOpenApiSpecifications(this IServiceCollectio private static string GetXmlDocumentationPath(IServiceCollection services) { - var hostingEnvironment = services.FirstOrDefault(service => service.ServiceType == typeof(IHostingEnvironment)); + var hostingEnvironment = services.FirstOrDefault(service => service.ServiceType == typeof(IWebHostEnvironment)); if (hostingEnvironment == null) { return string.Empty; } - var contentRootPath = ((IHostingEnvironment)hostingEnvironment.ImplementationInstance).ContentRootPath; + var contentRootPath = ((IWebHostEnvironment)hostingEnvironment.ImplementationInstance).ContentRootPath; var xmlDocumentationPath = $"{contentRootPath}/Docs/Open-Api.xml"; return File.Exists(xmlDocumentationPath) ? xmlDocumentationPath : string.Empty; diff --git a/src/Promitor.Scraper.Host/Program.cs b/src/Promitor.Scraper.Host/Program.cs index fe4c60a18..6d3c778b0 100644 --- a/src/Promitor.Scraper.Host/Program.cs +++ b/src/Promitor.Scraper.Host/Program.cs @@ -1,8 +1,9 @@ using System; using System.IO; -using Microsoft.AspNetCore; +using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; using Promitor.Core.Configuration.Model.Server; namespace Promitor.Scraper.Host @@ -14,6 +15,7 @@ public static void Main(string[] args) Welcome(); BuildWebHost(args) + .Build() .Run(); } @@ -28,25 +30,27 @@ public static IHostBuilder BuildWebHost(string[] args) var httpPort = DetermineHttpPort(configuration); var endpointUrl = $"http://+:{httpPort}"; + // TODO: Configure verbosity https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-3.0#add-providers + return Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder(args) - .UseKestrel(kestrelServerOptions => + .ConfigureWebHostDefaults(webHostBuilder => { - kestrelServerOptions.AddServerHeader = false; - }) - .UseConfiguration(configuration) - .UseUrls(endpointUrl) - .UseStartup() - .Build(); + webHostBuilder.UseKestrel(kestrelServerOptions => { kestrelServerOptions.AddServerHeader = false; }) + .ConfigureLogging((hostContext, loggingBuilder) => { loggingBuilder.AddConsole(consoleLoggerOptions => consoleLoggerOptions.TimestampFormat = "[u]"); }) + .UseConfiguration(configuration) + .UseUrls(endpointUrl) + .UseStartup(); + }); } private static IConfigurationRoot CreateConfiguration() { var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) - .AddYamlFile("/config/runtime.yaml", optional: false, reloadOnChange: true) + .AddYamlFile("/config/runtime.yaml", false, true) .AddEnvironmentVariables() - .AddEnvironmentVariables(prefix: "PROMITOR_") // Used for all environment variables for Promitor - .AddEnvironmentVariables(prefix: "PROMITOR_YAML_OVERRIDE_") // Used to overwrite runtime YAML + .AddEnvironmentVariables("PROMITOR_") // Used for all environment variables for Promitor + .AddEnvironmentVariables("PROMITOR_YAML_OVERRIDE_") // Used to overwrite runtime YAML .Build(); return configuration; diff --git a/src/Promitor.Scraper.Host/Scheduling/MetricScrapingJob.cs b/src/Promitor.Scraper.Host/Scheduling/MetricScrapingJob.cs index d03a1331e..d1b96a41d 100644 --- a/src/Promitor.Scraper.Host/Scheduling/MetricScrapingJob.cs +++ b/src/Promitor.Scraper.Host/Scheduling/MetricScrapingJob.cs @@ -1,7 +1,7 @@ using System; using System.Threading; using System.Threading.Tasks; -using CronScheduler.AspNetCore; +using CronScheduler.Extensions.Scheduler; using GuardNet; using Microsoft.Extensions.Logging; using Promitor.Core.Scraping.Configuration.Model; diff --git a/src/Promitor.Scraper.Host/Startup.cs b/src/Promitor.Scraper.Host/Startup.cs index c6faae6d6..cb9486792 100644 --- a/src/Promitor.Scraper.Host/Startup.cs +++ b/src/Promitor.Scraper.Host/Startup.cs @@ -1,7 +1,9 @@ using AutoMapper; using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; using Promitor.Core.Configuration.Model.Prometheus; using Promitor.Core.Scraping.Configuration.Serialization.v1.Mapping; using Promitor.Scraper.Host.Extensions; @@ -23,14 +25,15 @@ public Startup(IConfiguration configuration) } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IHostingEnvironment env) + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) + { app.UseDeveloperExceptionPage(); + } ValidateRuntimeConfiguration(app); - app.UseMvc(); app.UsePrometheusScraper(_prometheusBaseUriPath); app.UseOpenApiUi(); } diff --git a/src/Promitor.Scraper.Host/Validation/RuntimeValidator.cs b/src/Promitor.Scraper.Host/Validation/RuntimeValidator.cs index c3fb5e68b..986bd04c5 100644 --- a/src/Promitor.Scraper.Host/Validation/RuntimeValidator.cs +++ b/src/Promitor.Scraper.Host/Validation/RuntimeValidator.cs @@ -8,7 +8,6 @@ using Promitor.Core.Scraping.Configuration.Providers; using Promitor.Core.Scraping.Configuration.Serialization; using Promitor.Core.Scraping.Configuration.Serialization.v1.Model; -using Promitor.Core.Telemetry.Loggers; using Promitor.Scraper.Host.Validation.Exceptions; using Promitor.Scraper.Host.Validation.Interfaces; using Promitor.Scraper.Host.Validation.Steps; @@ -24,7 +23,7 @@ public class RuntimeValidator public RuntimeValidator( IOptions metricsConfiguration, - ValidationLogger validatorLogger, + ILogger validatorLogger, IConfiguration configuration, IMapper mapper, IDeserializer v1Deserializer) From afe7dd41788d38870d2cb3ec765ea4482bc6622b Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Sat, 12 Oct 2019 10:44:46 +0200 Subject: [PATCH 09/38] Fix broken dependencies and use ILogger Signed-off-by: Tom Kerkhove --- .../Providers/MetricsDeclarationProvider.cs | 7 ++-- .../Serialization/ConfigurationSerializer.cs | 2 +- .../v1/Core/AggregationDeserializer.cs | 2 +- .../v1/Core/AzureMetadataDeserializer.cs | 2 +- .../AzureMetricConfigurationDeserializer.cs | 2 +- .../Core/AzureResourceDeserializerFactory.cs | 36 ++++++++++++------- .../v1/Core/MetricAggregationDeserializer.cs | 2 +- .../v1/Core/MetricDefaultsDeserializer.cs | 2 +- .../v1/Core/MetricDefinitionDeserializer.cs | 2 +- .../v1/Core/ScrapingDeserializer.cs | 2 +- .../v1/Core/SecretDeserializer.cs | 2 +- .../Serialization/v1/Core/V1Deserializer.cs | 2 +- .../ContainerInstanceDeserializer.cs | 2 +- .../ContainerRegistryDeserializer.cs | 2 +- .../v1/Providers/CosmosDbDeserializer.cs | 2 +- .../Providers/GenericResourceDeserializer.cs | 2 +- .../Providers/NetworkInterfaceDeserializer.cs | 2 +- .../v1/Providers/PostgreSqlDeserializer.cs | 2 +- .../v1/Providers/RedisCacheDeserializer.cs | 2 +- .../Providers/ServiceBusQueueDeserializer.cs | 2 +- .../v1/Providers/StorageQueueDeserializer.cs | 2 +- .../Providers/VirtualMachineDeserializer.cs | 2 +- .../Factories/MetricScraperFactory.cs | 2 +- .../ApplicationInsightsTelemetry.cs | 2 +- .../IApplicationBuilderExtensions.cs | 22 ++++++------ .../IServiceCollectionExtensions.cs | 29 +++++++-------- .../Scheduling/MetricScrapingJob.cs | 2 +- .../Validation/RuntimeValidator.cs | 9 +++-- .../Metrics/v1/MetricsDeclarationBuilder.cs | 20 +++++------ .../YamlMappingNodeExtensionTests.cs | 4 +-- .../v1/Core/AggregationDeserializerTests.cs | 2 +- .../v1/Core/AzureMetadataDeserializerTests.cs | 2 +- ...ureMetricConfigurationDeserializerTests.cs | 4 +-- .../MetricAggregationDeserializerTests.cs | 4 +-- .../Core/MetricDefaultsDeserializerTests.cs | 2 +- .../Core/MetricDefinitionDeserializerTests.cs | 8 ++--- .../v1/Core/ScrapingDeserializerTests.cs | 2 +- .../v1/Core/SecretDeserializerTests.cs | 2 +- .../v1/Core/V1DeserializerTests.cs | 4 +-- .../ContainerInstanceDeserializerTests.cs | 7 ++-- .../ContainerRegistryDeserializerTests.cs | 7 ++-- .../v1/Providers/CosmosDbDeserializerTests.cs | 7 ++-- .../GenericResourceDeserializerTests.cs | 9 +++-- .../NetworkInterfaceDeserializerTests.cs | 9 ++--- .../Providers/PostgreSqlDeserializerTests.cs | 9 +++-- .../Providers/RedisCacheDeserializerTests.cs | 7 ++-- .../v1/Providers/ResourceDeserializerTest.cs | 7 ++-- .../ServiceBusQueueDeserializerTests.cs | 7 ++-- .../StorageQueueDeserializerTests.cs | 9 +++-- .../VirtualMachineDeserializerTests.cs | 7 ++-- .../Serialization/v1/V1DeserializerFactory.cs | 24 ++++++------- .../Serialization/v1/V1SerializationTests.cs | 8 ++--- .../Stubs/MetricsDeclarationProviderStub.cs | 3 +- 53 files changed, 161 insertions(+), 162 deletions(-) diff --git a/src/Promitor.Core.Scraping/Configuration/Providers/MetricsDeclarationProvider.cs b/src/Promitor.Core.Scraping/Configuration/Providers/MetricsDeclarationProvider.cs index 03f2d7ab9..f37badd76 100644 --- a/src/Promitor.Core.Scraping/Configuration/Providers/MetricsDeclarationProvider.cs +++ b/src/Promitor.Core.Scraping/Configuration/Providers/MetricsDeclarationProvider.cs @@ -1,13 +1,10 @@ using System; using System.IO; -using AutoMapper; using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; using Promitor.Core.Configuration.Model.Metrics; using Promitor.Core.Scraping.Configuration.Model; using Promitor.Core.Scraping.Configuration.Providers.Interfaces; using Promitor.Core.Scraping.Configuration.Serialization; -using Promitor.Core.Scraping.Configuration.Serialization.v1.Model; namespace Promitor.Core.Scraping.Configuration.Providers { @@ -16,9 +13,9 @@ public class MetricsDeclarationProvider : IMetricsDeclarationProvider private readonly ConfigurationSerializer _configurationSerializer; private readonly IConfiguration _configuration; - public MetricsDeclarationProvider(IConfiguration configuration, ILogger logger, IMapper mapper, IDeserializer v1Deserializer) + public MetricsDeclarationProvider(IConfiguration configuration, ConfigurationSerializer configurationSerializer) { - _configurationSerializer = new ConfigurationSerializer(logger, mapper, v1Deserializer); + _configurationSerializer = configurationSerializer; _configuration = configuration; } diff --git a/src/Promitor.Core.Scraping/Configuration/Serialization/ConfigurationSerializer.cs b/src/Promitor.Core.Scraping/Configuration/Serialization/ConfigurationSerializer.cs index c47c5367c..ce6c8e3cc 100644 --- a/src/Promitor.Core.Scraping/Configuration/Serialization/ConfigurationSerializer.cs +++ b/src/Promitor.Core.Scraping/Configuration/Serialization/ConfigurationSerializer.cs @@ -19,7 +19,7 @@ public class ConfigurationSerializer private readonly IMapper _mapper; private readonly IDeserializer _v1Deserializer; - public ConfigurationSerializer(ILogger logger, IMapper mapper, IDeserializer v1Deserializer) + public ConfigurationSerializer(ILogger logger, IMapper mapper, IDeserializer v1Deserializer) { _logger = logger; _mapper = mapper; diff --git a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/AggregationDeserializer.cs b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/AggregationDeserializer.cs index 01b8f74bb..d135f5b01 100644 --- a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/AggregationDeserializer.cs +++ b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/AggregationDeserializer.cs @@ -11,7 +11,7 @@ public class AggregationDeserializer : Deserializer private readonly TimeSpan _defaultAggregationInterval = TimeSpan.FromMinutes(5); - public AggregationDeserializer(ILogger logger) : base(logger) + public AggregationDeserializer(ILogger logger) : base(logger) { } diff --git a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/AzureMetadataDeserializer.cs b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/AzureMetadataDeserializer.cs index 3f92bc019..3a7993d66 100644 --- a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/AzureMetadataDeserializer.cs +++ b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/AzureMetadataDeserializer.cs @@ -10,7 +10,7 @@ public class AzureMetadataDeserializer : Deserializer private const string SubscriptionIdTag = "subscriptionId"; private const string ResourceGroupNameTag = "resourceGroupName"; - public AzureMetadataDeserializer(ILogger logger) : base(logger) + public AzureMetadataDeserializer(ILogger logger) : base(logger) { } diff --git a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/AzureMetricConfigurationDeserializer.cs b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/AzureMetricConfigurationDeserializer.cs index 3f963b36b..23699b2de 100644 --- a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/AzureMetricConfigurationDeserializer.cs +++ b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/AzureMetricConfigurationDeserializer.cs @@ -10,7 +10,7 @@ public class AzureMetricConfigurationDeserializer : Deserializer _aggregationDeserializer; - public AzureMetricConfigurationDeserializer(IDeserializer aggregationDeserializer, ILogger logger) + public AzureMetricConfigurationDeserializer(IDeserializer aggregationDeserializer, ILogger logger) : base(logger) { _aggregationDeserializer = aggregationDeserializer; diff --git a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/AzureResourceDeserializerFactory.cs b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/AzureResourceDeserializerFactory.cs index f292cfc97..9c980cf83 100644 --- a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/AzureResourceDeserializerFactory.cs +++ b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/AzureResourceDeserializerFactory.cs @@ -9,12 +9,12 @@ namespace Promitor.Core.Scraping.Configuration.Serialization.v1.Core public class AzureResourceDeserializerFactory : IAzureResourceDeserializerFactory { private readonly IDeserializer _secretDeserializer; - private readonly ILogger _logger; + private readonly ILoggerFactory _loggerFactory; - public AzureResourceDeserializerFactory(IDeserializer secretDeserializer, ILogger logger) + public AzureResourceDeserializerFactory(IDeserializer secretDeserializer, ILoggerFactory loggerFactory) { _secretDeserializer = secretDeserializer; - _logger = logger; + _loggerFactory = loggerFactory; } public IDeserializer GetDeserializerFor(ResourceType resourceType) @@ -22,25 +22,35 @@ public IDeserializer GetDeserializerFor(ResourceType switch (resourceType) { case ResourceType.ServiceBusQueue: - return new ServiceBusQueueDeserializer(_logger); + var serviceBusLogger = _loggerFactory.CreateLogger(); + return new ServiceBusQueueDeserializer(serviceBusLogger); case ResourceType.Generic: - return new GenericResourceDeserializer(_logger); + var genericLogger = _loggerFactory.CreateLogger(); + return new GenericResourceDeserializer(genericLogger); case ResourceType.StorageQueue: - return new StorageQueueDeserializer(_secretDeserializer, _logger); + var storageQueueLogger = _loggerFactory.CreateLogger(); + return new StorageQueueDeserializer(_secretDeserializer, storageQueueLogger); case ResourceType.ContainerInstance: - return new ContainerInstanceDeserializer(_logger); + var containerInstanceLogger = _loggerFactory.CreateLogger(); + return new ContainerInstanceDeserializer(containerInstanceLogger); case ResourceType.VirtualMachine: - return new VirtualMachineDeserializer(_logger); + var virtualMachineLogger = _loggerFactory.CreateLogger(); + return new VirtualMachineDeserializer(virtualMachineLogger); case ResourceType.ContainerRegistry: - return new ContainerRegistryDeserializer(_logger); + var containerRegistryLogger = _loggerFactory.CreateLogger(); + return new ContainerRegistryDeserializer(containerRegistryLogger); case ResourceType.NetworkInterface: - return new NetworkInterfaceDeserializer(_logger); + var networkLogger = _loggerFactory.CreateLogger(); + return new NetworkInterfaceDeserializer(networkLogger); case ResourceType.CosmosDb: - return new CosmosDbDeserializer(_logger); + var cosmosDbLogger = _loggerFactory.CreateLogger(); + return new CosmosDbDeserializer(cosmosDbLogger); case ResourceType.RedisCache: - return new RedisCacheDeserializer(_logger); + var redisCacheLogger = _loggerFactory.CreateLogger(); + return new RedisCacheDeserializer(redisCacheLogger); case ResourceType.PostgreSql: - return new PostgreSqlDeserializer(_logger); + var postgreSqlLogger = _loggerFactory.CreateLogger(); + return new PostgreSqlDeserializer(postgreSqlLogger); default: throw new ArgumentOutOfRangeException($"Resource Type {resourceType} not supported."); } diff --git a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/MetricAggregationDeserializer.cs b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/MetricAggregationDeserializer.cs index 189ad607b..870890263 100644 --- a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/MetricAggregationDeserializer.cs +++ b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/MetricAggregationDeserializer.cs @@ -10,7 +10,7 @@ public class MetricAggregationDeserializer : Deserializer private const string TypeTag = "type"; private const string IntervalTag = "interval"; - public MetricAggregationDeserializer(ILogger logger) : base(logger) + public MetricAggregationDeserializer(ILogger logger) : base(logger) { } diff --git a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/MetricDefaultsDeserializer.cs b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/MetricDefaultsDeserializer.cs index 7c2ff47f4..e754cdf8d 100644 --- a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/MetricDefaultsDeserializer.cs +++ b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/MetricDefaultsDeserializer.cs @@ -15,7 +15,7 @@ public class MetricDefaultsDeserializer : Deserializer public MetricDefaultsDeserializer( IDeserializer aggregationDeserializer, IDeserializer scrapingDeserializer, - ILogger logger) : base(logger) + ILogger logger) : base(logger) { _aggregationDeserializer = aggregationDeserializer; _scrapingDeserializer = scrapingDeserializer; diff --git a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/MetricDefinitionDeserializer.cs b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/MetricDefinitionDeserializer.cs index cd794e6a2..6c75c0c3a 100644 --- a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/MetricDefinitionDeserializer.cs +++ b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/MetricDefinitionDeserializer.cs @@ -22,7 +22,7 @@ public class MetricDefinitionDeserializer : Deserializer public MetricDefinitionDeserializer(IDeserializer azureMetricConfigurationDeserializer, IDeserializer scrapingDeserializer, IAzureResourceDeserializerFactory azureResourceDeserializerFactory, - ILogger logger) : base(logger) + ILogger logger) : base(logger) { _azureMetricConfigurationDeserializer = azureMetricConfigurationDeserializer; _scrapingDeserializer = scrapingDeserializer; diff --git a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/ScrapingDeserializer.cs b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/ScrapingDeserializer.cs index 6f46a6cf9..5b94c4290 100644 --- a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/ScrapingDeserializer.cs +++ b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/ScrapingDeserializer.cs @@ -8,7 +8,7 @@ public class ScrapingDeserializer : Deserializer { private const string ScheduleTag = "schedule"; - public ScrapingDeserializer(ILogger logger) : base(logger) + public ScrapingDeserializer(ILogger logger) : base(logger) { } diff --git a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/SecretDeserializer.cs b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/SecretDeserializer.cs index 70d4b3500..d55482700 100644 --- a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/SecretDeserializer.cs +++ b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/SecretDeserializer.cs @@ -9,7 +9,7 @@ public class SecretDeserializer : Deserializer private const string RawValueTag = "rawValue"; private const string EnvironmentVariableTag = "environmentVariable"; - public SecretDeserializer(ILogger logger) : base(logger) + public SecretDeserializer(ILogger logger) : base(logger) { } diff --git a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/V1Deserializer.cs b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/V1Deserializer.cs index a8905837c..67df4e73e 100644 --- a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/V1Deserializer.cs +++ b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/V1Deserializer.cs @@ -15,7 +15,7 @@ public class V1Deserializer : Deserializer public V1Deserializer(IDeserializer azureMetadataDeserializer, IDeserializer defaultsDeserializer, IDeserializer metricsDeserializer, - ILogger logger) : base(logger) + ILogger logger) : base(logger) { _azureMetadataDeserializer = azureMetadataDeserializer; _defaultsDeserializer = defaultsDeserializer; diff --git a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/ContainerInstanceDeserializer.cs b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/ContainerInstanceDeserializer.cs index ec68f6b64..15b2ef448 100644 --- a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/ContainerInstanceDeserializer.cs +++ b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/ContainerInstanceDeserializer.cs @@ -9,7 +9,7 @@ public class ContainerInstanceDeserializer : ResourceDeserializer { private const string ContainerGroupTag = "containerGroup"; - public ContainerInstanceDeserializer(ILogger logger) : base(logger) + public ContainerInstanceDeserializer(ILogger logger) : base(logger) { } diff --git a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/ContainerRegistryDeserializer.cs b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/ContainerRegistryDeserializer.cs index 3dd1be082..21df451b2 100644 --- a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/ContainerRegistryDeserializer.cs +++ b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/ContainerRegistryDeserializer.cs @@ -9,7 +9,7 @@ public class ContainerRegistryDeserializer : ResourceDeserializer { private const string RegistryNameTag = "registryName"; - public ContainerRegistryDeserializer(ILogger logger) : base(logger) + public ContainerRegistryDeserializer(ILogger logger) : base(logger) { } diff --git a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/CosmosDbDeserializer.cs b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/CosmosDbDeserializer.cs index 6582dde25..f24659897 100644 --- a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/CosmosDbDeserializer.cs +++ b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/CosmosDbDeserializer.cs @@ -9,7 +9,7 @@ public class CosmosDbDeserializer : ResourceDeserializer { private const string DatabaseNameTag = "dbName"; - public CosmosDbDeserializer(ILogger logger) : base(logger) + public CosmosDbDeserializer(ILogger logger) : base(logger) { } diff --git a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/GenericResourceDeserializer.cs b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/GenericResourceDeserializer.cs index dadfda114..598001aa3 100644 --- a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/GenericResourceDeserializer.cs +++ b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/GenericResourceDeserializer.cs @@ -10,7 +10,7 @@ public class GenericResourceDeserializer : ResourceDeserializer private const string FilterTag = "filter"; private const string ResourceUriTag = "resourceUri"; - public GenericResourceDeserializer(ILogger logger) : base(logger) + public GenericResourceDeserializer(ILogger logger) : base(logger) { } diff --git a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/NetworkInterfaceDeserializer.cs b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/NetworkInterfaceDeserializer.cs index 0c1ab380b..adde3fd32 100644 --- a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/NetworkInterfaceDeserializer.cs +++ b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/NetworkInterfaceDeserializer.cs @@ -9,7 +9,7 @@ public class NetworkInterfaceDeserializer : ResourceDeserializer { private const string NetworkInterfaceNameTag = "networkInterfaceName"; - public NetworkInterfaceDeserializer(ILogger logger) : base(logger) + public NetworkInterfaceDeserializer(ILogger logger) : base(logger) { } diff --git a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/PostgreSqlDeserializer.cs b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/PostgreSqlDeserializer.cs index db165db9d..cde1727f3 100644 --- a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/PostgreSqlDeserializer.cs +++ b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/PostgreSqlDeserializer.cs @@ -9,7 +9,7 @@ public class PostgreSqlDeserializer : ResourceDeserializer { private const string ServerNameTag = "serverName"; - public PostgreSqlDeserializer(ILogger logger) : base(logger) + public PostgreSqlDeserializer(ILogger logger) : base(logger) { } diff --git a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/RedisCacheDeserializer.cs b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/RedisCacheDeserializer.cs index 7131e6a47..1dfb22a43 100644 --- a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/RedisCacheDeserializer.cs +++ b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/RedisCacheDeserializer.cs @@ -9,7 +9,7 @@ public class RedisCacheDeserializer : ResourceDeserializer { private const string CacheNameTag = "cacheName"; - public RedisCacheDeserializer(ILogger logger) : base(logger) + public RedisCacheDeserializer(ILogger logger) : base(logger) { } diff --git a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/ServiceBusQueueDeserializer.cs b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/ServiceBusQueueDeserializer.cs index 9435fc474..780d47043 100644 --- a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/ServiceBusQueueDeserializer.cs +++ b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/ServiceBusQueueDeserializer.cs @@ -10,7 +10,7 @@ public class ServiceBusQueueDeserializer : ResourceDeserializer private const string QueueNameTag = "queueName"; private const string NamespaceTag = "namespace"; - public ServiceBusQueueDeserializer(ILogger logger) : base(logger) + public ServiceBusQueueDeserializer(ILogger logger) : base(logger) { } diff --git a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/StorageQueueDeserializer.cs b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/StorageQueueDeserializer.cs index 6a8731571..08f2391b6 100644 --- a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/StorageQueueDeserializer.cs +++ b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/StorageQueueDeserializer.cs @@ -13,7 +13,7 @@ public class StorageQueueDeserializer : ResourceDeserializer private readonly IDeserializer _secretDeserializer; - public StorageQueueDeserializer(IDeserializer secretDeserializer, ILogger logger) : base(logger) + public StorageQueueDeserializer(IDeserializer secretDeserializer, ILogger logger) : base(logger) { _secretDeserializer = secretDeserializer; } diff --git a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/VirtualMachineDeserializer.cs b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/VirtualMachineDeserializer.cs index 0e9b98a51..5369fdab3 100644 --- a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/VirtualMachineDeserializer.cs +++ b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Providers/VirtualMachineDeserializer.cs @@ -9,7 +9,7 @@ public class VirtualMachineDeserializer : ResourceDeserializer { private const string VirtualMachineNameTag = "virtualMachineName"; - public VirtualMachineDeserializer(ILogger logger) : base(logger) + public VirtualMachineDeserializer(ILogger logger) : base(logger) { } diff --git a/src/Promitor.Core.Scraping/Factories/MetricScraperFactory.cs b/src/Promitor.Core.Scraping/Factories/MetricScraperFactory.cs index 576157d9e..e1dad5c22 100644 --- a/src/Promitor.Core.Scraping/Factories/MetricScraperFactory.cs +++ b/src/Promitor.Core.Scraping/Factories/MetricScraperFactory.cs @@ -19,7 +19,7 @@ public class MetricScraperFactory private readonly IConfiguration _configuration; private readonly ILogger _logger; - public MetricScraperFactory(IConfiguration configuration, ILogger logger, IExceptionTracker exceptionTracker) + public MetricScraperFactory(IConfiguration configuration, ILogger logger, IExceptionTracker exceptionTracker) { Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(logger, nameof(logger)); diff --git a/src/Promitor.Core.Telemetry/ApplicationInsightsTelemetry.cs b/src/Promitor.Core.Telemetry/ApplicationInsightsTelemetry.cs index 17c247b37..f7f8ec913 100644 --- a/src/Promitor.Core.Telemetry/ApplicationInsightsTelemetry.cs +++ b/src/Promitor.Core.Telemetry/ApplicationInsightsTelemetry.cs @@ -15,7 +15,7 @@ public class ApplicationInsightsTelemetry : IExceptionTracker private readonly IOptionsMonitor _applicationInsightsConfiguration; private readonly TelemetryClient _telemetryClient; - public ApplicationInsightsTelemetry(IOptionsMonitor applicationInsightsConfiguration, ILogger logger) + public ApplicationInsightsTelemetry(IOptionsMonitor applicationInsightsConfiguration, ILogger logger) { Guard.NotNull(applicationInsightsConfiguration, nameof(applicationInsightsConfiguration)); Guard.NotNull(logger, nameof(logger)); diff --git a/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs b/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs index 2cd0d5bf7..7e5f7d2fb 100644 --- a/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs +++ b/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs @@ -14,17 +14,17 @@ public static class IApplicationBuilderExtensions /// Application Builder public static void UseOpenApiUi(this IApplicationBuilder app) { - app.UseSwagger(); - app.UseSwaggerUI(swaggerUiOptions => - { - swaggerUiOptions.SwaggerEndpoint("/swagger/v1/swagger.json", "Promitor API"); - swaggerUiOptions.DisplayOperationId(); - swaggerUiOptions.EnableDeepLinking(); - swaggerUiOptions.DocumentTitle = "Promitor API"; - swaggerUiOptions.DocExpansion(DocExpansion.List); - swaggerUiOptions.DisplayRequestDuration(); - swaggerUiOptions.EnableFilter(); - }); + //app.UseSwagger(); + //app.UseSwaggerUI(swaggerUiOptions => + //{ + // swaggerUiOptions.SwaggerEndpoint("/swagger/v1/swagger.json", "Promitor API"); + // swaggerUiOptions.DisplayOperationId(); + // swaggerUiOptions.EnableDeepLinking(); + // swaggerUiOptions.DocumentTitle = "Promitor API"; + // swaggerUiOptions.DocExpansion(DocExpansion.List); + // swaggerUiOptions.DisplayRequestDuration(); + // swaggerUiOptions.EnableFilter(); + //}); } /// diff --git a/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs b/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs index f6e6001ff..ae35c2b6d 100644 --- a/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs +++ b/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs @@ -41,8 +41,8 @@ public static class IServiceCollectionExtensions /// Collections of services in application public static IServiceCollection ScheduleMetricScraping(this IServiceCollection services) { - var spToCreateJobsWith = services.BuildServiceProvider(); - var metricsProvider = spToCreateJobsWith.GetService(); + var serviceProviderToCreateJobsWith = services.BuildServiceProvider(); + var metricsProvider = serviceProviderToCreateJobsWith.GetService(); var metrics = metricsProvider.Get(true); foreach (var metric in metrics.Metrics) @@ -56,7 +56,7 @@ public static IServiceCollection ScheduleMetricScraping(this IServiceCollection serviceProvider.GetService(), serviceProvider.GetService(), serviceProvider.GetService(), - serviceProvider.GetService(), + serviceProvider.GetService>(), serviceProvider.GetService())); builder.UnobservedTaskExceptionHandler = (sender, exceptionEventArgs) => UnobservedJobHandlerHandler(sender, exceptionEventArgs, services); }); @@ -78,6 +78,7 @@ public static IServiceCollection DefineDependencies(this IServiceCollection serv services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddSingleton, V1Deserializer>(); services.AddSingleton, AzureMetadataDeserializer>(); @@ -164,17 +165,17 @@ public static IServiceCollection UseOpenApiSpecifications(this IServiceCollectio var xmlDocumentationPath = GetXmlDocumentationPath(services); - services.AddSwaggerGen(swaggerGenerationOptions => - { - swaggerGenerationOptions.EnableAnnotations(); - swaggerGenerationOptions.SwaggerDoc($"v{apiVersion}", openApiInformation); - swaggerGenerationOptions.DescribeAllEnumsAsStrings(); - - if (string.IsNullOrEmpty(xmlDocumentationPath) == false) - { - swaggerGenerationOptions.IncludeXmlComments(xmlDocumentationPath); - } - }); + //services.AddSwaggerGen(swaggerGenerationOptions => + //{ + // swaggerGenerationOptions.EnableAnnotations(); + // swaggerGenerationOptions.SwaggerDoc($"v{apiVersion}", openApiInformation); + // swaggerGenerationOptions.DescribeAllEnumsAsStrings(); + + // if (string.IsNullOrEmpty(xmlDocumentationPath) == false) + // { + // swaggerGenerationOptions.IncludeXmlComments(xmlDocumentationPath); + // } + //}); return services; } diff --git a/src/Promitor.Scraper.Host/Scheduling/MetricScrapingJob.cs b/src/Promitor.Scraper.Host/Scheduling/MetricScrapingJob.cs index d1b96a41d..b8734e995 100644 --- a/src/Promitor.Scraper.Host/Scheduling/MetricScrapingJob.cs +++ b/src/Promitor.Scraper.Host/Scheduling/MetricScrapingJob.cs @@ -30,7 +30,7 @@ public MetricScrapingJob(ScrapeDefinition metric, IPrometheusMetricWriter prometheusMetricWriter, IRuntimeMetricsCollector runtimeMetricsCollector, MetricScraperFactory metricScraperFactory, - ILogger logger, IExceptionTracker exceptionTracker) + ILogger logger, IExceptionTracker exceptionTracker) { Guard.NotNull(metric, nameof(metric)); Guard.NotNull(metricsDeclarationProvider, nameof(metricsDeclarationProvider)); diff --git a/src/Promitor.Scraper.Host/Validation/RuntimeValidator.cs b/src/Promitor.Scraper.Host/Validation/RuntimeValidator.cs index 986bd04c5..0a2d99e3b 100644 --- a/src/Promitor.Scraper.Host/Validation/RuntimeValidator.cs +++ b/src/Promitor.Scraper.Host/Validation/RuntimeValidator.cs @@ -6,6 +6,7 @@ using Microsoft.Extensions.Options; using Promitor.Core.Configuration.Model.Metrics; using Promitor.Core.Scraping.Configuration.Providers; +using Promitor.Core.Scraping.Configuration.Providers.Interfaces; using Promitor.Core.Scraping.Configuration.Serialization; using Promitor.Core.Scraping.Configuration.Serialization.v1.Model; using Promitor.Scraper.Host.Validation.Exceptions; @@ -23,14 +24,12 @@ public class RuntimeValidator public RuntimeValidator( IOptions metricsConfiguration, - ILogger validatorLogger, - IConfiguration configuration, - IMapper mapper, - IDeserializer v1Deserializer) + ILogger validatorLogger, + IMetricsDeclarationProvider scrapeConfigurationProvider, + IConfiguration configuration) { _validationLogger = validatorLogger; - var scrapeConfigurationProvider = new MetricsDeclarationProvider(configuration, _validationLogger, mapper, v1Deserializer); _validationSteps = new List { new ConfigurationPathValidationStep(metricsConfiguration, _validationLogger), diff --git a/src/Promitor.Scraper.Tests.Unit/Builders/Metrics/v1/MetricsDeclarationBuilder.cs b/src/Promitor.Scraper.Tests.Unit/Builders/Metrics/v1/MetricsDeclarationBuilder.cs index 4cf9a42f6..eabae04ce 100644 --- a/src/Promitor.Scraper.Tests.Unit/Builders/Metrics/v1/MetricsDeclarationBuilder.cs +++ b/src/Promitor.Scraper.Tests.Unit/Builders/Metrics/v1/MetricsDeclarationBuilder.cs @@ -65,7 +65,7 @@ public string Build(IMapper mapper) _v1Deserializer = V1DeserializerFactory.CreateDeserializer(); - var configurationSerializer = new ConfigurationSerializer(NullLogger.Instance, mapper, _v1Deserializer); + var configurationSerializer = new ConfigurationSerializer(NullLogger.Instance, mapper, _v1Deserializer); return configurationSerializer.Serialize(metricsDeclaration); } @@ -83,7 +83,7 @@ public string Build(IMapper mapper) Name = metricName, Description = metricDescription, AzureMetricConfiguration = azureMetricConfiguration, - Resources = new List {resource}, + Resources = new List { resource }, ResourceType = ResourceType.ServiceBusQueue }; @@ -105,7 +105,7 @@ public string Build(IMapper mapper) Name = metricName, Description = metricDescription, AzureMetricConfiguration = azureMetricConfiguration, - Resources = new List {resource}, + Resources = new List { resource }, ResourceType = ResourceType.ContainerInstance }; @@ -127,7 +127,7 @@ public string Build(IMapper mapper) Name = metricName, Description = metricDescription, AzureMetricConfiguration = azureMetricConfiguration, - Resources = new List {resource}, + Resources = new List { resource }, ResourceType = ResourceType.ContainerRegistry }; @@ -149,7 +149,7 @@ public string Build(IMapper mapper) Name = metricName, Description = metricDescription, AzureMetricConfiguration = azureMetricConfiguration, - Resources = new List {resource}, + Resources = new List { resource }, ResourceType = ResourceType.CosmosDb }; @@ -200,7 +200,7 @@ public string Build(IMapper mapper) Name = metricName, Description = metricDescription, AzureMetricConfiguration = azureMetricConfiguration, - Resources = new List {resource}, + Resources = new List { resource }, ResourceType = ResourceType.VirtualMachine }; @@ -222,7 +222,7 @@ public string Build(IMapper mapper) Name = metricName, Description = metricDescription, AzureMetricConfiguration = azureMetricConfiguration, - Resources = new List {resource}, + Resources = new List { resource }, ResourceType = ResourceType.NetworkInterface }; @@ -245,7 +245,7 @@ public string Build(IMapper mapper) Name = metricName, Description = metricDescription, AzureMetricConfiguration = azureMetricConfiguration, - Resources = new List {resource}, + Resources = new List { resource }, ResourceType = ResourceType.Generic }; @@ -279,7 +279,7 @@ private AzureMetricConfigurationV1 CreateAzureMetricConfiguration(string azureMe Name = metricName, Description = metricDescription, AzureMetricConfiguration = azureMetricConfiguration, - Resources = new List {resource}, + Resources = new List { resource }, ResourceType = ResourceType.RedisCache }; @@ -301,7 +301,7 @@ private AzureMetricConfigurationV1 CreateAzureMetricConfiguration(string azureMe Name = metricName, Description = metricDescription, AzureMetricConfiguration = azureMetricConfiguration, - Resources = new List {resource}, + Resources = new List { resource }, ResourceType = ResourceType.PostgreSql }; diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/YamlMappingNodeExtensionTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/YamlMappingNodeExtensionTests.cs index fddda4536..10f2bd5fc 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/YamlMappingNodeExtensionTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/YamlMappingNodeExtensionTests.cs @@ -143,7 +143,7 @@ public void DeserializeChild_PropertySpecified_DeserializesChild() @"aggregation: interval: 00:05:00"; var node = YamlUtils.CreateYamlNode(yamlText); - var deserializer = new AggregationDeserializer(NullLogger.Instance); + var deserializer = new AggregationDeserializer(NullLogger.Instance); // Act var aggregation = node.DeserializeChild("aggregation", deserializer); @@ -157,7 +157,7 @@ public void DeserializeChild_PropertyNotSpecified_Null() { // Arrange var node = YamlUtils.CreateYamlNode(@"time: 00:05:30"); - var deserializer = new AggregationDeserializer(NullLogger.Instance); + var deserializer = new AggregationDeserializer(NullLogger.Instance); // Act var aggregation = node.DeserializeChild("aggregation", deserializer); diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/AggregationDeserializerTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/AggregationDeserializerTests.cs index 4700aa79c..4f6f2cdc1 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/AggregationDeserializerTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/AggregationDeserializerTests.cs @@ -13,7 +13,7 @@ public class AggregationDeserializerTests public AggregationDeserializerTests() { - _deserializer = new AggregationDeserializer(NullLogger.Instance); + _deserializer = new AggregationDeserializer(NullLogger.Instance); } [Fact] diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/AzureMetadataDeserializerTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/AzureMetadataDeserializerTests.cs index e96d872f5..0bed9775d 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/AzureMetadataDeserializerTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/AzureMetadataDeserializerTests.cs @@ -12,7 +12,7 @@ public class AzureMetadataDeserializerTests public AzureMetadataDeserializerTests() { - _deserializer = new AzureMetadataDeserializer(NullLogger.Instance); + _deserializer = new AzureMetadataDeserializer(NullLogger.Instance); } [Fact] diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/AzureMetricConfigurationDeserializerTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/AzureMetricConfigurationDeserializerTests.cs index 679084207..d35638f1a 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/AzureMetricConfigurationDeserializerTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/AzureMetricConfigurationDeserializerTests.cs @@ -19,7 +19,7 @@ public AzureMetricConfigurationDeserializerTests() { _aggregationDeserializer = new Mock>(); - _deserializer = new AzureMetricConfigurationDeserializer(_aggregationDeserializer.Object, NullLogger.Instance); + _deserializer = new AzureMetricConfigurationDeserializer(_aggregationDeserializer.Object, NullLogger.Instance); } [Fact] @@ -49,7 +49,7 @@ public void Deserialize_AggregationSupplied_UsesDeserializer() @"aggregation: type: Average"; var node = YamlUtils.CreateYamlNode(yamlText); - var aggregationNode = (YamlMappingNode) node.Children["aggregation"]; + var aggregationNode = (YamlMappingNode)node.Children["aggregation"]; var aggregation = new MetricAggregationV1(); _aggregationDeserializer.Setup(d => d.Deserialize(aggregationNode)).Returns(aggregation); diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/MetricAggregationDeserializerTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/MetricAggregationDeserializerTests.cs index 07e144fc5..a40150870 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/MetricAggregationDeserializerTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/MetricAggregationDeserializerTests.cs @@ -11,10 +11,10 @@ namespace Promitor.Scraper.Tests.Unit.Serialization.v1.Core public class MetricAggregationDeserializerTests { private readonly MetricAggregationDeserializer _deserializer; - + public MetricAggregationDeserializerTests() { - _deserializer = new MetricAggregationDeserializer(NullLogger.Instance); + _deserializer = new MetricAggregationDeserializer(NullLogger.Instance); } [Fact] diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/MetricDefaultsDeserializerTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/MetricDefaultsDeserializerTests.cs index 1b1c973ce..e963e17f1 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/MetricDefaultsDeserializerTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/MetricDefaultsDeserializerTests.cs @@ -22,7 +22,7 @@ public MetricDefaultsDeserializerTests() _scrapingDeserializer = new Mock>(); _deserializer = new MetricDefaultsDeserializer( - _aggregationDeserializer.Object, _scrapingDeserializer.Object, NullLogger.Instance); + _aggregationDeserializer.Object, _scrapingDeserializer.Object, NullLogger.Instance); } [Fact] diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/MetricDefinitionDeserializerTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/MetricDefinitionDeserializerTests.cs index 85bd506cc..a5a33a4dc 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/MetricDefinitionDeserializerTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/MetricDefinitionDeserializerTests.cs @@ -30,7 +30,7 @@ public MetricDefinitionDeserializerTests() _azureMetricConfigurationDeserializer.Object, _scrapingDeserializer.Object, _resourceDeserializerFactory.Object, - NullLogger.Instance); + NullLogger.Instance); } [Fact] @@ -95,7 +95,7 @@ public void Deserialize_LabelsSupplied_SetsLabels() YamlAssert.PropertySet( _deserializer, yamlText, - new Dictionary{{"app", "promitor"}, {"env", "test"}}, + new Dictionary { { "app", "promitor" }, { "env", "test" } }, d => d.Labels); } @@ -113,7 +113,7 @@ public void Deserialize_AzureMetricConfigurationSupplied_UsesDeserializer() @"azureMetricConfiguration: metricName: ActiveMessages"; var node = YamlUtils.CreateYamlNode(yamlText); - var configurationNode = (YamlMappingNode) node.Children["azureMetricConfiguration"]; + var configurationNode = (YamlMappingNode)node.Children["azureMetricConfiguration"]; var configuration = new AzureMetricConfigurationV1(); _azureMetricConfigurationDeserializer.Setup(d => d.Deserialize(configurationNode)).Returns(configuration); @@ -195,7 +195,7 @@ public void Deserialize_ResourcesSupplied_UsesDeserializer() var resources = new List(); resourceDeserializer.Setup( - d => d.Deserialize((YamlSequenceNode) node.Children["resources"])).Returns(resources); + d => d.Deserialize((YamlSequenceNode)node.Children["resources"])).Returns(resources); // Act var definition = _deserializer.Deserialize(node); diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/ScrapingDeserializerTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/ScrapingDeserializerTests.cs index cd3b4924a..494204f4a 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/ScrapingDeserializerTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/ScrapingDeserializerTests.cs @@ -12,7 +12,7 @@ public class ScrapingDeserializerTests public ScrapingDeserializerTests() { - _deserializer = new ScrapingDeserializer(NullLogger.Instance); + _deserializer = new ScrapingDeserializer(NullLogger.Instance); } [Fact] diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/SecretDeserializerTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/SecretDeserializerTests.cs index a60cea923..01cb36495 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/SecretDeserializerTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/SecretDeserializerTests.cs @@ -12,7 +12,7 @@ public class SecretDeserializerTests public SecretDeserializerTests() { - _deserializer = new SecretDeserializer(NullLogger.Instance); + _deserializer = new SecretDeserializer(NullLogger.Instance); } [Fact] diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/V1DeserializerTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/V1DeserializerTests.cs index 082882a2e..6d8b0bdab 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/V1DeserializerTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Core/V1DeserializerTests.cs @@ -29,7 +29,7 @@ public V1DeserializerTests() _metadataDeserializer.Object, _defaultsDeserializer.Object, _metricsDeserializer.Object, - NullLogger.Instance); + NullLogger.Instance); } [Fact] @@ -37,7 +37,7 @@ public void Deserialize_NoVersionSpecified_ThrowsException() { // Arrange var yamlNode = YamlUtils.CreateYamlNode("azureMetadata:"); - + // Act var exception = Assert.Throws(() => _deserializer.Deserialize(yamlNode)); diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/ContainerInstanceDeserializerTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/ContainerInstanceDeserializerTests.cs index 84453b953..9bd113523 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/ContainerInstanceDeserializerTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/ContainerInstanceDeserializerTests.cs @@ -1,5 +1,4 @@ using System.ComponentModel; -using Microsoft.Extensions.Logging.Abstractions; using Promitor.Core.Scraping.Configuration.Serialization; using Promitor.Core.Scraping.Configuration.Serialization.v1.Model; using Promitor.Core.Scraping.Configuration.Serialization.v1.Model.ResourceTypes; @@ -9,18 +8,18 @@ namespace Promitor.Scraper.Tests.Unit.Serialization.v1.Providers { [Category("Unit")] - public class ContainerInstanceDeserializerTests : ResourceDeserializerTest + public class ContainerInstanceDeserializerTests : ResourceDeserializerTest { private readonly ContainerInstanceDeserializer _deserializer; public ContainerInstanceDeserializerTests() { - _deserializer = new ContainerInstanceDeserializer(NullLogger.Instance); + _deserializer = new ContainerInstanceDeserializer(Logger); } protected override IDeserializer CreateDeserializer() { - return new ContainerInstanceDeserializer(NullLogger.Instance); + return new ContainerInstanceDeserializer(Logger); } [Fact] diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/ContainerRegistryDeserializerTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/ContainerRegistryDeserializerTests.cs index 2245c602f..75d0ac1b4 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/ContainerRegistryDeserializerTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/ContainerRegistryDeserializerTests.cs @@ -1,5 +1,4 @@ using System.ComponentModel; -using Microsoft.Extensions.Logging.Abstractions; using Promitor.Core.Scraping.Configuration.Serialization; using Promitor.Core.Scraping.Configuration.Serialization.v1.Model; using Promitor.Core.Scraping.Configuration.Serialization.v1.Model.ResourceTypes; @@ -9,13 +8,13 @@ namespace Promitor.Scraper.Tests.Unit.Serialization.v1.Providers { [Category("Unit")] - public class ContainerRegistryDeserializerTests : ResourceDeserializerTest + public class ContainerRegistryDeserializerTests : ResourceDeserializerTest { private readonly ContainerRegistryDeserializer _deserializer; public ContainerRegistryDeserializerTests() { - _deserializer = new ContainerRegistryDeserializer(NullLogger.Instance); + _deserializer = new ContainerRegistryDeserializer(Logger); } [Fact] @@ -39,7 +38,7 @@ public void Deserialize_RegistryNameNotSupplied_Null() protected override IDeserializer CreateDeserializer() { - return new ContainerRegistryDeserializer(NullLogger.Instance); + return new ContainerRegistryDeserializer(Logger); } } } diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/CosmosDbDeserializerTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/CosmosDbDeserializerTests.cs index d18c079e2..377851c33 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/CosmosDbDeserializerTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/CosmosDbDeserializerTests.cs @@ -1,5 +1,4 @@ using System.ComponentModel; -using Microsoft.Extensions.Logging.Abstractions; using Promitor.Core.Scraping.Configuration.Serialization; using Promitor.Core.Scraping.Configuration.Serialization.v1.Model; using Promitor.Core.Scraping.Configuration.Serialization.v1.Model.ResourceTypes; @@ -9,13 +8,13 @@ namespace Promitor.Scraper.Tests.Unit.Serialization.v1.Providers { [Category("Unit")] - public class CosmosDbDeserializerTests : ResourceDeserializerTest + public class CosmosDbDeserializerTests : ResourceDeserializerTest { private readonly CosmosDbDeserializer _deserializer; public CosmosDbDeserializerTests() { - _deserializer = new CosmosDbDeserializer(NullLogger.Instance); + _deserializer = new CosmosDbDeserializer(Logger); } [Fact] @@ -39,7 +38,7 @@ public void Deserialize_DbNameNotSupplied_Null() protected override IDeserializer CreateDeserializer() { - return new CosmosDbDeserializer(NullLogger.Instance); + return new CosmosDbDeserializer(Logger); } } } diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/GenericResourceDeserializerTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/GenericResourceDeserializerTests.cs index 54053491f..056aa5feb 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/GenericResourceDeserializerTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/GenericResourceDeserializerTests.cs @@ -1,5 +1,4 @@ -using Microsoft.Extensions.Logging.Abstractions; -using Promitor.Core.Scraping.Configuration.Serialization; +using Promitor.Core.Scraping.Configuration.Serialization; using Promitor.Core.Scraping.Configuration.Serialization.v1.Model; using Promitor.Core.Scraping.Configuration.Serialization.v1.Model.ResourceTypes; using Promitor.Core.Scraping.Configuration.Serialization.v1.Providers; @@ -7,13 +6,13 @@ namespace Promitor.Scraper.Tests.Unit.Serialization.v1.Providers { - public class GenericResourceDeserializerTests : ResourceDeserializerTest + public class GenericResourceDeserializerTests : ResourceDeserializerTest { private readonly GenericResourceDeserializer _deserializer; public GenericResourceDeserializerTests() { - _deserializer = new GenericResourceDeserializer(NullLogger.Instance); + _deserializer = new GenericResourceDeserializer(Logger); } [Fact] @@ -56,7 +55,7 @@ public void Deserialize_ResourceUriNotSupplied_Null() protected override IDeserializer CreateDeserializer() { - return new GenericResourceDeserializer(NullLogger.Instance); + return new GenericResourceDeserializer(Logger); } } } diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/NetworkInterfaceDeserializerTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/NetworkInterfaceDeserializerTests.cs index 03dd73e33..58377ef81 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/NetworkInterfaceDeserializerTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/NetworkInterfaceDeserializerTests.cs @@ -1,7 +1,4 @@ using System.ComponentModel; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions; -using Moq; using Promitor.Core.Scraping.Configuration.Serialization; using Promitor.Core.Scraping.Configuration.Serialization.v1.Model; using Promitor.Core.Scraping.Configuration.Serialization.v1.Model.ResourceTypes; @@ -11,13 +8,13 @@ namespace Promitor.Scraper.Tests.Unit.Serialization.v1.Providers { [Category("Unit")] - public class NetworkInterfaceDeserializerTests : ResourceDeserializerTest + public class NetworkInterfaceDeserializerTests : ResourceDeserializerTest { private readonly NetworkInterfaceDeserializer _deserializer; public NetworkInterfaceDeserializerTests() { - _deserializer = new NetworkInterfaceDeserializer(new Mock().Object); + _deserializer = new NetworkInterfaceDeserializer(Logger); } [Fact] @@ -41,7 +38,7 @@ public void Deserialize_NetworkInterfaceNameNotSupplied_Null() protected override IDeserializer CreateDeserializer() { - return new NetworkInterfaceDeserializer(NullLogger.Instance); + return new NetworkInterfaceDeserializer(Logger); } } } diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/PostgreSqlDeserializerTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/PostgreSqlDeserializerTests.cs index d1b5e1c26..8981e216e 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/PostgreSqlDeserializerTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/PostgreSqlDeserializerTests.cs @@ -1,5 +1,4 @@ -using Microsoft.Extensions.Logging.Abstractions; -using Promitor.Core.Scraping.Configuration.Serialization; +using Promitor.Core.Scraping.Configuration.Serialization; using Promitor.Core.Scraping.Configuration.Serialization.v1.Model; using Promitor.Core.Scraping.Configuration.Serialization.v1.Model.ResourceTypes; using Promitor.Core.Scraping.Configuration.Serialization.v1.Providers; @@ -7,13 +6,13 @@ namespace Promitor.Scraper.Tests.Unit.Serialization.v1.Providers { - public class PostgreSqlDeserializerTests : ResourceDeserializerTest + public class PostgreSqlDeserializerTests : ResourceDeserializerTest { private readonly PostgreSqlDeserializer _deserializer; public PostgreSqlDeserializerTests() { - _deserializer = new PostgreSqlDeserializer(NullLogger.Instance); + _deserializer = new PostgreSqlDeserializer(Logger); } [Fact] @@ -37,7 +36,7 @@ public void Deserialize_ServerNameNotSupplied_Null() protected override IDeserializer CreateDeserializer() { - return new PostgreSqlDeserializer(NullLogger.Instance); + return new PostgreSqlDeserializer(Logger); } } } diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/RedisCacheDeserializerTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/RedisCacheDeserializerTests.cs index cf99496d4..f8d2e5225 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/RedisCacheDeserializerTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/RedisCacheDeserializerTests.cs @@ -1,5 +1,4 @@ using System.ComponentModel; -using Microsoft.Extensions.Logging.Abstractions; using Promitor.Core.Scraping.Configuration.Serialization; using Promitor.Core.Scraping.Configuration.Serialization.v1.Model; using Promitor.Core.Scraping.Configuration.Serialization.v1.Model.ResourceTypes; @@ -9,13 +8,13 @@ namespace Promitor.Scraper.Tests.Unit.Serialization.v1.Providers { [Category("Unit")] - public class RedisCacheDeserializerTests : ResourceDeserializerTest + public class RedisCacheDeserializerTests : ResourceDeserializerTest { private readonly RedisCacheDeserializer _deserializer; public RedisCacheDeserializerTests() { - _deserializer = new RedisCacheDeserializer(NullLogger.Instance); + _deserializer = new RedisCacheDeserializer(Logger); } [Fact] @@ -39,7 +38,7 @@ public void Deserialize_CacheNameNotSupplied_Null() protected override IDeserializer CreateDeserializer() { - return new RedisCacheDeserializer(NullLogger.Instance); + return new RedisCacheDeserializer(Logger); } } } diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/ResourceDeserializerTest.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/ResourceDeserializerTest.cs index e02a8d0d2..e79d5904d 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/ResourceDeserializerTest.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/ResourceDeserializerTest.cs @@ -1,11 +1,14 @@ -using Promitor.Core.Scraping.Configuration.Serialization; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; +using Promitor.Core.Scraping.Configuration.Serialization; using Promitor.Core.Scraping.Configuration.Serialization.v1.Model; using Xunit; namespace Promitor.Scraper.Tests.Unit.Serialization.v1.Providers { - public abstract class ResourceDeserializerTest + public abstract class ResourceDeserializerTest { + protected ILogger Logger = NullLogger.Instance; protected abstract IDeserializer CreateDeserializer(); [Fact] diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/ServiceBusQueueDeserializerTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/ServiceBusQueueDeserializerTests.cs index e04b797d8..89ab19a22 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/ServiceBusQueueDeserializerTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/ServiceBusQueueDeserializerTests.cs @@ -1,5 +1,4 @@ using System.ComponentModel; -using Microsoft.Extensions.Logging.Abstractions; using Promitor.Core.Scraping.Configuration.Serialization; using Promitor.Core.Scraping.Configuration.Serialization.v1.Model; using Promitor.Core.Scraping.Configuration.Serialization.v1.Model.ResourceTypes; @@ -9,13 +8,13 @@ namespace Promitor.Scraper.Tests.Unit.Serialization.v1.Providers { [Category("Unit")] - public class ServiceBusQueueDeserializerTests : ResourceDeserializerTest + public class ServiceBusQueueDeserializerTests : ResourceDeserializerTest { private readonly ServiceBusQueueDeserializer _deserializer; public ServiceBusQueueDeserializerTests() { - _deserializer = new ServiceBusQueueDeserializer(NullLogger.Instance); + _deserializer = new ServiceBusQueueDeserializer(Logger); } [Fact] @@ -58,7 +57,7 @@ public void Deserialize_NamespaceNotSupplied_Null() protected override IDeserializer CreateDeserializer() { - return new ServiceBusQueueDeserializer(NullLogger.Instance); + return new ServiceBusQueueDeserializer(Logger); } } } diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/StorageQueueDeserializerTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/StorageQueueDeserializerTests.cs index 535fb4240..5e883c405 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/StorageQueueDeserializerTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/StorageQueueDeserializerTests.cs @@ -1,5 +1,4 @@ -using Microsoft.Extensions.Logging.Abstractions; -using Moq; +using Moq; using Promitor.Core.Scraping.Configuration.Serialization; using Promitor.Core.Scraping.Configuration.Serialization.v1.Model; using Promitor.Core.Scraping.Configuration.Serialization.v1.Model.ResourceTypes; @@ -9,7 +8,7 @@ namespace Promitor.Scraper.Tests.Unit.Serialization.v1.Providers { - public class StorageQueueDeserializerTests : ResourceDeserializerTest + public class StorageQueueDeserializerTests : ResourceDeserializerTest { private readonly Mock> _secretDeserializer; @@ -19,7 +18,7 @@ public StorageQueueDeserializerTests() { _secretDeserializer = new Mock>(); - _deserializer = new StorageQueueDeserializer(_secretDeserializer.Object, NullLogger.Instance); + _deserializer = new StorageQueueDeserializer(_secretDeserializer.Object, Logger); } [Fact] @@ -91,7 +90,7 @@ public void Deserialize_SasTokenNotSupplied_Null() protected override IDeserializer CreateDeserializer() { - return new StorageQueueDeserializer(new Mock>().Object, NullLogger.Instance); + return new StorageQueueDeserializer(new Mock>().Object, Logger); } } } diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/VirtualMachineDeserializerTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/VirtualMachineDeserializerTests.cs index 4c377e8ad..98360eee8 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/VirtualMachineDeserializerTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/VirtualMachineDeserializerTests.cs @@ -1,5 +1,4 @@ using System.ComponentModel; -using Microsoft.Extensions.Logging.Abstractions; using Promitor.Core.Scraping.Configuration.Serialization; using Promitor.Core.Scraping.Configuration.Serialization.v1.Model; using Promitor.Core.Scraping.Configuration.Serialization.v1.Model.ResourceTypes; @@ -9,13 +8,13 @@ namespace Promitor.Scraper.Tests.Unit.Serialization.v1.Providers { [Category("Unit")] - public class VirtualMachineDeserializerTests : ResourceDeserializerTest + public class VirtualMachineDeserializerTests : ResourceDeserializerTest { private readonly VirtualMachineDeserializer _deserializer; public VirtualMachineDeserializerTests() { - _deserializer = new VirtualMachineDeserializer(NullLogger.Instance); + _deserializer = new VirtualMachineDeserializer(Logger); } [Fact] @@ -39,7 +38,7 @@ public void Deserialize_VirtualMachineNameNotSupplied_Null() protected override IDeserializer CreateDeserializer() { - return new VirtualMachineDeserializer(NullLogger.Instance); + return new VirtualMachineDeserializer(Logger); } } } diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/V1DeserializerFactory.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/V1DeserializerFactory.cs index 9b5cebadd..639676206 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/V1DeserializerFactory.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/V1DeserializerFactory.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using Promitor.Core.Scraping.Configuration.Serialization.v1.Core; namespace Promitor.Scraper.Tests.Unit.Serialization.v1 @@ -10,21 +11,20 @@ public static class V1DeserializerFactory { public static V1Deserializer CreateDeserializer() { - var logger = NullLogger.Instance; return new V1Deserializer( - new AzureMetadataDeserializer(logger), + new AzureMetadataDeserializer(NullLogger.Instance), new MetricDefaultsDeserializer( - new AggregationDeserializer(logger), - new ScrapingDeserializer(logger), - logger), + new AggregationDeserializer(NullLogger.Instance), + new ScrapingDeserializer(NullLogger.Instance), + NullLogger.Instance), new MetricDefinitionDeserializer( new AzureMetricConfigurationDeserializer( - new MetricAggregationDeserializer(logger), - logger), - new ScrapingDeserializer(logger), - new AzureResourceDeserializerFactory(new SecretDeserializer(logger), logger), - logger), - logger); + new MetricAggregationDeserializer(NullLogger.Instance), + NullLogger.Instance), + new ScrapingDeserializer(NullLogger.Instance), + new AzureResourceDeserializerFactory(new SecretDeserializer(NullLogger.Instance), new LoggerFactory()), + NullLogger.Instance), + NullLogger.Instance); } } } diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/V1SerializationTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/V1SerializationTests.cs index 151ecc402..4a7ca8268 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/V1SerializationTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/V1SerializationTests.cs @@ -34,7 +34,7 @@ public V1SerializationTests() var mapper = mapperConfiguration.CreateMapper(); _v1Deserializer = V1DeserializerFactory.CreateDeserializer(); - _configurationSerializer = new ConfigurationSerializer(NullLogger.Instance, mapper, _v1Deserializer); + _configurationSerializer = new ConfigurationSerializer(NullLogger.Instance, mapper, _v1Deserializer); _metricsDeclaration = new MetricsDeclarationV1 { @@ -144,7 +144,7 @@ public void Deserialize_SerializedModel_CanDeserialize() Assert.Equal("promitor_demo_generic_queue_size", deserializedModel.Metrics.ElementAt(0).Name); Assert.Equal("Amount of active messages of the 'orders' queue (determined with Generic provider)", deserializedModel.Metrics.ElementAt(0).Description); Assert.Equal(ResourceType.Generic, deserializedModel.Metrics.ElementAt(0).ResourceType); - Assert.Equal(new Dictionary {{"app", "promitor"}}, deserializedModel.Metrics.ElementAt(0).Labels); + Assert.Equal(new Dictionary { { "app", "promitor" } }, deserializedModel.Metrics.ElementAt(0).Labels); Assert.Equal("ActiveMessages", deserializedModel.Metrics.ElementAt(0).AzureMetricConfiguration.MetricName); Assert.Equal(AggregationType.Average, deserializedModel.Metrics.ElementAt(0).AzureMetricConfiguration.Aggregation.Type); Assert.Equal(2, deserializedModel.Metrics.ElementAt(0).Resources.Count); @@ -188,7 +188,7 @@ public void Deserialize_SerializedYaml_CanDeserializeToRuntimeModel() Assert.Equal(ResourceType.Generic, firstMetric.ResourceType); Assert.Equal("promitor_demo_generic_queue_size", firstMetric.PrometheusMetricDefinition.Name); Assert.Equal("Amount of active messages of the 'orders' queue (determined with Generic provider)", firstMetric.PrometheusMetricDefinition.Description); - Assert.Collection(firstMetric.Resources, + Assert.Collection(firstMetric.Resources, r => { var definition = Assert.IsType(r); @@ -206,7 +206,7 @@ public void Deserialize_SerializedYaml_CanDeserializeToRuntimeModel() Assert.Equal(ResourceType.ServiceBusQueue, secondMetric.ResourceType); Assert.Equal("promitor_demo_servicebusqueue_queue_size", secondMetric.PrometheusMetricDefinition.Name); Assert.Equal("Amount of active messages of the 'orders' queue (determined with ServiceBusQueue provider)", secondMetric.PrometheusMetricDefinition.Description); - Assert.Collection(secondMetric.Resources, + Assert.Collection(secondMetric.Resources, r => { var definition = Assert.IsType(r); diff --git a/src/Promitor.Scraper.Tests.Unit/Stubs/MetricsDeclarationProviderStub.cs b/src/Promitor.Scraper.Tests.Unit/Stubs/MetricsDeclarationProviderStub.cs index 43271fc7a..da2ae6e09 100644 --- a/src/Promitor.Scraper.Tests.Unit/Stubs/MetricsDeclarationProviderStub.cs +++ b/src/Promitor.Scraper.Tests.Unit/Stubs/MetricsDeclarationProviderStub.cs @@ -1,6 +1,7 @@ using AutoMapper; using Microsoft.Extensions.Logging.Abstractions; using Promitor.Core.Scraping.Configuration.Providers; +using Promitor.Core.Scraping.Configuration.Serialization; using Promitor.Scraper.Tests.Unit.Serialization.v1; namespace Promitor.Scraper.Tests.Unit.Stubs @@ -9,7 +10,7 @@ public class MetricsDeclarationProviderStub : MetricsDeclarationProvider { private readonly string _rawMetricsDeclaration; - public MetricsDeclarationProviderStub(string rawMetricsDeclaration, IMapper mapper) : base(configuration: null, logger: NullLogger.Instance, mapper: mapper, v1Deserializer: V1DeserializerFactory.CreateDeserializer()) + public MetricsDeclarationProviderStub(string rawMetricsDeclaration, IMapper mapper) : base(null, new ConfigurationSerializer(NullLogger.Instance, mapper, V1DeserializerFactory.CreateDeserializer())) { _rawMetricsDeclaration = rawMetricsDeclaration; } From 1517dd33686b09b7942706d958e3c23ce989b7e9 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Sat, 12 Oct 2019 11:06:43 +0200 Subject: [PATCH 10/38] Bring back OpenAPI docs! --- .../IApplicationBuilderExtensions.cs | 24 ++++++------ .../IServiceCollectionExtensions.cs | 37 ++++++++++--------- .../Promitor.Scraper.Host.csproj | 4 +- 3 files changed, 34 insertions(+), 31 deletions(-) diff --git a/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs b/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs index 7e5f7d2fb..ed98b95a6 100644 --- a/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs +++ b/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs @@ -14,17 +14,19 @@ public static class IApplicationBuilderExtensions /// Application Builder public static void UseOpenApiUi(this IApplicationBuilder app) { - //app.UseSwagger(); - //app.UseSwaggerUI(swaggerUiOptions => - //{ - // swaggerUiOptions.SwaggerEndpoint("/swagger/v1/swagger.json", "Promitor API"); - // swaggerUiOptions.DisplayOperationId(); - // swaggerUiOptions.EnableDeepLinking(); - // swaggerUiOptions.DocumentTitle = "Promitor API"; - // swaggerUiOptions.DocExpansion(DocExpansion.List); - // swaggerUiOptions.DisplayRequestDuration(); - // swaggerUiOptions.EnableFilter(); - //}); + app.UseSwagger(setupAction => setupAction.RouteTemplate = "api/{documentName}/docs.json"); + app.UseSwagger(setupAction => setupAction.SerializeAsV2 = true); + app.UseSwaggerUI(swaggerUiOptions => + { + swaggerUiOptions.SwaggerEndpoint("/api/v1/docs.json", "Promitor API"); + swaggerUiOptions.SwaggerEndpoint("/swagger/v1/swagger.json", "Promitor API (Swagger 2.0)"); + swaggerUiOptions.DisplayOperationId(); + swaggerUiOptions.EnableDeepLinking(); + swaggerUiOptions.DocumentTitle = "Promitor API"; + swaggerUiOptions.DocExpansion(DocExpansion.List); + swaggerUiOptions.DisplayRequestDuration(); + swaggerUiOptions.EnableFilter(); + }); } /// diff --git a/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs b/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs index ae35c2b6d..714398e2d 100644 --- a/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs +++ b/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs @@ -1,4 +1,6 @@ -using System.IO; +using System; +using System.ComponentModel; +using System.IO; using System.Linq; using System.Text.Json.Serialization; using System.Threading.Tasks; @@ -7,6 +9,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Logging; +using Microsoft.OpenApi.Models; using Promitor.Core.Configuration.Model; using Promitor.Core.Scraping.Configuration.Providers; using Promitor.Core.Scraping.Configuration.Providers.Interfaces; @@ -27,7 +30,6 @@ using Promitor.Core.Telemetry.Metrics.Interfaces; using Promitor.Scraper.Host.Scheduling; using Promitor.Scraper.Host.Validation; -using Swashbuckle.AspNetCore.Swagger; // ReSharper disable once CheckNamespace namespace Promitor.Scraper.Host.Extensions @@ -146,36 +148,35 @@ public static IServiceCollection ConfigureYamlConfiguration(this IServiceCollect /// Version of the API public static IServiceCollection UseOpenApiSpecifications(this IServiceCollection services, string prometheusScrapeEndpointPath, int apiVersion) { - var openApiInformation = new Info + var openApiInformation = new OpenApiInfo { - Contact = new Contact + Contact = new OpenApiContact { Name = "Tom Kerkhove", - Url = "https://blog.tomkerkhove.be" + Url = new Uri("https://blog.tomkerkhove.be") }, Title = $"Promitor v{apiVersion}", Description = $"Collection of APIs to manage the Azure Monitor scrape endpoint for Prometheus.\r\nThe scrape endpoint is exposed at '{prometheusScrapeEndpointPath}'", Version = $"v{apiVersion}", - License = new License + License = new OpenApiLicense { Name = "MIT", - Url = "https://github.com/tomkerkhove/promitor/LICENSE" + Url = new Uri("https://github.com/tomkerkhove/promitor/LICENSE") } }; var xmlDocumentationPath = GetXmlDocumentationPath(services); - //services.AddSwaggerGen(swaggerGenerationOptions => - //{ - // swaggerGenerationOptions.EnableAnnotations(); - // swaggerGenerationOptions.SwaggerDoc($"v{apiVersion}", openApiInformation); - // swaggerGenerationOptions.DescribeAllEnumsAsStrings(); - - // if (string.IsNullOrEmpty(xmlDocumentationPath) == false) - // { - // swaggerGenerationOptions.IncludeXmlComments(xmlDocumentationPath); - // } - //}); + services.AddSwaggerGen(swaggerGenerationOptions => + { + swaggerGenerationOptions.EnableAnnotations(); + swaggerGenerationOptions.SwaggerDoc($"v{apiVersion}", openApiInformation); + + if (string.IsNullOrEmpty(xmlDocumentationPath) == false) + { + swaggerGenerationOptions.IncludeXmlComments(xmlDocumentationPath); + } + }); return services; } diff --git a/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj b/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj index 05c113d25..ef8079bed 100644 --- a/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj +++ b/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj @@ -38,8 +38,8 @@ - - + + From 843bf4bd81ccb523904e85d475a4e87ad8fa4771 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Sat, 12 Oct 2019 11:23:37 +0200 Subject: [PATCH 11/38] Fix Dockerfile --- src/Promitor.Scraper.Host/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Promitor.Scraper.Host/Dockerfile b/src/Promitor.Scraper.Host/Dockerfile index 1ee4772bb..d4322613c 100644 --- a/src/Promitor.Scraper.Host/Dockerfile +++ b/src/Promitor.Scraper.Host/Dockerfile @@ -8,10 +8,10 @@ COPY Promitor.Core.Telemetry.Metrics/* Promitor.Core.Telemetry.Metrics/ COPY Promitor.Integrations.AzureMonitor/* Promitor.Integrations.AzureMonitor/ COPY Promitor.Integrations.AzureStorage/* Promitor.Integrations.AzureStorage/ COPY Promitor.Scraper.Host/* Promitor.Scraper.Host/ -RUN dotnet publish Promitor.Scraper.Host/Promitor.Scraper.Host.csproj --configuration release -o app +RUN dotnet publish Promitor.Scraper.Host/Promitor.Scraper.Host.csproj --configuration release --output app FROM mcr.microsoft.com/dotnet/core/aspnet:3.0.0-alpine3.9 as runtime WORKDIR /app -COPY --from=build /src/Promitor.Scraper.Host/app . +COPY --from=build /src/app . ENTRYPOINT ["dotnet", "Promitor.Scraper.Host.dll"] From aab7c9498f6d8d434be192adc6842b4d7866d177 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Mon, 21 Oct 2019 15:18:49 +0200 Subject: [PATCH 12/38] Finalize merge Signed-off-by: Tom Kerkhove --- .../v1/Providers/AzureSqlDatabaseDeserializerTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/AzureSqlDatabaseDeserializerTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/AzureSqlDatabaseDeserializerTests.cs index 1aca49da8..caae2b660 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/AzureSqlDatabaseDeserializerTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/AzureSqlDatabaseDeserializerTests.cs @@ -9,7 +9,7 @@ namespace Promitor.Scraper.Tests.Unit.Serialization.v1.Providers { [Category("Unit")] - public class AzureSqlDatabaseDeserializerTests : ResourceDeserializerTest + public class AzureSqlDatabaseDeserializerTests : ResourceDeserializerTest { private readonly AzureSqlDatabaseDeserializer _deserializer; From b2ebda095e39d1ffca974cbfd07c25369fec951b Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Mon, 21 Oct 2019 15:41:17 +0200 Subject: [PATCH 13/38] Use 3.0.0 as RuntimeFrameworkVersion Signed-off-by: Tom Kerkhove --- .../Promitor.Core.Configuration.csproj | 2 +- .../Promitor.Core.Telemetry.Metrics.csproj | 4 ++-- src/Promitor.Core.Telemetry/Promitor.Core.Telemetry.csproj | 4 ++-- src/Promitor.Scraper.Host/Program.cs | 7 ++++++- .../Promitor.Scraper.Tests.Unit.csproj | 2 +- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj b/src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj index 2f9e131b8..6df604069 100644 --- a/src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj +++ b/src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj @@ -2,7 +2,7 @@ netcoreapp3.0 - 2.2.3 + 3.0.0 diff --git a/src/Promitor.Core.Telemetry.Metrics/Promitor.Core.Telemetry.Metrics.csproj b/src/Promitor.Core.Telemetry.Metrics/Promitor.Core.Telemetry.Metrics.csproj index b89d7e076..43b0537c7 100644 --- a/src/Promitor.Core.Telemetry.Metrics/Promitor.Core.Telemetry.Metrics.csproj +++ b/src/Promitor.Core.Telemetry.Metrics/Promitor.Core.Telemetry.Metrics.csproj @@ -1,8 +1,8 @@ - + netcoreapp3.0 - 2.2.3 + 3.0.0 diff --git a/src/Promitor.Core.Telemetry/Promitor.Core.Telemetry.csproj b/src/Promitor.Core.Telemetry/Promitor.Core.Telemetry.csproj index d2101935d..bc21f4e85 100644 --- a/src/Promitor.Core.Telemetry/Promitor.Core.Telemetry.csproj +++ b/src/Promitor.Core.Telemetry/Promitor.Core.Telemetry.csproj @@ -1,8 +1,8 @@ - + netcoreapp3.0 - 2.2.3 + 3.0.0 diff --git a/src/Promitor.Scraper.Host/Program.cs b/src/Promitor.Scraper.Host/Program.cs index 6d3c778b0..3fcb59ecd 100644 --- a/src/Promitor.Scraper.Host/Program.cs +++ b/src/Promitor.Scraper.Host/Program.cs @@ -36,7 +36,12 @@ public static IHostBuilder BuildWebHost(string[] args) .ConfigureWebHostDefaults(webHostBuilder => { webHostBuilder.UseKestrel(kestrelServerOptions => { kestrelServerOptions.AddServerHeader = false; }) - .ConfigureLogging((hostContext, loggingBuilder) => { loggingBuilder.AddConsole(consoleLoggerOptions => consoleLoggerOptions.TimestampFormat = "[u]"); }) + .ConfigureLogging((hostContext, loggingBuilder) => + { + loggingBuilder.AddConsole(consoleLoggerOptions => consoleLoggerOptions.TimestampFormat = "[HH:mm:ss] "); + loggingBuilder.AddDebug(); + loggingBuilder.SetMinimumLevel(LogLevel.Information); + }) .UseConfiguration(configuration) .UseUrls(endpointUrl) .UseStartup(); diff --git a/src/Promitor.Scraper.Tests.Unit/Promitor.Scraper.Tests.Unit.csproj b/src/Promitor.Scraper.Tests.Unit/Promitor.Scraper.Tests.Unit.csproj index 72409d48e..19d6abb8c 100644 --- a/src/Promitor.Scraper.Tests.Unit/Promitor.Scraper.Tests.Unit.csproj +++ b/src/Promitor.Scraper.Tests.Unit/Promitor.Scraper.Tests.Unit.csproj @@ -2,7 +2,7 @@ netcoreapp3.0 - 2.2.3 + 3.0.0 true From 3c82bef698f0fd4818086b8ce0a1d07390e97d0a Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Mon, 21 Oct 2019 15:42:52 +0200 Subject: [PATCH 14/38] Re-add parameter names Signed-off-by: Tom Kerkhove --- src/Promitor.Scraper.Host/Program.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Promitor.Scraper.Host/Program.cs b/src/Promitor.Scraper.Host/Program.cs index 3fcb59ecd..d71f68061 100644 --- a/src/Promitor.Scraper.Host/Program.cs +++ b/src/Promitor.Scraper.Host/Program.cs @@ -52,10 +52,10 @@ private static IConfigurationRoot CreateConfiguration() { var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) - .AddYamlFile("/config/runtime.yaml", false, true) + .AddYamlFile("/config/runtime.yaml", optional: false, reloadOnChange: true) .AddEnvironmentVariables() - .AddEnvironmentVariables("PROMITOR_") // Used for all environment variables for Promitor - .AddEnvironmentVariables("PROMITOR_YAML_OVERRIDE_") // Used to overwrite runtime YAML + .AddEnvironmentVariables(prefix: "PROMITOR_") // Used for all environment variables for Promitor + .AddEnvironmentVariables(prefix: "PROMITOR_YAML_OVERRIDE_") // Used to overwrite runtime YAML .Build(); return configuration; From dfcf6129a61ead379161aeb493ba51ed6d74ef74 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Mon, 21 Oct 2019 17:01:54 +0200 Subject: [PATCH 15/38] Provide new Swagger UI Signed-off-by: Tom Kerkhove --- .../IApplicationBuilderExtensions.cs | 20 ++++++++------ .../Extensions/SwaggerUIOptionsExtensions.cs | 27 +++++++++++++++++++ 2 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 src/Promitor.Scraper.Host/Extensions/SwaggerUIOptionsExtensions.cs diff --git a/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs b/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs index ed98b95a6..34c036453 100644 --- a/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs +++ b/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs @@ -14,18 +14,22 @@ public static class IApplicationBuilderExtensions /// Application Builder public static void UseOpenApiUi(this IApplicationBuilder app) { + // New Swagger UI app.UseSwagger(setupAction => setupAction.RouteTemplate = "api/{documentName}/docs.json"); - app.UseSwagger(setupAction => setupAction.SerializeAsV2 = true); app.UseSwaggerUI(swaggerUiOptions => { + swaggerUiOptions.ConfigureDefaultOptions(); swaggerUiOptions.SwaggerEndpoint("/api/v1/docs.json", "Promitor API"); - swaggerUiOptions.SwaggerEndpoint("/swagger/v1/swagger.json", "Promitor API (Swagger 2.0)"); - swaggerUiOptions.DisplayOperationId(); - swaggerUiOptions.EnableDeepLinking(); - swaggerUiOptions.DocumentTitle = "Promitor API"; - swaggerUiOptions.DocExpansion(DocExpansion.List); - swaggerUiOptions.DisplayRequestDuration(); - swaggerUiOptions.EnableFilter(); + swaggerUiOptions.RoutePrefix = "api/docs"; + }); + + // Deprecated Swagger UI + app.UseSwagger(setupAction => setupAction.SerializeAsV2 = true); + app.UseSwaggerUI(swaggerUiOptions => + { + swaggerUiOptions.SwaggerEndpoint("/swagger/v1/swagger.json", "Promitor API"); + swaggerUiOptions.SwaggerEndpoint("/api/v1/docs.json", "Promitor API (OpenAPI 3.0)"); + swaggerUiOptions.ConfigureDefaultOptions(); }); } diff --git a/src/Promitor.Scraper.Host/Extensions/SwaggerUIOptionsExtensions.cs b/src/Promitor.Scraper.Host/Extensions/SwaggerUIOptionsExtensions.cs new file mode 100644 index 000000000..12d16be73 --- /dev/null +++ b/src/Promitor.Scraper.Host/Extensions/SwaggerUIOptionsExtensions.cs @@ -0,0 +1,27 @@ +using Microsoft.AspNetCore.Builder; + +// ReSharper disable once CheckNamespace +namespace Swashbuckle.AspNetCore.SwaggerUI +{ + // ReSharper disable once InconsistentNaming + internal static class SwaggerUIOptionsExtensions + { + /// + /// Configure the default options for our Swagger UI portal + /// + /// Swagger UI portal options + internal static SwaggerUIOptions ConfigureDefaultOptions(this SwaggerUIOptions swaggerUiOptions) + { + GuardNet.Guard.NotNull(swaggerUiOptions, nameof(swaggerUiOptions)); + + swaggerUiOptions.DisplayOperationId(); + swaggerUiOptions.EnableDeepLinking(); + swaggerUiOptions.DocumentTitle = "Promitor API"; + swaggerUiOptions.DocExpansion(DocExpansion.List); + swaggerUiOptions.DisplayRequestDuration(); + swaggerUiOptions.EnableFilter(); + + return swaggerUiOptions; + } + } +} From b5ab868af8187e841b0480b42a3c7a014409558e Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Thu, 28 Nov 2019 21:48:03 +0100 Subject: [PATCH 16/38] Fix build Signed-off-by: Tom Kerkhove --- src/Promitor.Scraper.Host/Docs/Open-Api.xml | 6 ++++++ .../v1/Providers/SqlDatabaseDeserializerTests.cs | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Promitor.Scraper.Host/Docs/Open-Api.xml b/src/Promitor.Scraper.Host/Docs/Open-Api.xml index f1da82138..0aa869dd2 100644 --- a/src/Promitor.Scraper.Host/Docs/Open-Api.xml +++ b/src/Promitor.Scraper.Host/Docs/Open-Api.xml @@ -93,5 +93,11 @@ + + + Configure the default options for our Swagger UI portal + + Swagger UI portal options + diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/SqlDatabaseDeserializerTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/SqlDatabaseDeserializerTests.cs index 82054d87d..586591510 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/SqlDatabaseDeserializerTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/Providers/SqlDatabaseDeserializerTests.cs @@ -9,7 +9,7 @@ namespace Promitor.Scraper.Tests.Unit.Serialization.v1.Providers { [Category("Unit")] - public class AzureSqlDatabaseDeserializerTests : ResourceDeserializerTest + public class SqlDatabaseDeserializerTests : ResourceDeserializerTest { private readonly SqlDatabaseDeserializer _deserializer; From cb65f3790d0b82fc7c3034732a7e513b0a955746 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Thu, 28 Nov 2019 21:54:53 +0100 Subject: [PATCH 17/38] Update dependencies Signed-off-by: Tom Kerkhove --- .../Promitor.Core.Configuration.csproj | 6 +++--- .../Promitor.Core.Telemetry.Metrics.csproj | 4 ++-- src/Promitor.Core.Telemetry/Promitor.Core.Telemetry.csproj | 4 ++-- .../Promitor.Integrations.AzureStorage.csproj | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj b/src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj index 6df604069..51163bb88 100644 --- a/src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj +++ b/src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj @@ -14,9 +14,9 @@ - - - + + + diff --git a/src/Promitor.Core.Telemetry.Metrics/Promitor.Core.Telemetry.Metrics.csproj b/src/Promitor.Core.Telemetry.Metrics/Promitor.Core.Telemetry.Metrics.csproj index 43b0537c7..e69c41178 100644 --- a/src/Promitor.Core.Telemetry.Metrics/Promitor.Core.Telemetry.Metrics.csproj +++ b/src/Promitor.Core.Telemetry.Metrics/Promitor.Core.Telemetry.Metrics.csproj @@ -15,8 +15,8 @@ - - + + diff --git a/src/Promitor.Core.Telemetry/Promitor.Core.Telemetry.csproj b/src/Promitor.Core.Telemetry/Promitor.Core.Telemetry.csproj index bc21f4e85..d9d0bda8c 100644 --- a/src/Promitor.Core.Telemetry/Promitor.Core.Telemetry.csproj +++ b/src/Promitor.Core.Telemetry/Promitor.Core.Telemetry.csproj @@ -15,8 +15,8 @@ - - + + diff --git a/src/Promitor.Integrations.AzureStorage/Promitor.Integrations.AzureStorage.csproj b/src/Promitor.Integrations.AzureStorage/Promitor.Integrations.AzureStorage.csproj index c0f164449..3580cc969 100644 --- a/src/Promitor.Integrations.AzureStorage/Promitor.Integrations.AzureStorage.csproj +++ b/src/Promitor.Integrations.AzureStorage/Promitor.Integrations.AzureStorage.csproj @@ -8,7 +8,7 @@ - + From cb5310e60b8137608107d6c96a7351f74c0e3964 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Thu, 28 Nov 2019 22:13:48 +0100 Subject: [PATCH 18/38] Code quality Signed-off-by: Tom Kerkhove --- .../Extensions/IServiceCollectionExtensions.cs | 3 +-- src/Promitor.Scraper.Host/Validation/RuntimeValidator.cs | 4 ---- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs b/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs index 714398e2d..71f643904 100644 --- a/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs +++ b/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs @@ -1,5 +1,4 @@ using System; -using System.ComponentModel; using System.IO; using System.Linq; using System.Text.Json.Serialization; @@ -156,7 +155,7 @@ public static IServiceCollection UseOpenApiSpecifications(this IServiceCollectio Url = new Uri("https://blog.tomkerkhove.be") }, Title = $"Promitor v{apiVersion}", - Description = $"Collection of APIs to manage the Azure Monitor scrape endpoint for Prometheus.\r\nThe scrape endpoint is exposed at '{prometheusScrapeEndpointPath}'", + Description = $"Collection of APIs to manage the Azure Monitor scrape endpoint for Prometheus.\r\nThe scrape endpoint is exposed at '{prometheusScrapeEndpointPath}'", Version = $"v{apiVersion}", License = new OpenApiLicense { diff --git a/src/Promitor.Scraper.Host/Validation/RuntimeValidator.cs b/src/Promitor.Scraper.Host/Validation/RuntimeValidator.cs index 0a2d99e3b..c4ed65f00 100644 --- a/src/Promitor.Scraper.Host/Validation/RuntimeValidator.cs +++ b/src/Promitor.Scraper.Host/Validation/RuntimeValidator.cs @@ -1,14 +1,10 @@ using System.Collections.Generic; using System.Linq; -using AutoMapper; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Promitor.Core.Configuration.Model.Metrics; -using Promitor.Core.Scraping.Configuration.Providers; using Promitor.Core.Scraping.Configuration.Providers.Interfaces; -using Promitor.Core.Scraping.Configuration.Serialization; -using Promitor.Core.Scraping.Configuration.Serialization.v1.Model; using Promitor.Scraper.Host.Validation.Exceptions; using Promitor.Scraper.Host.Validation.Interfaces; using Promitor.Scraper.Host.Validation.Steps; From 17a163841403ee05826f5140a0f329736a2b0af4 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Mon, 2 Dec 2019 12:11:27 +0100 Subject: [PATCH 19/38] Hook in Serilog Signed-off-by: Tom Kerkhove --- src/Promitor.Scraper.Host/Program.cs | 13 +++++++------ .../Promitor.Scraper.Host.csproj | 2 ++ .../Promitor.Scraper.Tests.Unit.csproj | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Promitor.Scraper.Host/Program.cs b/src/Promitor.Scraper.Host/Program.cs index d71f68061..ec7f29524 100644 --- a/src/Promitor.Scraper.Host/Program.cs +++ b/src/Promitor.Scraper.Host/Program.cs @@ -5,6 +5,7 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Promitor.Core.Configuration.Model.Server; +using Serilog; namespace Promitor.Scraper.Host { @@ -14,6 +15,11 @@ public static void Main(string[] args) { Welcome(); + Log.Logger = new LoggerConfiguration() + .Enrich.FromLogContext() + .WriteTo.Console() + .CreateLogger(); + BuildWebHost(args) .Build() .Run(); @@ -33,15 +39,10 @@ public static IHostBuilder BuildWebHost(string[] args) // TODO: Configure verbosity https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-3.0#add-providers return Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder(args) + .UseSerilog() .ConfigureWebHostDefaults(webHostBuilder => { webHostBuilder.UseKestrel(kestrelServerOptions => { kestrelServerOptions.AddServerHeader = false; }) - .ConfigureLogging((hostContext, loggingBuilder) => - { - loggingBuilder.AddConsole(consoleLoggerOptions => consoleLoggerOptions.TimestampFormat = "[HH:mm:ss] "); - loggingBuilder.AddDebug(); - loggingBuilder.SetMinimumLevel(LogLevel.Information); - }) .UseConfiguration(configuration) .UseUrls(endpointUrl) .UseStartup(); diff --git a/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj b/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj index d5745ad6b..43339463f 100644 --- a/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj +++ b/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj @@ -38,6 +38,8 @@ + + diff --git a/src/Promitor.Scraper.Tests.Unit/Promitor.Scraper.Tests.Unit.csproj b/src/Promitor.Scraper.Tests.Unit/Promitor.Scraper.Tests.Unit.csproj index a9e9f8671..41d916207 100644 --- a/src/Promitor.Scraper.Tests.Unit/Promitor.Scraper.Tests.Unit.csproj +++ b/src/Promitor.Scraper.Tests.Unit/Promitor.Scraper.Tests.Unit.csproj @@ -26,7 +26,7 @@ - + From 5e9bcc6b8c5232b957b5d7f02c7b477ad5e15391 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Tue, 3 Dec 2019 17:49:26 +0100 Subject: [PATCH 20/38] Remove legacy --- src/Promitor.Core.Configuration/Defaults.cs | 7 +-- .../Interfaces/ISinkConfiguration.cs | 4 +- .../Sinks/ApplicationInsightsConfiguration.cs | 6 +-- .../Sinks/ContainerLogConfiguration.cs | 6 +-- .../Model/Telemetry/TelemetryConfiguration.cs | 6 +-- .../Promitor.Core.Configuration.csproj | 1 + .../Factories/MetricScraperFactory.cs | 8 +--- .../Promitor.Core.Scraping.csproj | 1 - src/Promitor.Core.Scraping/Scraper.cs | 13 +++--- .../ScraperConfiguration.cs | 11 +---- .../ApplicationInsightsTelemetry.cs | 2 +- src/Promitor.Scraper.Host/Docs/Open-Api.xml | 7 +++ .../IApplicationBuilderExtensions.cs | 45 +++++++++++++++++++ .../IServiceCollectionExtensions.cs | 24 +++++----- src/Promitor.Scraper.Host/Program.cs | 22 +++++---- .../Promitor.Scraper.Host.csproj | 3 +- .../Scheduling/MetricScrapingJob.cs | 9 +--- src/Promitor.Scraper.Host/Startup.cs | 5 ++- .../RuntimeConfigurationUnitTest.cs | 8 ++-- .../BogusRuntimeConfigurationGenerator.cs | 8 ++-- .../Config/RuntimeConfigurationGenerator.cs | 8 ++-- src/Promitor.sln | 7 --- 22 files changed, 119 insertions(+), 92 deletions(-) diff --git a/src/Promitor.Core.Configuration/Defaults.cs b/src/Promitor.Core.Configuration/Defaults.cs index e5691ef64..87d5932e0 100644 --- a/src/Promitor.Core.Configuration/Defaults.cs +++ b/src/Promitor.Core.Configuration/Defaults.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.Logging; +using Serilog.Events; namespace Promitor.Core.Configuration { @@ -23,17 +24,17 @@ public static class MetricsConfiguration public class Telemetry { - public static LogLevel? DefaultVerbosity { get; set; } = LogLevel.Error; + public static LogEventLevel? DefaultVerbosity { get; set; } = LogEventLevel.Error; public class ContainerLogs { - public static LogLevel? Verbosity { get; set; } = null; + public static LogEventLevel? Verbosity { get; set; } = null; public static bool IsEnabled { get; set; } = true; } public class ApplicationInsights { - public static LogLevel? Verbosity { get; set; } = null; + public static LogEventLevel? Verbosity { get; set; } = null; public static bool IsEnabled { get; set; } = false; } } diff --git a/src/Promitor.Core.Configuration/Model/Telemetry/Interfaces/ISinkConfiguration.cs b/src/Promitor.Core.Configuration/Model/Telemetry/Interfaces/ISinkConfiguration.cs index 3c25a1a2d..90e138567 100644 --- a/src/Promitor.Core.Configuration/Model/Telemetry/Interfaces/ISinkConfiguration.cs +++ b/src/Promitor.Core.Configuration/Model/Telemetry/Interfaces/ISinkConfiguration.cs @@ -1,10 +1,10 @@ -using Microsoft.Extensions.Logging; +using Serilog.Events; namespace Promitor.Core.Configuration.Model.Telemetry.Interfaces { public interface ISinkConfiguration { - LogLevel? Verbosity { get; } + LogEventLevel? Verbosity { get; } bool IsEnabled { get; } } } diff --git a/src/Promitor.Core.Configuration/Model/Telemetry/Sinks/ApplicationInsightsConfiguration.cs b/src/Promitor.Core.Configuration/Model/Telemetry/Sinks/ApplicationInsightsConfiguration.cs index 4968c11b1..644e22dbe 100644 --- a/src/Promitor.Core.Configuration/Model/Telemetry/Sinks/ApplicationInsightsConfiguration.cs +++ b/src/Promitor.Core.Configuration/Model/Telemetry/Sinks/ApplicationInsightsConfiguration.cs @@ -1,11 +1,11 @@ -using Microsoft.Extensions.Logging; -using Promitor.Core.Configuration.Model.Telemetry.Interfaces; +using Promitor.Core.Configuration.Model.Telemetry.Interfaces; +using Serilog.Events; namespace Promitor.Core.Configuration.Model.Telemetry.Sinks { public class ApplicationInsightsConfiguration : ISinkConfiguration { - public LogLevel? Verbosity { get; set; } = Defaults.Telemetry.ApplicationInsights.Verbosity; + public LogEventLevel? Verbosity { get; set; } = Defaults.Telemetry.ApplicationInsights.Verbosity; public bool IsEnabled { get; set; } = Defaults.Telemetry.ApplicationInsights.IsEnabled; public string InstrumentationKey { get; set; } } diff --git a/src/Promitor.Core.Configuration/Model/Telemetry/Sinks/ContainerLogConfiguration.cs b/src/Promitor.Core.Configuration/Model/Telemetry/Sinks/ContainerLogConfiguration.cs index ae6679edf..2b954e052 100644 --- a/src/Promitor.Core.Configuration/Model/Telemetry/Sinks/ContainerLogConfiguration.cs +++ b/src/Promitor.Core.Configuration/Model/Telemetry/Sinks/ContainerLogConfiguration.cs @@ -1,11 +1,11 @@ -using Microsoft.Extensions.Logging; -using Promitor.Core.Configuration.Model.Telemetry.Interfaces; +using Promitor.Core.Configuration.Model.Telemetry.Interfaces; +using Serilog.Events; namespace Promitor.Core.Configuration.Model.Telemetry.Sinks { public class ContainerLogConfiguration : ISinkConfiguration { - public LogLevel? Verbosity { get; set; } = Defaults.Telemetry.ContainerLogs.Verbosity; + public LogEventLevel? Verbosity { get; set; } = Defaults.Telemetry.ContainerLogs.Verbosity; public bool IsEnabled { get; set; } = Defaults.Telemetry.ContainerLogs.IsEnabled; } } diff --git a/src/Promitor.Core.Configuration/Model/Telemetry/TelemetryConfiguration.cs b/src/Promitor.Core.Configuration/Model/Telemetry/TelemetryConfiguration.cs index 40c4d000a..b2f0eef2d 100644 --- a/src/Promitor.Core.Configuration/Model/Telemetry/TelemetryConfiguration.cs +++ b/src/Promitor.Core.Configuration/Model/Telemetry/TelemetryConfiguration.cs @@ -1,11 +1,11 @@ -using Microsoft.Extensions.Logging; -using Promitor.Core.Configuration.Model.Telemetry.Sinks; +using Promitor.Core.Configuration.Model.Telemetry.Sinks; +using Serilog.Events; namespace Promitor.Core.Configuration.Model.Telemetry { public class TelemetryConfiguration { - public LogLevel? DefaultVerbosity { get; set; } = Defaults.Telemetry.DefaultVerbosity; + public LogEventLevel? DefaultVerbosity { get; set; } = Defaults.Telemetry.DefaultVerbosity; public ContainerLogConfiguration ContainerLogs { get; set; } = new ContainerLogConfiguration(); public ApplicationInsightsConfiguration ApplicationInsights { get; set; } = new ApplicationInsightsConfiguration(); } diff --git a/src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj b/src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj index 51163bb88..3380d5599 100644 --- a/src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj +++ b/src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj @@ -17,6 +17,7 @@ + diff --git a/src/Promitor.Core.Scraping/Factories/MetricScraperFactory.cs b/src/Promitor.Core.Scraping/Factories/MetricScraperFactory.cs index 83e8be16d..8ee4a07b3 100644 --- a/src/Promitor.Core.Scraping/Factories/MetricScraperFactory.cs +++ b/src/Promitor.Core.Scraping/Factories/MetricScraperFactory.cs @@ -7,7 +7,6 @@ using Promitor.Core.Scraping.Interfaces; using Promitor.Core.Scraping.Prometheus.Interfaces; using Promitor.Core.Scraping.ResourceTypes; -using Promitor.Core.Telemetry.Interfaces; using Promitor.Core.Telemetry.Metrics.Interfaces; using Promitor.Integrations.AzureMonitor; @@ -15,19 +14,16 @@ namespace Promitor.Core.Scraping.Factories { public class MetricScraperFactory { - private readonly IExceptionTracker _exceptionTracker; private readonly IConfiguration _configuration; private readonly ILogger _logger; - public MetricScraperFactory(IConfiguration configuration, ILogger logger, IExceptionTracker exceptionTracker) + public MetricScraperFactory(IConfiguration configuration, ILogger logger) { Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(logger, nameof(logger)); - Guard.NotNull(exceptionTracker, nameof(exceptionTracker)); _logger = logger; _configuration = configuration; - _exceptionTracker = exceptionTracker; } /// @@ -41,7 +37,7 @@ public IScraper CreateScraper(ResourceType metricDefini IPrometheusMetricWriter prometheusMetricWriter, IRuntimeMetricsCollector runtimeMetricsCollector) { var azureMonitorClient = CreateAzureMonitorClient(azureMetadata, runtimeMetricsCollector); - var scraperConfiguration = new ScraperConfiguration(azureMetadata, azureMonitorClient, prometheusMetricWriter, _logger, _exceptionTracker); + var scraperConfiguration = new ScraperConfiguration(azureMetadata, azureMonitorClient, prometheusMetricWriter, _logger); switch (metricDefinitionResourceType) { diff --git a/src/Promitor.Core.Scraping/Promitor.Core.Scraping.csproj b/src/Promitor.Core.Scraping/Promitor.Core.Scraping.csproj index 5d4676506..e4273e441 100644 --- a/src/Promitor.Core.Scraping/Promitor.Core.Scraping.csproj +++ b/src/Promitor.Core.Scraping/Promitor.Core.Scraping.csproj @@ -23,7 +23,6 @@ - diff --git a/src/Promitor.Core.Scraping/Scraper.cs b/src/Promitor.Core.Scraping/Scraper.cs index 8aae1d3f5..7df8d88d5 100644 --- a/src/Promitor.Core.Scraping/Scraper.cs +++ b/src/Promitor.Core.Scraping/Scraper.cs @@ -8,7 +8,6 @@ using Promitor.Core.Scraping.Configuration.Model.Metrics; using Promitor.Core.Scraping.Interfaces; using Promitor.Core.Scraping.Prometheus.Interfaces; -using Promitor.Core.Telemetry.Interfaces; using Promitor.Integrations.AzureMonitor; // ReSharper disable All @@ -22,7 +21,6 @@ namespace Promitor.Core.Scraping public abstract class Scraper : IScraper where TResourceDefinition : AzureResourceDefinition { - private readonly IExceptionTracker _exceptionTracker; private readonly ILogger _logger; private readonly IPrometheusMetricWriter _prometheusMetricWriter; private readonly ScraperConfiguration _scraperConfiguration; @@ -35,7 +33,6 @@ protected Scraper(ScraperConfiguration scraperConfiguration) Guard.NotNull(scraperConfiguration, nameof(scraperConfiguration)); _logger = scraperConfiguration.Logger; - _exceptionTracker = scraperConfiguration.ExceptionTracker; _scraperConfiguration = scraperConfiguration; _prometheusMetricWriter = scraperConfiguration.PrometheusMetricWriter; @@ -88,15 +85,15 @@ public async Task ScrapeAsync(ScrapeDefinition scrapeDe } catch (ErrorResponseException errorResponseException) { - HandleErrorResponseException(errorResponseException); + HandleErrorResponseException(errorResponseException, scrapeDefinition.PrometheusMetricDefinition.Name); } catch (Exception exception) { - _exceptionTracker.Track(exception); + _logger.LogCritical(exception, "Failed to scrape resource for metric '{MetricName}'", scrapeDefinition.PrometheusMetricDefinition.Name); } } - private void HandleErrorResponseException(ErrorResponseException errorResponseException) + private void HandleErrorResponseException(ErrorResponseException errorResponseException, string metricName) { string reason = string.Empty; @@ -127,11 +124,11 @@ private void HandleErrorResponseException(ErrorResponseException errorResponseEx catch (Exception) { // do nothing. maybe a bad deserialization of json content. Just fallback on outer exception message. - _exceptionTracker.Track(errorResponseException); + _logger.LogCritical(errorResponseException, "Failed to scrape resource for metric '{MetricName}'", metricName); } } - _exceptionTracker.Track(new Exception(reason)); + _logger.LogCritical(reason); } /// diff --git a/src/Promitor.Core.Scraping/ScraperConfiguration.cs b/src/Promitor.Core.Scraping/ScraperConfiguration.cs index c0a0b2970..321e8cf0d 100644 --- a/src/Promitor.Core.Scraping/ScraperConfiguration.cs +++ b/src/Promitor.Core.Scraping/ScraperConfiguration.cs @@ -2,7 +2,6 @@ using Microsoft.Extensions.Logging; using Promitor.Core.Scraping.Configuration.Model; using Promitor.Core.Scraping.Prometheus.Interfaces; -using Promitor.Core.Telemetry.Interfaces; using Promitor.Integrations.AzureMonitor; namespace Promitor.Core.Scraping @@ -29,11 +28,6 @@ public class ScraperConfiguration /// public ILogger Logger { get; } - /// - /// Used for exception tracking - /// - public IExceptionTracker ExceptionTracker { get; } - /// /// Constructor /// @@ -41,20 +35,17 @@ public class ScraperConfiguration /// Client to communicate with Azure Monitor /// Metrics collector for our Prometheus scraping endpoint /// General logger - /// Exception tracker - public ScraperConfiguration(AzureMetadata azureMetadata, AzureMonitorClient azureMonitorClient, IPrometheusMetricWriter prometheusMetricWriter, ILogger logger, IExceptionTracker exceptionTracker) + public ScraperConfiguration(AzureMetadata azureMetadata, AzureMonitorClient azureMonitorClient, IPrometheusMetricWriter prometheusMetricWriter, ILogger logger) { Guard.NotNull(azureMetadata, nameof(azureMetadata)); Guard.NotNull(azureMonitorClient, nameof(azureMonitorClient)); Guard.NotNull(prometheusMetricWriter, nameof(prometheusMetricWriter)); Guard.NotNull(logger, nameof(logger)); - Guard.NotNull(exceptionTracker, nameof(exceptionTracker)); AzureMetadata = azureMetadata; AzureMonitorClient = azureMonitorClient; PrometheusMetricWriter = prometheusMetricWriter; Logger = logger; - ExceptionTracker = exceptionTracker; } } } \ No newline at end of file diff --git a/src/Promitor.Core.Telemetry/ApplicationInsightsTelemetry.cs b/src/Promitor.Core.Telemetry/ApplicationInsightsTelemetry.cs index f7f8ec913..9c637befe 100644 --- a/src/Promitor.Core.Telemetry/ApplicationInsightsTelemetry.cs +++ b/src/Promitor.Core.Telemetry/ApplicationInsightsTelemetry.cs @@ -47,7 +47,7 @@ private TelemetryClient ConfigureTelemetryClient(IOptionsMonitor Provides an indication about the health of the scraper + + + Use Serilog to emit logs to multiple sinks + + Application Builder + Configuration of the application + Add support for Open API with API explorer diff --git a/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs b/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs index 34c036453..09f820136 100644 --- a/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs +++ b/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs @@ -1,5 +1,10 @@ using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.Configuration; using Prometheus.Client.AspNetCore; +using Promitor.Core.Configuration.Model.Telemetry; +using Promitor.Core.Configuration.Model.Telemetry.Sinks; +using Serilog; +using Serilog.Events; using Swashbuckle.AspNetCore.SwaggerUI; // ReSharper disable once CheckNamespace @@ -8,6 +13,46 @@ namespace Promitor.Scraper.Host.Extensions // ReSharper disable once InconsistentNaming public static class IApplicationBuilderExtensions { + /// + /// Use Serilog to emit logs to multiple sinks + /// + /// Application Builder + /// Configuration of the application + public static IApplicationBuilder UseSerilog(this IApplicationBuilder app, IConfiguration configuration) + { + var telemetryConfiguration = configuration.Get(); + var ai = configuration.Get(); + + var defaultLogLevel = DetermineSinkLogLevel(telemetryConfiguration.DefaultVerbosity); + var loggerConfiguration = new LoggerConfiguration() + .MinimumLevel.Is(defaultLogLevel) + .Enrich.FromLogContext(); + + var appInsightsConfig = telemetryConfiguration.ApplicationInsights; + if (appInsightsConfig?.IsEnabled == true) + { + var logLevel = DetermineSinkLogLevel(appInsightsConfig.Verbosity); + loggerConfiguration.WriteTo.ApplicationInsights(appInsightsConfig.InstrumentationKey, TelemetryConverter.Traces, restrictedToMinimumLevel: logLevel); + } + + var consoleLogConfig = telemetryConfiguration.ContainerLogs; + if (consoleLogConfig?.IsEnabled == true) + { + var logLevel = DetermineSinkLogLevel(consoleLogConfig.Verbosity); + + loggerConfiguration.WriteTo.Console(restrictedToMinimumLevel: logLevel); + } + + Log.Logger = loggerConfiguration.CreateLogger(); + + return app; + } + + private static LogEventLevel DetermineSinkLogLevel(LogEventLevel? logLevel) + { + return logLevel ?? LogEventLevel.Verbose; + } + /// /// Add support for Open API with API explorer /// diff --git a/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs b/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs index 71f643904..3dbddc14c 100644 --- a/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs +++ b/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs @@ -23,8 +23,6 @@ using Promitor.Core.Scraping.Factories; using Promitor.Core.Scraping.Prometheus; using Promitor.Core.Scraping.Prometheus.Interfaces; -using Promitor.Core.Telemetry; -using Promitor.Core.Telemetry.Interfaces; using Promitor.Core.Telemetry.Metrics; using Promitor.Core.Telemetry.Metrics.Interfaces; using Promitor.Scraper.Host.Scheduling; @@ -57,8 +55,7 @@ public static IServiceCollection ScheduleMetricScraping(this IServiceCollection serviceProvider.GetService(), serviceProvider.GetService(), serviceProvider.GetService(), - serviceProvider.GetService>(), - serviceProvider.GetService())); + serviceProvider.GetService>())); builder.UnobservedTaskExceptionHandler = (sender, exceptionEventArgs) => UnobservedJobHandlerHandler(sender, exceptionEventArgs, services); }); } @@ -73,7 +70,6 @@ public static IServiceCollection ScheduleMetricScraping(this IServiceCollection /// Collections of services in application public static IServiceCollection DefineDependencies(this IServiceCollection services) { - services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -116,7 +112,7 @@ public static IServiceCollection UseWebApi(this IServiceCollection services) .AddJsonOptions(jsonOptions => { jsonOptions.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); - jsonOptions.JsonSerializerOptions.IgnoreNullValues=true; + jsonOptions.JsonSerializerOptions.IgnoreNullValues = true; }); return services; @@ -127,14 +123,14 @@ public static IServiceCollection UseWebApi(this IServiceCollection services) /// public static IServiceCollection ConfigureYamlConfiguration(this IServiceCollection services, IConfiguration configuration) { - services.Configure(configuration); - services.Configure(configuration.GetSection("metricsConfiguration")); - services.Configure(configuration.GetSection("telemetry")); services.Configure(configuration.GetSection("telemetry:applicationInsights")); services.Configure(configuration.GetSection("telemetry:containerLogs")); + services.Configure(configuration.GetSection("prometheus:scrapeEndpoint")); + services.Configure(configuration.GetSection("metricsConfiguration")); + services.Configure(configuration.GetSection("telemetry")); services.Configure(configuration.GetSection("server")); services.Configure(configuration.GetSection("prometheus")); - services.Configure(configuration.GetSection("prometheus:scrapeEndpoint")); + services.Configure(configuration); return services; } @@ -170,7 +166,7 @@ public static IServiceCollection UseOpenApiSpecifications(this IServiceCollectio { swaggerGenerationOptions.EnableAnnotations(); swaggerGenerationOptions.SwaggerDoc($"v{apiVersion}", openApiInformation); - + if (string.IsNullOrEmpty(xmlDocumentationPath) == false) { swaggerGenerationOptions.IncludeXmlComments(xmlDocumentationPath); @@ -197,9 +193,9 @@ private static string GetXmlDocumentationPath(IServiceCollection services) // ReSharper disable once UnusedParameter.Local private static void UnobservedJobHandlerHandler(object sender, UnobservedTaskExceptionEventArgs e, IServiceCollection services) { - var exceptionTrackerService = services.FirstOrDefault(service => service.ServiceType == typeof(IExceptionTracker)); - var exceptionTracker = (IExceptionTracker)exceptionTrackerService?.ImplementationInstance; - exceptionTracker?.Track(e.Exception); + var logger = services.FirstOrDefault(service => service.ServiceType == typeof(ILogger)); + var loggerInstance = (ILogger)logger?.ImplementationInstance; + loggerInstance?.LogCritical(e.Exception, "Unhandled job exception"); e.SetObserved(); } diff --git a/src/Promitor.Scraper.Host/Program.cs b/src/Promitor.Scraper.Host/Program.cs index ec7f29524..f2d10083e 100644 --- a/src/Promitor.Scraper.Host/Program.cs +++ b/src/Promitor.Scraper.Host/Program.cs @@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; using Promitor.Core.Configuration.Model.Server; using Serilog; @@ -15,10 +14,8 @@ public static void Main(string[] args) { Welcome(); - Log.Logger = new LoggerConfiguration() - .Enrich.FromLogContext() - .WriteTo.Console() - .CreateLogger(); + // Let's hook in a logger for start-up purposes. + ConfigureStartupLogging(); BuildWebHost(args) .Build() @@ -36,13 +33,14 @@ public static IHostBuilder BuildWebHost(string[] args) var httpPort = DetermineHttpPort(configuration); var endpointUrl = $"http://+:{httpPort}"; - // TODO: Configure verbosity https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-3.0#add-providers - return Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder(args) .UseSerilog() .ConfigureWebHostDefaults(webHostBuilder => { - webHostBuilder.UseKestrel(kestrelServerOptions => { kestrelServerOptions.AddServerHeader = false; }) + webHostBuilder.UseKestrel(kestrelServerOptions => + { + kestrelServerOptions.AddServerHeader = false; + }) .UseConfiguration(configuration) .UseUrls(endpointUrl) .UseStartup(); @@ -68,5 +66,13 @@ private static int DetermineHttpPort(IConfiguration configuration) return serverConfiguration?.HttpPort ?? 80; } + + private static void ConfigureStartupLogging() + { + Log.Logger = new LoggerConfiguration() + .Enrich.FromLogContext() + .WriteTo.Console() + .CreateLogger(); + } } } \ No newline at end of file diff --git a/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj b/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj index 43339463f..1292b9a2c 100644 --- a/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj +++ b/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj @@ -38,8 +38,8 @@ - + @@ -53,7 +53,6 @@ - diff --git a/src/Promitor.Scraper.Host/Scheduling/MetricScrapingJob.cs b/src/Promitor.Scraper.Host/Scheduling/MetricScrapingJob.cs index b8734e995..35e69850d 100644 --- a/src/Promitor.Scraper.Host/Scheduling/MetricScrapingJob.cs +++ b/src/Promitor.Scraper.Host/Scheduling/MetricScrapingJob.cs @@ -9,7 +9,6 @@ using Promitor.Core.Scraping.Configuration.Providers.Interfaces; using Promitor.Core.Scraping.Factories; using Promitor.Core.Scraping.Prometheus.Interfaces; -using Promitor.Core.Telemetry.Interfaces; using Promitor.Core.Telemetry.Metrics.Interfaces; namespace Promitor.Scraper.Host.Scheduling @@ -20,7 +19,6 @@ public class MetricScrapingJob : IScheduledJob private readonly IMetricsDeclarationProvider _metricsDeclarationProvider; private readonly IPrometheusMetricWriter _prometheusMetricWriter; private readonly IRuntimeMetricsCollector _runtimeMetricsCollector; - private readonly IExceptionTracker _exceptionTracker; private readonly ILogger _logger; private readonly MetricScraperFactory _metricScraperFactory; @@ -30,7 +28,7 @@ public MetricScrapingJob(ScrapeDefinition metric, IPrometheusMetricWriter prometheusMetricWriter, IRuntimeMetricsCollector runtimeMetricsCollector, MetricScraperFactory metricScraperFactory, - ILogger logger, IExceptionTracker exceptionTracker) + ILogger logger) { Guard.NotNull(metric, nameof(metric)); Guard.NotNull(metricsDeclarationProvider, nameof(metricsDeclarationProvider)); @@ -38,13 +36,11 @@ public MetricScrapingJob(ScrapeDefinition metric, Guard.NotNull(runtimeMetricsCollector, nameof(runtimeMetricsCollector)); Guard.NotNull(metricScraperFactory, nameof(metricScraperFactory)); Guard.NotNull(logger, nameof(logger)); - Guard.NotNull(exceptionTracker, nameof(exceptionTracker)); _metric = metric; _metricsDeclarationProvider = metricsDeclarationProvider; _prometheusMetricWriter = prometheusMetricWriter; _runtimeMetricsCollector = runtimeMetricsCollector; - _exceptionTracker = exceptionTracker; _logger = logger; _metricScraperFactory = metricScraperFactory; @@ -74,8 +70,7 @@ public async Task ExecuteAsync(CancellationToken cancellationToken) } catch (Exception exception) { - _logger.LogError($"Failed to scrape: {exception.Message}"); - _exceptionTracker.Track(exception); + _logger.LogCritical(exception, $"Failed to scrape: {exception.Message}"); } } diff --git a/src/Promitor.Scraper.Host/Startup.cs b/src/Promitor.Scraper.Host/Startup.cs index cb9486792..ae55c1958 100644 --- a/src/Promitor.Scraper.Host/Startup.cs +++ b/src/Promitor.Scraper.Host/Startup.cs @@ -34,8 +34,9 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) ValidateRuntimeConfiguration(app); - app.UsePrometheusScraper(_prometheusBaseUriPath); - app.UseOpenApiUi(); + app.UsePrometheusScraper(_prometheusBaseUriPath) + .UseSerilog(_configuration) + .UseOpenApiUi(); } // This method gets called by the runtime. Use this method to add services to the container. diff --git a/src/Promitor.Scraper.Tests.Unit/Configuration/RuntimeConfigurationUnitTest.cs b/src/Promitor.Scraper.Tests.Unit/Configuration/RuntimeConfigurationUnitTest.cs index 12416de5b..3cc752691 100644 --- a/src/Promitor.Scraper.Tests.Unit/Configuration/RuntimeConfigurationUnitTest.cs +++ b/src/Promitor.Scraper.Tests.Unit/Configuration/RuntimeConfigurationUnitTest.cs @@ -2,10 +2,10 @@ using System.Threading.Tasks; using Bogus; using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; using Promitor.Core.Configuration; using Promitor.Core.Configuration.Model; using Promitor.Scraper.Tests.Unit.Generators.Config; +using Serilog.Events; using Xunit; namespace Promitor.Scraper.Tests.Unit.Configuration @@ -75,7 +75,7 @@ public async Task RuntimeConfiguration_HasConfiguredApplicationInsightsInstrumen public async Task RuntimeConfiguration_HasConfiguredApplicationInsightsVerbosity_UsesConfigured() { // Arrange - var verbosity = LogLevel.Error; + var verbosity = LogEventLevel.Error; var configuration = await RuntimeConfigurationGenerator.WithServerConfiguration() .WithApplicationInsightsTelemetry(verbosity: verbosity) .GenerateAsync(); @@ -93,7 +93,7 @@ public async Task RuntimeConfiguration_HasConfiguredApplicationInsightsVerbosity public async Task RuntimeConfiguration_HasConfiguredContainerLogVerbosity_UsesConfigured() { // Arrange - var verbosity = LogLevel.Error; + var verbosity = LogEventLevel.Error; var configuration = await RuntimeConfigurationGenerator.WithServerConfiguration() .WithContainerTelemetry(verbosity) .GenerateAsync(); @@ -111,7 +111,7 @@ public async Task RuntimeConfiguration_HasConfiguredContainerLogVerbosity_UsesCo public async Task RuntimeConfiguration_HasConfiguredDefaultTelemetryVerbosityConfigured_UsesConfigured() { // Arrange - var defaultVerbosity = LogLevel.Error; + var defaultVerbosity = LogEventLevel.Error; var configuration = await RuntimeConfigurationGenerator.WithServerConfiguration() .WithGeneralTelemetry(defaultVerbosity) .GenerateAsync(); diff --git a/src/Promitor.Scraper.Tests.Unit/Generators/Config/BogusRuntimeConfigurationGenerator.cs b/src/Promitor.Scraper.Tests.Unit/Generators/Config/BogusRuntimeConfigurationGenerator.cs index 073faf519..48a1b57f6 100644 --- a/src/Promitor.Scraper.Tests.Unit/Generators/Config/BogusRuntimeConfigurationGenerator.cs +++ b/src/Promitor.Scraper.Tests.Unit/Generators/Config/BogusRuntimeConfigurationGenerator.cs @@ -1,11 +1,11 @@ using Bogus; -using Microsoft.Extensions.Logging; using Promitor.Core.Configuration.Model; using Promitor.Core.Configuration.Model.Metrics; using Promitor.Core.Configuration.Model.Prometheus; using Promitor.Core.Configuration.Model.Server; using Promitor.Core.Configuration.Model.Telemetry; using Promitor.Core.Configuration.Model.Telemetry.Sinks; +using Serilog.Events; namespace Promitor.Scraper.Tests.Unit.Generators.Config { @@ -34,20 +34,20 @@ internal static RuntimeConfiguration Generate() var containerLogConfiguration = new Faker() .StrictMode(true) - .RuleFor(containerConfiguration => containerConfiguration.Verbosity, faker => LogLevel.Critical) + .RuleFor(containerConfiguration => containerConfiguration.Verbosity, faker => LogEventLevel.Error) .RuleFor(containerConfiguration => containerConfiguration.IsEnabled, faker => faker.Random.Bool()) .Generate(); var applicationInsightsConfiguration = new Faker() .StrictMode(true) - .RuleFor(containerConfiguration => containerConfiguration.Verbosity, faker => LogLevel.Critical) + .RuleFor(containerConfiguration => containerConfiguration.Verbosity, faker => LogEventLevel.Error) .RuleFor(containerConfiguration => containerConfiguration.IsEnabled, faker => faker.Random.Bool()) .RuleFor(containerConfiguration => containerConfiguration.InstrumentationKey, faker => faker.Random.Guid().ToString()) .Generate(); var telemetryConfiguration = new Faker() .StrictMode(true) - .RuleFor(telemetry => telemetry.DefaultVerbosity, faker => LogLevel.Critical) + .RuleFor(telemetry => telemetry.DefaultVerbosity, faker => LogEventLevel.Error) .RuleFor(telemetry => telemetry.ContainerLogs, faker => containerLogConfiguration) .RuleFor(telemetry => telemetry.ApplicationInsights, faker => applicationInsightsConfiguration) .Generate(); diff --git a/src/Promitor.Scraper.Tests.Unit/Generators/Config/RuntimeConfigurationGenerator.cs b/src/Promitor.Scraper.Tests.Unit/Generators/Config/RuntimeConfigurationGenerator.cs index 38f7e9696..516a4cc88 100644 --- a/src/Promitor.Scraper.Tests.Unit/Generators/Config/RuntimeConfigurationGenerator.cs +++ b/src/Promitor.Scraper.Tests.Unit/Generators/Config/RuntimeConfigurationGenerator.cs @@ -4,13 +4,13 @@ using System.Text; using System.Threading.Tasks; using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; using Promitor.Core.Configuration.Model; using Promitor.Core.Configuration.Model.Metrics; using Promitor.Core.Configuration.Model.Prometheus; using Promitor.Core.Configuration.Model.Server; using Promitor.Core.Configuration.Model.Telemetry; using Promitor.Core.Configuration.Model.Telemetry.Sinks; +using Serilog.Events; namespace Promitor.Scraper.Tests.Unit.Generators.Config { @@ -97,7 +97,7 @@ public RuntimeConfigurationGenerator WithMetricsConfiguration(string absolutePat return this; } - public RuntimeConfigurationGenerator WithGeneralTelemetry(LogLevel? defaultVerbosity = LogLevel.Trace) + public RuntimeConfigurationGenerator WithGeneralTelemetry(LogEventLevel? defaultVerbosity = LogEventLevel.Verbose) { var telemetryConfiguration = defaultVerbosity == null ? null @@ -111,7 +111,7 @@ public RuntimeConfigurationGenerator WithGeneralTelemetry(LogLevel? defaultVerbo return this; } - public RuntimeConfigurationGenerator WithContainerTelemetry(LogLevel? verbosity = LogLevel.Trace, bool? isEnabled = true) + public RuntimeConfigurationGenerator WithContainerTelemetry(LogEventLevel? verbosity = LogEventLevel.Verbose, bool? isEnabled = true) { var containerLogConfiguration = verbosity == null && isEnabled == null ? null @@ -131,7 +131,7 @@ public RuntimeConfigurationGenerator WithContainerTelemetry(LogLevel? verbosity return this; } - public RuntimeConfigurationGenerator WithApplicationInsightsTelemetry(string instrumentationKey = "XYZ", LogLevel? verbosity = LogLevel.Trace, bool? isEnabled = true) + public RuntimeConfigurationGenerator WithApplicationInsightsTelemetry(string instrumentationKey = "XYZ", LogEventLevel? verbosity = LogEventLevel.Verbose, bool? isEnabled = true) { var applicationInsightsTelemetry = verbosity == null && isEnabled == null && string.IsNullOrWhiteSpace(instrumentationKey) ? null diff --git a/src/Promitor.sln b/src/Promitor.sln index fa303f664..294abc409 100644 --- a/src/Promitor.sln +++ b/src/Promitor.sln @@ -11,8 +11,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Promitor.Scraper.Tests.Unit EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{34CA9F50-3DF7-490F-A22F-A7C63650F8AB}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Promitor.Core.Telemetry", "Promitor.Core.Telemetry\Promitor.Core.Telemetry.csproj", "{EF19E7C2-271B-4651-BF70-0AC4E0834463}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Promitor.Scraper.Host", "Promitor.Scraper.Host\Promitor.Scraper.Host.csproj", "{D4428510-993A-44F1-A8B2-63EE497327D7}" EndProject Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "Promitor.Docker", "Promitor.Docker.dcproj", "{D61A88B9-F9BB-43E2-ABD3-754E3ED32317}" @@ -56,10 +54,6 @@ Global {D53C3256-A239-4FA9-8B54-56487570EE33}.Debug|Any CPU.Build.0 = Debug|Any CPU {D53C3256-A239-4FA9-8B54-56487570EE33}.Release|Any CPU.ActiveCfg = Release|Any CPU {D53C3256-A239-4FA9-8B54-56487570EE33}.Release|Any CPU.Build.0 = Release|Any CPU - {EF19E7C2-271B-4651-BF70-0AC4E0834463}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {EF19E7C2-271B-4651-BF70-0AC4E0834463}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EF19E7C2-271B-4651-BF70-0AC4E0834463}.Release|Any CPU.ActiveCfg = Release|Any CPU - {EF19E7C2-271B-4651-BF70-0AC4E0834463}.Release|Any CPU.Build.0 = Release|Any CPU {D4428510-993A-44F1-A8B2-63EE497327D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D4428510-993A-44F1-A8B2-63EE497327D7}.Debug|Any CPU.Build.0 = Debug|Any CPU {D4428510-993A-44F1-A8B2-63EE497327D7}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -99,7 +93,6 @@ Global {19235B76-EE2F-4343-AA08-47615EC684EC} = {710EC1C2-88E8-4D5C-A2DA-89C321CB7D48} {710EC1C2-88E8-4D5C-A2DA-89C321CB7D48} = {9D006E55-567F-4521-9366-490679CA00BF} {D53C3256-A239-4FA9-8B54-56487570EE33} = {34CA9F50-3DF7-490F-A22F-A7C63650F8AB} - {EF19E7C2-271B-4651-BF70-0AC4E0834463} = {05524B1B-9965-4E36-9626-A2823B8588AA} {D4428510-993A-44F1-A8B2-63EE497327D7} = {19235B76-EE2F-4343-AA08-47615EC684EC} {05524B1B-9965-4E36-9626-A2823B8588AA} = {9D006E55-567F-4521-9366-490679CA00BF} {E39EA07D-C6E3-4D5A-8748-DB0CB8E08C1F} = {59D7FFBC-3929-48AD-8C9C-242280D01CBD} From b8d1760fb41dbf83ff169b170741076427326d67 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Fri, 6 Dec 2019 13:27:16 +0100 Subject: [PATCH 21/38] Use netcoreapp3.1 LTS --- .../Promitor.Core.Configuration.csproj | 10 +++++----- .../Promitor.Core.Scraping.csproj | 4 ++-- .../Promitor.Core.Telemetry.Metrics.csproj | 8 ++++---- .../Promitor.Core.Telemetry.csproj | 4 ++-- src/Promitor.Core/Promitor.Core.csproj | 4 ++-- .../Promitor.Integrations.AzureMonitor.csproj | 4 ++-- .../Promitor.Integrations.AzureStorage.csproj | 6 +++--- src/Promitor.Scraper.Host/Dockerfile | 4 ++-- src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj | 4 ++-- .../Promitor.Scraper.Tests.Unit.csproj | 6 +++--- 10 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj b/src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj index 3380d5599..73c376c23 100644 --- a/src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj +++ b/src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj @@ -1,8 +1,8 @@  - netcoreapp3.0 - 3.0.0 + netcoreapp3.1 + 3.1.0 @@ -14,9 +14,9 @@ - - - + + + diff --git a/src/Promitor.Core.Scraping/Promitor.Core.Scraping.csproj b/src/Promitor.Core.Scraping/Promitor.Core.Scraping.csproj index e4273e441..e04b7c26e 100644 --- a/src/Promitor.Core.Scraping/Promitor.Core.Scraping.csproj +++ b/src/Promitor.Core.Scraping/Promitor.Core.Scraping.csproj @@ -1,8 +1,8 @@  - netcoreapp3.0 - 3.0.0 + netcoreapp3.1 + 3.1.0 diff --git a/src/Promitor.Core.Telemetry.Metrics/Promitor.Core.Telemetry.Metrics.csproj b/src/Promitor.Core.Telemetry.Metrics/Promitor.Core.Telemetry.Metrics.csproj index e69c41178..7d06fd6d0 100644 --- a/src/Promitor.Core.Telemetry.Metrics/Promitor.Core.Telemetry.Metrics.csproj +++ b/src/Promitor.Core.Telemetry.Metrics/Promitor.Core.Telemetry.Metrics.csproj @@ -1,8 +1,8 @@  - netcoreapp3.0 - 3.0.0 + netcoreapp3.1 + 3.1.0 @@ -15,8 +15,8 @@ - - + + diff --git a/src/Promitor.Core.Telemetry/Promitor.Core.Telemetry.csproj b/src/Promitor.Core.Telemetry/Promitor.Core.Telemetry.csproj index d9d0bda8c..199a5479d 100644 --- a/src/Promitor.Core.Telemetry/Promitor.Core.Telemetry.csproj +++ b/src/Promitor.Core.Telemetry/Promitor.Core.Telemetry.csproj @@ -1,8 +1,8 @@  - netcoreapp3.0 - 3.0.0 + netcoreapp3.1 + 3.1.0 diff --git a/src/Promitor.Core/Promitor.Core.csproj b/src/Promitor.Core/Promitor.Core.csproj index ee24534d5..ce8d9be68 100644 --- a/src/Promitor.Core/Promitor.Core.csproj +++ b/src/Promitor.Core/Promitor.Core.csproj @@ -1,8 +1,8 @@ - netcoreapp3.0 - 3.0.0 + netcoreapp3.1 + 3.1.0 diff --git a/src/Promitor.Integrations.AzureMonitor/Promitor.Integrations.AzureMonitor.csproj b/src/Promitor.Integrations.AzureMonitor/Promitor.Integrations.AzureMonitor.csproj index 8f618b2e8..6295154ed 100644 --- a/src/Promitor.Integrations.AzureMonitor/Promitor.Integrations.AzureMonitor.csproj +++ b/src/Promitor.Integrations.AzureMonitor/Promitor.Integrations.AzureMonitor.csproj @@ -1,8 +1,8 @@  - netcoreapp3.0 - 3.0.0 + netcoreapp3.1 + 3.1.0 diff --git a/src/Promitor.Integrations.AzureStorage/Promitor.Integrations.AzureStorage.csproj b/src/Promitor.Integrations.AzureStorage/Promitor.Integrations.AzureStorage.csproj index 3580cc969..af2a67a9b 100644 --- a/src/Promitor.Integrations.AzureStorage/Promitor.Integrations.AzureStorage.csproj +++ b/src/Promitor.Integrations.AzureStorage/Promitor.Integrations.AzureStorage.csproj @@ -1,14 +1,14 @@  - netcoreapp3.0 - 3.0.0 + netcoreapp3.1 + 3.1.0 - + diff --git a/src/Promitor.Scraper.Host/Dockerfile b/src/Promitor.Scraper.Host/Dockerfile index d4322613c..a0475c083 100644 --- a/src/Promitor.Scraper.Host/Dockerfile +++ b/src/Promitor.Scraper.Host/Dockerfile @@ -1,4 +1,4 @@ -FROM mcr.microsoft.com/dotnet/core/sdk:3.0.100-alpine3.9 AS build +FROM mcr.microsoft.com/dotnet/core/sdk:3.1.100-alpine AS build WORKDIR /src COPY Promitor.Core/* Promitor.Core/ COPY Promitor.Core.Configuration/* Promitor.Core.Configuration/ @@ -10,7 +10,7 @@ COPY Promitor.Integrations.AzureStorage/* Promitor.Integrations.AzureStorage/ COPY Promitor.Scraper.Host/* Promitor.Scraper.Host/ RUN dotnet publish Promitor.Scraper.Host/Promitor.Scraper.Host.csproj --configuration release --output app -FROM mcr.microsoft.com/dotnet/core/aspnet:3.0.0-alpine3.9 as runtime +FROM mcr.microsoft.com/dotnet/core/aspnet:3.1.0-alpine as runtime WORKDIR /app COPY --from=build /src/app . diff --git a/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj b/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj index 1292b9a2c..8c3cb1105 100644 --- a/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj +++ b/src/Promitor.Scraper.Host/Promitor.Scraper.Host.csproj @@ -1,9 +1,9 @@  - netcoreapp3.0 + netcoreapp3.1 ..\docker-compose.dcproj - 3.0.0 + 3.1.0 diff --git a/src/Promitor.Scraper.Tests.Unit/Promitor.Scraper.Tests.Unit.csproj b/src/Promitor.Scraper.Tests.Unit/Promitor.Scraper.Tests.Unit.csproj index 41d916207..74d6f4975 100644 --- a/src/Promitor.Scraper.Tests.Unit/Promitor.Scraper.Tests.Unit.csproj +++ b/src/Promitor.Scraper.Tests.Unit/Promitor.Scraper.Tests.Unit.csproj @@ -1,8 +1,8 @@  - netcoreapp3.0 - 3.0.0 + netcoreapp3.1 + 3.1.0 true @@ -26,7 +26,7 @@ - + From 186bd40d22cacd67080f78c66769ca6b79dff5f4 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Fri, 6 Dec 2019 15:26:12 +0100 Subject: [PATCH 22/38] Use 3.1.100 SDK in builds --- build/azure-devops/agents-scraper-release-official.yml | 2 +- build/azure-devops/agents-scraper-release-preview.yml | 2 +- build/azure-devops/scraper-ci.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build/azure-devops/agents-scraper-release-official.yml b/build/azure-devops/agents-scraper-release-official.yml index 689dd0957..110429a8b 100644 --- a/build/azure-devops/agents-scraper-release-official.yml +++ b/build/azure-devops/agents-scraper-release-official.yml @@ -4,7 +4,7 @@ resources: trigger: none pr: none variables: - DotNet.SDK.Version: '3.0.100' + DotNet.SDK.Version: '3.1.100' Image.Name: 'tomkerkhove/promitor-agent-scraper' Image.TaggedName: '$(Image.Name):$(Image.Version)' Release.TagName: '$(Build.BuildNumber)' diff --git a/build/azure-devops/agents-scraper-release-preview.yml b/build/azure-devops/agents-scraper-release-preview.yml index b052da02e..bc9e37f5a 100644 --- a/build/azure-devops/agents-scraper-release-preview.yml +++ b/build/azure-devops/agents-scraper-release-preview.yml @@ -4,7 +4,7 @@ resources: trigger: none pr: none variables: - DotNet.SDK.Version: '3.0.100' + DotNet.SDK.Version: '3.1.100' Image.Name: 'tomkerkhove/promitor-agent-scraper' Image.TaggedName: '$(Image.Name):$(Image.Version)' Release.TagName: '$(Build.BuildNumber)' diff --git a/build/azure-devops/scraper-ci.yml b/build/azure-devops/scraper-ci.yml index e2679aeba..0afa0769a 100644 --- a/build/azure-devops/scraper-ci.yml +++ b/build/azure-devops/scraper-ci.yml @@ -14,7 +14,7 @@ pr: - charts/promitor-agent-scraper/* - deploy/automation/docker-hub/ci/* # Add Docker Hub bot here to trigger it for testing sake variables: - DotNet.SDK.Version: '3.0.100' + DotNet.SDK.Version: '3.1.100' DotNet.Configuration: 'release' Image.Name: 'tomkerkhove/promitor-agent-scraper-ci' Image.TaggedName: '$(Image.Name):$(Build.BuildNumber)' From 829a70f0ff25ad91605321d89b1a031a01840ed6 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Fri, 6 Dec 2019 15:33:29 +0100 Subject: [PATCH 23/38] Install correct version --- build/azure-devops/scraper-ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build/azure-devops/scraper-ci.yml b/build/azure-devops/scraper-ci.yml index 0afa0769a..1056f59cd 100644 --- a/build/azure-devops/scraper-ci.yml +++ b/build/azure-devops/scraper-ci.yml @@ -101,6 +101,10 @@ stages: pool: vmImage: ubuntu-16.04 steps: + - task: DotNetCoreInstaller@0 + displayName: 'Import .Net Core Sdk ($(DotNet.Sdk.Version))' + inputs: + version: '$(DotNet.Sdk.Version)' - task: DotNetCoreCLI@2 displayName: 'dotnet test' inputs: From 795d8f47fb0d1835ee0947ba87954884936d6558 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Fri, 6 Dec 2019 17:28:52 +0100 Subject: [PATCH 24/38] Fix configuration Signed-off-by: Tom Kerkhove --- .../Extensions/IApplicationBuilderExtensions.cs | 13 +++++++++---- .../Extensions/IServiceCollectionExtensions.cs | 8 ++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs b/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs index 09f820136..22c860625 100644 --- a/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs +++ b/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs @@ -1,8 +1,10 @@ -using Microsoft.AspNetCore.Builder; +using System; +using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; using Prometheus.Client.AspNetCore; +using Promitor.Core.Configuration.Model; using Promitor.Core.Configuration.Model.Telemetry; -using Promitor.Core.Configuration.Model.Telemetry.Sinks; using Serilog; using Serilog.Events; using Swashbuckle.AspNetCore.SwaggerUI; @@ -20,8 +22,11 @@ public static class IApplicationBuilderExtensions /// Configuration of the application public static IApplicationBuilder UseSerilog(this IApplicationBuilder app, IConfiguration configuration) { - var telemetryConfiguration = configuration.Get(); - var ai = configuration.Get(); + var telemetryConfiguration = configuration.Get()?.Telemetry; + if (telemetryConfiguration == null) + { + throw new Exception("Unable to get telemetry configuration"); + } var defaultLogLevel = DetermineSinkLogLevel(telemetryConfiguration.DefaultVerbosity); var loggerConfiguration = new LoggerConfiguration() diff --git a/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs b/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs index 3dbddc14c..ee91c1435 100644 --- a/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs +++ b/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs @@ -123,14 +123,14 @@ public static IServiceCollection UseWebApi(this IServiceCollection services) /// public static IServiceCollection ConfigureYamlConfiguration(this IServiceCollection services, IConfiguration configuration) { - services.Configure(configuration.GetSection("telemetry:applicationInsights")); - services.Configure(configuration.GetSection("telemetry:containerLogs")); - services.Configure(configuration.GetSection("prometheus:scrapeEndpoint")); + services.Configure(configuration); services.Configure(configuration.GetSection("metricsConfiguration")); services.Configure(configuration.GetSection("telemetry")); services.Configure(configuration.GetSection("server")); services.Configure(configuration.GetSection("prometheus")); - services.Configure(configuration); + services.Configure(configuration.GetSection("telemetry:applicationInsights")); + services.Configure(configuration.GetSection("telemetry:containerLogs")); + services.Configure(configuration.GetSection("prometheus:scrapeEndpoint")); return services; } From 8f1e426f5b2fb4dda73eeb5068ae7d731c946596 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Fri, 6 Dec 2019 17:34:11 +0100 Subject: [PATCH 25/38] Revert to LogLevel Signed-off-by: Tom Kerkhove --- src/Promitor.Core.Configuration/Defaults.cs | 7 ++--- .../Interfaces/ISinkConfiguration.cs | 4 +-- .../Sinks/ApplicationInsightsConfiguration.cs | 6 ++-- .../Sinks/ContainerLogConfiguration.cs | 6 ++-- .../Model/Telemetry/TelemetryConfiguration.cs | 6 ++-- .../IApplicationBuilderExtensions.cs | 30 ++++++++++++++++--- .../RuntimeConfigurationUnitTest.cs | 8 ++--- .../BogusRuntimeConfigurationGenerator.cs | 8 ++--- .../Config/RuntimeConfigurationGenerator.cs | 8 ++--- 9 files changed, 52 insertions(+), 31 deletions(-) diff --git a/src/Promitor.Core.Configuration/Defaults.cs b/src/Promitor.Core.Configuration/Defaults.cs index 87d5932e0..e5691ef64 100644 --- a/src/Promitor.Core.Configuration/Defaults.cs +++ b/src/Promitor.Core.Configuration/Defaults.cs @@ -1,5 +1,4 @@ using Microsoft.Extensions.Logging; -using Serilog.Events; namespace Promitor.Core.Configuration { @@ -24,17 +23,17 @@ public static class MetricsConfiguration public class Telemetry { - public static LogEventLevel? DefaultVerbosity { get; set; } = LogEventLevel.Error; + public static LogLevel? DefaultVerbosity { get; set; } = LogLevel.Error; public class ContainerLogs { - public static LogEventLevel? Verbosity { get; set; } = null; + public static LogLevel? Verbosity { get; set; } = null; public static bool IsEnabled { get; set; } = true; } public class ApplicationInsights { - public static LogEventLevel? Verbosity { get; set; } = null; + public static LogLevel? Verbosity { get; set; } = null; public static bool IsEnabled { get; set; } = false; } } diff --git a/src/Promitor.Core.Configuration/Model/Telemetry/Interfaces/ISinkConfiguration.cs b/src/Promitor.Core.Configuration/Model/Telemetry/Interfaces/ISinkConfiguration.cs index 90e138567..3c25a1a2d 100644 --- a/src/Promitor.Core.Configuration/Model/Telemetry/Interfaces/ISinkConfiguration.cs +++ b/src/Promitor.Core.Configuration/Model/Telemetry/Interfaces/ISinkConfiguration.cs @@ -1,10 +1,10 @@ -using Serilog.Events; +using Microsoft.Extensions.Logging; namespace Promitor.Core.Configuration.Model.Telemetry.Interfaces { public interface ISinkConfiguration { - LogEventLevel? Verbosity { get; } + LogLevel? Verbosity { get; } bool IsEnabled { get; } } } diff --git a/src/Promitor.Core.Configuration/Model/Telemetry/Sinks/ApplicationInsightsConfiguration.cs b/src/Promitor.Core.Configuration/Model/Telemetry/Sinks/ApplicationInsightsConfiguration.cs index 644e22dbe..4968c11b1 100644 --- a/src/Promitor.Core.Configuration/Model/Telemetry/Sinks/ApplicationInsightsConfiguration.cs +++ b/src/Promitor.Core.Configuration/Model/Telemetry/Sinks/ApplicationInsightsConfiguration.cs @@ -1,11 +1,11 @@ -using Promitor.Core.Configuration.Model.Telemetry.Interfaces; -using Serilog.Events; +using Microsoft.Extensions.Logging; +using Promitor.Core.Configuration.Model.Telemetry.Interfaces; namespace Promitor.Core.Configuration.Model.Telemetry.Sinks { public class ApplicationInsightsConfiguration : ISinkConfiguration { - public LogEventLevel? Verbosity { get; set; } = Defaults.Telemetry.ApplicationInsights.Verbosity; + public LogLevel? Verbosity { get; set; } = Defaults.Telemetry.ApplicationInsights.Verbosity; public bool IsEnabled { get; set; } = Defaults.Telemetry.ApplicationInsights.IsEnabled; public string InstrumentationKey { get; set; } } diff --git a/src/Promitor.Core.Configuration/Model/Telemetry/Sinks/ContainerLogConfiguration.cs b/src/Promitor.Core.Configuration/Model/Telemetry/Sinks/ContainerLogConfiguration.cs index 2b954e052..ae6679edf 100644 --- a/src/Promitor.Core.Configuration/Model/Telemetry/Sinks/ContainerLogConfiguration.cs +++ b/src/Promitor.Core.Configuration/Model/Telemetry/Sinks/ContainerLogConfiguration.cs @@ -1,11 +1,11 @@ -using Promitor.Core.Configuration.Model.Telemetry.Interfaces; -using Serilog.Events; +using Microsoft.Extensions.Logging; +using Promitor.Core.Configuration.Model.Telemetry.Interfaces; namespace Promitor.Core.Configuration.Model.Telemetry.Sinks { public class ContainerLogConfiguration : ISinkConfiguration { - public LogEventLevel? Verbosity { get; set; } = Defaults.Telemetry.ContainerLogs.Verbosity; + public LogLevel? Verbosity { get; set; } = Defaults.Telemetry.ContainerLogs.Verbosity; public bool IsEnabled { get; set; } = Defaults.Telemetry.ContainerLogs.IsEnabled; } } diff --git a/src/Promitor.Core.Configuration/Model/Telemetry/TelemetryConfiguration.cs b/src/Promitor.Core.Configuration/Model/Telemetry/TelemetryConfiguration.cs index b2f0eef2d..40c4d000a 100644 --- a/src/Promitor.Core.Configuration/Model/Telemetry/TelemetryConfiguration.cs +++ b/src/Promitor.Core.Configuration/Model/Telemetry/TelemetryConfiguration.cs @@ -1,11 +1,11 @@ -using Promitor.Core.Configuration.Model.Telemetry.Sinks; -using Serilog.Events; +using Microsoft.Extensions.Logging; +using Promitor.Core.Configuration.Model.Telemetry.Sinks; namespace Promitor.Core.Configuration.Model.Telemetry { public class TelemetryConfiguration { - public LogEventLevel? DefaultVerbosity { get; set; } = Defaults.Telemetry.DefaultVerbosity; + public LogLevel? DefaultVerbosity { get; set; } = Defaults.Telemetry.DefaultVerbosity; public ContainerLogConfiguration ContainerLogs { get; set; } = new ContainerLogConfiguration(); public ApplicationInsightsConfiguration ApplicationInsights { get; set; } = new ApplicationInsightsConfiguration(); } diff --git a/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs b/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs index 22c860625..34f5c368e 100644 --- a/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs +++ b/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs @@ -1,10 +1,9 @@ using System; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; using Prometheus.Client.AspNetCore; using Promitor.Core.Configuration.Model; -using Promitor.Core.Configuration.Model.Telemetry; using Serilog; using Serilog.Events; using Swashbuckle.AspNetCore.SwaggerUI; @@ -53,9 +52,32 @@ public static IApplicationBuilder UseSerilog(this IApplicationBuilder app, IConf return app; } - private static LogEventLevel DetermineSinkLogLevel(LogEventLevel? logLevel) + private static LogEventLevel DetermineSinkLogLevel(LogLevel? logLevel) { - return logLevel ?? LogEventLevel.Verbose; + if (logLevel == null) + { + return LogEventLevel.Error; + } + + switch (logLevel) + { + case LogLevel.Critical: + return LogEventLevel.Fatal; + case LogLevel.Trace: + return LogEventLevel.Verbose; + case LogLevel.Error: + return LogEventLevel.Error; + case LogLevel.Debug: + return LogEventLevel.Debug; + case LogLevel.Information: + return LogEventLevel.Information; + case LogLevel.None: + return LogEventLevel.Fatal; + case LogLevel.Warning: + return LogEventLevel.Warning; + default: + throw new ArgumentOutOfRangeException(nameof(logLevel),logLevel, "Unable to determine correct log event level."); + } } /// diff --git a/src/Promitor.Scraper.Tests.Unit/Configuration/RuntimeConfigurationUnitTest.cs b/src/Promitor.Scraper.Tests.Unit/Configuration/RuntimeConfigurationUnitTest.cs index 3cc752691..12416de5b 100644 --- a/src/Promitor.Scraper.Tests.Unit/Configuration/RuntimeConfigurationUnitTest.cs +++ b/src/Promitor.Scraper.Tests.Unit/Configuration/RuntimeConfigurationUnitTest.cs @@ -2,10 +2,10 @@ using System.Threading.Tasks; using Bogus; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; using Promitor.Core.Configuration; using Promitor.Core.Configuration.Model; using Promitor.Scraper.Tests.Unit.Generators.Config; -using Serilog.Events; using Xunit; namespace Promitor.Scraper.Tests.Unit.Configuration @@ -75,7 +75,7 @@ public async Task RuntimeConfiguration_HasConfiguredApplicationInsightsInstrumen public async Task RuntimeConfiguration_HasConfiguredApplicationInsightsVerbosity_UsesConfigured() { // Arrange - var verbosity = LogEventLevel.Error; + var verbosity = LogLevel.Error; var configuration = await RuntimeConfigurationGenerator.WithServerConfiguration() .WithApplicationInsightsTelemetry(verbosity: verbosity) .GenerateAsync(); @@ -93,7 +93,7 @@ public async Task RuntimeConfiguration_HasConfiguredApplicationInsightsVerbosity public async Task RuntimeConfiguration_HasConfiguredContainerLogVerbosity_UsesConfigured() { // Arrange - var verbosity = LogEventLevel.Error; + var verbosity = LogLevel.Error; var configuration = await RuntimeConfigurationGenerator.WithServerConfiguration() .WithContainerTelemetry(verbosity) .GenerateAsync(); @@ -111,7 +111,7 @@ public async Task RuntimeConfiguration_HasConfiguredContainerLogVerbosity_UsesCo public async Task RuntimeConfiguration_HasConfiguredDefaultTelemetryVerbosityConfigured_UsesConfigured() { // Arrange - var defaultVerbosity = LogEventLevel.Error; + var defaultVerbosity = LogLevel.Error; var configuration = await RuntimeConfigurationGenerator.WithServerConfiguration() .WithGeneralTelemetry(defaultVerbosity) .GenerateAsync(); diff --git a/src/Promitor.Scraper.Tests.Unit/Generators/Config/BogusRuntimeConfigurationGenerator.cs b/src/Promitor.Scraper.Tests.Unit/Generators/Config/BogusRuntimeConfigurationGenerator.cs index 48a1b57f6..4c69ffae2 100644 --- a/src/Promitor.Scraper.Tests.Unit/Generators/Config/BogusRuntimeConfigurationGenerator.cs +++ b/src/Promitor.Scraper.Tests.Unit/Generators/Config/BogusRuntimeConfigurationGenerator.cs @@ -1,11 +1,11 @@ using Bogus; +using Microsoft.Extensions.Logging; using Promitor.Core.Configuration.Model; using Promitor.Core.Configuration.Model.Metrics; using Promitor.Core.Configuration.Model.Prometheus; using Promitor.Core.Configuration.Model.Server; using Promitor.Core.Configuration.Model.Telemetry; using Promitor.Core.Configuration.Model.Telemetry.Sinks; -using Serilog.Events; namespace Promitor.Scraper.Tests.Unit.Generators.Config { @@ -34,20 +34,20 @@ internal static RuntimeConfiguration Generate() var containerLogConfiguration = new Faker() .StrictMode(true) - .RuleFor(containerConfiguration => containerConfiguration.Verbosity, faker => LogEventLevel.Error) + .RuleFor(containerConfiguration => containerConfiguration.Verbosity, faker => LogLevel.Error) .RuleFor(containerConfiguration => containerConfiguration.IsEnabled, faker => faker.Random.Bool()) .Generate(); var applicationInsightsConfiguration = new Faker() .StrictMode(true) - .RuleFor(containerConfiguration => containerConfiguration.Verbosity, faker => LogEventLevel.Error) + .RuleFor(containerConfiguration => containerConfiguration.Verbosity, faker => LogLevel.Error) .RuleFor(containerConfiguration => containerConfiguration.IsEnabled, faker => faker.Random.Bool()) .RuleFor(containerConfiguration => containerConfiguration.InstrumentationKey, faker => faker.Random.Guid().ToString()) .Generate(); var telemetryConfiguration = new Faker() .StrictMode(true) - .RuleFor(telemetry => telemetry.DefaultVerbosity, faker => LogEventLevel.Error) + .RuleFor(telemetry => telemetry.DefaultVerbosity, faker => LogLevel.Error) .RuleFor(telemetry => telemetry.ContainerLogs, faker => containerLogConfiguration) .RuleFor(telemetry => telemetry.ApplicationInsights, faker => applicationInsightsConfiguration) .Generate(); diff --git a/src/Promitor.Scraper.Tests.Unit/Generators/Config/RuntimeConfigurationGenerator.cs b/src/Promitor.Scraper.Tests.Unit/Generators/Config/RuntimeConfigurationGenerator.cs index 516a4cc88..38f7e9696 100644 --- a/src/Promitor.Scraper.Tests.Unit/Generators/Config/RuntimeConfigurationGenerator.cs +++ b/src/Promitor.Scraper.Tests.Unit/Generators/Config/RuntimeConfigurationGenerator.cs @@ -4,13 +4,13 @@ using System.Text; using System.Threading.Tasks; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; using Promitor.Core.Configuration.Model; using Promitor.Core.Configuration.Model.Metrics; using Promitor.Core.Configuration.Model.Prometheus; using Promitor.Core.Configuration.Model.Server; using Promitor.Core.Configuration.Model.Telemetry; using Promitor.Core.Configuration.Model.Telemetry.Sinks; -using Serilog.Events; namespace Promitor.Scraper.Tests.Unit.Generators.Config { @@ -97,7 +97,7 @@ public RuntimeConfigurationGenerator WithMetricsConfiguration(string absolutePat return this; } - public RuntimeConfigurationGenerator WithGeneralTelemetry(LogEventLevel? defaultVerbosity = LogEventLevel.Verbose) + public RuntimeConfigurationGenerator WithGeneralTelemetry(LogLevel? defaultVerbosity = LogLevel.Trace) { var telemetryConfiguration = defaultVerbosity == null ? null @@ -111,7 +111,7 @@ public RuntimeConfigurationGenerator WithGeneralTelemetry(LogEventLevel? default return this; } - public RuntimeConfigurationGenerator WithContainerTelemetry(LogEventLevel? verbosity = LogEventLevel.Verbose, bool? isEnabled = true) + public RuntimeConfigurationGenerator WithContainerTelemetry(LogLevel? verbosity = LogLevel.Trace, bool? isEnabled = true) { var containerLogConfiguration = verbosity == null && isEnabled == null ? null @@ -131,7 +131,7 @@ public RuntimeConfigurationGenerator WithContainerTelemetry(LogEventLevel? verbo return this; } - public RuntimeConfigurationGenerator WithApplicationInsightsTelemetry(string instrumentationKey = "XYZ", LogEventLevel? verbosity = LogEventLevel.Verbose, bool? isEnabled = true) + public RuntimeConfigurationGenerator WithApplicationInsightsTelemetry(string instrumentationKey = "XYZ", LogLevel? verbosity = LogLevel.Trace, bool? isEnabled = true) { var applicationInsightsTelemetry = verbosity == null && isEnabled == null && string.IsNullOrWhiteSpace(instrumentationKey) ? null From a5f2ecb6dc011fed053ba3d5b9401d01de891929 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Sat, 7 Dec 2019 19:00:28 +0100 Subject: [PATCH 26/38] Document traces for Application Insights --- changelog/content/experimental/unreleased.md | 1 + docs/configuration/v1.x/runtime.md | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/changelog/content/experimental/unreleased.md b/changelog/content/experimental/unreleased.md index 1f50930c7..709e78714 100644 --- a/changelog/content/experimental/unreleased.md +++ b/changelog/content/experimental/unreleased.md @@ -9,3 +9,4 @@ version: - {{% tag added %}} OpenAPI v3.0 support (`/api/v1/docs.json` | [#734](https://github.com/tomkerkhove/promitor/issues/734)) - {{% tag added %}} OpenAPI UI based on OpenAPI v3.0 (`/api/docs/` | [#734](https://github.com/tomkerkhove/promitor/issues/734)) - {{% tag changed %}} Helm Chart creates apps/v1 Deployment instead of v1beta1 ([#669](https://github.com/tomkerkhove/promitor/issues/669)) +- {{% tag added %}} Provide traces in Azure Application Insights diff --git a/docs/configuration/v1.x/runtime.md b/docs/configuration/v1.x/runtime.md index 4227fe880..18ac30e77 100644 --- a/docs/configuration/v1.x/runtime.md +++ b/docs/configuration/v1.x/runtime.md @@ -157,7 +157,8 @@ Promitor can send telemetry to Azure Application Insights when there is a need t It currently supports: -- Exceptions during scraping +- Traces _(starting of v1.1)_ +- Exceptions In order to enable use this sink, the following configuration needs to be provided: From 6750c7989e412d8a124d1ff94d2b9e5c8243e128 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Sat, 7 Dec 2019 19:03:57 +0100 Subject: [PATCH 27/38] Add issue number & docs for traces --- changelog/content/experimental/unreleased.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/changelog/content/experimental/unreleased.md b/changelog/content/experimental/unreleased.md index 709e78714..28c10f696 100644 --- a/changelog/content/experimental/unreleased.md +++ b/changelog/content/experimental/unreleased.md @@ -9,4 +9,5 @@ version: - {{% tag added %}} OpenAPI v3.0 support (`/api/v1/docs.json` | [#734](https://github.com/tomkerkhove/promitor/issues/734)) - {{% tag added %}} OpenAPI UI based on OpenAPI v3.0 (`/api/docs/` | [#734](https://github.com/tomkerkhove/promitor/issues/734)) - {{% tag changed %}} Helm Chart creates apps/v1 Deployment instead of v1beta1 ([#669](https://github.com/tomkerkhove/promitor/issues/669)) -- {{% tag added %}} Provide traces in Azure Application Insights +- {{% tag changed %}} Provide exceptions in Azure Application Insights for all exceptions, not just scraping ([docs](https://promitor.io/configuration/v1.x/runtime#azure-application-insights) | [#29](https://github.com/tomkerkhove/promitor/issues/29))) +- {{% tag added %}} Provide traces in Azure Application Insights ([docs](https://promitor.io/configuration/v1.x/runtime#azure-application-insights) | [#29](https://github.com/tomkerkhove/promitor/issues/29))) From 1f4f672ade5124c9b4ca80dc1ad2ec0050a90b70 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Sat, 7 Dec 2019 19:55:03 +0100 Subject: [PATCH 28/38] Update badges --- docs/configuration/v0.x/metrics/generic-azure-resource.md | 2 +- docs/configuration/v0.x/metrics/service-bus-queue.md | 2 +- docs/configuration/v1.x/metrics/container-instances.md | 2 +- docs/configuration/v1.x/metrics/container-registry.md | 2 +- docs/configuration/v1.x/metrics/cosmos-db.md | 2 +- docs/configuration/v1.x/metrics/generic-azure-resource.md | 2 +- docs/configuration/v1.x/metrics/network-interface.md | 2 +- docs/configuration/v1.x/metrics/postgresql.md | 2 +- docs/configuration/v1.x/metrics/redis-cache.md | 2 +- docs/configuration/v1.x/metrics/service-bus-queue.md | 2 +- docs/configuration/v1.x/metrics/sql-database.md | 2 +- docs/configuration/v1.x/metrics/storage-queue.md | 2 +- docs/configuration/v1.x/metrics/virtual-machine.md | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/configuration/v0.x/metrics/generic-azure-resource.md b/docs/configuration/v0.x/metrics/generic-azure-resource.md index c051cd442..ccc9fb1dd 100644 --- a/docs/configuration/v0.x/metrics/generic-azure-resource.md +++ b/docs/configuration/v0.x/metrics/generic-azure-resource.md @@ -3,7 +3,7 @@ layout: default title: Generic Azure Resource Declaration --- -## Generic Azure Resource - ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v0.2.0-green.svg) +## Generic Azure Resource - ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v0.2-green.svg) You can declare to scrape a generic Azure resource via the `Generic` resource type. diff --git a/docs/configuration/v0.x/metrics/service-bus-queue.md b/docs/configuration/v0.x/metrics/service-bus-queue.md index 6bbdf4b55..b89543b42 100644 --- a/docs/configuration/v0.x/metrics/service-bus-queue.md +++ b/docs/configuration/v0.x/metrics/service-bus-queue.md @@ -3,7 +3,7 @@ layout: default title: Azure Service Bus Queue Declaration --- -## Azure Service Bus Queue - ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v0.1.0-green.svg) +## Azure Service Bus Queue - ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v0.1-green.svg) You can declare to scrape an Azure Service Bus Queue via the `ServiceBusQueue` resource type. diff --git a/docs/configuration/v1.x/metrics/container-instances.md b/docs/configuration/v1.x/metrics/container-instances.md index 7b3f23d08..d8e6e04b8 100644 --- a/docs/configuration/v1.x/metrics/container-instances.md +++ b/docs/configuration/v1.x/metrics/container-instances.md @@ -3,7 +3,7 @@ layout: default title: Azure Container Instances Declaration --- -## Azure Container Instances - ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v1.0.0-green.svg) +## Azure Container Instances - ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v1.0-green.svg) You can declare to scrape an Azure Container Instances via the `ContainerInstance` resource type. diff --git a/docs/configuration/v1.x/metrics/container-registry.md b/docs/configuration/v1.x/metrics/container-registry.md index a34a316b2..6f2ac541d 100644 --- a/docs/configuration/v1.x/metrics/container-registry.md +++ b/docs/configuration/v1.x/metrics/container-registry.md @@ -3,7 +3,7 @@ layout: default title: Azure Container Registry Declaration --- -## Azure Container Registry - ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v1.0.0-green.svg) +## Azure Container Registry - ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v1.0-green.svg) You can declare to scrape an Azure Container Registry via the `ContainerRegistry` resource type. diff --git a/docs/configuration/v1.x/metrics/cosmos-db.md b/docs/configuration/v1.x/metrics/cosmos-db.md index c0dd8b76d..4e4f8d10c 100644 --- a/docs/configuration/v1.x/metrics/cosmos-db.md +++ b/docs/configuration/v1.x/metrics/cosmos-db.md @@ -3,7 +3,7 @@ layout: default title: Azure Cosmos Db Declaration --- -## Azure Cosmos Db - ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v1.0.0-green.svg) +## Azure Cosmos Db - ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v1.0-green.svg) You can declare to scrape Cosmos Db via the `CosmosDb` resource type. diff --git a/docs/configuration/v1.x/metrics/generic-azure-resource.md b/docs/configuration/v1.x/metrics/generic-azure-resource.md index f7ac4a8e5..bbcb46b1f 100644 --- a/docs/configuration/v1.x/metrics/generic-azure-resource.md +++ b/docs/configuration/v1.x/metrics/generic-azure-resource.md @@ -3,7 +3,7 @@ layout: default title: Generic Azure Resource Declaration --- -## Generic Azure Resource - ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v0.2.0-green.svg) +## Generic Azure Resource - ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v0.2-green.svg) You can declare to scrape a generic Azure resource via the `Generic` resource type. diff --git a/docs/configuration/v1.x/metrics/network-interface.md b/docs/configuration/v1.x/metrics/network-interface.md index c0b8fd0da..4f101e8a0 100644 --- a/docs/configuration/v1.x/metrics/network-interface.md +++ b/docs/configuration/v1.x/metrics/network-interface.md @@ -3,7 +3,7 @@ layout: default title: Azure Network Interface Declaration --- -## Azure Network Interface - ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v1.0.0-green.svg) +## Azure Network Interface - ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v1.0-green.svg) You can declare to scrape an [Azure Network Interface](https://docs.microsoft.com/en-us/azure/virtual-network/virtual-network-network-interface) via the `NetworkInterface` resource type. diff --git a/docs/configuration/v1.x/metrics/postgresql.md b/docs/configuration/v1.x/metrics/postgresql.md index ae3393996..d315a0b5d 100644 --- a/docs/configuration/v1.x/metrics/postgresql.md +++ b/docs/configuration/v1.x/metrics/postgresql.md @@ -3,7 +3,7 @@ layout: default title: Azure Database for PostgreSQL --- -## Azure Database for PostgreSQL - ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v1.0.0-green.svg) +## Azure Database for PostgreSQL - ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v1.0-green.svg) You can declare to scrape an Azure Database for PostgreSQL server via the `PostgreSql` resource type. diff --git a/docs/configuration/v1.x/metrics/redis-cache.md b/docs/configuration/v1.x/metrics/redis-cache.md index e118f9e67..7bba755fb 100644 --- a/docs/configuration/v1.x/metrics/redis-cache.md +++ b/docs/configuration/v1.x/metrics/redis-cache.md @@ -3,7 +3,7 @@ layout: default title: Azure Cache for Redis Declaration --- -## Azure Cache for Redis - ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v1.0.0-green.svg) +## Azure Cache for Redis - ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v1.0-green.svg) You can declare to scrape an Azure Cache for Redis via the `RedisCache` resource type. diff --git a/docs/configuration/v1.x/metrics/service-bus-queue.md b/docs/configuration/v1.x/metrics/service-bus-queue.md index 459ea0791..50e69cadb 100644 --- a/docs/configuration/v1.x/metrics/service-bus-queue.md +++ b/docs/configuration/v1.x/metrics/service-bus-queue.md @@ -3,7 +3,7 @@ layout: default title: Azure Service Bus Queue Declaration --- -## Azure Service Bus Queue - ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v0.1.0-green.svg) +## Azure Service Bus Queue - ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v0.1-green.svg) You can declare to scrape an Azure Service Bus Queue via the `ServiceBusQueue` resource type. diff --git a/docs/configuration/v1.x/metrics/sql-database.md b/docs/configuration/v1.x/metrics/sql-database.md index 19d0353f4..9d86725f9 100644 --- a/docs/configuration/v1.x/metrics/sql-database.md +++ b/docs/configuration/v1.x/metrics/sql-database.md @@ -3,7 +3,7 @@ layout: default title: Azure SQL Database Declaration --- -## Azure SQL Database - ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v1.1.0-green.svg) +## Azure SQL Database - ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v1.1-green.svg) You can scrape an Azure SQL Database via the `SqlDatabase` resource type. diff --git a/docs/configuration/v1.x/metrics/storage-queue.md b/docs/configuration/v1.x/metrics/storage-queue.md index 04b051559..3952c0358 100644 --- a/docs/configuration/v1.x/metrics/storage-queue.md +++ b/docs/configuration/v1.x/metrics/storage-queue.md @@ -3,7 +3,7 @@ layout: default title: Azure Storage Queue Declaration --- -## Azure Storage Queue - ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v1.0.0-green.svg) +## Azure Storage Queue - ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v1.0-green.svg) You can declare to scrape an Azure Queue via the `StorageQueue` resource type. diff --git a/docs/configuration/v1.x/metrics/virtual-machine.md b/docs/configuration/v1.x/metrics/virtual-machine.md index c89a646d7..3d4d8e248 100644 --- a/docs/configuration/v1.x/metrics/virtual-machine.md +++ b/docs/configuration/v1.x/metrics/virtual-machine.md @@ -3,7 +3,7 @@ layout: default title: Azure Virtual Machine Declaration --- -## Azure Virtual Machine - ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v1.0.0-green.svg) +## Azure Virtual Machine - ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v1.0-green.svg) You can declare to scrape an Azure Virtual Machine via the `VirtualMachine` resource type. From f6277f664b42062bb7b59afbb3aebb9019fb9572 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Sat, 7 Dec 2019 19:55:12 +0100 Subject: [PATCH 29/38] Dcoument exploring APIS --- changelog/content/experimental/unreleased.md | 4 ++-- docs/operations/index.md | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/changelog/content/experimental/unreleased.md b/changelog/content/experimental/unreleased.md index 28c10f696..cab871510 100644 --- a/changelog/content/experimental/unreleased.md +++ b/changelog/content/experimental/unreleased.md @@ -6,8 +6,8 @@ version: --- - {{% tag added %}} Azure SQL Database Scraper ([docs](https://promitor.io/configuration/v1.x/metrics/sql-database) | [#317](https://github.com/tomkerkhove/promitor/issues/317)) -- {{% tag added %}} OpenAPI v3.0 support (`/api/v1/docs.json` | [#734](https://github.com/tomkerkhove/promitor/issues/734)) -- {{% tag added %}} OpenAPI UI based on OpenAPI v3.0 (`/api/docs/` | [#734](https://github.com/tomkerkhove/promitor/issues/734)) +- {{% tag added %}} OpenAPI v3.0 support (`/api/v1/docs.json` | [docs](ttps://promitor.io/operations/#exploring-our-rest-apis) | [#734](https://github.com/tomkerkhove/promitor/issues/734)) +- {{% tag added %}} OpenAPI UI based on OpenAPI v3.0 (`/api/docs/` | [docs](ttps://promitor.io/operations/#exploring-our-rest-apis) | [#734](https://github.com/tomkerkhove/promitor/issues/734)) - {{% tag changed %}} Helm Chart creates apps/v1 Deployment instead of v1beta1 ([#669](https://github.com/tomkerkhove/promitor/issues/669)) - {{% tag changed %}} Provide exceptions in Azure Application Insights for all exceptions, not just scraping ([docs](https://promitor.io/configuration/v1.x/runtime#azure-application-insights) | [#29](https://github.com/tomkerkhove/promitor/issues/29))) - {{% tag added %}} Provide traces in Azure Application Insights ([docs](https://promitor.io/configuration/v1.x/runtime#azure-application-insights) | [#29](https://github.com/tomkerkhove/promitor/issues/29))) diff --git a/docs/operations/index.md b/docs/operations/index.md index 7f0381a36..b47cf185e 100644 --- a/docs/operations/index.md +++ b/docs/operations/index.md @@ -61,4 +61,16 @@ Therefor we provide the following REST APIs: For security reasons, some sections of the configuration might be sanitized in the response to avoid leaking secrets. +### Exploring our REST APIs + +We provide API documentation to make it easier for you to consume our REST APIs them: + +- **OpenAPI 3.0 format** ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v1.1-green.svg) + - You can explore it with OpenAPI UI on `/api/docs` + - You can find the raw documentation on `/api/v1/docs.json` +- **Swagger 2.0 format** [![Deprecation Badge](https://img.shields.io/badge/Deprecated%20as%20of-v1.1-red)](http://changelog.promitor.io/) + - You can explore it with Swagger UI on `/swagger` + - You can find the raw documentation on `/swagger/v1/swagger.json` + + [← back](/) From b29202626a11848f67febb29bce53c30856e885e Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Sat, 7 Dec 2019 20:06:17 +0100 Subject: [PATCH 30/38] Fix order --- changelog/content/experimental/unreleased.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/content/experimental/unreleased.md b/changelog/content/experimental/unreleased.md index cab871510..5bff390d6 100644 --- a/changelog/content/experimental/unreleased.md +++ b/changelog/content/experimental/unreleased.md @@ -8,6 +8,6 @@ version: - {{% tag added %}} Azure SQL Database Scraper ([docs](https://promitor.io/configuration/v1.x/metrics/sql-database) | [#317](https://github.com/tomkerkhove/promitor/issues/317)) - {{% tag added %}} OpenAPI v3.0 support (`/api/v1/docs.json` | [docs](ttps://promitor.io/operations/#exploring-our-rest-apis) | [#734](https://github.com/tomkerkhove/promitor/issues/734)) - {{% tag added %}} OpenAPI UI based on OpenAPI v3.0 (`/api/docs/` | [docs](ttps://promitor.io/operations/#exploring-our-rest-apis) | [#734](https://github.com/tomkerkhove/promitor/issues/734)) +- {{% tag added %}} Provide traces in Azure Application Insights ([docs](https://promitor.io/configuration/v1.x/runtime#azure-application-insights) | [#29](https://github.com/tomkerkhove/promitor/issues/29)) - {{% tag changed %}} Helm Chart creates apps/v1 Deployment instead of v1beta1 ([#669](https://github.com/tomkerkhove/promitor/issues/669)) - {{% tag changed %}} Provide exceptions in Azure Application Insights for all exceptions, not just scraping ([docs](https://promitor.io/configuration/v1.x/runtime#azure-application-insights) | [#29](https://github.com/tomkerkhove/promitor/issues/29))) -- {{% tag added %}} Provide traces in Azure Application Insights ([docs](https://promitor.io/configuration/v1.x/runtime#azure-application-insights) | [#29](https://github.com/tomkerkhove/promitor/issues/29))) From b2c3d736c6268af0708aef6121bf8ea228d5535c Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Sat, 7 Dec 2019 20:06:24 +0100 Subject: [PATCH 31/38] Use badge instead --- docs/configuration/v1.x/runtime.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/configuration/v1.x/runtime.md b/docs/configuration/v1.x/runtime.md index 18ac30e77..053ba35ef 100644 --- a/docs/configuration/v1.x/runtime.md +++ b/docs/configuration/v1.x/runtime.md @@ -157,7 +157,7 @@ Promitor can send telemetry to Azure Application Insights when there is a need t It currently supports: -- Traces _(starting of v1.1)_ +- Traces ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v1.1-green.svg) - Exceptions In order to enable use this sink, the following configuration needs to be provided: From f5d88bf07f025d59c4cded87a849049d6c74c43c Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Sat, 7 Dec 2019 20:19:11 +0100 Subject: [PATCH 32/38] Small fix for changelog --- changelog/content/experimental/unreleased.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/content/experimental/unreleased.md b/changelog/content/experimental/unreleased.md index 5bff390d6..cf3d85b5c 100644 --- a/changelog/content/experimental/unreleased.md +++ b/changelog/content/experimental/unreleased.md @@ -10,4 +10,4 @@ version: - {{% tag added %}} OpenAPI UI based on OpenAPI v3.0 (`/api/docs/` | [docs](ttps://promitor.io/operations/#exploring-our-rest-apis) | [#734](https://github.com/tomkerkhove/promitor/issues/734)) - {{% tag added %}} Provide traces in Azure Application Insights ([docs](https://promitor.io/configuration/v1.x/runtime#azure-application-insights) | [#29](https://github.com/tomkerkhove/promitor/issues/29)) - {{% tag changed %}} Helm Chart creates apps/v1 Deployment instead of v1beta1 ([#669](https://github.com/tomkerkhove/promitor/issues/669)) -- {{% tag changed %}} Provide exceptions in Azure Application Insights for all exceptions, not just scraping ([docs](https://promitor.io/configuration/v1.x/runtime#azure-application-insights) | [#29](https://github.com/tomkerkhove/promitor/issues/29))) +- {{% tag changed %}} Provide exceptions in Azure Application Insights for all exceptions, not just scraping ([docs](https://promitor.io/configuration/v1.x/runtime#azure-application-insights) | [#29](https://github.com/tomkerkhove/promitor/issues/29)) From 8f559e214b77cd430f1814bf2822489615502bd2 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Sat, 7 Dec 2019 20:22:28 +0100 Subject: [PATCH 33/38] Fix markdown styling --- docs/operations/index.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/docs/operations/index.md b/docs/operations/index.md index b47cf185e..b731486d5 100644 --- a/docs/operations/index.md +++ b/docs/operations/index.md @@ -66,11 +66,10 @@ the response to avoid leaking secrets. We provide API documentation to make it easier for you to consume our REST APIs them: - **OpenAPI 3.0 format** ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v1.1-green.svg) - - You can explore it with OpenAPI UI on `/api/docs` - - You can find the raw documentation on `/api/v1/docs.json` + - You can explore it with OpenAPI UI on `/api/docs` + - You can find the raw documentation on `/api/v1/docs.json` - **Swagger 2.0 format** [![Deprecation Badge](https://img.shields.io/badge/Deprecated%20as%20of-v1.1-red)](http://changelog.promitor.io/) - - You can explore it with Swagger UI on `/swagger` - - You can find the raw documentation on `/swagger/v1/swagger.json` - + - You can explore it with Swagger UI on `/swagger` + - You can find the raw documentation on `/swagger/v1/swagger.json` [← back](/) From d92c74815fa7616b97dd04fdde59d69e56df91d7 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Fri, 13 Dec 2019 12:30:49 +0100 Subject: [PATCH 34/38] Fix broken API endpoints --- .../Extensions/IApplicationBuilderExtensions.cs | 4 +++- .../Extensions/IServiceCollectionExtensions.cs | 3 ++- src/Promitor.Scraper.Host/Startup.cs | 10 ++++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs b/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs index 34f5c368e..28c1206c8 100644 --- a/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs +++ b/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs @@ -84,7 +84,7 @@ private static LogEventLevel DetermineSinkLogLevel(LogLevel? logLevel) /// Add support for Open API with API explorer /// /// Application Builder - public static void UseOpenApiUi(this IApplicationBuilder app) + public static IApplicationBuilder UseOpenApiUi(this IApplicationBuilder app) { // New Swagger UI app.UseSwagger(setupAction => setupAction.RouteTemplate = "api/{documentName}/docs.json"); @@ -103,6 +103,8 @@ public static void UseOpenApiUi(this IApplicationBuilder app) swaggerUiOptions.SwaggerEndpoint("/api/v1/docs.json", "Promitor API (OpenAPI 3.0)"); swaggerUiOptions.ConfigureDefaultOptions(); }); + + return app; } /// diff --git a/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs b/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs index ee91c1435..db28c6e12 100644 --- a/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs +++ b/src/Promitor.Scraper.Host/Extensions/IServiceCollectionExtensions.cs @@ -108,7 +108,8 @@ public static IServiceCollection UseHealthChecks(this IServiceCollection service /// public static IServiceCollection UseWebApi(this IServiceCollection services) { - services.AddControllers() + services.AddRouting() + .AddControllers() .AddJsonOptions(jsonOptions => { jsonOptions.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); diff --git a/src/Promitor.Scraper.Host/Startup.cs b/src/Promitor.Scraper.Host/Startup.cs index ae55c1958..fc658b0a9 100644 --- a/src/Promitor.Scraper.Host/Startup.cs +++ b/src/Promitor.Scraper.Host/Startup.cs @@ -28,7 +28,7 @@ public Startup(IConfiguration configuration) public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) - { + { app.UseDeveloperExceptionPage(); } @@ -36,7 +36,9 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) app.UsePrometheusScraper(_prometheusBaseUriPath) .UseSerilog(_configuration) - .UseOpenApiUi(); + .UseOpenApiUi() + .UseRouting() + .UseEndpoints(endpoints => endpoints.MapControllers()); } // This method gets called by the runtime. Use this method to add services to the container. @@ -45,10 +47,10 @@ public void ConfigureServices(IServiceCollection services) services.AddAutoMapper(typeof(V1MappingProfile).Assembly) .DefineDependencies() .ConfigureYamlConfiguration(_configuration) - .UseWebApi() .UseOpenApiSpecifications(_prometheusBaseUriPath, 1) .UseHealthChecks() - .ScheduleMetricScraping(); + .ScheduleMetricScraping() + .UseWebApi(); } private void ValidateRuntimeConfiguration(IApplicationBuilder app) From 1f57599493385082d2a47e326eb66f053f945c85 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Wed, 18 Dec 2019 08:52:34 +0100 Subject: [PATCH 35/38] Wire-up Serilog --- .../IApplicationBuilderExtensions.cs | 66 ------------------- src/Promitor.Scraper.Host/Program.cs | 66 ++++++++++++++++++- src/Promitor.Scraper.Host/Startup.cs | 1 - 3 files changed, 64 insertions(+), 69 deletions(-) diff --git a/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs b/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs index 28c1206c8..eded2a9b1 100644 --- a/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs +++ b/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs @@ -14,72 +14,6 @@ namespace Promitor.Scraper.Host.Extensions // ReSharper disable once InconsistentNaming public static class IApplicationBuilderExtensions { - /// - /// Use Serilog to emit logs to multiple sinks - /// - /// Application Builder - /// Configuration of the application - public static IApplicationBuilder UseSerilog(this IApplicationBuilder app, IConfiguration configuration) - { - var telemetryConfiguration = configuration.Get()?.Telemetry; - if (telemetryConfiguration == null) - { - throw new Exception("Unable to get telemetry configuration"); - } - - var defaultLogLevel = DetermineSinkLogLevel(telemetryConfiguration.DefaultVerbosity); - var loggerConfiguration = new LoggerConfiguration() - .MinimumLevel.Is(defaultLogLevel) - .Enrich.FromLogContext(); - - var appInsightsConfig = telemetryConfiguration.ApplicationInsights; - if (appInsightsConfig?.IsEnabled == true) - { - var logLevel = DetermineSinkLogLevel(appInsightsConfig.Verbosity); - loggerConfiguration.WriteTo.ApplicationInsights(appInsightsConfig.InstrumentationKey, TelemetryConverter.Traces, restrictedToMinimumLevel: logLevel); - } - - var consoleLogConfig = telemetryConfiguration.ContainerLogs; - if (consoleLogConfig?.IsEnabled == true) - { - var logLevel = DetermineSinkLogLevel(consoleLogConfig.Verbosity); - - loggerConfiguration.WriteTo.Console(restrictedToMinimumLevel: logLevel); - } - - Log.Logger = loggerConfiguration.CreateLogger(); - - return app; - } - - private static LogEventLevel DetermineSinkLogLevel(LogLevel? logLevel) - { - if (logLevel == null) - { - return LogEventLevel.Error; - } - - switch (logLevel) - { - case LogLevel.Critical: - return LogEventLevel.Fatal; - case LogLevel.Trace: - return LogEventLevel.Verbose; - case LogLevel.Error: - return LogEventLevel.Error; - case LogLevel.Debug: - return LogEventLevel.Debug; - case LogLevel.Information: - return LogEventLevel.Information; - case LogLevel.None: - return LogEventLevel.Fatal; - case LogLevel.Warning: - return LogEventLevel.Warning; - default: - throw new ArgumentOutOfRangeException(nameof(logLevel),logLevel, "Unable to determine correct log event level."); - } - } - /// /// Add support for Open API with API explorer /// diff --git a/src/Promitor.Scraper.Host/Program.cs b/src/Promitor.Scraper.Host/Program.cs index f2d10083e..b8a69b304 100644 --- a/src/Promitor.Scraper.Host/Program.cs +++ b/src/Promitor.Scraper.Host/Program.cs @@ -3,8 +3,11 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Promitor.Core.Configuration.Model; using Promitor.Core.Configuration.Model.Server; using Serilog; +using Serilog.Events; namespace Promitor.Scraper.Host { @@ -34,7 +37,7 @@ public static IHostBuilder BuildWebHost(string[] args) var endpointUrl = $"http://+:{httpPort}"; return Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder(args) - .UseSerilog() + .ConfigureWebHostDefaults(webHostBuilder => { webHostBuilder.UseKestrel(kestrelServerOptions => @@ -43,7 +46,8 @@ public static IHostBuilder BuildWebHost(string[] args) }) .UseConfiguration(configuration) .UseUrls(endpointUrl) - .UseStartup(); + .UseStartup() + .UseSerilog((hostingContext, loggerConfiguration) => ConfigureSerilog(configuration, loggerConfiguration)); }); } @@ -74,5 +78,63 @@ private static void ConfigureStartupLogging() .WriteTo.Console() .CreateLogger(); } + + public static LoggerConfiguration ConfigureSerilog(IConfiguration configuration, LoggerConfiguration loggerConfiguration) + { + var telemetryConfiguration = configuration.Get()?.Telemetry; + if (telemetryConfiguration == null) + { + throw new Exception("Unable to get telemetry configuration"); + } + + var defaultLogLevel = DetermineSinkLogLevel(telemetryConfiguration.DefaultVerbosity); + loggerConfiguration.MinimumLevel.Is(defaultLogLevel) + .Enrich.FromLogContext(); + + var appInsightsConfig = telemetryConfiguration.ApplicationInsights; + if (appInsightsConfig?.IsEnabled == true) + { + var logLevel = DetermineSinkLogLevel(appInsightsConfig.Verbosity); + loggerConfiguration.WriteTo.ApplicationInsights(appInsightsConfig.InstrumentationKey, TelemetryConverter.Traces, restrictedToMinimumLevel: logLevel); + } + + var consoleLogConfig = telemetryConfiguration.ContainerLogs; + if (consoleLogConfig?.IsEnabled == true) + { + var logLevel = DetermineSinkLogLevel(consoleLogConfig.Verbosity); + + loggerConfiguration.WriteTo.Console(restrictedToMinimumLevel: logLevel); + } + + return loggerConfiguration; + } + + private static LogEventLevel DetermineSinkLogLevel(LogLevel? logLevel) + { + if (logLevel == null) + { + return LogEventLevel.Verbose; + } + + switch (logLevel) + { + case LogLevel.Critical: + return LogEventLevel.Fatal; + case LogLevel.Trace: + return LogEventLevel.Verbose; + case LogLevel.Error: + return LogEventLevel.Error; + case LogLevel.Debug: + return LogEventLevel.Debug; + case LogLevel.Information: + return LogEventLevel.Information; + case LogLevel.None: + return LogEventLevel.Fatal; + case LogLevel.Warning: + return LogEventLevel.Warning; + default: + throw new ArgumentOutOfRangeException(nameof(logLevel), logLevel, "Unable to determine correct log event level."); + } + } } } \ No newline at end of file diff --git a/src/Promitor.Scraper.Host/Startup.cs b/src/Promitor.Scraper.Host/Startup.cs index fc658b0a9..37762418e 100644 --- a/src/Promitor.Scraper.Host/Startup.cs +++ b/src/Promitor.Scraper.Host/Startup.cs @@ -35,7 +35,6 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) ValidateRuntimeConfiguration(app); app.UsePrometheusScraper(_prometheusBaseUriPath) - .UseSerilog(_configuration) .UseOpenApiUi() .UseRouting() .UseEndpoints(endpoints => endpoints.MapControllers()); From a975fd6e58c33411b2cdd1b13730901103f7c737 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Wed, 18 Dec 2019 08:52:48 +0100 Subject: [PATCH 36/38] Tweak logs --- .../Prometheus/PrometheusMetricWriter.cs | 2 +- src/Promitor.Core.Scraping/Scraper.cs | 4 ++-- .../AzureStorageQueueClient.cs | 2 +- src/Promitor.Scraper.Host/Docs/Open-Api.xml | 7 ------- src/Promitor.Scraper.Host/Scheduling/MetricScrapingJob.cs | 6 +++--- 5 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/Promitor.Core.Scraping/Prometheus/PrometheusMetricWriter.cs b/src/Promitor.Core.Scraping/Prometheus/PrometheusMetricWriter.cs index 99101771b..361854605 100644 --- a/src/Promitor.Core.Scraping/Prometheus/PrometheusMetricWriter.cs +++ b/src/Promitor.Core.Scraping/Prometheus/PrometheusMetricWriter.cs @@ -51,7 +51,7 @@ private double DetermineMetricMeasurement(ScrapeResult scrapedMetricResult) { if (labels.ContainsKey(customLabel.Key)) { - _logger.LogWarning("Custom label '{CustomLabelName}' was already specified with value 'LabelValue' instead of 'CustomLabelValue'. Ignoring...", customLabel.Key, labels[customLabel.Key], customLabel.Value); + _logger.LogWarning("Custom label {CustomLabelName} was already specified with value 'LabelValue' instead of 'CustomLabelValue'. Ignoring...", customLabel.Key, labels[customLabel.Key], customLabel.Value); continue; } diff --git a/src/Promitor.Core.Scraping/Scraper.cs b/src/Promitor.Core.Scraping/Scraper.cs index 7df8d88d5..8929d8790 100644 --- a/src/Promitor.Core.Scraping/Scraper.cs +++ b/src/Promitor.Core.Scraping/Scraper.cs @@ -67,7 +67,7 @@ public async Task ScrapeAsync(ScrapeDefinition scrapeDe var castedMetricDefinition = scrapeDefinition.Resource as TResourceDefinition; if (castedMetricDefinition == null) { - throw new ArgumentException($"Could not cast metric definition of type '{scrapeDefinition.Resource.ResourceType}' to {typeof(TResourceDefinition)}. Payload: {JsonConvert.SerializeObject(scrapeDefinition)}"); + throw new ArgumentException($"Could not cast metric definition of type {scrapeDefinition.Resource.ResourceType} to {typeof(TResourceDefinition)}. Payload: {JsonConvert.SerializeObject(scrapeDefinition)}"); } var aggregationInterval = scrapeDefinition.AzureMetricConfiguration.Aggregation.Interval; @@ -79,7 +79,7 @@ public async Task ScrapeAsync(ScrapeDefinition scrapeDe aggregationType, aggregationInterval.Value); - _logger.LogInformation("Found value '{MetricValue}' for metric '{MetricName}' with aggregation interval '{AggregationInterval}'", scrapedMetricResult, scrapeDefinition.PrometheusMetricDefinition.Name, aggregationInterval); + _logger.LogInformation("Found value {MetricValue} for metric {MetricName} with aggregation interval {AggregationInterval}", scrapedMetricResult, scrapeDefinition.PrometheusMetricDefinition.Name, aggregationInterval); _prometheusMetricWriter.ReportMetric(scrapeDefinition.PrometheusMetricDefinition, scrapedMetricResult); } diff --git a/src/Promitor.Integrations.AzureStorage/AzureStorageQueueClient.cs b/src/Promitor.Integrations.AzureStorage/AzureStorageQueueClient.cs index ddf728dab..5b5ce47ab 100644 --- a/src/Promitor.Integrations.AzureStorage/AzureStorageQueueClient.cs +++ b/src/Promitor.Integrations.AzureStorage/AzureStorageQueueClient.cs @@ -33,7 +33,7 @@ public async Task GetQueueMessageCountAsync(string accountName, string queu await queue.FetchAttributesAsync(); var messageCount = queue.ApproximateMessageCount ?? 0; - _logger.LogInformation("Current size of queue {0} is {1}", queueName, messageCount); + _logger.LogInformation("Current size of queue {QueueName} is {Count}", queueName, messageCount); return messageCount; } diff --git a/src/Promitor.Scraper.Host/Docs/Open-Api.xml b/src/Promitor.Scraper.Host/Docs/Open-Api.xml index 605f37c08..0aa869dd2 100644 --- a/src/Promitor.Scraper.Host/Docs/Open-Api.xml +++ b/src/Promitor.Scraper.Host/Docs/Open-Api.xml @@ -22,13 +22,6 @@ Provides an indication about the health of the scraper - - - Use Serilog to emit logs to multiple sinks - - Application Builder - Configuration of the application - Add support for Open API with API explorer diff --git a/src/Promitor.Scraper.Host/Scheduling/MetricScrapingJob.cs b/src/Promitor.Scraper.Host/Scheduling/MetricScrapingJob.cs index 35e69850d..c3c67ce08 100644 --- a/src/Promitor.Scraper.Host/Scheduling/MetricScrapingJob.cs +++ b/src/Promitor.Scraper.Host/Scheduling/MetricScrapingJob.cs @@ -61,7 +61,7 @@ private void ConfigureJob() public async Task ExecuteAsync(CancellationToken cancellationToken) { - _logger.LogInformation("Scraping Azure Monitor - {timestamp}", DateTimeOffset.Now); + _logger.LogInformation("Scraping Azure Monitor - {Timestamp}", DateTimeOffset.UtcNow); var scrapeConfiguration = _metricsDeclarationProvider.Get(); try @@ -70,13 +70,13 @@ public async Task ExecuteAsync(CancellationToken cancellationToken) } catch (Exception exception) { - _logger.LogCritical(exception, $"Failed to scrape: {exception.Message}"); + _logger.LogCritical(exception, "Failed to scrape: {Exception}", exception.Message); } } private async Task ScrapeMetric(AzureMetadata azureMetadata, ScrapeDefinition metricDefinitionDefinition) { - _logger.LogInformation("Scraping '{MetricName}' for resource type '{ResourceType}'", metricDefinitionDefinition.PrometheusMetricDefinition.Name, metricDefinitionDefinition.Resource.ResourceType); + _logger.LogInformation("Scraping {MetricName} for resource type {ResourceType}", metricDefinitionDefinition.PrometheusMetricDefinition.Name, metricDefinitionDefinition.Resource.ResourceType); var scraper = _metricScraperFactory.CreateScraper(metricDefinitionDefinition.Resource.ResourceType, azureMetadata, _prometheusMetricWriter, _runtimeMetricsCollector); await scraper.ScrapeAsync(metricDefinitionDefinition); From 02c85100a945b6996b05560738ea661973d06872 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Wed, 18 Dec 2019 09:10:57 +0100 Subject: [PATCH 37/38] Add request logging --- src/Promitor.Scraper.Host/Startup.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Promitor.Scraper.Host/Startup.cs b/src/Promitor.Scraper.Host/Startup.cs index 37762418e..fa0a1f718 100644 --- a/src/Promitor.Scraper.Host/Startup.cs +++ b/src/Promitor.Scraper.Host/Startup.cs @@ -8,6 +8,7 @@ using Promitor.Core.Scraping.Configuration.Serialization.v1.Mapping; using Promitor.Scraper.Host.Extensions; using Promitor.Scraper.Host.Validation; +using Serilog; namespace Promitor.Scraper.Host { @@ -36,6 +37,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) app.UsePrometheusScraper(_prometheusBaseUriPath) .UseOpenApiUi() + .UseSerilogRequestLogging() .UseRouting() .UseEndpoints(endpoints => endpoints.MapControllers()); } From 6f319571c6dd241dd4605ccf34678fe3a6b41361 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Wed, 18 Dec 2019 09:12:05 +0100 Subject: [PATCH 38/38] Cleanup for code quality --- .../Extensions/IApplicationBuilderExtensions.cs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs b/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs index eded2a9b1..0862fde2e 100644 --- a/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs +++ b/src/Promitor.Scraper.Host/Extensions/IApplicationBuilderExtensions.cs @@ -1,11 +1,5 @@ -using System; -using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; +using Microsoft.AspNetCore.Builder; using Prometheus.Client.AspNetCore; -using Promitor.Core.Configuration.Model; -using Serilog; -using Serilog.Events; using Swashbuckle.AspNetCore.SwaggerUI; // ReSharper disable once CheckNamespace