From 4e0fe237963112920698359b624a4fd6ea9e3630 Mon Sep 17 00:00:00 2001 From: bunkrur Date: Thu, 8 Jun 2023 08:57:59 -0700 Subject: [PATCH 01/10] Update IServiceCollectionExtensions.cs --- .../Extensions/IServiceCollectionExtensions.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Promitor.Agents.Scraper/Extensions/IServiceCollectionExtensions.cs b/src/Promitor.Agents.Scraper/Extensions/IServiceCollectionExtensions.cs index 6f26ebbdd..7218e66cb 100644 --- a/src/Promitor.Agents.Scraper/Extensions/IServiceCollectionExtensions.cs +++ b/src/Promitor.Agents.Scraper/Extensions/IServiceCollectionExtensions.cs @@ -236,7 +236,10 @@ private static void AddOpenTelemetryCollectorMetricSink(string collectorUri, str { metricsBuilder.SetResourceBuilder(resourceBuilder) .AddMeter("Promitor.Scraper.Metrics.AzureMonitor") - .AddOtlpExporter(options => options.Endpoint = new Uri(collectorUri)); + .AddOtlpExporter(options => + options.Endpoint = new Uri(collectorUri), + options.Protocol = (metricSinkConfiguration.OpenTelemetryCollector.CollectorUri.StartsWith("https")) ? OtlpExporterProtocol.HttpProtobuf : OtlpExporterProtocol.Grpc + ); }); services.AddTransient(); services.AddTransient(); @@ -345,4 +348,4 @@ public static IServiceCollection ConfigureYamlConfiguration(this IServiceCollect return services; } } -} \ No newline at end of file +} From 0e173e4773432909354b76b3104e9d2f37bf0c06 Mon Sep 17 00:00:00 2001 From: bunkrur Date: Thu, 8 Jun 2023 09:13:24 -0700 Subject: [PATCH 02/10] Update IServiceCollectionExtensions.cs --- .../Extensions/IServiceCollectionExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Promitor.Agents.Scraper/Extensions/IServiceCollectionExtensions.cs b/src/Promitor.Agents.Scraper/Extensions/IServiceCollectionExtensions.cs index 7218e66cb..0ebcd7b72 100644 --- a/src/Promitor.Agents.Scraper/Extensions/IServiceCollectionExtensions.cs +++ b/src/Promitor.Agents.Scraper/Extensions/IServiceCollectionExtensions.cs @@ -238,7 +238,7 @@ private static void AddOpenTelemetryCollectorMetricSink(string collectorUri, str .AddMeter("Promitor.Scraper.Metrics.AzureMonitor") .AddOtlpExporter(options => options.Endpoint = new Uri(collectorUri), - options.Protocol = (metricSinkConfiguration.OpenTelemetryCollector.CollectorUri.StartsWith("https")) ? OtlpExporterProtocol.HttpProtobuf : OtlpExporterProtocol.Grpc + options.Protocol = (metricSinkConfiguration.OpenTelemetryCollector.CollectorUri.StartsWith("https")) ? OtlpExportProtocol.HttpProtobuf : OtlpExportProtocol.Grpc ); }); services.AddTransient(); From 72b74236ae64bb5dc98e6cf2661649e53edde028 Mon Sep 17 00:00:00 2001 From: bunkrur Date: Thu, 8 Jun 2023 09:24:30 -0700 Subject: [PATCH 03/10] Update IServiceCollectionExtensions.cs --- .../Extensions/IServiceCollectionExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Promitor.Agents.Scraper/Extensions/IServiceCollectionExtensions.cs b/src/Promitor.Agents.Scraper/Extensions/IServiceCollectionExtensions.cs index 0ebcd7b72..02ec54705 100644 --- a/src/Promitor.Agents.Scraper/Extensions/IServiceCollectionExtensions.cs +++ b/src/Promitor.Agents.Scraper/Extensions/IServiceCollectionExtensions.cs @@ -238,7 +238,7 @@ private static void AddOpenTelemetryCollectorMetricSink(string collectorUri, str .AddMeter("Promitor.Scraper.Metrics.AzureMonitor") .AddOtlpExporter(options => options.Endpoint = new Uri(collectorUri), - options.Protocol = (metricSinkConfiguration.OpenTelemetryCollector.CollectorUri.StartsWith("https")) ? OtlpExportProtocol.HttpProtobuf : OtlpExportProtocol.Grpc + options.Protocol = (metricSinkConfiguration.OpenTelemetryCollector.CollectorProtocol.StartsWith("http")) ? OtlpExportProtocol.HttpProtobuf : OtlpExportProtocol.Grpc ); }); services.AddTransient(); From d4a7dbe1e39a3a0319bc777db76a6ad1843c0922 Mon Sep 17 00:00:00 2001 From: bunkrur Date: Thu, 8 Jun 2023 11:50:30 -0700 Subject: [PATCH 04/10] Added: CollectorProtocol option Changed: AddOpenTelemetryCollectorMetricSink now takes all Otel Options Added: options.Protocol to OpenTelemetry exporter. Defaults to Grpc if http not found in config. Grpc is already default. --- .../IServiceCollectionExtensions.cs | 25 +++++++++++-------- ...OpenTelemetryCollectorSinkConfiguration.cs | 1 + 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Promitor.Agents.Scraper/Extensions/IServiceCollectionExtensions.cs b/src/Promitor.Agents.Scraper/Extensions/IServiceCollectionExtensions.cs index 02ec54705..2d706f92d 100644 --- a/src/Promitor.Agents.Scraper/Extensions/IServiceCollectionExtensions.cs +++ b/src/Promitor.Agents.Scraper/Extensions/IServiceCollectionExtensions.cs @@ -4,6 +4,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Logging; +using OpenTelemetry.Exporter; using OpenTelemetry.Metrics; using OpenTelemetry.Resources; using Promitor.Agents.Core.Configuration.Server; @@ -110,7 +111,7 @@ public static IServiceCollection AddAtlassianStatuspageClient(this IServiceColle public static IServiceCollection DefineDependencies(this IServiceCollection services) { Guard.NotNull(services, nameof(services)); - + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -198,7 +199,7 @@ public static IServiceCollection UseMetricSinks(this IServiceCollection services if (metricSinkConfiguration?.OpenTelemetryCollector != null && string.IsNullOrWhiteSpace(metricSinkConfiguration.OpenTelemetryCollector.CollectorUri) == false) { - AddOpenTelemetryCollectorMetricSink(metricSinkConfiguration.OpenTelemetryCollector.CollectorUri, agentVersion, services, metricSinkAsciiTable); + AddOpenTelemetryCollectorMetricSink(metricSinkConfiguration.OpenTelemetryCollector, agentVersion, services, metricSinkAsciiTable); } AnsiConsole.Write(metricSinkAsciiTable); @@ -224,9 +225,9 @@ private static void AddAtlassianStatuspageMetricSink(string pageId, IServiceColl const string OpenTelemetryServiceName = "promitor-scraper"; - private static void AddOpenTelemetryCollectorMetricSink(string collectorUri, string agentVersion, IServiceCollection services, Table metricSinkAsciiTable) + private static void AddOpenTelemetryCollectorMetricSink(Promitor.Integrations.Sinks.OpenTelemetry.Configuration.OpenTelemetryCollectorSinkConfiguration otelConfiguration, string agentVersion, IServiceCollection services, Table metricSinkAsciiTable) { - metricSinkAsciiTable.AddRow("OpenTelemetry Collector", $"Url: {collectorUri}."); + metricSinkAsciiTable.AddRow("OpenTelemetry Collector", $"Url: {otelConfiguration.CollectorUri}."); var resourceBuilder = ResourceBuilder.CreateDefault() .AddService(OpenTelemetryServiceName, serviceVersion: agentVersion); @@ -237,9 +238,11 @@ private static void AddOpenTelemetryCollectorMetricSink(string collectorUri, str metricsBuilder.SetResourceBuilder(resourceBuilder) .AddMeter("Promitor.Scraper.Metrics.AzureMonitor") .AddOtlpExporter(options => - options.Endpoint = new Uri(collectorUri), - options.Protocol = (metricSinkConfiguration.OpenTelemetryCollector.CollectorProtocol.StartsWith("http")) ? OtlpExportProtocol.HttpProtobuf : OtlpExportProtocol.Grpc - ); + { + options.Endpoint = new Uri(otelConfiguration.CollectorUri); + options.Protocol = (otelConfiguration.CollectorProtocol.StartsWith("http")) ? OtlpExportProtocol.HttpProtobuf : OtlpExportProtocol.Grpc; + } + ); }); services.AddTransient(); services.AddTransient(); @@ -247,7 +250,7 @@ private static void AddOpenTelemetryCollectorMetricSink(string collectorUri, str } private static void AddStatsdMetricSink(IServiceCollection services, StatsdSinkConfiguration statsdConfiguration, Table metricSinkAsciiTable) - { + { metricSinkAsciiTable.AddRow("StatsD", $"Url: {statsdConfiguration.Host}:{statsdConfiguration.Port}."); metricSinkAsciiTable.AddRow("", $"Format: {statsdConfiguration.MetricFormat}."); @@ -311,9 +314,9 @@ public static IServiceCollection AddScrapingMutex(this IServiceCollection servic } var serverConfiguration = configuration.GetSection("server").Get(); - + services.TryAdd(ServiceDescriptor.Singleton(_ => ScrapingMutexBuilder(serverConfiguration))); - + return services; } @@ -348,4 +351,4 @@ public static IServiceCollection ConfigureYamlConfiguration(this IServiceCollect return services; } } -} +} \ No newline at end of file diff --git a/src/Promitor.Integrations.Sinks.OpenTelemetry/Configuration/OpenTelemetryCollectorSinkConfiguration.cs b/src/Promitor.Integrations.Sinks.OpenTelemetry/Configuration/OpenTelemetryCollectorSinkConfiguration.cs index 4bd66695b..eef696ad0 100644 --- a/src/Promitor.Integrations.Sinks.OpenTelemetry/Configuration/OpenTelemetryCollectorSinkConfiguration.cs +++ b/src/Promitor.Integrations.Sinks.OpenTelemetry/Configuration/OpenTelemetryCollectorSinkConfiguration.cs @@ -3,5 +3,6 @@ public class OpenTelemetryCollectorSinkConfiguration { public string CollectorUri { get; set; } + public string CollectorProtocol { get; set; } } } From b1589f8a015669475279392da54e9dd915e9e24d Mon Sep 17 00:00:00 2001 From: bunkrur Date: Thu, 8 Jun 2023 12:52:07 -0700 Subject: [PATCH 05/10] Added: Output for Protocol Changed: To equals from Startswith. Lets be explicit. Added: Validation for protocol, even if using default Added: Forcing grpc (which is already default) within CollectorInfo properties. Added: Nested CollectorInfo class --- .../Extensions/IServiceCollectionExtensions.cs | 4 ++-- ...nTelemetryCollectorMetricSinkValidationStep.cs | 15 ++++++++++++++- .../OpenTelemetryCollectorSinkConfiguration.cs | 12 ++++++++++-- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/Promitor.Agents.Scraper/Extensions/IServiceCollectionExtensions.cs b/src/Promitor.Agents.Scraper/Extensions/IServiceCollectionExtensions.cs index 2d706f92d..493d76866 100644 --- a/src/Promitor.Agents.Scraper/Extensions/IServiceCollectionExtensions.cs +++ b/src/Promitor.Agents.Scraper/Extensions/IServiceCollectionExtensions.cs @@ -228,7 +228,7 @@ private static void AddAtlassianStatuspageMetricSink(string pageId, IServiceColl private static void AddOpenTelemetryCollectorMetricSink(Promitor.Integrations.Sinks.OpenTelemetry.Configuration.OpenTelemetryCollectorSinkConfiguration otelConfiguration, string agentVersion, IServiceCollection services, Table metricSinkAsciiTable) { metricSinkAsciiTable.AddRow("OpenTelemetry Collector", $"Url: {otelConfiguration.CollectorUri}."); - + metricSinkAsciiTable.AddRow("OpenTelemetry Collector", $"Protocol: {otelConfiguration.Collector.CollectorProtocol}."); var resourceBuilder = ResourceBuilder.CreateDefault() .AddService(OpenTelemetryServiceName, serviceVersion: agentVersion); @@ -240,7 +240,7 @@ private static void AddOpenTelemetryCollectorMetricSink(Promitor.Integrations.Si .AddOtlpExporter(options => { options.Endpoint = new Uri(otelConfiguration.CollectorUri); - options.Protocol = (otelConfiguration.CollectorProtocol.StartsWith("http")) ? OtlpExportProtocol.HttpProtobuf : OtlpExportProtocol.Grpc; + options.Protocol = (otelConfiguration.Collector.CollectorProtocol.Equals("http")) ? OtlpExportProtocol.HttpProtobuf : OtlpExportProtocol.Grpc; } ); }); diff --git a/src/Promitor.Agents.Scraper/Validation/Steps/Sinks/OpenTelemetryCollectorMetricSinkValidationStep.cs b/src/Promitor.Agents.Scraper/Validation/Steps/Sinks/OpenTelemetryCollectorMetricSinkValidationStep.cs index f75715405..863432048 100644 --- a/src/Promitor.Agents.Scraper/Validation/Steps/Sinks/OpenTelemetryCollectorMetricSinkValidationStep.cs +++ b/src/Promitor.Agents.Scraper/Validation/Steps/Sinks/OpenTelemetryCollectorMetricSinkValidationStep.cs @@ -3,6 +3,7 @@ using System.Linq; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +using OpenTelemetry.Exporter; using Promitor.Agents.Core.Validation; using Promitor.Agents.Core.Validation.Interfaces; using Promitor.Agents.Core.Validation.Steps; @@ -33,6 +34,18 @@ public ValidationResult Run() var errorMessages = new List(); var collectorUri = openTelemetryCollectorSinkConfiguration.CollectorUri; + var collectorProtocol = openTelemetryCollectorSinkConfiguration.Collector.CollectorProtocol; + + // Protocol Validation + if (string.IsNullOrWhiteSpace(collectorProtocol)) + { + errorMessages.Add("No Protocol for the OpenTelemetry Collector is configured."); + } + else if (collectorProtocol != "http" && collectorProtocol != "grpc") + { + errorMessages.Add($"Configured Protocol ({collectorProtocol}) for the OpenTelemetry Collector should be either 'http' or 'grpc'."); + } + // URI Validation if (string.IsNullOrWhiteSpace(collectorUri)) { errorMessages.Add("No URI for the OpenTelemetry Collector is configured."); @@ -48,7 +61,7 @@ public ValidationResult Run() errorMessages.Add($"Configured URI ({collectorUri}) for the OpenTelemetry Collector is not a valid URI."); } } - + return errorMessages.Any() ? ValidationResult.Failure(ComponentName, errorMessages) : ValidationResult.Successful(ComponentName); } } diff --git a/src/Promitor.Integrations.Sinks.OpenTelemetry/Configuration/OpenTelemetryCollectorSinkConfiguration.cs b/src/Promitor.Integrations.Sinks.OpenTelemetry/Configuration/OpenTelemetryCollectorSinkConfiguration.cs index eef696ad0..abf5af092 100644 --- a/src/Promitor.Integrations.Sinks.OpenTelemetry/Configuration/OpenTelemetryCollectorSinkConfiguration.cs +++ b/src/Promitor.Integrations.Sinks.OpenTelemetry/Configuration/OpenTelemetryCollectorSinkConfiguration.cs @@ -1,8 +1,16 @@ -namespace Promitor.Integrations.Sinks.OpenTelemetry.Configuration +using OpenTelemetry.Exporter; + +namespace Promitor.Integrations.Sinks.OpenTelemetry.Configuration { public class OpenTelemetryCollectorSinkConfiguration { public string CollectorUri { get; set; } - public string CollectorProtocol { get; set; } + + public CollectorInfo Collector { get; set; } + + public class CollectorInfo + { + public string CollectorProtocol { get; set; } = "grpc"; + } } } From 6fff02eff278f91d00a817b9d92b781431fcbd2b Mon Sep 17 00:00:00 2001 From: bunkrur Date: Fri, 9 Jun 2023 12:51:21 -0700 Subject: [PATCH 06/10] adding requested changes --- .../IServiceCollectionExtensions.cs | 10 ++++----- src/Promitor.Agents.Scraper/Startup.cs | 3 ++- ...emetryCollectorMetricSinkValidationStep.cs | 21 ++++++++----------- .../OpenTelemetryCollectorConfiguration.cs | 17 +++++++++++++++ ...OpenTelemetryCollectorSinkConfiguration.cs | 16 -------------- .../RuntimeConfigurationUnitTest.cs | 4 ++-- ...gusScraperRuntimeConfigurationGenerator.cs | 2 +- .../Config/RuntimeConfigurationGenerator.cs | 13 +++++++++--- ...yCollectorMetricSinkValidationStepTests.cs | 6 +++--- 9 files changed, 49 insertions(+), 43 deletions(-) create mode 100644 src/Promitor.Integrations.Sinks.OpenTelemetry/Configuration/OpenTelemetryCollectorConfiguration.cs delete mode 100644 src/Promitor.Integrations.Sinks.OpenTelemetry/Configuration/OpenTelemetryCollectorSinkConfiguration.cs diff --git a/src/Promitor.Agents.Scraper/Extensions/IServiceCollectionExtensions.cs b/src/Promitor.Agents.Scraper/Extensions/IServiceCollectionExtensions.cs index 493d76866..aa88dd3b6 100644 --- a/src/Promitor.Agents.Scraper/Extensions/IServiceCollectionExtensions.cs +++ b/src/Promitor.Agents.Scraper/Extensions/IServiceCollectionExtensions.cs @@ -197,9 +197,9 @@ public static IServiceCollection UseMetricSinks(this IServiceCollection services } if (metricSinkConfiguration?.OpenTelemetryCollector != null - && string.IsNullOrWhiteSpace(metricSinkConfiguration.OpenTelemetryCollector.CollectorUri) == false) + && string.IsNullOrWhiteSpace(metricSinkConfiguration.OpenTelemetryCollector.CollectorInfo.CollectorUri) == false) { - AddOpenTelemetryCollectorMetricSink(metricSinkConfiguration.OpenTelemetryCollector, agentVersion, services, metricSinkAsciiTable); + AddOpenTelemetryCollectorMetricSink(metricSinkConfiguration.OpenTelemetryCollector.CollectorInfo, agentVersion, services, metricSinkAsciiTable); } AnsiConsole.Write(metricSinkAsciiTable); @@ -225,10 +225,10 @@ private static void AddAtlassianStatuspageMetricSink(string pageId, IServiceColl const string OpenTelemetryServiceName = "promitor-scraper"; - private static void AddOpenTelemetryCollectorMetricSink(Promitor.Integrations.Sinks.OpenTelemetry.Configuration.OpenTelemetryCollectorSinkConfiguration otelConfiguration, string agentVersion, IServiceCollection services, Table metricSinkAsciiTable) + private static void AddOpenTelemetryCollectorMetricSink(Promitor.Integrations.Sinks.OpenTelemetry.Configuration.OpenTelemetryCollectorSinkConfiguration.CollectorInfoConfiguration otelConfiguration, string agentVersion, IServiceCollection services, Table metricSinkAsciiTable) { metricSinkAsciiTable.AddRow("OpenTelemetry Collector", $"Url: {otelConfiguration.CollectorUri}."); - metricSinkAsciiTable.AddRow("OpenTelemetry Collector", $"Protocol: {otelConfiguration.Collector.CollectorProtocol}."); + metricSinkAsciiTable.AddRow("OpenTelemetry Collector", $"Protocol: {otelConfiguration.Protocol}."); var resourceBuilder = ResourceBuilder.CreateDefault() .AddService(OpenTelemetryServiceName, serviceVersion: agentVersion); @@ -240,7 +240,7 @@ private static void AddOpenTelemetryCollectorMetricSink(Promitor.Integrations.Si .AddOtlpExporter(options => { options.Endpoint = new Uri(otelConfiguration.CollectorUri); - options.Protocol = (otelConfiguration.Collector.CollectorProtocol.Equals("http")) ? OtlpExportProtocol.HttpProtobuf : OtlpExportProtocol.Grpc; + options.Protocol = otelConfiguration.Protocol; } ); }); diff --git a/src/Promitor.Agents.Scraper/Startup.cs b/src/Promitor.Agents.Scraper/Startup.cs index 65524b8ba..ed1db9d4d 100644 --- a/src/Promitor.Agents.Scraper/Startup.cs +++ b/src/Promitor.Agents.Scraper/Startup.cs @@ -114,7 +114,8 @@ private string BuildOpenApiDescription(IConfiguration configuration) if (metricSinkConfiguration.OpenTelemetryCollector != null) { - openApiDescriptionBuilder.AppendLine($"
  • OpenTelemetry Collector located on {metricSinkConfiguration.OpenTelemetryCollector.CollectorUri}
  • "); + openApiDescriptionBuilder.AppendLine($"
  • OpenTelemetry Collector located on {metricSinkConfiguration.OpenTelemetryCollector.CollectorInfo.CollectorUri}
  • "); + openApiDescriptionBuilder.AppendLine($"
  • OpenTelemetry Collector Protocol selected: {metricSinkConfiguration.OpenTelemetryCollector.CollectorInfo.Protocol}
  • "); } if (metricSinkConfiguration.Statsd != null) diff --git a/src/Promitor.Agents.Scraper/Validation/Steps/Sinks/OpenTelemetryCollectorMetricSinkValidationStep.cs b/src/Promitor.Agents.Scraper/Validation/Steps/Sinks/OpenTelemetryCollectorMetricSinkValidationStep.cs index 863432048..04b837713 100644 --- a/src/Promitor.Agents.Scraper/Validation/Steps/Sinks/OpenTelemetryCollectorMetricSinkValidationStep.cs +++ b/src/Promitor.Agents.Scraper/Validation/Steps/Sinks/OpenTelemetryCollectorMetricSinkValidationStep.cs @@ -33,18 +33,9 @@ public ValidationResult Run() } var errorMessages = new List(); - var collectorUri = openTelemetryCollectorSinkConfiguration.CollectorUri; - var collectorProtocol = openTelemetryCollectorSinkConfiguration.Collector.CollectorProtocol; + var collectorUri = openTelemetryCollectorSinkConfiguration.CollectorInfo.CollectorUri; + var collectorProtocol = openTelemetryCollectorSinkConfiguration.CollectorInfo.Protocol; - // Protocol Validation - if (string.IsNullOrWhiteSpace(collectorProtocol)) - { - errorMessages.Add("No Protocol for the OpenTelemetry Collector is configured."); - } - else if (collectorProtocol != "http" && collectorProtocol != "grpc") - { - errorMessages.Add($"Configured Protocol ({collectorProtocol}) for the OpenTelemetry Collector should be either 'http' or 'grpc'."); - } // URI Validation if (string.IsNullOrWhiteSpace(collectorUri)) { @@ -61,7 +52,13 @@ public ValidationResult Run() errorMessages.Add($"Configured URI ({collectorUri}) for the OpenTelemetry Collector is not a valid URI."); } } - + + // Protocol Validation + if (!Enum.IsDefined(typeof(OtlpExportProtocol), collectorProtocol)) + { + errorMessages.Add($"Invalid Protocol ({collectorProtocol}) for the OpenTelemetry Collector is configured. Please check here for valid protocols: https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md#otlpexporteroptions"); + } + return errorMessages.Any() ? ValidationResult.Failure(ComponentName, errorMessages) : ValidationResult.Successful(ComponentName); } } diff --git a/src/Promitor.Integrations.Sinks.OpenTelemetry/Configuration/OpenTelemetryCollectorConfiguration.cs b/src/Promitor.Integrations.Sinks.OpenTelemetry/Configuration/OpenTelemetryCollectorConfiguration.cs new file mode 100644 index 000000000..28972389b --- /dev/null +++ b/src/Promitor.Integrations.Sinks.OpenTelemetry/Configuration/OpenTelemetryCollectorConfiguration.cs @@ -0,0 +1,17 @@ +using OpenTelemetry.Exporter; + +namespace Promitor.Integrations.Sinks.OpenTelemetry.Configuration +{ + public class OpenTelemetryCollectorSinkConfiguration + { + public CollectorInfoConfiguration CollectorInfo { get; set; } + + public class CollectorInfoConfiguration + { + public OtlpExportProtocol Protocol { get; set; } = default(OtlpExportProtocol); + public string CollectorUri { get; set; } + //Todo: Headers + + } + } +} diff --git a/src/Promitor.Integrations.Sinks.OpenTelemetry/Configuration/OpenTelemetryCollectorSinkConfiguration.cs b/src/Promitor.Integrations.Sinks.OpenTelemetry/Configuration/OpenTelemetryCollectorSinkConfiguration.cs deleted file mode 100644 index abf5af092..000000000 --- a/src/Promitor.Integrations.Sinks.OpenTelemetry/Configuration/OpenTelemetryCollectorSinkConfiguration.cs +++ /dev/null @@ -1,16 +0,0 @@ -using OpenTelemetry.Exporter; - -namespace Promitor.Integrations.Sinks.OpenTelemetry.Configuration -{ - public class OpenTelemetryCollectorSinkConfiguration - { - public string CollectorUri { get; set; } - - public CollectorInfo Collector { get; set; } - - public class CollectorInfo - { - public string CollectorProtocol { get; set; } = "grpc"; - } - } -} diff --git a/src/Promitor.Tests.Unit/Configuration/RuntimeConfigurationUnitTest.cs b/src/Promitor.Tests.Unit/Configuration/RuntimeConfigurationUnitTest.cs index f100abcf0..151d25768 100644 --- a/src/Promitor.Tests.Unit/Configuration/RuntimeConfigurationUnitTest.cs +++ b/src/Promitor.Tests.Unit/Configuration/RuntimeConfigurationUnitTest.cs @@ -401,7 +401,7 @@ public async Task RuntimeConfiguration_HasConfiguredCollectorUriInOpenTelemetryC Assert.NotNull(runtimeConfiguration); Assert.NotNull(runtimeConfiguration.MetricSinks); Assert.NotNull(runtimeConfiguration.MetricSinks.OpenTelemetryCollector); - Assert.Equal(collectorUri, runtimeConfiguration.MetricSinks.OpenTelemetryCollector.CollectorUri); + Assert.Equal(collectorUri, runtimeConfiguration.MetricSinks.OpenTelemetryCollector.CollectorInfo.CollectorUri); } [Fact] @@ -418,7 +418,7 @@ public async Task RuntimeConfiguration_HasConfiguredNoCollectorUriInOpenTelemetr // Assert Assert.NotNull(runtimeConfiguration); Assert.NotNull(runtimeConfiguration.MetricSinks); - Assert.Null(runtimeConfiguration.MetricSinks.OpenTelemetryCollector); + Assert.Null(runtimeConfiguration.MetricSinks.OpenTelemetryCollector.CollectorInfo); } [Fact] diff --git a/src/Promitor.Tests.Unit/Generators/Config/BogusScraperRuntimeConfigurationGenerator.cs b/src/Promitor.Tests.Unit/Generators/Config/BogusScraperRuntimeConfigurationGenerator.cs index 0724c3a0b..35ba0069a 100644 --- a/src/Promitor.Tests.Unit/Generators/Config/BogusScraperRuntimeConfigurationGenerator.cs +++ b/src/Promitor.Tests.Unit/Generators/Config/BogusScraperRuntimeConfigurationGenerator.cs @@ -155,7 +155,7 @@ private static OpenTelemetryCollectorSinkConfiguration GenerateOpenTelemetryColl { var openTelemetryCollectorSinkConfiguration = new Faker() .StrictMode(true) - .RuleFor(promConfiguration => promConfiguration.CollectorUri, faker => faker.Internet.Url()) + .RuleFor(promConfiguration => promConfiguration.CollectorInfo.CollectorUri, faker => faker.Internet.Url()) .Generate(); return openTelemetryCollectorSinkConfiguration; } diff --git a/src/Promitor.Tests.Unit/Generators/Config/RuntimeConfigurationGenerator.cs b/src/Promitor.Tests.Unit/Generators/Config/RuntimeConfigurationGenerator.cs index cbcab7220..5dc022d15 100644 --- a/src/Promitor.Tests.Unit/Generators/Config/RuntimeConfigurationGenerator.cs +++ b/src/Promitor.Tests.Unit/Generators/Config/RuntimeConfigurationGenerator.cs @@ -6,6 +6,7 @@ using Microsoft.Azure.Management.ResourceManager.Fluent.Core; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using OpenTelemetry.Exporter; using Promitor.Agents.Core.Configuration.Server; using Promitor.Agents.Core.Configuration.Telemetry; using Promitor.Agents.Core.Configuration.Telemetry.Sinks; @@ -16,6 +17,7 @@ using Promitor.Integrations.Sinks.Prometheus.Configuration; using Promitor.Integrations.Sinks.Statsd.Configuration; + namespace Promitor.Tests.Unit.Generators.Config { internal class RuntimeConfigurationGenerator @@ -85,13 +87,18 @@ public RuntimeConfigurationGenerator WithPrometheusMetricSink(double? metricUnav return this; } - public RuntimeConfigurationGenerator WithOpenTelemetryCollectorMetricSink(string collectorUri = "https://opentelemetry-collector:8888") + public RuntimeConfigurationGenerator WithOpenTelemetryCollectorMetricSink(string collectorUri = "https://opentelemetry-collector:8888", OtlpExportProtocol protocol = OtlpExportProtocol.Grpc) { if (string.IsNullOrWhiteSpace(collectorUri) == false) { _runtimeConfiguration.MetricSinks.OpenTelemetryCollector = new OpenTelemetryCollectorSinkConfiguration { - CollectorUri = collectorUri + CollectorInfo = new Promitor.Integrations.Sinks.OpenTelemetry.Configuration.OpenTelemetryCollectorSinkConfiguration.CollectorInfoConfiguration + { + CollectorUri = collectorUri, + Protocol = protocol + // Todo: Headers + } }; } @@ -295,7 +302,7 @@ public async Task GenerateAsync() if (_runtimeConfiguration?.MetricSinks.OpenTelemetryCollector != null) { configurationBuilder.AppendLine(" openTelemetryCollector:"); - configurationBuilder.AppendLine($" collectorUri: {_runtimeConfiguration?.MetricSinks.OpenTelemetryCollector.CollectorUri}"); + configurationBuilder.AppendLine($" collectorUri: {_runtimeConfiguration?.MetricSinks.OpenTelemetryCollector.CollectorInfo.CollectorUri}"); } } diff --git a/src/Promitor.Tests.Unit/Validation/Scraper/Metrics/Sinks/OpenTelemetryCollectorMetricSinkValidationStepTests.cs b/src/Promitor.Tests.Unit/Validation/Scraper/Metrics/Sinks/OpenTelemetryCollectorMetricSinkValidationStepTests.cs index ebe103bc3..d847c68cc 100644 --- a/src/Promitor.Tests.Unit/Validation/Scraper/Metrics/Sinks/OpenTelemetryCollectorMetricSinkValidationStepTests.cs +++ b/src/Promitor.Tests.Unit/Validation/Scraper/Metrics/Sinks/OpenTelemetryCollectorMetricSinkValidationStepTests.cs @@ -62,7 +62,7 @@ public void Validate_OpenTelemetryCollectorWithUnspecifiedCollectorUri_Fails(str { // Arrange var runtimeConfiguration = CreateRuntimeConfiguration(); - runtimeConfiguration.Value.MetricSinks.OpenTelemetryCollector.CollectorUri = collectorUri; + runtimeConfiguration.Value.MetricSinks.OpenTelemetryCollector.CollectorInfo.CollectorUri = collectorUri; // Act var openTelemetryCollectorValidationStep = new OpenTelemetryCollectorMetricSinkValidationStep(runtimeConfiguration, NullLogger.Instance); @@ -81,7 +81,7 @@ public void Validate_OpenTelemetryCollectorWithInvalidCollectorUri_Fails(string { // Arrange var runtimeConfiguration = CreateRuntimeConfiguration(); - runtimeConfiguration.Value.MetricSinks.OpenTelemetryCollector.CollectorUri = collectorUri; + runtimeConfiguration.Value.MetricSinks.OpenTelemetryCollector.CollectorInfo.CollectorUri = collectorUri; // Act var openTelemetryCollectorValidationStep = new OpenTelemetryCollectorMetricSinkValidationStep(runtimeConfiguration, NullLogger.Instance); @@ -104,7 +104,7 @@ public void Validate_OpenTelemetryCollectorWithValidCollectorUri_Fails(string co { // Arrange var runtimeConfiguration = CreateRuntimeConfiguration(); - runtimeConfiguration.Value.MetricSinks.OpenTelemetryCollector.CollectorUri = collectorUri; + runtimeConfiguration.Value.MetricSinks.OpenTelemetryCollector.CollectorInfo.CollectorUri = collectorUri; // Act var openTelemetryCollectorValidationStep = new OpenTelemetryCollectorMetricSinkValidationStep(runtimeConfiguration, NullLogger.Instance); From 99740eeb37293e12b5966931f8b347cd026a870a Mon Sep 17 00:00:00 2001 From: Sameer Nafdey Date: Fri, 9 Jun 2023 13:51:40 -0700 Subject: [PATCH 07/10] Added changes from comments. --- config/promitor/scraper/runtime.yaml | 1 + .../IServiceCollectionExtensions.cs | 13 ++++---- src/Promitor.Agents.Scraper/Startup.cs | 10 +++--- ...emetryCollectorMetricSinkValidationStep.cs | 12 +++---- .../OpenTelemetryCollectorConfiguration.cs | 12 ++----- .../RuntimeConfigurationUnitTest.cs | 17 ++++++---- ...gusScraperRuntimeConfigurationGenerator.cs | 20 ++++++------ .../Config/RuntimeConfigurationGenerator.cs | 32 +++++++++---------- ...yCollectorMetricSinkValidationStepTests.cs | 10 +++--- 9 files changed, 62 insertions(+), 65 deletions(-) diff --git a/config/promitor/scraper/runtime.yaml b/config/promitor/scraper/runtime.yaml index 8c236eb45..22d2cbfc9 100644 --- a/config/promitor/scraper/runtime.yaml +++ b/config/promitor/scraper/runtime.yaml @@ -11,6 +11,7 @@ metricSinks: promitorMetricName: promitor_demo_documentation_availability openTelemetryCollector: collectorUri: http://opentelemetry-collector:4317 + protocol: Banana prometheusScrapingEndpoint: metricUnavailableValue: -1 enableMetricTimestamps: true # true by default diff --git a/src/Promitor.Agents.Scraper/Extensions/IServiceCollectionExtensions.cs b/src/Promitor.Agents.Scraper/Extensions/IServiceCollectionExtensions.cs index aa88dd3b6..74b27392c 100644 --- a/src/Promitor.Agents.Scraper/Extensions/IServiceCollectionExtensions.cs +++ b/src/Promitor.Agents.Scraper/Extensions/IServiceCollectionExtensions.cs @@ -1,10 +1,8 @@ -using System; -using GuardNet; +using GuardNet; using JustEat.StatsD; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Logging; -using OpenTelemetry.Exporter; using OpenTelemetry.Metrics; using OpenTelemetry.Resources; using Promitor.Agents.Core.Configuration.Server; @@ -45,6 +43,7 @@ using Promitor.Integrations.Sinks.Statsd; using Promitor.Integrations.Sinks.Statsd.Configuration; using Spectre.Console; +using System; // ReSharper disable once CheckNamespace namespace Microsoft.Extensions.DependencyInjection @@ -64,7 +63,7 @@ public static IServiceCollection AddResourceDiscoveryClient(this IServiceCollect var resourceDiscoveryConfiguration = configuration.Get(); - if(resourceDiscoveryConfiguration?.ResourceDiscovery?.IsConfigured == true) + if (resourceDiscoveryConfiguration?.ResourceDiscovery?.IsConfigured == true) { services.AddHttpClient(client => { @@ -197,9 +196,9 @@ public static IServiceCollection UseMetricSinks(this IServiceCollection services } if (metricSinkConfiguration?.OpenTelemetryCollector != null - && string.IsNullOrWhiteSpace(metricSinkConfiguration.OpenTelemetryCollector.CollectorInfo.CollectorUri) == false) + && string.IsNullOrWhiteSpace(metricSinkConfiguration.OpenTelemetryCollector.CollectorUri) == false) { - AddOpenTelemetryCollectorMetricSink(metricSinkConfiguration.OpenTelemetryCollector.CollectorInfo, agentVersion, services, metricSinkAsciiTable); + AddOpenTelemetryCollectorMetricSink(metricSinkConfiguration.OpenTelemetryCollector, agentVersion, services, metricSinkAsciiTable); } AnsiConsole.Write(metricSinkAsciiTable); @@ -225,7 +224,7 @@ private static void AddAtlassianStatuspageMetricSink(string pageId, IServiceColl const string OpenTelemetryServiceName = "promitor-scraper"; - private static void AddOpenTelemetryCollectorMetricSink(Promitor.Integrations.Sinks.OpenTelemetry.Configuration.OpenTelemetryCollectorSinkConfiguration.CollectorInfoConfiguration otelConfiguration, string agentVersion, IServiceCollection services, Table metricSinkAsciiTable) + private static void AddOpenTelemetryCollectorMetricSink(Promitor.Integrations.Sinks.OpenTelemetry.Configuration.OpenTelemetryCollectorSinkConfiguration otelConfiguration, string agentVersion, IServiceCollection services, Table metricSinkAsciiTable) { metricSinkAsciiTable.AddRow("OpenTelemetry Collector", $"Url: {otelConfiguration.CollectorUri}."); metricSinkAsciiTable.AddRow("OpenTelemetry Collector", $"Protocol: {otelConfiguration.Protocol}."); diff --git a/src/Promitor.Agents.Scraper/Startup.cs b/src/Promitor.Agents.Scraper/Startup.cs index ed1db9d4d..208207d7d 100644 --- a/src/Promitor.Agents.Scraper/Startup.cs +++ b/src/Promitor.Agents.Scraper/Startup.cs @@ -1,6 +1,4 @@ -using System; -using System.Text; -using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -15,6 +13,8 @@ using Promitor.Core.Scraping.Configuration.Serialization.v1.Mapping; using Promitor.Integrations.AzureMonitor.Logging; using Serilog; +using System; +using System.Text; using Version = Promitor.Core.Version; namespace Promitor.Agents.Scraper @@ -114,8 +114,8 @@ private string BuildOpenApiDescription(IConfiguration configuration) if (metricSinkConfiguration.OpenTelemetryCollector != null) { - openApiDescriptionBuilder.AppendLine($"
  • OpenTelemetry Collector located on {metricSinkConfiguration.OpenTelemetryCollector.CollectorInfo.CollectorUri}
  • "); - openApiDescriptionBuilder.AppendLine($"
  • OpenTelemetry Collector Protocol selected: {metricSinkConfiguration.OpenTelemetryCollector.CollectorInfo.Protocol}
  • "); + openApiDescriptionBuilder.AppendLine($"
  • OpenTelemetry Collector located on {metricSinkConfiguration.OpenTelemetryCollector.CollectorUri}
  • "); + openApiDescriptionBuilder.AppendLine($"
  • OpenTelemetry Collector Protocol selected: {metricSinkConfiguration.OpenTelemetryCollector.Protocol}
  • "); } if (metricSinkConfiguration.Statsd != null) diff --git a/src/Promitor.Agents.Scraper/Validation/Steps/Sinks/OpenTelemetryCollectorMetricSinkValidationStep.cs b/src/Promitor.Agents.Scraper/Validation/Steps/Sinks/OpenTelemetryCollectorMetricSinkValidationStep.cs index 04b837713..29d84ae3d 100644 --- a/src/Promitor.Agents.Scraper/Validation/Steps/Sinks/OpenTelemetryCollectorMetricSinkValidationStep.cs +++ b/src/Promitor.Agents.Scraper/Validation/Steps/Sinks/OpenTelemetryCollectorMetricSinkValidationStep.cs @@ -1,13 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using OpenTelemetry.Exporter; using Promitor.Agents.Core.Validation; using Promitor.Agents.Core.Validation.Interfaces; using Promitor.Agents.Core.Validation.Steps; using Promitor.Agents.Scraper.Configuration; +using System; +using System.Collections.Generic; +using System.Linq; namespace Promitor.Agents.Scraper.Validation.Steps.Sinks { @@ -33,8 +33,8 @@ public ValidationResult Run() } var errorMessages = new List(); - var collectorUri = openTelemetryCollectorSinkConfiguration.CollectorInfo.CollectorUri; - var collectorProtocol = openTelemetryCollectorSinkConfiguration.CollectorInfo.Protocol; + var collectorUri = openTelemetryCollectorSinkConfiguration.CollectorUri; + var collectorProtocol = openTelemetryCollectorSinkConfiguration.Protocol; // URI Validation if (string.IsNullOrWhiteSpace(collectorUri)) diff --git a/src/Promitor.Integrations.Sinks.OpenTelemetry/Configuration/OpenTelemetryCollectorConfiguration.cs b/src/Promitor.Integrations.Sinks.OpenTelemetry/Configuration/OpenTelemetryCollectorConfiguration.cs index 28972389b..51083cb0d 100644 --- a/src/Promitor.Integrations.Sinks.OpenTelemetry/Configuration/OpenTelemetryCollectorConfiguration.cs +++ b/src/Promitor.Integrations.Sinks.OpenTelemetry/Configuration/OpenTelemetryCollectorConfiguration.cs @@ -4,14 +4,8 @@ namespace Promitor.Integrations.Sinks.OpenTelemetry.Configuration { public class OpenTelemetryCollectorSinkConfiguration { - public CollectorInfoConfiguration CollectorInfo { get; set; } - - public class CollectorInfoConfiguration - { - public OtlpExportProtocol Protocol { get; set; } = default(OtlpExportProtocol); - public string CollectorUri { get; set; } - //Todo: Headers - - } + public OtlpExportProtocol Protocol { get; set; } = default(OtlpExportProtocol); + public string CollectorUri { get; set; } + //Todo: Headers } } diff --git a/src/Promitor.Tests.Unit/Configuration/RuntimeConfigurationUnitTest.cs b/src/Promitor.Tests.Unit/Configuration/RuntimeConfigurationUnitTest.cs index 151d25768..42f9cda0f 100644 --- a/src/Promitor.Tests.Unit/Configuration/RuntimeConfigurationUnitTest.cs +++ b/src/Promitor.Tests.Unit/Configuration/RuntimeConfigurationUnitTest.cs @@ -1,11 +1,12 @@ -using System.ComponentModel; -using System.Threading.Tasks; -using Microsoft.Azure.Management.ResourceManager.Fluent.Core; +using Microsoft.Azure.Management.ResourceManager.Fluent.Core; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using OpenTelemetry.Exporter; using Promitor.Agents.Scraper.Configuration; using Promitor.Integrations.Sinks.Statsd.Configuration; using Promitor.Tests.Unit.Generators.Config; +using System.ComponentModel; +using System.Threading.Tasks; using Xunit; using DefaultsCore = Promitor.Agents.Core.Configuration.Defaults; @@ -364,7 +365,8 @@ public async Task RuntimeConfiguration_HasConfiguredGenevaInStatsDEndpoint_UsesC var genevaAccountName = "abc"; var genevaNamespace = "xyz"; - var geneva = new GenevaConfiguration { + var geneva = new GenevaConfiguration + { Account = genevaAccountName, Namespace = genevaNamespace }; @@ -391,7 +393,7 @@ public async Task RuntimeConfiguration_HasConfiguredCollectorUriInOpenTelemetryC // Arrange var collectorUri = "https://foo.bar"; var configuration = await RuntimeConfigurationGenerator.WithServerConfiguration() - .WithOpenTelemetryCollectorMetricSink(collectorUri: collectorUri) + .WithOpenTelemetryCollectorMetricSink(collectorUri: collectorUri, protocol: OtlpExportProtocol.HttpProtobuf) .GenerateAsync(); // Act @@ -401,7 +403,8 @@ public async Task RuntimeConfiguration_HasConfiguredCollectorUriInOpenTelemetryC Assert.NotNull(runtimeConfiguration); Assert.NotNull(runtimeConfiguration.MetricSinks); Assert.NotNull(runtimeConfiguration.MetricSinks.OpenTelemetryCollector); - Assert.Equal(collectorUri, runtimeConfiguration.MetricSinks.OpenTelemetryCollector.CollectorInfo.CollectorUri); + Assert.Equal(collectorUri, runtimeConfiguration.MetricSinks.OpenTelemetryCollector.CollectorUri); + Assert.Equal(OtlpExportProtocol.HttpProtobuf, runtimeConfiguration.MetricSinks.OpenTelemetryCollector.Protocol); } [Fact] @@ -418,7 +421,7 @@ public async Task RuntimeConfiguration_HasConfiguredNoCollectorUriInOpenTelemetr // Assert Assert.NotNull(runtimeConfiguration); Assert.NotNull(runtimeConfiguration.MetricSinks); - Assert.Null(runtimeConfiguration.MetricSinks.OpenTelemetryCollector.CollectorInfo); + Assert.Null(runtimeConfiguration.MetricSinks.OpenTelemetryCollector); } [Fact] diff --git a/src/Promitor.Tests.Unit/Generators/Config/BogusScraperRuntimeConfigurationGenerator.cs b/src/Promitor.Tests.Unit/Generators/Config/BogusScraperRuntimeConfigurationGenerator.cs index 35ba0069a..375627569 100644 --- a/src/Promitor.Tests.Unit/Generators/Config/BogusScraperRuntimeConfigurationGenerator.cs +++ b/src/Promitor.Tests.Unit/Generators/Config/BogusScraperRuntimeConfigurationGenerator.cs @@ -1,6 +1,6 @@ -using System.Collections.Generic; -using Bogus; +using Bogus; using Microsoft.Extensions.Logging; +using OpenTelemetry.Exporter; using Promitor.Agents.Core.Configuration.Server; using Promitor.Agents.Core.Configuration.Telemetry; using Promitor.Agents.Core.Configuration.Telemetry.Sinks; @@ -11,6 +11,7 @@ using Promitor.Integrations.Sinks.OpenTelemetry.Configuration; using Promitor.Integrations.Sinks.Prometheus.Configuration; using Promitor.Integrations.Sinks.Statsd.Configuration; +using System.Collections.Generic; namespace Promitor.Tests.Unit.Generators.Config { @@ -72,10 +73,10 @@ private static StatsdSinkConfiguration GenerateStatsdSinkConfiguration() .RuleFor(statsdSinkConfiguration => statsdSinkConfiguration.Port, faker => faker.Random.Int(min: 0)) .RuleFor(statsdSinkConfiguration => statsdSinkConfiguration.MetricPrefix, faker => faker.Person.FirstName) .RuleFor(statsdSinkConfiguration => statsdSinkConfiguration.MetricFormat, _ => StatsdFormatterTypesEnum.Default) - .RuleFor(statsdSinkConfiguration => statsdSinkConfiguration.Geneva, faker => new GenevaConfiguration - { - Account = faker.Person.FirstName, - Namespace = faker.Person.LastName + .RuleFor(statsdSinkConfiguration => statsdSinkConfiguration.Geneva, faker => new GenevaConfiguration + { + Account = faker.Person.FirstName, + Namespace = faker.Person.LastName }) .Generate(); return statsDConfiguration; @@ -131,13 +132,13 @@ private static ServerConfiguration GenerateServerConfiguration() .Generate(); return serverConfiguration; } - + private static AtlassianStatusPageSinkConfiguration GenerateAtlassianStatusPageSinkConfiguration() { var atlassianStatusPageSinkConfiguration = new Faker() .StrictMode(true) .RuleFor(promConfiguration => promConfiguration.PageId, faker => faker.Person.FirstName) - .RuleFor(promConfiguration => promConfiguration.SystemMetricMapping, _ => new List { GenerateAtlassianStatuspageSystemMetricMapping() }) + .RuleFor(promConfiguration => promConfiguration.SystemMetricMapping, _ => new List { GenerateAtlassianStatuspageSystemMetricMapping() }) .Generate(); return atlassianStatusPageSinkConfiguration; } @@ -155,7 +156,8 @@ private static OpenTelemetryCollectorSinkConfiguration GenerateOpenTelemetryColl { var openTelemetryCollectorSinkConfiguration = new Faker() .StrictMode(true) - .RuleFor(promConfiguration => promConfiguration.CollectorInfo.CollectorUri, faker => faker.Internet.Url()) + .RuleFor(promConfiguration => promConfiguration.CollectorUri, faker => faker.Internet.Url()) + .RuleFor(promConfiguration => promConfiguration.Protocol, faker => OtlpExportProtocol.HttpProtobuf) .Generate(); return openTelemetryCollectorSinkConfiguration; } diff --git a/src/Promitor.Tests.Unit/Generators/Config/RuntimeConfigurationGenerator.cs b/src/Promitor.Tests.Unit/Generators/Config/RuntimeConfigurationGenerator.cs index 5dc022d15..4ffb224af 100644 --- a/src/Promitor.Tests.Unit/Generators/Config/RuntimeConfigurationGenerator.cs +++ b/src/Promitor.Tests.Unit/Generators/Config/RuntimeConfigurationGenerator.cs @@ -1,9 +1,4 @@ -using System; -using System.IO; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; -using Microsoft.Azure.Management.ResourceManager.Fluent.Core; +using Microsoft.Azure.Management.ResourceManager.Fluent.Core; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using OpenTelemetry.Exporter; @@ -16,6 +11,11 @@ using Promitor.Integrations.Sinks.OpenTelemetry.Configuration; using Promitor.Integrations.Sinks.Prometheus.Configuration; using Promitor.Integrations.Sinks.Statsd.Configuration; +using System; +using System.IO; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; namespace Promitor.Tests.Unit.Generators.Config @@ -73,12 +73,12 @@ public RuntimeConfigurationGenerator WithPrometheusMetricSink(double? metricUnav if (metricUnavailableValue != null) { - prometheusSinkConfiguration.MetricUnavailableValue = (double) metricUnavailableValue; + prometheusSinkConfiguration.MetricUnavailableValue = (double)metricUnavailableValue; } if (enableMetricsTimestamp != null) { - prometheusSinkConfiguration.EnableMetricTimestamps = (bool) enableMetricsTimestamp; + prometheusSinkConfiguration.EnableMetricTimestamps = (bool)enableMetricsTimestamp; } } @@ -93,12 +93,9 @@ public RuntimeConfigurationGenerator WithOpenTelemetryCollectorMetricSink(string { _runtimeConfiguration.MetricSinks.OpenTelemetryCollector = new OpenTelemetryCollectorSinkConfiguration { - CollectorInfo = new Promitor.Integrations.Sinks.OpenTelemetry.Configuration.OpenTelemetryCollectorSinkConfiguration.CollectorInfoConfiguration - { - CollectorUri = collectorUri, - Protocol = protocol - // Todo: Headers - } + CollectorUri = collectorUri, + Protocol = protocol + // Todo: Headers }; } @@ -208,7 +205,7 @@ public RuntimeConfigurationGenerator WithContainerTelemetry(LogLevel? verbosity }; _runtimeConfiguration.Telemetry ??= new TelemetryConfiguration(); -_runtimeConfiguration.Telemetry.ContainerLogs = containerLogConfiguration; + _runtimeConfiguration.Telemetry.ContainerLogs = containerLogConfiguration; return this; } @@ -291,7 +288,7 @@ public async Task GenerateAsync() configurationBuilder.AppendLine($" account: {_runtimeConfiguration?.MetricSinks.Statsd.Geneva.Account}"); configurationBuilder.AppendLine($" namespace: {_runtimeConfiguration?.MetricSinks.Statsd.Geneva.Namespace}"); } - } + } if (_runtimeConfiguration?.MetricSinks.PrometheusScrapingEndpoint != null) { configurationBuilder.AppendLine(" prometheusScrapingEndpoint:"); @@ -302,7 +299,8 @@ public async Task GenerateAsync() if (_runtimeConfiguration?.MetricSinks.OpenTelemetryCollector != null) { configurationBuilder.AppendLine(" openTelemetryCollector:"); - configurationBuilder.AppendLine($" collectorUri: {_runtimeConfiguration?.MetricSinks.OpenTelemetryCollector.CollectorInfo.CollectorUri}"); + configurationBuilder.AppendLine($" collectorUri: {_runtimeConfiguration?.MetricSinks.OpenTelemetryCollector.CollectorUri}"); + configurationBuilder.AppendLine($" protocol: {_runtimeConfiguration?.MetricSinks.OpenTelemetryCollector.Protocol}"); } } diff --git a/src/Promitor.Tests.Unit/Validation/Scraper/Metrics/Sinks/OpenTelemetryCollectorMetricSinkValidationStepTests.cs b/src/Promitor.Tests.Unit/Validation/Scraper/Metrics/Sinks/OpenTelemetryCollectorMetricSinkValidationStepTests.cs index d847c68cc..58689a69e 100644 --- a/src/Promitor.Tests.Unit/Validation/Scraper/Metrics/Sinks/OpenTelemetryCollectorMetricSinkValidationStepTests.cs +++ b/src/Promitor.Tests.Unit/Validation/Scraper/Metrics/Sinks/OpenTelemetryCollectorMetricSinkValidationStepTests.cs @@ -1,9 +1,9 @@ -using System.ComponentModel; -using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; using Promitor.Agents.Scraper.Configuration; using Promitor.Agents.Scraper.Validation.Steps.Sinks; using Promitor.Tests.Unit.Generators.Config; +using System.ComponentModel; using Xunit; namespace Promitor.Tests.Unit.Validation.Scraper.Metrics.Sinks @@ -62,7 +62,7 @@ public void Validate_OpenTelemetryCollectorWithUnspecifiedCollectorUri_Fails(str { // Arrange var runtimeConfiguration = CreateRuntimeConfiguration(); - runtimeConfiguration.Value.MetricSinks.OpenTelemetryCollector.CollectorInfo.CollectorUri = collectorUri; + runtimeConfiguration.Value.MetricSinks.OpenTelemetryCollector.CollectorUri = collectorUri; // Act var openTelemetryCollectorValidationStep = new OpenTelemetryCollectorMetricSinkValidationStep(runtimeConfiguration, NullLogger.Instance); @@ -81,7 +81,7 @@ public void Validate_OpenTelemetryCollectorWithInvalidCollectorUri_Fails(string { // Arrange var runtimeConfiguration = CreateRuntimeConfiguration(); - runtimeConfiguration.Value.MetricSinks.OpenTelemetryCollector.CollectorInfo.CollectorUri = collectorUri; + runtimeConfiguration.Value.MetricSinks.OpenTelemetryCollector.CollectorUri = collectorUri; // Act var openTelemetryCollectorValidationStep = new OpenTelemetryCollectorMetricSinkValidationStep(runtimeConfiguration, NullLogger.Instance); @@ -104,7 +104,7 @@ public void Validate_OpenTelemetryCollectorWithValidCollectorUri_Fails(string co { // Arrange var runtimeConfiguration = CreateRuntimeConfiguration(); - runtimeConfiguration.Value.MetricSinks.OpenTelemetryCollector.CollectorInfo.CollectorUri = collectorUri; + runtimeConfiguration.Value.MetricSinks.OpenTelemetryCollector.CollectorUri = collectorUri; // Act var openTelemetryCollectorValidationStep = new OpenTelemetryCollectorMetricSinkValidationStep(runtimeConfiguration, NullLogger.Instance); From 9de3e5d2d3000b3345d795e80dae98e8e4f06ff2 Mon Sep 17 00:00:00 2001 From: bunkrur Date: Fri, 9 Jun 2023 16:54:59 -0700 Subject: [PATCH 08/10] fix: fixing banana to Grpc --- config/promitor/scraper/runtime.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/promitor/scraper/runtime.yaml b/config/promitor/scraper/runtime.yaml index 22d2cbfc9..f4b852b45 100644 --- a/config/promitor/scraper/runtime.yaml +++ b/config/promitor/scraper/runtime.yaml @@ -11,7 +11,7 @@ metricSinks: promitorMetricName: promitor_demo_documentation_availability openTelemetryCollector: collectorUri: http://opentelemetry-collector:4317 - protocol: Banana + protocol: Grpc prometheusScrapingEndpoint: metricUnavailableValue: -1 enableMetricTimestamps: true # true by default From 7f34354fecc02bf1aefce24c9b6ce9f079cc8c53 Mon Sep 17 00:00:00 2001 From: bunkrur Date: Fri, 9 Jun 2023 13:51:40 -0700 Subject: [PATCH 09/10] Added changes from comments. --- config/promitor/scraper/runtime.yaml | 1 + .../IServiceCollectionExtensions.cs | 13 ++++---- src/Promitor.Agents.Scraper/Startup.cs | 10 +++--- ...emetryCollectorMetricSinkValidationStep.cs | 12 +++---- .../OpenTelemetryCollectorConfiguration.cs | 12 ++----- .../RuntimeConfigurationUnitTest.cs | 17 ++++++---- ...gusScraperRuntimeConfigurationGenerator.cs | 20 ++++++------ .../Config/RuntimeConfigurationGenerator.cs | 32 +++++++++---------- ...yCollectorMetricSinkValidationStepTests.cs | 10 +++--- 9 files changed, 62 insertions(+), 65 deletions(-) diff --git a/config/promitor/scraper/runtime.yaml b/config/promitor/scraper/runtime.yaml index 8c236eb45..22d2cbfc9 100644 --- a/config/promitor/scraper/runtime.yaml +++ b/config/promitor/scraper/runtime.yaml @@ -11,6 +11,7 @@ metricSinks: promitorMetricName: promitor_demo_documentation_availability openTelemetryCollector: collectorUri: http://opentelemetry-collector:4317 + protocol: Banana prometheusScrapingEndpoint: metricUnavailableValue: -1 enableMetricTimestamps: true # true by default diff --git a/src/Promitor.Agents.Scraper/Extensions/IServiceCollectionExtensions.cs b/src/Promitor.Agents.Scraper/Extensions/IServiceCollectionExtensions.cs index aa88dd3b6..74b27392c 100644 --- a/src/Promitor.Agents.Scraper/Extensions/IServiceCollectionExtensions.cs +++ b/src/Promitor.Agents.Scraper/Extensions/IServiceCollectionExtensions.cs @@ -1,10 +1,8 @@ -using System; -using GuardNet; +using GuardNet; using JustEat.StatsD; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Logging; -using OpenTelemetry.Exporter; using OpenTelemetry.Metrics; using OpenTelemetry.Resources; using Promitor.Agents.Core.Configuration.Server; @@ -45,6 +43,7 @@ using Promitor.Integrations.Sinks.Statsd; using Promitor.Integrations.Sinks.Statsd.Configuration; using Spectre.Console; +using System; // ReSharper disable once CheckNamespace namespace Microsoft.Extensions.DependencyInjection @@ -64,7 +63,7 @@ public static IServiceCollection AddResourceDiscoveryClient(this IServiceCollect var resourceDiscoveryConfiguration = configuration.Get(); - if(resourceDiscoveryConfiguration?.ResourceDiscovery?.IsConfigured == true) + if (resourceDiscoveryConfiguration?.ResourceDiscovery?.IsConfigured == true) { services.AddHttpClient(client => { @@ -197,9 +196,9 @@ public static IServiceCollection UseMetricSinks(this IServiceCollection services } if (metricSinkConfiguration?.OpenTelemetryCollector != null - && string.IsNullOrWhiteSpace(metricSinkConfiguration.OpenTelemetryCollector.CollectorInfo.CollectorUri) == false) + && string.IsNullOrWhiteSpace(metricSinkConfiguration.OpenTelemetryCollector.CollectorUri) == false) { - AddOpenTelemetryCollectorMetricSink(metricSinkConfiguration.OpenTelemetryCollector.CollectorInfo, agentVersion, services, metricSinkAsciiTable); + AddOpenTelemetryCollectorMetricSink(metricSinkConfiguration.OpenTelemetryCollector, agentVersion, services, metricSinkAsciiTable); } AnsiConsole.Write(metricSinkAsciiTable); @@ -225,7 +224,7 @@ private static void AddAtlassianStatuspageMetricSink(string pageId, IServiceColl const string OpenTelemetryServiceName = "promitor-scraper"; - private static void AddOpenTelemetryCollectorMetricSink(Promitor.Integrations.Sinks.OpenTelemetry.Configuration.OpenTelemetryCollectorSinkConfiguration.CollectorInfoConfiguration otelConfiguration, string agentVersion, IServiceCollection services, Table metricSinkAsciiTable) + private static void AddOpenTelemetryCollectorMetricSink(Promitor.Integrations.Sinks.OpenTelemetry.Configuration.OpenTelemetryCollectorSinkConfiguration otelConfiguration, string agentVersion, IServiceCollection services, Table metricSinkAsciiTable) { metricSinkAsciiTable.AddRow("OpenTelemetry Collector", $"Url: {otelConfiguration.CollectorUri}."); metricSinkAsciiTable.AddRow("OpenTelemetry Collector", $"Protocol: {otelConfiguration.Protocol}."); diff --git a/src/Promitor.Agents.Scraper/Startup.cs b/src/Promitor.Agents.Scraper/Startup.cs index ed1db9d4d..208207d7d 100644 --- a/src/Promitor.Agents.Scraper/Startup.cs +++ b/src/Promitor.Agents.Scraper/Startup.cs @@ -1,6 +1,4 @@ -using System; -using System.Text; -using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -15,6 +13,8 @@ using Promitor.Core.Scraping.Configuration.Serialization.v1.Mapping; using Promitor.Integrations.AzureMonitor.Logging; using Serilog; +using System; +using System.Text; using Version = Promitor.Core.Version; namespace Promitor.Agents.Scraper @@ -114,8 +114,8 @@ private string BuildOpenApiDescription(IConfiguration configuration) if (metricSinkConfiguration.OpenTelemetryCollector != null) { - openApiDescriptionBuilder.AppendLine($"
  • OpenTelemetry Collector located on {metricSinkConfiguration.OpenTelemetryCollector.CollectorInfo.CollectorUri}
  • "); - openApiDescriptionBuilder.AppendLine($"
  • OpenTelemetry Collector Protocol selected: {metricSinkConfiguration.OpenTelemetryCollector.CollectorInfo.Protocol}
  • "); + openApiDescriptionBuilder.AppendLine($"
  • OpenTelemetry Collector located on {metricSinkConfiguration.OpenTelemetryCollector.CollectorUri}
  • "); + openApiDescriptionBuilder.AppendLine($"
  • OpenTelemetry Collector Protocol selected: {metricSinkConfiguration.OpenTelemetryCollector.Protocol}
  • "); } if (metricSinkConfiguration.Statsd != null) diff --git a/src/Promitor.Agents.Scraper/Validation/Steps/Sinks/OpenTelemetryCollectorMetricSinkValidationStep.cs b/src/Promitor.Agents.Scraper/Validation/Steps/Sinks/OpenTelemetryCollectorMetricSinkValidationStep.cs index 04b837713..29d84ae3d 100644 --- a/src/Promitor.Agents.Scraper/Validation/Steps/Sinks/OpenTelemetryCollectorMetricSinkValidationStep.cs +++ b/src/Promitor.Agents.Scraper/Validation/Steps/Sinks/OpenTelemetryCollectorMetricSinkValidationStep.cs @@ -1,13 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using OpenTelemetry.Exporter; using Promitor.Agents.Core.Validation; using Promitor.Agents.Core.Validation.Interfaces; using Promitor.Agents.Core.Validation.Steps; using Promitor.Agents.Scraper.Configuration; +using System; +using System.Collections.Generic; +using System.Linq; namespace Promitor.Agents.Scraper.Validation.Steps.Sinks { @@ -33,8 +33,8 @@ public ValidationResult Run() } var errorMessages = new List(); - var collectorUri = openTelemetryCollectorSinkConfiguration.CollectorInfo.CollectorUri; - var collectorProtocol = openTelemetryCollectorSinkConfiguration.CollectorInfo.Protocol; + var collectorUri = openTelemetryCollectorSinkConfiguration.CollectorUri; + var collectorProtocol = openTelemetryCollectorSinkConfiguration.Protocol; // URI Validation if (string.IsNullOrWhiteSpace(collectorUri)) diff --git a/src/Promitor.Integrations.Sinks.OpenTelemetry/Configuration/OpenTelemetryCollectorConfiguration.cs b/src/Promitor.Integrations.Sinks.OpenTelemetry/Configuration/OpenTelemetryCollectorConfiguration.cs index 28972389b..51083cb0d 100644 --- a/src/Promitor.Integrations.Sinks.OpenTelemetry/Configuration/OpenTelemetryCollectorConfiguration.cs +++ b/src/Promitor.Integrations.Sinks.OpenTelemetry/Configuration/OpenTelemetryCollectorConfiguration.cs @@ -4,14 +4,8 @@ namespace Promitor.Integrations.Sinks.OpenTelemetry.Configuration { public class OpenTelemetryCollectorSinkConfiguration { - public CollectorInfoConfiguration CollectorInfo { get; set; } - - public class CollectorInfoConfiguration - { - public OtlpExportProtocol Protocol { get; set; } = default(OtlpExportProtocol); - public string CollectorUri { get; set; } - //Todo: Headers - - } + public OtlpExportProtocol Protocol { get; set; } = default(OtlpExportProtocol); + public string CollectorUri { get; set; } + //Todo: Headers } } diff --git a/src/Promitor.Tests.Unit/Configuration/RuntimeConfigurationUnitTest.cs b/src/Promitor.Tests.Unit/Configuration/RuntimeConfigurationUnitTest.cs index 151d25768..42f9cda0f 100644 --- a/src/Promitor.Tests.Unit/Configuration/RuntimeConfigurationUnitTest.cs +++ b/src/Promitor.Tests.Unit/Configuration/RuntimeConfigurationUnitTest.cs @@ -1,11 +1,12 @@ -using System.ComponentModel; -using System.Threading.Tasks; -using Microsoft.Azure.Management.ResourceManager.Fluent.Core; +using Microsoft.Azure.Management.ResourceManager.Fluent.Core; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using OpenTelemetry.Exporter; using Promitor.Agents.Scraper.Configuration; using Promitor.Integrations.Sinks.Statsd.Configuration; using Promitor.Tests.Unit.Generators.Config; +using System.ComponentModel; +using System.Threading.Tasks; using Xunit; using DefaultsCore = Promitor.Agents.Core.Configuration.Defaults; @@ -364,7 +365,8 @@ public async Task RuntimeConfiguration_HasConfiguredGenevaInStatsDEndpoint_UsesC var genevaAccountName = "abc"; var genevaNamespace = "xyz"; - var geneva = new GenevaConfiguration { + var geneva = new GenevaConfiguration + { Account = genevaAccountName, Namespace = genevaNamespace }; @@ -391,7 +393,7 @@ public async Task RuntimeConfiguration_HasConfiguredCollectorUriInOpenTelemetryC // Arrange var collectorUri = "https://foo.bar"; var configuration = await RuntimeConfigurationGenerator.WithServerConfiguration() - .WithOpenTelemetryCollectorMetricSink(collectorUri: collectorUri) + .WithOpenTelemetryCollectorMetricSink(collectorUri: collectorUri, protocol: OtlpExportProtocol.HttpProtobuf) .GenerateAsync(); // Act @@ -401,7 +403,8 @@ public async Task RuntimeConfiguration_HasConfiguredCollectorUriInOpenTelemetryC Assert.NotNull(runtimeConfiguration); Assert.NotNull(runtimeConfiguration.MetricSinks); Assert.NotNull(runtimeConfiguration.MetricSinks.OpenTelemetryCollector); - Assert.Equal(collectorUri, runtimeConfiguration.MetricSinks.OpenTelemetryCollector.CollectorInfo.CollectorUri); + Assert.Equal(collectorUri, runtimeConfiguration.MetricSinks.OpenTelemetryCollector.CollectorUri); + Assert.Equal(OtlpExportProtocol.HttpProtobuf, runtimeConfiguration.MetricSinks.OpenTelemetryCollector.Protocol); } [Fact] @@ -418,7 +421,7 @@ public async Task RuntimeConfiguration_HasConfiguredNoCollectorUriInOpenTelemetr // Assert Assert.NotNull(runtimeConfiguration); Assert.NotNull(runtimeConfiguration.MetricSinks); - Assert.Null(runtimeConfiguration.MetricSinks.OpenTelemetryCollector.CollectorInfo); + Assert.Null(runtimeConfiguration.MetricSinks.OpenTelemetryCollector); } [Fact] diff --git a/src/Promitor.Tests.Unit/Generators/Config/BogusScraperRuntimeConfigurationGenerator.cs b/src/Promitor.Tests.Unit/Generators/Config/BogusScraperRuntimeConfigurationGenerator.cs index 35ba0069a..375627569 100644 --- a/src/Promitor.Tests.Unit/Generators/Config/BogusScraperRuntimeConfigurationGenerator.cs +++ b/src/Promitor.Tests.Unit/Generators/Config/BogusScraperRuntimeConfigurationGenerator.cs @@ -1,6 +1,6 @@ -using System.Collections.Generic; -using Bogus; +using Bogus; using Microsoft.Extensions.Logging; +using OpenTelemetry.Exporter; using Promitor.Agents.Core.Configuration.Server; using Promitor.Agents.Core.Configuration.Telemetry; using Promitor.Agents.Core.Configuration.Telemetry.Sinks; @@ -11,6 +11,7 @@ using Promitor.Integrations.Sinks.OpenTelemetry.Configuration; using Promitor.Integrations.Sinks.Prometheus.Configuration; using Promitor.Integrations.Sinks.Statsd.Configuration; +using System.Collections.Generic; namespace Promitor.Tests.Unit.Generators.Config { @@ -72,10 +73,10 @@ private static StatsdSinkConfiguration GenerateStatsdSinkConfiguration() .RuleFor(statsdSinkConfiguration => statsdSinkConfiguration.Port, faker => faker.Random.Int(min: 0)) .RuleFor(statsdSinkConfiguration => statsdSinkConfiguration.MetricPrefix, faker => faker.Person.FirstName) .RuleFor(statsdSinkConfiguration => statsdSinkConfiguration.MetricFormat, _ => StatsdFormatterTypesEnum.Default) - .RuleFor(statsdSinkConfiguration => statsdSinkConfiguration.Geneva, faker => new GenevaConfiguration - { - Account = faker.Person.FirstName, - Namespace = faker.Person.LastName + .RuleFor(statsdSinkConfiguration => statsdSinkConfiguration.Geneva, faker => new GenevaConfiguration + { + Account = faker.Person.FirstName, + Namespace = faker.Person.LastName }) .Generate(); return statsDConfiguration; @@ -131,13 +132,13 @@ private static ServerConfiguration GenerateServerConfiguration() .Generate(); return serverConfiguration; } - + private static AtlassianStatusPageSinkConfiguration GenerateAtlassianStatusPageSinkConfiguration() { var atlassianStatusPageSinkConfiguration = new Faker() .StrictMode(true) .RuleFor(promConfiguration => promConfiguration.PageId, faker => faker.Person.FirstName) - .RuleFor(promConfiguration => promConfiguration.SystemMetricMapping, _ => new List { GenerateAtlassianStatuspageSystemMetricMapping() }) + .RuleFor(promConfiguration => promConfiguration.SystemMetricMapping, _ => new List { GenerateAtlassianStatuspageSystemMetricMapping() }) .Generate(); return atlassianStatusPageSinkConfiguration; } @@ -155,7 +156,8 @@ private static OpenTelemetryCollectorSinkConfiguration GenerateOpenTelemetryColl { var openTelemetryCollectorSinkConfiguration = new Faker() .StrictMode(true) - .RuleFor(promConfiguration => promConfiguration.CollectorInfo.CollectorUri, faker => faker.Internet.Url()) + .RuleFor(promConfiguration => promConfiguration.CollectorUri, faker => faker.Internet.Url()) + .RuleFor(promConfiguration => promConfiguration.Protocol, faker => OtlpExportProtocol.HttpProtobuf) .Generate(); return openTelemetryCollectorSinkConfiguration; } diff --git a/src/Promitor.Tests.Unit/Generators/Config/RuntimeConfigurationGenerator.cs b/src/Promitor.Tests.Unit/Generators/Config/RuntimeConfigurationGenerator.cs index 5dc022d15..4ffb224af 100644 --- a/src/Promitor.Tests.Unit/Generators/Config/RuntimeConfigurationGenerator.cs +++ b/src/Promitor.Tests.Unit/Generators/Config/RuntimeConfigurationGenerator.cs @@ -1,9 +1,4 @@ -using System; -using System.IO; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; -using Microsoft.Azure.Management.ResourceManager.Fluent.Core; +using Microsoft.Azure.Management.ResourceManager.Fluent.Core; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using OpenTelemetry.Exporter; @@ -16,6 +11,11 @@ using Promitor.Integrations.Sinks.OpenTelemetry.Configuration; using Promitor.Integrations.Sinks.Prometheus.Configuration; using Promitor.Integrations.Sinks.Statsd.Configuration; +using System; +using System.IO; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; namespace Promitor.Tests.Unit.Generators.Config @@ -73,12 +73,12 @@ public RuntimeConfigurationGenerator WithPrometheusMetricSink(double? metricUnav if (metricUnavailableValue != null) { - prometheusSinkConfiguration.MetricUnavailableValue = (double) metricUnavailableValue; + prometheusSinkConfiguration.MetricUnavailableValue = (double)metricUnavailableValue; } if (enableMetricsTimestamp != null) { - prometheusSinkConfiguration.EnableMetricTimestamps = (bool) enableMetricsTimestamp; + prometheusSinkConfiguration.EnableMetricTimestamps = (bool)enableMetricsTimestamp; } } @@ -93,12 +93,9 @@ public RuntimeConfigurationGenerator WithOpenTelemetryCollectorMetricSink(string { _runtimeConfiguration.MetricSinks.OpenTelemetryCollector = new OpenTelemetryCollectorSinkConfiguration { - CollectorInfo = new Promitor.Integrations.Sinks.OpenTelemetry.Configuration.OpenTelemetryCollectorSinkConfiguration.CollectorInfoConfiguration - { - CollectorUri = collectorUri, - Protocol = protocol - // Todo: Headers - } + CollectorUri = collectorUri, + Protocol = protocol + // Todo: Headers }; } @@ -208,7 +205,7 @@ public RuntimeConfigurationGenerator WithContainerTelemetry(LogLevel? verbosity }; _runtimeConfiguration.Telemetry ??= new TelemetryConfiguration(); -_runtimeConfiguration.Telemetry.ContainerLogs = containerLogConfiguration; + _runtimeConfiguration.Telemetry.ContainerLogs = containerLogConfiguration; return this; } @@ -291,7 +288,7 @@ public async Task GenerateAsync() configurationBuilder.AppendLine($" account: {_runtimeConfiguration?.MetricSinks.Statsd.Geneva.Account}"); configurationBuilder.AppendLine($" namespace: {_runtimeConfiguration?.MetricSinks.Statsd.Geneva.Namespace}"); } - } + } if (_runtimeConfiguration?.MetricSinks.PrometheusScrapingEndpoint != null) { configurationBuilder.AppendLine(" prometheusScrapingEndpoint:"); @@ -302,7 +299,8 @@ public async Task GenerateAsync() if (_runtimeConfiguration?.MetricSinks.OpenTelemetryCollector != null) { configurationBuilder.AppendLine(" openTelemetryCollector:"); - configurationBuilder.AppendLine($" collectorUri: {_runtimeConfiguration?.MetricSinks.OpenTelemetryCollector.CollectorInfo.CollectorUri}"); + configurationBuilder.AppendLine($" collectorUri: {_runtimeConfiguration?.MetricSinks.OpenTelemetryCollector.CollectorUri}"); + configurationBuilder.AppendLine($" protocol: {_runtimeConfiguration?.MetricSinks.OpenTelemetryCollector.Protocol}"); } } diff --git a/src/Promitor.Tests.Unit/Validation/Scraper/Metrics/Sinks/OpenTelemetryCollectorMetricSinkValidationStepTests.cs b/src/Promitor.Tests.Unit/Validation/Scraper/Metrics/Sinks/OpenTelemetryCollectorMetricSinkValidationStepTests.cs index d847c68cc..58689a69e 100644 --- a/src/Promitor.Tests.Unit/Validation/Scraper/Metrics/Sinks/OpenTelemetryCollectorMetricSinkValidationStepTests.cs +++ b/src/Promitor.Tests.Unit/Validation/Scraper/Metrics/Sinks/OpenTelemetryCollectorMetricSinkValidationStepTests.cs @@ -1,9 +1,9 @@ -using System.ComponentModel; -using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; using Promitor.Agents.Scraper.Configuration; using Promitor.Agents.Scraper.Validation.Steps.Sinks; using Promitor.Tests.Unit.Generators.Config; +using System.ComponentModel; using Xunit; namespace Promitor.Tests.Unit.Validation.Scraper.Metrics.Sinks @@ -62,7 +62,7 @@ public void Validate_OpenTelemetryCollectorWithUnspecifiedCollectorUri_Fails(str { // Arrange var runtimeConfiguration = CreateRuntimeConfiguration(); - runtimeConfiguration.Value.MetricSinks.OpenTelemetryCollector.CollectorInfo.CollectorUri = collectorUri; + runtimeConfiguration.Value.MetricSinks.OpenTelemetryCollector.CollectorUri = collectorUri; // Act var openTelemetryCollectorValidationStep = new OpenTelemetryCollectorMetricSinkValidationStep(runtimeConfiguration, NullLogger.Instance); @@ -81,7 +81,7 @@ public void Validate_OpenTelemetryCollectorWithInvalidCollectorUri_Fails(string { // Arrange var runtimeConfiguration = CreateRuntimeConfiguration(); - runtimeConfiguration.Value.MetricSinks.OpenTelemetryCollector.CollectorInfo.CollectorUri = collectorUri; + runtimeConfiguration.Value.MetricSinks.OpenTelemetryCollector.CollectorUri = collectorUri; // Act var openTelemetryCollectorValidationStep = new OpenTelemetryCollectorMetricSinkValidationStep(runtimeConfiguration, NullLogger.Instance); @@ -104,7 +104,7 @@ public void Validate_OpenTelemetryCollectorWithValidCollectorUri_Fails(string co { // Arrange var runtimeConfiguration = CreateRuntimeConfiguration(); - runtimeConfiguration.Value.MetricSinks.OpenTelemetryCollector.CollectorInfo.CollectorUri = collectorUri; + runtimeConfiguration.Value.MetricSinks.OpenTelemetryCollector.CollectorUri = collectorUri; // Act var openTelemetryCollectorValidationStep = new OpenTelemetryCollectorMetricSinkValidationStep(runtimeConfiguration, NullLogger.Instance); From 3639be3fdc1416d9fb1f051b8d26b8aece54c235 Mon Sep 17 00:00:00 2001 From: bunkrur Date: Fri, 9 Jun 2023 16:54:59 -0700 Subject: [PATCH 10/10] fix: fixing banana to Grpc --- config/promitor/scraper/runtime.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/promitor/scraper/runtime.yaml b/config/promitor/scraper/runtime.yaml index 22d2cbfc9..f4b852b45 100644 --- a/config/promitor/scraper/runtime.yaml +++ b/config/promitor/scraper/runtime.yaml @@ -11,7 +11,7 @@ metricSinks: promitorMetricName: promitor_demo_documentation_availability openTelemetryCollector: collectorUri: http://opentelemetry-collector:4317 - protocol: Banana + protocol: Grpc prometheusScrapingEndpoint: metricUnavailableValue: -1 enableMetricTimestamps: true # true by default