Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to runtime configuration YAML #608

Merged
merged 46 commits into from
Jul 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
31812c1
Provide foundation for config via YAML
tomkerkhove Jul 1, 2019
205b046
ENV over YAML
tomkerkhove Jul 1, 2019
053b53b
Provide environment variables with prefix as well
tomkerkhove Jul 1, 2019
b029c95
WIP
tomkerkhove Jul 1, 2019
8bf8106
WIP
tomkerkhove Jul 1, 2019
d485c88
Improve defaults
tomkerkhove Jul 2, 2019
20ce005
Simplify
tomkerkhove Jul 2, 2019
304e733
Break all the things
tomkerkhove Jul 2, 2019
484d632
Improve code quality
tomkerkhove Jul 7, 2019
599ef5b
Clean-up Dockerfile
tomkerkhove Jul 7, 2019
503a621
Remove temporary variable
tomkerkhove Jul 7, 2019
3027a9c
Code quality fixes
tomkerkhove Jul 7, 2019
0f34cc9
Re-enable runtime validation
tomkerkhove Jul 7, 2019
0d2b906
Code quality
tomkerkhove Jul 7, 2019
c3e399c
Provide foundation for config via YAML
tomkerkhove Jul 1, 2019
7390f82
ENV over YAML
tomkerkhove Jul 1, 2019
63c9f9b
Provide environment variables with prefix as well
tomkerkhove Jul 1, 2019
31face6
WIP
tomkerkhove Jul 1, 2019
8a8d91e
WIP
tomkerkhove Jul 1, 2019
ee62049
Improve defaults
tomkerkhove Jul 2, 2019
311f28a
Simplify
tomkerkhove Jul 2, 2019
1baf7fd
Break all the things
tomkerkhove Jul 2, 2019
be5ddb2
Improve code quality
tomkerkhove Jul 7, 2019
9e8018b
Clean-up Dockerfile
tomkerkhove Jul 7, 2019
0c400a9
Remove temporary variable
tomkerkhove Jul 7, 2019
1cd5a76
Code quality fixes
tomkerkhove Jul 7, 2019
23c11ca
Re-enable runtime validation
tomkerkhove Jul 7, 2019
96c4723
Code quality
tomkerkhove Jul 7, 2019
f9af327
Merge branch 'features-runtime-config-yaml' of https://github.com/tom…
tomkerkhove Jul 7, 2019
06c6954
Inject logger
tomkerkhove Jul 8, 2019
9fa6b7e
Merge branch 'master' into features-runtime-config-yaml
tomkerkhove Jul 9, 2019
80c8b58
WIP
tomkerkhove Jul 10, 2019
34a5de8
Merge master
tomkerkhove Jul 11, 2019
57e7ed2
Code cleanup
tomkerkhove Jul 11, 2019
6e3d8c4
Provide very basic & ugly bogus + runtime config generator
tomkerkhove Jul 11, 2019
abef119
Merge branch 'master' into features-runtime-config-yaml
tomkerkhove Jul 19, 2019
2755c1c
Code cleanup
tomkerkhove Jul 19, 2019
b4446ab
Merge branch 'master' into features-runtime-config-yaml
tomkerkhove Jul 22, 2019
9885ea3
WIP
tomkerkhove Jul 22, 2019
9408159
Provide more tests
tomkerkhove Jul 22, 2019
f8b5d79
Code cleanup
tomkerkhove Jul 22, 2019
23b322d
Most specific over least specific verbosity for logging
tomkerkhove Jul 22, 2019
860d4a5
Add new volume mount to landing page
tomkerkhove Jul 23, 2019
4367373
Merge branch 'master' into features-runtime-config-yaml
tomkerkhove Jul 25, 2019
69a7c86
Fix configuration for Application Insights
tomkerkhove Jul 25, 2019
473a698
Fix inverted flag for disabling telemetry
tomkerkhove Jul 25, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ docker run -d -p 8999:80 --name promitor-agent-scraper \
--env PROMITOR_AUTH_APPID='<azure-ad-app-id>' \
--env-file C:/Promitor/az-mon-auth.creds \
--volume C:/Promitor/metrics-declaration.yaml:/config/metrics-declaration.yaml \
--volume C:/Promitor/runtime-config.yaml:/config/runtime.yaml \
tomkerkhove/promitor-agent-scraper:1.0.0-preview-8
```

Expand Down
1 change: 1 addition & 0 deletions docs/thank-you.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ We are using the following GitHub Apps:

# NuGet Packages
Here is an overview of the NuGet packages that we rely on:
- [NetEscapades.Configuration.Yaml](https://www.nuget.org/packages/NetEscapades.Configuration.Yaml) - YAML configuration provider for .NET Core
- [CronScheduler.AspNetCore](https://github.com/kdcllc/CronScheduler.AspNetCore) - Asp.Net Core 2.x Hosted or .Net Core 2.x Self-hosted Cron Scheduler
- [Swashbuckle.AspNetCore](https://github.com/domaindrivendev/Swashbuckle.AspNetCore) - Swagger tools for documenting API's built on ASP.NET Core
- [Prometheus.Client](https://github.com/PrometheusClientNet/Prometheus.Client) - .NET client for prometheus.io
Expand Down
44 changes: 44 additions & 0 deletions src/Promitor.Core.Configuration/Defaults.cs
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;
}
}
}
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}'");
}
}
}
}
7 changes: 7 additions & 0 deletions src/Promitor.Core.Configuration/FeatureFlags/ToggleNames.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Promitor.Core.Configuration.FeatureFlags
{
public enum ToggleNames
{
DisableMetricTimestamps
}
}
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;
}
}
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;
}
}
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();
}
}
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 src/Promitor.Core.Configuration/Model/RuntimeConfiguration.cs
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();
}
}
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;
}
}
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; }
}
}
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; }
}
}
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;
}
}
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();
}
}
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>
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.IO;
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.Core;
Expand All @@ -10,10 +12,12 @@ namespace Promitor.Core.Scraping.Configuration.Providers
public class MetricsDeclarationProvider : IMetricsDeclarationProvider
{
private readonly ConfigurationSerializer _configurationSerializer;
private readonly IConfiguration _configuration;

public MetricsDeclarationProvider(ILogger logger)
public MetricsDeclarationProvider(IConfiguration configuration, ILogger logger)
{
_configurationSerializer = new ConfigurationSerializer(logger);
_configuration = configuration;
}

public virtual MetricsDeclaration Get(bool applyDefaults = false)
Expand Down Expand Up @@ -64,11 +68,12 @@ public virtual MetricsDeclaration Get(bool applyDefaults = false)

public virtual string ReadRawDeclaration()
{
var scrapingConfigurationPath = Environment.GetEnvironmentVariable(EnvironmentVariables.Configuration.Path);
var metricConfiguration = _configuration.GetSection("metricsConfiguration").Get<MetricsConfiguration>();
var scrapingConfigurationPath = metricConfiguration?.AbsolutePath;

if (string.IsNullOrWhiteSpace(scrapingConfigurationPath))
{
Console.WriteLine($"No scraping configuration path was specified, falling back to default '{Constants.Defaults.MetricsDeclarationPath}'...");
scrapingConfigurationPath = Constants.Defaults.MetricsDeclarationPath;
throw new Exception("No scraping configuration path was specified.");
}

var rawMetricsDeclaration = File.ReadAllText(scrapingConfigurationPath);
Expand Down
10 changes: 0 additions & 10 deletions src/Promitor.Core.Scraping/Constants.cs

This file was deleted.

Loading