Skip to content

Commit

Permalink
Add tests and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
robertcoltheart committed May 16, 2024
1 parent 8e59472 commit 519dfcc
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 64 deletions.
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Exporter.Prometheus.AspNetCore/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

* Fixed an issue with corrupted buffers when reading both OpenMetrics and
plain text formats formats from Prometheus exporters
([#5517](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5517))

## 1.8.0-rc.1

Released 2024-Mar-27
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

* Fixed an issue with corrupted buffers when reading both OpenMetrics and
plain text formats formats from Prometheus exporters
([#5517](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5517))

## 1.8.0-rc.1

Released 2024-Mar-27
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ internal sealed class PrometheusCollectionManager
private ArraySegment<byte> previousPlainTextDataView;
private ArraySegment<byte> previousOpenMetricsDataView;
private int globalLockState;
private DateTime? previousDataViewGeneratedAtUtc;
private DateTime? previousPlainTextDataViewGeneratedAtUtc;
private DateTime? previousOpenMetricsDataViewGeneratedAtUtc;
private int readerCount;
private bool collectionRunning;
private TaskCompletionSource<CollectionResponse> collectionTcs;
Expand All @@ -46,16 +47,20 @@ public Task<CollectionResponse> EnterCollect(bool openMetricsRequested)

// If we are within {ScrapeResponseCacheDurationMilliseconds} of the
// last successful collect, return the previous view.
if (this.previousDataViewGeneratedAtUtc.HasValue
var previousDataViewGeneratedAtUtc = openMetricsRequested
? this.previousOpenMetricsDataViewGeneratedAtUtc
: this.previousPlainTextDataViewGeneratedAtUtc;

if (previousDataViewGeneratedAtUtc.HasValue
&& this.scrapeResponseCacheDurationMilliseconds > 0
&& this.previousDataViewGeneratedAtUtc.Value.AddMilliseconds(this.scrapeResponseCacheDurationMilliseconds) >= DateTime.UtcNow)
&& previousDataViewGeneratedAtUtc.Value.AddMilliseconds(this.scrapeResponseCacheDurationMilliseconds) >= DateTime.UtcNow)
{
Interlocked.Increment(ref this.readerCount);
this.ExitGlobalLock();
#if NET6_0_OR_GREATER
return new ValueTask<CollectionResponse>(new CollectionResponse(this.previousOpenMetricsDataView, this.previousPlainTextDataView, this.previousDataViewGeneratedAtUtc.Value, fromCache: true));
return new ValueTask<CollectionResponse>(new CollectionResponse(this.previousOpenMetricsDataView, this.previousPlainTextDataView, openMetricsRequested, previousDataViewGeneratedAtUtc.Value, fromCache: true));
#else
return Task.FromResult(new CollectionResponse(this.previousOpenMetricsDataView, this.previousPlainTextDataView, this.previousDataViewGeneratedAtUtc.Value, fromCache: true));
return Task.FromResult(new CollectionResponse(this.previousOpenMetricsDataView, this.previousPlainTextDataView, openMetricsRequested, previousDataViewGeneratedAtUtc.Value, fromCache: true));
#endif
}

Expand All @@ -80,16 +85,35 @@ public Task<CollectionResponse> EnterCollect(bool openMetricsRequested)

// Start a collection on the current thread.
this.collectionRunning = true;
this.previousDataViewGeneratedAtUtc = null;
if (openMetricsRequested)
{
this.previousOpenMetricsDataViewGeneratedAtUtc = null;
}
else
{
this.previousPlainTextDataViewGeneratedAtUtc = null;
}

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (ubuntu-latest, net8.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (ubuntu-latest, net8.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (ubuntu-latest, net8.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (ubuntu-latest, net8.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (ubuntu-latest, net8.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (ubuntu-latest, net7.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (ubuntu-latest, net7.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (ubuntu-latest, net7.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (ubuntu-latest, net7.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (ubuntu-latest, net7.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (ubuntu-latest, net6.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (ubuntu-latest, net6.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (ubuntu-latest, net6.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (ubuntu-latest, net6.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (ubuntu-latest, net6.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net8.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net8.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net8.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net8.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net8.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net6.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net6.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net6.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net6.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net6.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net6.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net6.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net6.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net6.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net6.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net7.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net7.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net7.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net7.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net7.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net8.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net8.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net8.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net8.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net8.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net7.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net7.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net7.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net7.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net7.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net6.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net6.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net6.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net6.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net6.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net462)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net462)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net462)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net462)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net462)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net8.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net8.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net8.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net8.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-experimental

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-experimental

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-experimental

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-experimental

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-experimental

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-stable

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-stable

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-stable

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-stable

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-stable

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net7.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net7.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net7.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net7.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net7.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net8.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net8.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net8.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net8.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net8.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net6.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net6.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net6.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net6.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net6.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net462)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net462)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net462)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net462)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net462)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net7.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net7.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net7.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net7.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net7.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net7.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net7.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net7.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net7.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net7.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net462)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net462)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net462)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net462)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net462)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net6.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net6.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net6.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net6.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net6.0)

Check warning on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-stable

Closing brace should be followed by blank line

Check warning on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-stable

Closing brace should be followed by blank line

Check warning on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-stable

Closing brace should be followed by blank line

Check warning on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-stable

Closing brace should be followed by blank line

Check warning on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-stable

Closing brace should be followed by blank line

Check warning on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-stable

Closing brace should be followed by blank line

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net8.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net8.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net8.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net8.0)

Check failure on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net8.0)

Check warning on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-experimental

Closing brace should be followed by blank line

Check warning on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-experimental

Closing brace should be followed by blank line

Check warning on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-experimental

Closing brace should be followed by blank line

Check warning on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-experimental

Closing brace should be followed by blank line

Check warning on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-experimental

Closing brace should be followed by blank line

Check warning on line 95 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-experimental

Closing brace should be followed by blank line
Interlocked.Increment(ref this.readerCount);
this.ExitGlobalLock();

CollectionResponse response;
var result = this.ExecuteCollect(openMetricsRequested);
if (result)
{
this.previousDataViewGeneratedAtUtc = DateTime.UtcNow;
response = new CollectionResponse(this.previousOpenMetricsDataView, this.previousPlainTextDataView, this.previousDataViewGeneratedAtUtc.Value, fromCache: false);
if (openMetricsRequested)
{
this.previousOpenMetricsDataViewGeneratedAtUtc = DateTime.UtcNow;
}
else
{
this.previousPlainTextDataViewGeneratedAtUtc = DateTime.UtcNow;
}

previousDataViewGeneratedAtUtc = openMetricsRequested
? this.previousOpenMetricsDataViewGeneratedAtUtc
: this.previousPlainTextDataViewGeneratedAtUtc;

response = new CollectionResponse(this.previousOpenMetricsDataView, this.previousPlainTextDataView, openMetricsRequested, previousDataViewGeneratedAtUtc.Value, fromCache: false);
}
else
{
Expand Down Expand Up @@ -216,6 +240,10 @@ private ExportResult OnCollect(Batch<Metric> metrics)
}
}
}
else
{
int a = 1;

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (ubuntu-latest, net8.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (ubuntu-latest, net8.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (ubuntu-latest, net8.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (ubuntu-latest, net8.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (ubuntu-latest, net8.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (ubuntu-latest, net7.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (ubuntu-latest, net7.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (ubuntu-latest, net7.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (ubuntu-latest, net7.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (ubuntu-latest, net7.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (ubuntu-latest, net6.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (ubuntu-latest, net6.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (ubuntu-latest, net6.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (ubuntu-latest, net6.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (ubuntu-latest, net6.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net8.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net8.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net8.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net8.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net8.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net6.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net6.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net6.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net6.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net6.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net6.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net6.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net6.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net6.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net6.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net7.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net7.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net7.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net7.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net7.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net8.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net8.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net8.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net8.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net8.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net7.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net7.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net7.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net7.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net7.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net6.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net6.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net6.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net6.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net6.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net462)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net462)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net462)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net462)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net462)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net8.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net8.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net8.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net8.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net8.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-unstable-core / build-test (windows-latest, net8.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-experimental

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-experimental

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-experimental

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-experimental

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-experimental

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-stable

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-stable

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-stable

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-stable

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-stable

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net7.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net7.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net7.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net7.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net7.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net8.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net8.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net8.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net8.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net8.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net6.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net6.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net6.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net6.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net6.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net462)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net462)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net462)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net462)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net462)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net7.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net7.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net7.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net7.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net7.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net7.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net7.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net7.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net7.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net7.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net462)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net462)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net462)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net462)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net462)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net6.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net6.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net6.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net6.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net6.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net8.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net8.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net8.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net8.0)

The variable 'a' is assigned but its value is never used

Check failure on line 245 in src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net8.0)

