From 24ea8d6768bdb2e55cc99a77ddc71d28fbe21903 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Thu, 16 May 2019 13:06:18 +0200 Subject: [PATCH 1/4] Provide docs --- docs/configuration/index.md | 8 +++++++- docs/index.md | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/configuration/index.md b/docs/configuration/index.md index 7c90ea8f9..21510167d 100644 --- a/docs/configuration/index.md +++ b/docs/configuration/index.md @@ -30,7 +30,13 @@ This information can be found on the newly created AD Application as documented The entity in the Azure AD needs to have `Monitoring Reader` permission on the resource group that will be queried. More information can be found [here](https://docs.microsoft.com/en-us/azure/monitoring-and-diagnostics/monitoring-roles-permissions-security). -# Telemetry +# Logging & Telemetry +We provide insights in how our runtime is doing and is written to `stdout`. + +This can be controlled via the following environment variables: +- **PROMITOR_LOGGING_MINIMUMLOGLEVEL** - Defines the minimum log level that should be logged. If none is configured, `Warning` will be used. Allowed values are `Trace`, `Debug`, `Information`, `Warning`, `Error`, `Critical`, `None` ordered from most to least verbose. + +## External Telemetry Promitor can send telemetry to Azure Application Insights when there is a need to. It currently supports: diff --git a/docs/index.md b/docs/index.md index 1e777b5cf..22500aaeb 100644 --- a/docs/index.md +++ b/docs/index.md @@ -47,7 +47,7 @@ And there is more on the way - Check our [backlog](https://github.com/tomkerkhov - [Runtime](configuration#runtime) - [Scraping](configuration#scraping) - [Authentication with Azure Monitor](configuration#authentication-with-azure-monitor) - - [Telemetry](configuration#telemetry) + - [Logging & Telemetry](configuration#logging-&-telemetry) - **Operations** - [Azure Resource Manager API - Consumption & Throttling](operations#azure-resource-manager-api---consumption--throttling) - [Health](operations#health) From a368eb38b9164020455771131d1ea8670385d900 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Thu, 16 May 2019 13:06:38 +0200 Subject: [PATCH 2/4] Provide capability to configure log verbosity --- src/Promitor.Core.Telemetry/Loggers/Logger.cs | 26 +++++++++++++++++++ .../Loggers/RuntimeLogger.cs | 11 ++++++++ .../Loggers/ValidationLogger.cs | 11 ++++++++ src/Promitor.Core.Telemetry/RuntimeLogger.cs | 12 --------- src/Promitor.Core/EnvironmentVariables.cs | 5 ++++ src/Promitor.Scraper.Host/Startup.cs | 1 + .../Validation/RuntimeValidator.cs | 6 ++--- src/docker-compose.override.yml | 1 + 8 files changed, 58 insertions(+), 15 deletions(-) create mode 100644 src/Promitor.Core.Telemetry/Loggers/Logger.cs create mode 100644 src/Promitor.Core.Telemetry/Loggers/RuntimeLogger.cs create mode 100644 src/Promitor.Core.Telemetry/Loggers/ValidationLogger.cs delete mode 100644 src/Promitor.Core.Telemetry/RuntimeLogger.cs diff --git a/src/Promitor.Core.Telemetry/Loggers/Logger.cs b/src/Promitor.Core.Telemetry/Loggers/Logger.cs new file mode 100644 index 000000000..33a4addaf --- /dev/null +++ b/src/Promitor.Core.Telemetry/Loggers/Logger.cs @@ -0,0 +1,26 @@ +using System; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Console; + +#pragma warning disable 618 + +namespace Promitor.Core.Telemetry.Loggers +{ + public class Logger : ConsoleLogger + { + public Logger(string name) : base(name, (loggerName, logLevel) => IsFilteringRequired(logLevel), includeScopes: true) + { + } + + private static bool IsFilteringRequired(LogLevel usedLogLevel) + { + var rawMinimalLogLevel = Environment.GetEnvironmentVariable(EnvironmentVariables.Logging.MinimumLogLevel); + if (Enum.TryParse(rawMinimalLogLevel, out LogLevel minimalLogLevel)) + { + return minimalLogLevel <= usedLogLevel; + } + + return LogLevel.Warning <= 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 new file mode 100644 index 000000000..a83aaa553 --- /dev/null +++ b/src/Promitor.Core.Telemetry/Loggers/RuntimeLogger.cs @@ -0,0 +1,11 @@ +#pragma warning disable 618 + +namespace Promitor.Core.Telemetry.Loggers +{ + public class RuntimeLogger : Logger + { + public RuntimeLogger() : base("Runtime") + { + } + } +} \ No newline at end of file diff --git a/src/Promitor.Core.Telemetry/Loggers/ValidationLogger.cs b/src/Promitor.Core.Telemetry/Loggers/ValidationLogger.cs new file mode 100644 index 000000000..835c32ed8 --- /dev/null +++ b/src/Promitor.Core.Telemetry/Loggers/ValidationLogger.cs @@ -0,0 +1,11 @@ +#pragma warning disable 618 + +namespace Promitor.Core.Telemetry.Loggers +{ + public class ValidationLogger : Logger + { + public ValidationLogger() : base("Validation") + { + } + } +} \ No newline at end of file diff --git a/src/Promitor.Core.Telemetry/RuntimeLogger.cs b/src/Promitor.Core.Telemetry/RuntimeLogger.cs deleted file mode 100644 index 0f87ac564..000000000 --- a/src/Promitor.Core.Telemetry/RuntimeLogger.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Microsoft.Extensions.Logging.Console; -#pragma warning disable 618 - -namespace Promitor.Core.Telemetry -{ - public class RuntimeLogger : ConsoleLogger - { - public RuntimeLogger() : base("Runtime", (loggerName, logLevel) => true, includeScopes: true) - { - } - } -} \ No newline at end of file diff --git a/src/Promitor.Core/EnvironmentVariables.cs b/src/Promitor.Core/EnvironmentVariables.cs index 97831057c..f94667486 100644 --- a/src/Promitor.Core/EnvironmentVariables.cs +++ b/src/Promitor.Core/EnvironmentVariables.cs @@ -28,5 +28,10 @@ public class Telemetry { public const string InstrumentationKey = "PROMITOR_TELEMETRY_INSTRUMENTATIONKEY"; } + + public class Logging + { + public const string MinimumLogLevel = "PROMITOR_LOGGING_MINIMUMLOGLEVEL"; + } } } \ No newline at end of file diff --git a/src/Promitor.Scraper.Host/Startup.cs b/src/Promitor.Scraper.Host/Startup.cs index 29c4f4889..62eb9e7df 100644 --- a/src/Promitor.Scraper.Host/Startup.cs +++ b/src/Promitor.Scraper.Host/Startup.cs @@ -8,6 +8,7 @@ using Promitor.Core.Scraping.Configuration.Providers.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.Extensions; diff --git a/src/Promitor.Scraper.Host/Validation/RuntimeValidator.cs b/src/Promitor.Scraper.Host/Validation/RuntimeValidator.cs index 65d2cfe14..664c05558 100644 --- a/src/Promitor.Scraper.Host/Validation/RuntimeValidator.cs +++ b/src/Promitor.Scraper.Host/Validation/RuntimeValidator.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; using System.Linq; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Console; using Promitor.Core.Scraping.Configuration.Providers; +using Promitor.Core.Telemetry.Loggers; using Promitor.Scraper.Host.Validation.Exceptions; using Promitor.Scraper.Host.Validation.Interfaces; using Promitor.Scraper.Host.Validation.Steps; @@ -17,7 +17,7 @@ public class RuntimeValidator public RuntimeValidator() { - _validationLogger = new ConsoleLogger("Validation", (message, logLevel) => true, includeScopes: true); + _validationLogger = new ValidationLogger(); var scrapeConfigurationProvider = new MetricsDeclarationProvider(_validationLogger); _validationSteps = new List @@ -31,7 +31,7 @@ public RuntimeValidator() public void Run() { - var validationLogger = new ConsoleLogger("Validation", (message, logLevel) => true, includeScopes: true); + var validationLogger = new ValidationLogger(); validationLogger.LogInformation("Starting validation of Promitor setup"); var validationResults = RunValidationSteps(); diff --git a/src/docker-compose.override.yml b/src/docker-compose.override.yml index 1d7329e2e..678ed304f 100644 --- a/src/docker-compose.override.yml +++ b/src/docker-compose.override.yml @@ -8,6 +8,7 @@ services: - PROMITOR_AUTH_APPID=ceb249a3-44ce-4c90-8863-6776336f5b7e - PROMITOR_AUTH_APPKEY=ZgLy6zYNh9SEmIl0B+rv+ZuQQ2wJyQi/tTXnp2Wp9PM= - PROMITOR_TELEMETRY_INSTRUMENTATIONKEY= + - PROMITOR_LOGGING_MINIMUMLOGLEVEL=Trace - "SECRETS_STORAGEQUEUE_SAS=?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-07-28T02:33:14Z&st=2019-03-24T18:33:14Z&spr=https&sig=OiwNEYueCWlOhveapM1K6cRgV%2Be21gNhoq%2FDZqJEMZE%3D" ports: - "88" \ No newline at end of file From dc650b2e22591f7d762414ceaceeee34a958b380 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Thu, 16 May 2019 13:09:26 +0200 Subject: [PATCH 3/4] PROMITOR_LOGGING_MINIMUMLOGLEVEL -> PROMITOR_LOGGING_MINIMUMLEVEL --- docs/configuration/index.md | 2 +- src/Promitor.Core/EnvironmentVariables.cs | 2 +- src/docker-compose.override.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/configuration/index.md b/docs/configuration/index.md index 21510167d..2ba39d335 100644 --- a/docs/configuration/index.md +++ b/docs/configuration/index.md @@ -34,7 +34,7 @@ The entity in the Azure AD needs to have `Monitoring Reader` permission on the r We provide insights in how our runtime is doing and is written to `stdout`. This can be controlled via the following environment variables: -- **PROMITOR_LOGGING_MINIMUMLOGLEVEL** - Defines the minimum log level that should be logged. If none is configured, `Warning` will be used. Allowed values are `Trace`, `Debug`, `Information`, `Warning`, `Error`, `Critical`, `None` ordered from most to least verbose. +- **PROMITOR_LOGGING_MINIMUMLEVEL** - Defines the minimum log level that should be logged. If none is configured, `Warning` will be used. Allowed values are `Trace`, `Debug`, `Information`, `Warning`, `Error`, `Critical`, `None` ordered from most to least verbose. ## External Telemetry Promitor can send telemetry to Azure Application Insights when there is a need to. diff --git a/src/Promitor.Core/EnvironmentVariables.cs b/src/Promitor.Core/EnvironmentVariables.cs index f94667486..fcdb734c6 100644 --- a/src/Promitor.Core/EnvironmentVariables.cs +++ b/src/Promitor.Core/EnvironmentVariables.cs @@ -31,7 +31,7 @@ public class Telemetry public class Logging { - public const string MinimumLogLevel = "PROMITOR_LOGGING_MINIMUMLOGLEVEL"; + public const string MinimumLogLevel = "PROMITOR_LOGGING_MINIMUMLEVEL"; } } } \ No newline at end of file diff --git a/src/docker-compose.override.yml b/src/docker-compose.override.yml index 678ed304f..5a17659d3 100644 --- a/src/docker-compose.override.yml +++ b/src/docker-compose.override.yml @@ -8,7 +8,7 @@ services: - PROMITOR_AUTH_APPID=ceb249a3-44ce-4c90-8863-6776336f5b7e - PROMITOR_AUTH_APPKEY=ZgLy6zYNh9SEmIl0B+rv+ZuQQ2wJyQi/tTXnp2Wp9PM= - PROMITOR_TELEMETRY_INSTRUMENTATIONKEY= - - PROMITOR_LOGGING_MINIMUMLOGLEVEL=Trace + - PROMITOR_LOGGING_MINIMUMLEVEL=Trace - "SECRETS_STORAGEQUEUE_SAS=?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-07-28T02:33:14Z&st=2019-03-24T18:33:14Z&spr=https&sig=OiwNEYueCWlOhveapM1K6cRgV%2Be21gNhoq%2FDZqJEMZE%3D" ports: - "88" \ No newline at end of file From 490191a624e8ab93f36f63a36eb69d530f933425 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Thu, 16 May 2019 13:12:10 +0200 Subject: [PATCH 4/4] Docs - Change headers --- docs/configuration/index.md | 4 ++-- docs/index.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/configuration/index.md b/docs/configuration/index.md index 2ba39d335..08bc79bd9 100644 --- a/docs/configuration/index.md +++ b/docs/configuration/index.md @@ -30,13 +30,13 @@ This information can be found on the newly created AD Application as documented The entity in the Azure AD needs to have `Monitoring Reader` permission on the resource group that will be queried. More information can be found [here](https://docs.microsoft.com/en-us/azure/monitoring-and-diagnostics/monitoring-roles-permissions-security). -# Logging & Telemetry +# Logging We provide insights in how our runtime is doing and is written to `stdout`. This can be controlled via the following environment variables: - **PROMITOR_LOGGING_MINIMUMLEVEL** - Defines the minimum log level that should be logged. If none is configured, `Warning` will be used. Allowed values are `Trace`, `Debug`, `Information`, `Warning`, `Error`, `Critical`, `None` ordered from most to least verbose. -## External Telemetry +## External Providers Promitor can send telemetry to Azure Application Insights when there is a need to. It currently supports: diff --git a/docs/index.md b/docs/index.md index 22500aaeb..c9cf8eb55 100644 --- a/docs/index.md +++ b/docs/index.md @@ -47,7 +47,7 @@ And there is more on the way - Check our [backlog](https://github.com/tomkerkhov - [Runtime](configuration#runtime) - [Scraping](configuration#scraping) - [Authentication with Azure Monitor](configuration#authentication-with-azure-monitor) - - [Logging & Telemetry](configuration#logging-&-telemetry) + - [Logging & External Providers](configuration#logging) - **Operations** - [Azure Resource Manager API - Consumption & Throttling](operations#azure-resource-manager-api---consumption--throttling) - [Health](operations#health)