Skip to content

Commit

Permalink
Provide capability to configure log verbosity (#553)
Browse files Browse the repository at this point in the history
* Provide docs

* Provide capability to configure log verbosity

* PROMITOR_LOGGING_MINIMUMLOGLEVEL -> PROMITOR_LOGGING_MINIMUMLEVEL

* Docs - Change headers
  • Loading branch information
tomkerkhove authored May 16, 2019
1 parent dca4f24 commit c7950a9
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 17 deletions.
8 changes: 7 additions & 1 deletion docs/configuration/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 Providers
Promitor can send telemetry to Azure Application Insights when there is a need to.

It currently supports:
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 & External Providers](configuration#logging)
- **Operations**
- [Azure Resource Manager API - Consumption & Throttling](operations#azure-resource-manager-api---consumption--throttling)
- [Health](operations#health)
Expand Down
26 changes: 26 additions & 0 deletions src/Promitor.Core.Telemetry/Loggers/Logger.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
11 changes: 11 additions & 0 deletions src/Promitor.Core.Telemetry/Loggers/RuntimeLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma warning disable 618

namespace Promitor.Core.Telemetry.Loggers
{
public class RuntimeLogger : Logger
{
public RuntimeLogger() : base("Runtime")
{
}
}
}
11 changes: 11 additions & 0 deletions src/Promitor.Core.Telemetry/Loggers/ValidationLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma warning disable 618

namespace Promitor.Core.Telemetry.Loggers
{
public class ValidationLogger : Logger
{
public ValidationLogger() : base("Validation")
{
}
}
}
12 changes: 0 additions & 12 deletions src/Promitor.Core.Telemetry/RuntimeLogger.cs

This file was deleted.

5 changes: 5 additions & 0 deletions src/Promitor.Core/EnvironmentVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,10 @@ public class Telemetry
{
public const string InstrumentationKey = "PROMITOR_TELEMETRY_INSTRUMENTATIONKEY";
}

public class Logging
{
public const string MinimumLogLevel = "PROMITOR_LOGGING_MINIMUMLEVEL";
}
}
}
1 change: 1 addition & 0 deletions src/Promitor.Scraper.Host/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/Promitor.Scraper.Host/Validation/RuntimeValidator.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<IValidationStep>
Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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_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"

0 comments on commit c7950a9

Please sign in to comment.