The variable 'a' is assigned but its value is never used
}

foreach (var metric in metrics)
{
Expand Down Expand Up @@ -350,10 +378,11 @@ private PrometheusMetric GetPrometheusMetric(Metric metric)

public readonly struct CollectionResponse
{
public CollectionResponse(ArraySegment<byte> openMetricsView, ArraySegment<byte> plainTextView, DateTime generatedAtUtc, bool fromCache)
public CollectionResponse(ArraySegment<byte> openMetricsView, ArraySegment<byte> plainTextView, bool openMetricsRequested, DateTime generatedAtUtc, bool fromCache)
{
this.OpenMetricsView = openMetricsView;
this.PlainTextView = plainTextView;
this.OpenMetricsRequested = openMetricsRequested;
this.GeneratedAtUtc = generatedAtUtc;
this.FromCache = fromCache;
}
Expand All @@ -362,6 +391,8 @@ public CollectionResponse(ArraySegment<byte> openMetricsView, ArraySegment<byte>

public ArraySegment<byte> PlainTextView { get; }

public bool OpenMetricsRequested { get; }

public DateTime GeneratedAtUtc { get; }

public bool FromCache { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,46 @@ public Task PrometheusExporterMiddlewareIntegration_UseOpenMetricsVersionHeader(
acceptHeader: "application/openmetrics-text; version=1.0.0");
}

[Fact]
public async Task PrometheusExporterMiddlewareIntegration_CanServeOpenMetricsAndPlainFormats()
{
using var host = await StartTestHostAsync(
app => app.UseOpenTelemetryPrometheusScrapingEndpoint());

var tags = new KeyValuePair<string, object>[]
{
new KeyValuePair<string, object>("key1", "value1"),
new KeyValuePair<string, object>("key2", "value2"),
};

using var meter = new Meter(MeterName, MeterVersion);

var beginTimestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();

var counter = meter.CreateCounter<double>("counter_double");
counter.Add(100.18D, tags);
counter.Add(0.99D, tags);

var testCases = new bool[] { true, false };

using var client = host.GetTestClient();

foreach (var testCase in testCases)
{
using var request = new HttpRequestMessage
{
Headers = { { "Accept", testCase ? "application/openmetrics-text" : "text/plain" } },
RequestUri = new Uri("/metrics", UriKind.Relative),
Method = HttpMethod.Get,
};
using var response = await client.SendAsync(request);
var endTimestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
await VerifyAsync(beginTimestamp, endTimestamp, response, testCase);
}

await host.StopAsync();
}

private static async Task RunPrometheusExporterMiddlewareIntegrationTest(
string path,
Action<IApplicationBuilder> configure,
Expand All @@ -260,26 +300,7 @@ private static async Task RunPrometheusExporterMiddlewareIntegrationTest(
{
var requestOpenMetrics = acceptHeader.StartsWith("application/openmetrics-text");

using var host = await new HostBuilder()
.ConfigureWebHost(webBuilder => webBuilder
.UseTestServer()
.ConfigureServices(services =>
{
if (registerMeterProvider)
{
services.AddOpenTelemetry().WithMetrics(builder => builder
.ConfigureResource(x => x.Clear().AddService("my_service", serviceInstanceId: "id1"))
.AddMeter(MeterName)
.AddPrometheusExporter(o =>
{
configureOptions?.Invoke(o);
}));
}
configureServices?.Invoke(services);
})
.Configure(configure))
.StartAsync();
using var host = await StartTestHostAsync(configure, configureServices, registerMeterProvider, configureOptions);

var tags = new KeyValuePair<string, object>[]
{
Expand Down Expand Up @@ -310,51 +331,89 @@ private static async Task RunPrometheusExporterMiddlewareIntegrationTest(
var endTimestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();

if (!skipMetrics)
{
await VerifyAsync(beginTimestamp, endTimestamp, response, requestOpenMetrics);
}
else
{
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.True(response.Content.Headers.Contains("Last-Modified"));

if (requestOpenMetrics)
{
Assert.Equal("application/openmetrics-text; version=1.0.0; charset=utf-8", response.Content.Headers.ContentType.ToString());
}
else
{
Assert.Equal("text/plain; charset=utf-8; version=0.0.4", response.Content.Headers.ContentType.ToString());
}

string content = await response.Content.ReadAsStringAsync();

string expected = requestOpenMetrics
? "# TYPE target info\n"
+ "# HELP target Target metadata\n"
+ "target_info{service_name='my_service',service_instance_id='id1'} 1\n"
+ "# TYPE otel_scope_info info\n"
+ "# HELP otel_scope_info Scope metadata\n"
+ $"otel_scope_info{{otel_scope_name='{MeterName}'}} 1\n"
+ "# TYPE counter_double_total counter\n"
+ $"counter_double_total{{otel_scope_name='{MeterName}',otel_scope_version='{MeterVersion}',key1='value1',key2='value2'}} 101.17 (\\d+\\.\\d{{3}})\n"
+ "# EOF\n"
: "# TYPE counter_double_total counter\n"
+ $"counter_double_total{{otel_scope_name='{MeterName}',otel_scope_version='{MeterVersion}',key1='value1',key2='value2'}} 101.17 (\\d+)\n"
+ "# EOF\n";
}

var matches = Regex.Matches(content, ("^" + expected + "$").Replace('\'', '"'));
validateResponse?.Invoke(response);

Assert.Single(matches);
await host.StopAsync();
}

var timestamp = long.Parse(matches[0].Groups[1].Value.Replace(".", string.Empty));
private static async Task VerifyAsync(long beginTimestamp, long endTimestamp, HttpResponseMessage response, bool requestOpenMetrics)
{
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.True(response.Content.Headers.Contains("Last-Modified"));

Assert.True(beginTimestamp <= timestamp && timestamp <= endTimestamp);
if (requestOpenMetrics)
{
Assert.Equal("application/openmetrics-text; version=1.0.0; charset=utf-8", response.Content.Headers.ContentType.ToString());
}
else
{
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal("text/plain; charset=utf-8; version=0.0.4", response.Content.Headers.ContentType.ToString());
}

validateResponse?.Invoke(response);
string content = (await response.Content.ReadAsStringAsync()).ReplaceLineEndings();

await host.StopAsync();
string expected = requestOpenMetrics
? $$"""
# TYPE target info
# HELP target Target metadata
target_info{service_name="my_service",service_instance_id="id1"} 1
# TYPE otel_scope_info info
# HELP otel_scope_info Scope metadata
otel_scope_info{otel_scope_name="{{MeterName}}"} 1
# TYPE counter_double_total counter
counter_double_total{otel_scope_name="{{MeterName}}",otel_scope_version="{{MeterVersion}}",key1="value1",key2="value2"} 101.17 (\d+\.\d{3})
# EOF

""".ReplaceLineEndings()
: $$"""
# TYPE counter_double_total counter
counter_double_total{otel_scope_name="{{MeterName}}",otel_scope_version="{{MeterVersion}}",key1="value1",key2="value2"} 101.17 (\d+)
# EOF

""".ReplaceLineEndings();

var matches = Regex.Matches(content, "^" + expected + "$");

Assert.True(matches.Count == 1, content);

var timestamp = long.Parse(matches[0].Groups[1].Value.Replace(".", string.Empty));

Assert.True(beginTimestamp <= timestamp && timestamp <= endTimestamp, $"{beginTimestamp} {timestamp} {endTimestamp}");
}

private static Task<IHost> StartTestHostAsync(
Action<IApplicationBuilder> configure,
Action<IServiceCollection> configureServices = null,
bool registerMeterProvider = true,
Action<PrometheusAspNetCoreOptions> configureOptions = null)
{
return new HostBuilder()
.ConfigureWebHost(webBuilder => webBuilder
.UseTestServer()
.ConfigureServices(services =>
{
if (registerMeterProvider)
{
services.AddOpenTelemetry().WithMetrics(builder => builder
.ConfigureResource(x => x.Clear().AddService("my_service", serviceInstanceId: "id1"))
.AddMeter(MeterName)
.AddPrometheusExporter(o =>
{
configureOptions?.Invoke(o);
}));
}

Check warning on line 412 in test/OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests/PrometheusExporterMiddlewareTests.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-stable

Closing brace should be followed by blank line

Check warning on line 412 in test/OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests/PrometheusExporterMiddlewareTests.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-stable

Closing brace should be followed by blank line

Check warning on line 412 in test/OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests/PrometheusExporterMiddlewareTests.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-stable

Closing brace should be followed by blank line

Check warning on line 412 in test/OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests/PrometheusExporterMiddlewareTests.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-experimental

Closing brace should be followed by blank line

Check warning on line 412 in test/OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests/PrometheusExporterMiddlewareTests.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-experimental

Closing brace should be followed by blank line

Check warning on line 412 in test/OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests/PrometheusExporterMiddlewareTests.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-experimental

Closing brace should be followed by blank line
configureServices?.Invoke(services);
})
.Configure(configure))
.StartAsync();
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public async Task EnterExitCollectTest(int scrapeResponseCacheDurationMillisecon
return new Response
{
CollectionResponse = response,
ViewPayload = response.View.ToArray(),
ViewPayload = openMetricsRequested ? response.OpenMetricsView.ToArray() : response.PlainTextView.ToArray(),
};
}
finally
Expand Down Expand Up @@ -124,7 +124,7 @@ public async Task EnterExitCollectTest(int scrapeResponseCacheDurationMillisecon
return new Response
{
CollectionResponse = response,
ViewPayload = response.View.ToArray(),
ViewPayload = openMetricsRequested ? response.OpenMetricsView.ToArray() : response.PlainTextView.ToArray(),
};
}
finally
Expand Down

0 comments on commit 519dfcc

Please sign in to comment.