-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to runtime configuration YAML (#608)
* Provide foundation for config via YAML * ENV over YAML * Provide environment variables with prefix as well Signed-off-by: Tom Kerkhove <[email protected]> * WIP Signed-off-by: Tom Kerkhove <[email protected]> * WIP Signed-off-by: Tom Kerkhove <[email protected]> * Improve defaults Signed-off-by: Tom Kerkhove <[email protected]> * Simplify * Break all the things Signed-off-by: Tom Kerkhove <[email protected]> * Improve code quality * Clean-up Dockerfile * Remove temporary variable * Code quality fixes * Re-enable runtime validation Signed-off-by: Tom Kerkhove <[email protected]> * Code quality Signed-off-by: Tom Kerkhove <[email protected]> * Provide foundation for config via YAML * ENV over YAML * Provide environment variables with prefix as well Signed-off-by: Tom Kerkhove <[email protected]> * WIP Signed-off-by: Tom Kerkhove <[email protected]> * WIP Signed-off-by: Tom Kerkhove <[email protected]> * Improve defaults Signed-off-by: Tom Kerkhove <[email protected]> * Simplify * Break all the things Signed-off-by: Tom Kerkhove <[email protected]> * Improve code quality * Clean-up Dockerfile * Remove temporary variable * Code quality fixes * Re-enable runtime validation Signed-off-by: Tom Kerkhove <[email protected]> * Code quality Signed-off-by: Tom Kerkhove <[email protected]> * Inject logger * WIP * Code cleanup Signed-off-by: Tom Kerkhove <[email protected]> * Provide very basic & ugly bogus + runtime config generator * Code cleanup * WIP Signed-off-by: Tom Kerkhove <[email protected]> * Provide more tests * Code cleanup Signed-off-by: Tom Kerkhove <[email protected]> * Most specific over least specific verbosity for logging * Add new volume mount to landing page * Fix configuration for Application Insights * Fix inverted flag for disabling telemetry
- Loading branch information
1 parent
ddd9dfe
commit fca5900
Showing
72 changed files
with
1,467 additions
and
544 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Promitor.Core.Configuration | ||
{ | ||
public static class Defaults | ||
{ | ||
public static class Server | ||
{ | ||
public static int HttpPort { get; } = 80; | ||
} | ||
|
||
public static class Prometheus | ||
{ | ||
public static string ScrapeEndpointBaseUri { get; } = "/metrics"; | ||
} | ||
|
||
public static class MetricsConfiguration | ||
{ | ||
public static string AbsolutePath { get; } = "/config/metrics-declaration.yaml"; | ||
} | ||
|
||
public class Telemetry | ||
{ | ||
public static LogLevel? DefaultVerbosity { get; set; } = null; | ||
|
||
public class ContainerLogs | ||
{ | ||
public static LogLevel? Verbosity { get; set; } = null; | ||
public static bool IsEnabled { get; set; } = true; | ||
} | ||
|
||
public class ApplicationInsights | ||
{ | ||
public static LogLevel? Verbosity { get; set; } = null; | ||
public static bool IsEnabled { get; set; } = true; | ||
} | ||
} | ||
|
||
public static class FeatureFlags | ||
{ | ||
public static bool DisableMetricTimestamps { get; set; } = false; | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/Promitor.Core.Configuration/FeatureFlags/FeatureToggleClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using Microsoft.Extensions.Options; | ||
using Promitor.Core.Configuration.Model.FeatureFlags; | ||
|
||
namespace Promitor.Core.Configuration.FeatureFlags | ||
{ | ||
public class FeatureToggleClient | ||
{ | ||
private readonly IOptionsMonitor<FeatureFlagsConfiguration> _featureFlagConfiguration; | ||
|
||
public FeatureToggleClient(IOptionsMonitor<FeatureFlagsConfiguration> featureFlagConfiguration) | ||
{ | ||
_featureFlagConfiguration = featureFlagConfiguration; | ||
} | ||
|
||
/// <summary> | ||
/// Determine if a feature flag is active or not | ||
/// </summary> | ||
/// <param name="toggleName">Name of the feature flag</param> | ||
/// <param name="defaultFlagState">Default state of the feature flag if it's not configured</param> | ||
public bool IsActive(ToggleNames toggleName, bool defaultFlagState = true) | ||
{ | ||
var featureFlagConfiguration = _featureFlagConfiguration.CurrentValue; | ||
if (featureFlagConfiguration == null) | ||
{ | ||
return defaultFlagState; | ||
} | ||
|
||
switch (toggleName) | ||
{ | ||
case ToggleNames.DisableMetricTimestamps: | ||
return featureFlagConfiguration.DisableMetricTimestamps; | ||
default: | ||
throw new Exception($"Unable to determine feature flag state for '{toggleName}'"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Promitor.Core.Configuration.FeatureFlags | ||
{ | ||
public enum ToggleNames | ||
{ | ||
DisableMetricTimestamps | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/Promitor.Core.Configuration/Model/FeatureFlags/FeatureFlagsConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Promitor.Core.Configuration.Model.FeatureFlags | ||
{ | ||
public class FeatureFlagsConfiguration | ||
{ | ||
public bool DisableMetricTimestamps { get; set; } = Defaults.FeatureFlags.DisableMetricTimestamps; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/Promitor.Core.Configuration/Model/Metrics/MetricsConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Promitor.Core.Configuration.Model.Metrics | ||
{ | ||
public class MetricsConfiguration | ||
{ | ||
public string AbsolutePath { get; set; } = Defaults.MetricsConfiguration.AbsolutePath; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/Promitor.Core.Configuration/Model/Prometheus/PrometheusConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Promitor.Core.Configuration.Model.Prometheus | ||
{ | ||
public class PrometheusConfiguration | ||
{ | ||
public ScrapeEndpointConfiguration ScrapeEndpoint { get; set; } = new ScrapeEndpointConfiguration(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/Promitor.Core.Configuration/Model/Prometheus/ScrapeEndpointConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Promitor.Core.Configuration.Model.Prometheus | ||
{ | ||
public class ScrapeEndpointConfiguration | ||
{ | ||
public string BaseUriPath { get; set; } = Defaults.Prometheus.ScrapeEndpointBaseUri; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Promitor.Core.Configuration/Model/RuntimeConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Promitor.Core.Configuration.Model.FeatureFlags; | ||
using Promitor.Core.Configuration.Model.Metrics; | ||
using Promitor.Core.Configuration.Model.Prometheus; | ||
using Promitor.Core.Configuration.Model.Server; | ||
using Promitor.Core.Configuration.Model.Telemetry; | ||
|
||
namespace Promitor.Core.Configuration.Model | ||
{ | ||
public class RuntimeConfiguration | ||
{ | ||
public ServerConfiguration Server { get; set; } = new ServerConfiguration(); | ||
public PrometheusConfiguration Prometheus { get; set; } = new PrometheusConfiguration(); | ||
public MetricsConfiguration MetricsConfiguration { get; set; } = new MetricsConfiguration(); | ||
public TelemetryConfiguration Telemetry { get; set; } = new TelemetryConfiguration(); | ||
public FeatureFlagsConfiguration FeatureFlags { get; set; } = new FeatureFlagsConfiguration(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/Promitor.Core.Configuration/Model/Server/ServerConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Promitor.Core.Configuration.Model.Server | ||
{ | ||
public class ServerConfiguration | ||
{ | ||
public int HttpPort { get; set; } = Defaults.Server.HttpPort; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Promitor.Core.Configuration/Model/Telemetry/Interfaces/ISinkConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Promitor.Core.Configuration.Model.Telemetry.Interfaces | ||
{ | ||
public interface ISinkConfiguration | ||
{ | ||
LogLevel? Verbosity { get; } | ||
bool IsEnabled { get; } | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/Promitor.Core.Configuration/Model/Telemetry/Sinks/ApplicationInsightsConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Microsoft.Extensions.Logging; | ||
using Promitor.Core.Configuration.Model.Telemetry.Interfaces; | ||
|
||
namespace Promitor.Core.Configuration.Model.Telemetry.Sinks | ||
{ | ||
public class ApplicationInsightsConfiguration : ISinkConfiguration | ||
{ | ||
public LogLevel? Verbosity { get; set; } = Defaults.Telemetry.ApplicationInsights.Verbosity; | ||
public bool IsEnabled { get; set; } = Defaults.Telemetry.ApplicationInsights.IsEnabled; | ||
public string InstrumentationKey { get; set; } | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Promitor.Core.Configuration/Model/Telemetry/Sinks/ContainerLogConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Microsoft.Extensions.Logging; | ||
using Promitor.Core.Configuration.Model.Telemetry.Interfaces; | ||
|
||
namespace Promitor.Core.Configuration.Model.Telemetry.Sinks | ||
{ | ||
public class ContainerLogConfiguration : ISinkConfiguration | ||
{ | ||
public LogLevel? Verbosity { get; set; } = Defaults.Telemetry.ContainerLogs.Verbosity; | ||
public bool IsEnabled { get; set; } = Defaults.Telemetry.ContainerLogs.IsEnabled; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/Promitor.Core.Configuration/Model/Telemetry/TelemetryConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Microsoft.Extensions.Logging; | ||
using Promitor.Core.Configuration.Model.Telemetry.Sinks; | ||
|
||
namespace Promitor.Core.Configuration.Model.Telemetry | ||
{ | ||
public class TelemetryConfiguration | ||
{ | ||
public LogLevel? DefaultVerbosity { get; set; } = Defaults.Telemetry.DefaultVerbosity; | ||
public ContainerLogConfiguration ContainerLogs { get; set; } = new ContainerLogConfiguration(); | ||
public ApplicationInsightsConfiguration ApplicationInsights { get; set; } = new ApplicationInsightsConfiguration(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/Promitor.Core.Configuration/Promitor.Core.Configuration.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.2</TargetFramework> | ||
<RuntimeFrameworkVersion>2.2.3</RuntimeFrameworkVersion> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | ||
<NoWarn>1701;1702;1591</NoWarn> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||
<NoWarn>1701;1702;1591</NoWarn> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.2.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.