Add Prometheus exporter integration test (#918)
* Add Prometheus exporter integration test * Refactor
This commit is contained in:
parent
987092738c
commit
b413fde253
|
@ -84,7 +84,7 @@ public class GraphQLTests : TestHelper
|
|||
|
||||
int aspNetCorePort = TcpPortProvider.GetOpenPort();
|
||||
using (var agent = new MockZipkinCollector(Output))
|
||||
using (Process process = StartTestApplication(agent.Port, arguments: null, packageVersion: string.Empty, aspNetCorePort: aspNetCorePort))
|
||||
using (var process = StartTestApplication(agent.Port, aspNetCorePort: aspNetCorePort))
|
||||
{
|
||||
if (process.HasExited)
|
||||
{
|
||||
|
|
|
@ -121,17 +121,22 @@ public abstract class TestHelper
|
|||
/// StartTestApplication starts the test application
|
||||
// and returns the Process instance for further interaction.
|
||||
/// </summary>
|
||||
public Process StartTestApplication(int traceAgentPort, string arguments, string packageVersion, int aspNetCorePort, string framework = "", bool enableStartupHook = true)
|
||||
public Process StartTestApplication(int traceAgentPort = 0, string arguments = null, string packageVersion = "", int aspNetCorePort = 0, string framework = "", bool enableStartupHook = true)
|
||||
{
|
||||
var testSettings = new TestSettings
|
||||
{
|
||||
TracesSettings = new TracesSettings { Port = traceAgentPort },
|
||||
Arguments = arguments,
|
||||
PackageVersion = packageVersion,
|
||||
AspNetCorePort = aspNetCorePort,
|
||||
Framework = framework,
|
||||
EnableStartupHook = enableStartupHook
|
||||
};
|
||||
|
||||
if (traceAgentPort != 0)
|
||||
{
|
||||
testSettings.TracesSettings = new() { Port = traceAgentPort };
|
||||
}
|
||||
|
||||
return StartTestApplication(testSettings);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,8 +18,12 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using FluentAssertions.Execution;
|
||||
using FluentAssertions.Extensions;
|
||||
using IntegrationTests.Helpers;
|
||||
using IntegrationTests.Helpers.Mocks;
|
||||
using IntegrationTests.Helpers.Models;
|
||||
|
@ -145,6 +149,39 @@ public class SmokeTests : TestHelper
|
|||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", "EndToEnd")]
|
||||
public async Task PrometheusExporter()
|
||||
{
|
||||
SetEnvironmentVariable("LONG_RUNNING", "true");
|
||||
SetEnvironmentVariable("OTEL_METRICS_EXPORTER", "prometheus");
|
||||
SetEnvironmentVariable("OTEL_DOTNET_AUTO_METRICS_ADDITIONAL_SOURCES", "MyCompany.MyProduct.MyLibrary");
|
||||
string defaultPrometheusMetricsEndpoint = "http://localhost:9464/metrics";
|
||||
|
||||
using var process = StartTestApplication();
|
||||
|
||||
try
|
||||
{
|
||||
var assert = async () =>
|
||||
{
|
||||
var response = await new HttpClient().GetAsync(defaultPrometheusMetricsEndpoint);
|
||||
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
|
||||
var content = await response.Content.ReadAsStringAsync();
|
||||
Output.WriteLine("Raw metrics from Prometheus:");
|
||||
Output.WriteLine(content);
|
||||
content.Should().Contain("TYPE MyFruitCounter counter");
|
||||
};
|
||||
await assert.Should().NotThrowAfterAsync(
|
||||
waitTime: 30.Seconds(),
|
||||
pollInterval: 1.Seconds());
|
||||
}
|
||||
finally
|
||||
{
|
||||
process.Kill();
|
||||
}
|
||||
}
|
||||
|
||||
private static void AssertNoSpansReceived(IImmutableList<IMockSpan> spans)
|
||||
{
|
||||
Assert.True(spans.Count() == 0, $"Expecting no spans, received {spans.Count()}");
|
||||
|
|
|
@ -14,10 +14,12 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.Metrics;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
|
||||
namespace TestApplication.Smoke
|
||||
{
|
||||
|
@ -29,6 +31,12 @@ namespace TestApplication.Smoke
|
|||
{
|
||||
EmitTraces();
|
||||
EmitMetrics();
|
||||
|
||||
var longRunning = Environment.GetEnvironmentVariable("LONG_RUNNING");
|
||||
while (longRunning == "true")
|
||||
{
|
||||
Thread.Yield();
|
||||
}
|
||||
}
|
||||
|
||||
private static void EmitTraces()
|
||||
|
|
Loading…
Reference in New Issue