From 152bd516df5770694bc0ea0640ac21513320b8aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Justinas=20=C4=8Cin=C4=8Dikas?= Date: Sun, 23 Jun 2024 14:54:07 +0300 Subject: [PATCH] Style changes --- .../PrometheusHttpListenerTests.cs | 84 +++++++++---------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusHttpListenerTests.cs b/test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusHttpListenerTests.cs index a619c561040..cbaf619cbe9 100644 --- a/test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusHttpListenerTests.cs +++ b/test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusHttpListenerTests.cs @@ -194,6 +194,48 @@ private static void TestPrometheusHttpListenerUriPrefixOptions(string[] uriPrefi }); } + private static MeterProvider BuildMeterProvider(Meter meter, IEnumerable> attributes, out string address) + { + Random random = new Random(); + int retryAttempts = 5; + int port = 0; + string generatedAddress = null; + MeterProvider provider = null; + + while (retryAttempts-- != 0) + { + port = random.Next(2000, 5000); + generatedAddress = $"http://localhost:{port}/"; + + try + { + provider = Sdk.CreateMeterProviderBuilder() + .AddMeter(meter.Name) + .ConfigureResource(x => x.Clear().AddService("my_service", serviceInstanceId: "id1").AddAttributes(attributes)) + .AddPrometheusHttpListener(options => + { + options.UriPrefixes = new string[] { generatedAddress }; + }) + .Build(); + + break; + } + catch + { + // ignored + } + } + + address = generatedAddress; + + if (provider == null) + { + throw new InvalidOperationException("HttpListener could not be started"); + } + + return provider; + } + private async Task RunPrometheusExporterHttpServerIntegrationTest(bool skipMetrics = false, string acceptHeader = "application/openmetrics-text") { var requestOpenMetrics = acceptHeader.StartsWith("application/openmetrics-text"); @@ -265,46 +307,4 @@ private async Task RunPrometheusExporterHttpServerIntegrationTest(bool skipMetri provider.Dispose(); } - - private static MeterProvider BuildMeterProvider(Meter meter, IEnumerable> attributes, out string address) - { - Random random = new Random(); - int retryAttempts = 5; - int port = 0; - string generatedAddress = null; - MeterProvider provider = null; - - while (retryAttempts-- != 0) - { - port = random.Next(2000, 5000); - generatedAddress = $"http://localhost:{port}/"; - - try - { - provider = Sdk.CreateMeterProviderBuilder() - .AddMeter(meter.Name) - .ConfigureResource(x => x.Clear().AddService("my_service", serviceInstanceId: "id1").AddAttributes(attributes)) - .AddPrometheusHttpListener(options => - { - options.UriPrefixes = new string[] { generatedAddress }; - }) - .Build(); - - break; - } - catch - { - // ignored - } - } - - address = generatedAddress; - - if (provider == null) - { - throw new InvalidOperationException("HttpListener could not be started"); - } - - return provider; - } }