Skip to content

Commit

Permalink
Style changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jcin193 committed Jun 23, 2024
1 parent 47ad841 commit 152bd51
Showing 1 changed file with 42 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,48 @@ private static void TestPrometheusHttpListenerUriPrefixOptions(string[] uriPrefi
});
}

private static MeterProvider BuildMeterProvider(Meter meter, IEnumerable<KeyValuePair<string, object>> 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");
Expand Down Expand Up @@ -265,46 +307,4 @@ private async Task RunPrometheusExporterHttpServerIntegrationTest(bool skipMetri

provider.Dispose();
}

private static MeterProvider BuildMeterProvider(Meter meter, IEnumerable<KeyValuePair<string, object>> 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;
}
}

0 comments on commit 152bd51

Please sign in to comment.