[Prometheus] Remove shared project and move the shared code under listener project (#3503)

This commit is contained in:
Yun-Ting Lin 2022-07-29 17:16:20 -07:00 committed by GitHub
parent f21afc8ce9
commit 084244ccae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 427 additions and 106 deletions

View File

@ -239,14 +239,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Exporter.Prom
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Exporter.Prometheus.HttpListener", "src\OpenTelemetry.Exporter.Prometheus.HttpListener\OpenTelemetry.Exporter.Prometheus.HttpListener.csproj", "{6B0232B7-5F29-4FB5-B383-1AA02DFE1089}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Exporter.Prometheus.Shared", "src\OpenTelemetry.Exporter.Prometheus.Shared\OpenTelemetry.Exporter.Prometheus.Shared.csproj", "{4AD27517-BAFC-413B-A8F0-988C3CEDC662}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests", "test\OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests\OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests.csproj", "{FBD12B0B-6731-4DD4-9C13-86F34593E974}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Exporter.Prometheus.HttpListener.Tests", "test\OpenTelemetry.Exporter.Prometheus.HttpListener.Tests\OpenTelemetry.Exporter.Prometheus.HttpListener.Tests.csproj", "{4EF4364F-6E64-43CE-BED1-E6FE01024899}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Exporter.Prometheus.Shared.Tests", "test\OpenTelemetry.Exporter.Prometheus.Shared.Tests\OpenTelemetry.Exporter.Prometheus.Shared.Tests.csproj", "{8E75AEE2-017B-474F-A96D-035DF76A1C9E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -501,10 +497,6 @@ Global
{6B0232B7-5F29-4FB5-B383-1AA02DFE1089}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6B0232B7-5F29-4FB5-B383-1AA02DFE1089}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6B0232B7-5F29-4FB5-B383-1AA02DFE1089}.Release|Any CPU.Build.0 = Release|Any CPU
{4AD27517-BAFC-413B-A8F0-988C3CEDC662}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4AD27517-BAFC-413B-A8F0-988C3CEDC662}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4AD27517-BAFC-413B-A8F0-988C3CEDC662}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4AD27517-BAFC-413B-A8F0-988C3CEDC662}.Release|Any CPU.Build.0 = Release|Any CPU
{FBD12B0B-6731-4DD4-9C13-86F34593E974}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FBD12B0B-6731-4DD4-9C13-86F34593E974}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FBD12B0B-6731-4DD4-9C13-86F34593E974}.Release|Any CPU.ActiveCfg = Release|Any CPU
@ -513,10 +505,6 @@ Global
{4EF4364F-6E64-43CE-BED1-E6FE01024899}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4EF4364F-6E64-43CE-BED1-E6FE01024899}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4EF4364F-6E64-43CE-BED1-E6FE01024899}.Release|Any CPU.Build.0 = Release|Any CPU
{8E75AEE2-017B-474F-A96D-035DF76A1C9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8E75AEE2-017B-474F-A96D-035DF76A1C9E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8E75AEE2-017B-474F-A96D-035DF76A1C9E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8E75AEE2-017B-474F-A96D-035DF76A1C9E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -19,12 +19,12 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.Shared\PrometheusCollectionManager.cs" Link="Includes/PrometheusCollectionManager.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.Shared\PrometheusExporter.cs" Link="Includes/PrometheusExporter.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.Shared\PrometheusExporterEventSource.cs" Link="Includes/PrometheusExporterEventSource.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.Shared\PrometheusExporterOptions.cs" Link="Includes/PrometheusExporterOptions.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.Shared\PrometheusSerializer.cs" Link="Includes/PrometheusSerializer.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.Shared\PrometheusSerializerExt.cs" Link="Includes/PrometheusSerializerExt.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.HttpListener\Shared\PrometheusCollectionManager.cs" Link="Includes/PrometheusCollectionManager.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.HttpListener\Shared\PrometheusExporter.cs" Link="Includes/PrometheusExporter.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.HttpListener\Shared\PrometheusExporterEventSource.cs" Link="Includes/PrometheusExporterEventSource.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.HttpListener\Shared\PrometheusExporterOptions.cs" Link="Includes/PrometheusExporterOptions.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.HttpListener\Shared\PrometheusSerializer.cs" Link="Includes/PrometheusSerializer.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.HttpListener\Shared\PrometheusSerializerExt.cs" Link="Includes/PrometheusSerializerExt.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\ExceptionExtensions.cs" Link="Includes\ExceptionExtensions.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\Guard.cs" Link="Includes\Guard.cs" />
</ItemGroup>

View File

@ -16,7 +16,7 @@
using System;
using OpenTelemetry.Exporter.Prometheus.AspNetCore;
using OpenTelemetry.Exporter.Prometheus.Shared;
using OpenTelemetry.Exporter.Prometheus.HttpListener.Shared;
using OpenTelemetry.Internal;
namespace OpenTelemetry.Metrics

View File

@ -19,7 +19,7 @@ using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using OpenTelemetry.Exporter.Prometheus.Shared;
using OpenTelemetry.Exporter.Prometheus.HttpListener.Shared;
using OpenTelemetry.Internal;
using OpenTelemetry.Metrics;

View File

@ -1,12 +1,12 @@
OpenTelemetry.Exporter.Prometheus.HttpListener.PrometheusExporterOptions
OpenTelemetry.Exporter.Prometheus.HttpListener.PrometheusExporterOptions.PrometheusExporterOptions() -> void
OpenTelemetry.Exporter.Prometheus.HttpListener.PrometheusExporterOptions.ScrapeEndpointPath.get -> string
OpenTelemetry.Exporter.Prometheus.HttpListener.PrometheusExporterOptions.ScrapeEndpointPath.set -> void
OpenTelemetry.Exporter.Prometheus.HttpListener.PrometheusExporterOptions.ScrapeResponseCacheDurationMilliseconds.get -> int
OpenTelemetry.Exporter.Prometheus.HttpListener.PrometheusExporterOptions.ScrapeResponseCacheDurationMilliseconds.set -> void
OpenTelemetry.Exporter.Prometheus.HttpListener.PrometheusHttpListenerOptions
OpenTelemetry.Exporter.Prometheus.HttpListener.PrometheusHttpListenerOptions.Prefixes.get -> System.Collections.Generic.IReadOnlyCollection<string>
OpenTelemetry.Exporter.Prometheus.HttpListener.PrometheusHttpListenerOptions.Prefixes.set -> void
OpenTelemetry.Exporter.Prometheus.HttpListener.PrometheusHttpListenerOptions.PrometheusHttpListenerOptions() -> void
OpenTelemetry.Exporter.Prometheus.HttpListener.Shared.PrometheusExporterOptions
OpenTelemetry.Exporter.Prometheus.HttpListener.Shared.PrometheusExporterOptions.PrometheusExporterOptions() -> void
OpenTelemetry.Exporter.Prometheus.HttpListener.Shared.PrometheusExporterOptions.ScrapeEndpointPath.get -> string
OpenTelemetry.Exporter.Prometheus.HttpListener.Shared.PrometheusExporterOptions.ScrapeEndpointPath.set -> void
OpenTelemetry.Exporter.Prometheus.HttpListener.Shared.PrometheusExporterOptions.ScrapeResponseCacheDurationMilliseconds.get -> int
OpenTelemetry.Exporter.Prometheus.HttpListener.Shared.PrometheusExporterOptions.ScrapeResponseCacheDurationMilliseconds.set -> void
OpenTelemetry.Metrics.PrometheusExporterHttpListenerMeterProviderBuilderExtensions
static OpenTelemetry.Metrics.PrometheusExporterHttpListenerMeterProviderBuilderExtensions.AddPrometheusHttpListener(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action<OpenTelemetry.Exporter.Prometheus.HttpListener.PrometheusExporterOptions> configureExporterOptions = null, System.Action<OpenTelemetry.Exporter.Prometheus.HttpListener.PrometheusHttpListenerOptions> configureListenerOptions = null) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Metrics.PrometheusExporterHttpListenerMeterProviderBuilderExtensions.AddPrometheusHttpListener(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action<OpenTelemetry.Exporter.Prometheus.HttpListener.Shared.PrometheusExporterOptions> configureExporterOptions = null, System.Action<OpenTelemetry.Exporter.Prometheus.HttpListener.PrometheusHttpListenerOptions> configureListenerOptions = null) -> OpenTelemetry.Metrics.MeterProviderBuilder

View File

@ -1,12 +1,12 @@
OpenTelemetry.Exporter.Prometheus.HttpListener.PrometheusExporterOptions
OpenTelemetry.Exporter.Prometheus.HttpListener.PrometheusExporterOptions.PrometheusExporterOptions() -> void
OpenTelemetry.Exporter.Prometheus.HttpListener.PrometheusExporterOptions.ScrapeEndpointPath.get -> string
OpenTelemetry.Exporter.Prometheus.HttpListener.PrometheusExporterOptions.ScrapeEndpointPath.set -> void
OpenTelemetry.Exporter.Prometheus.HttpListener.PrometheusExporterOptions.ScrapeResponseCacheDurationMilliseconds.get -> int
OpenTelemetry.Exporter.Prometheus.HttpListener.PrometheusExporterOptions.ScrapeResponseCacheDurationMilliseconds.set -> void
OpenTelemetry.Exporter.Prometheus.HttpListener.PrometheusHttpListenerOptions
OpenTelemetry.Exporter.Prometheus.HttpListener.PrometheusHttpListenerOptions.Prefixes.get -> System.Collections.Generic.IReadOnlyCollection<string>
OpenTelemetry.Exporter.Prometheus.HttpListener.PrometheusHttpListenerOptions.Prefixes.set -> void
OpenTelemetry.Exporter.Prometheus.HttpListener.PrometheusHttpListenerOptions.PrometheusHttpListenerOptions() -> void
OpenTelemetry.Exporter.Prometheus.HttpListener.Shared.PrometheusExporterOptions
OpenTelemetry.Exporter.Prometheus.HttpListener.Shared.PrometheusExporterOptions.PrometheusExporterOptions() -> void
OpenTelemetry.Exporter.Prometheus.HttpListener.Shared.PrometheusExporterOptions.ScrapeEndpointPath.get -> string
OpenTelemetry.Exporter.Prometheus.HttpListener.Shared.PrometheusExporterOptions.ScrapeEndpointPath.set -> void
OpenTelemetry.Exporter.Prometheus.HttpListener.Shared.PrometheusExporterOptions.ScrapeResponseCacheDurationMilliseconds.get -> int
OpenTelemetry.Exporter.Prometheus.HttpListener.Shared.PrometheusExporterOptions.ScrapeResponseCacheDurationMilliseconds.set -> void
OpenTelemetry.Metrics.PrometheusExporterHttpListenerMeterProviderBuilderExtensions
static OpenTelemetry.Metrics.PrometheusExporterHttpListenerMeterProviderBuilderExtensions.AddPrometheusHttpListener(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action<OpenTelemetry.Exporter.Prometheus.HttpListener.PrometheusExporterOptions> configureExporterOptions = null, System.Action<OpenTelemetry.Exporter.Prometheus.HttpListener.PrometheusHttpListenerOptions> configureListenerOptions = null) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Metrics.PrometheusExporterHttpListenerMeterProviderBuilderExtensions.AddPrometheusHttpListener(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action<OpenTelemetry.Exporter.Prometheus.HttpListener.Shared.PrometheusExporterOptions> configureExporterOptions = null, System.Action<OpenTelemetry.Exporter.Prometheus.HttpListener.PrometheusHttpListenerOptions> configureListenerOptions = null) -> OpenTelemetry.Metrics.MeterProviderBuilder

View File

@ -17,9 +17,9 @@
using System.Runtime.CompilerServices;
#if SIGNED
[assembly: InternalsVisibleTo("OpenTelemetry.Exporter.Prometheus.HttpListener.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010051c1562a090fb0c9f391012a32198b5e5d9a60e9b80fa2d7b434c9e5ccb7259bd606e66f9660676afc6692b8cdc6793d190904551d2103b7b22fa636dcbb8208839785ba402ea08fc00c8f1500ccef28bbf599aa64ffb1e1d5dc1bf3420a3777badfe697856e9d52070a50c3ea5821c80bef17ca3acffa28f89dd413f096f898")]
[assembly: InternalsVisibleTo("Benchmarks, PublicKey=002400000480000094000000060200000024000052534131000400000100010051c1562a090fb0c9f391012a32198b5e5d9a60e9b80fa2d7b434c9e5ccb7259bd606e66f9660676afc6692b8cdc6793d190904551d2103b7b22fa636dcbb8208839785ba402ea08fc00c8f1500ccef28bbf599aa64ffb1e1d5dc1bf3420a3777badfe697856e9d52070a50c3ea5821c80bef17ca3acffa28f89dd413f096f898")]
[assembly: InternalsVisibleTo("OpenTelemetry.Exporter.Prometheus.Shared.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010051c1562a090fb0c9f391012a32198b5e5d9a60e9b80fa2d7b434c9e5ccb7259bd606e66f9660676afc6692b8cdc6793d190904551d2103b7b22fa636dcbb8208839785ba402ea08fc00c8f1500ccef28bbf599aa64ffb1e1d5dc1bf3420a3777badfe697856e9d52070a50c3ea5821c80bef17ca3acffa28f89dd413f096f898")]
#else
[assembly: InternalsVisibleTo("OpenTelemetry.Exporter.Prometheus.HttpListener.Tests")]
[assembly: InternalsVisibleTo("Benchmarks")]
[assembly: InternalsVisibleTo("OpenTelemetry.Exporter.Prometheus.Shared.Tests")]
#endif

View File

@ -14,21 +14,11 @@
<RunApiCompat>false</RunApiCompat>
</PropertyGroup>
<PropertyGroup>
<DefineConstants>$(DefineConstants);PROMETHEUS_HTTPLISTENER</DefineConstants>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry\OpenTelemetry.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.Shared\PrometheusCollectionManager.cs" Link="Includes/PrometheusCollectionManager.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.Shared\PrometheusExporter.cs" Link="Includes/PrometheusExporter.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.Shared\PrometheusExporterEventSource.cs" Link="Includes/PrometheusExporterEventSource.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.Shared\PrometheusExporterOptions.cs" Link="Includes/PrometheusExporterOptions.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.Shared\PrometheusSerializer.cs" Link="Includes/PrometheusSerializer.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.Shared\PrometheusSerializerExt.cs" Link="Includes/PrometheusSerializerExt.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\ExceptionExtensions.cs" Link="Includes\ExceptionExtensions.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\Guard.cs" Link="Includes\Guard.cs" />
</ItemGroup>

View File

@ -16,7 +16,7 @@
using System;
using OpenTelemetry.Exporter.Prometheus.HttpListener;
using OpenTelemetry.Exporter.Prometheus.Shared;
using OpenTelemetry.Exporter.Prometheus.HttpListener.Shared;
using OpenTelemetry.Internal;
namespace OpenTelemetry.Metrics

View File

@ -18,7 +18,7 @@ using System;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using OpenTelemetry.Exporter.Prometheus.Shared;
using OpenTelemetry.Exporter.Prometheus.HttpListener.Shared;
using OpenTelemetry.Internal;
namespace OpenTelemetry.Exporter.Prometheus.HttpListener

View File

@ -20,7 +20,7 @@ using System.Threading;
using System.Threading.Tasks;
using OpenTelemetry.Metrics;
namespace OpenTelemetry.Exporter.Prometheus.Shared
namespace OpenTelemetry.Exporter.Prometheus.HttpListener.Shared
{
internal sealed class PrometheusCollectionManager
{
@ -91,7 +91,7 @@ namespace OpenTelemetry.Exporter.Prometheus.Shared
this.ExitGlobalLock();
CollectionResponse response;
bool result = this.ExecuteCollect();
var result = this.ExecuteCollect();
if (result)
{
this.previousDataViewGeneratedAtUtc = DateTime.UtcNow;
@ -169,14 +169,14 @@ namespace OpenTelemetry.Exporter.Prometheus.Shared
private bool ExecuteCollect()
{
this.exporter.OnExport = this.onCollectRef;
bool result = this.exporter.Collect(Timeout.Infinite);
var result = this.exporter.Collect(Timeout.Infinite);
this.exporter.OnExport = null;
return result;
}
private ExportResult OnCollect(Batch<Metric> metrics)
{
int cursor = 0;
var cursor = 0;
try
{
@ -191,7 +191,7 @@ namespace OpenTelemetry.Exporter.Prometheus.Shared
}
catch (IndexOutOfRangeException)
{
int bufferSize = this.buffer.Length * 2;
var bufferSize = this.buffer.Length * 2;
// there are two cases we might run into the following condition:
// 1. we have many metrics to be exported - in this case we probably want

View File

@ -17,12 +17,10 @@
using System;
#if PROMETHEUS_ASPNETCORE
using OpenTelemetry.Exporter.Prometheus.AspNetCore;
#elif PROMETHEUS_HTTPLISTENER
using OpenTelemetry.Exporter.Prometheus.HttpListener;
#endif
using OpenTelemetry.Metrics;
namespace OpenTelemetry.Exporter.Prometheus.Shared
namespace OpenTelemetry.Exporter.Prometheus.HttpListener.Shared
{
/// <summary>
/// Exporter of OpenTelemetry metrics to Prometheus.

View File

@ -18,7 +18,7 @@ using System;
using System.Diagnostics.Tracing;
using OpenTelemetry.Internal;
namespace OpenTelemetry.Exporter.Prometheus.Shared
namespace OpenTelemetry.Exporter.Prometheus.HttpListener.Shared
{
/// <summary>
/// EventSource events emitted from the project.

View File

@ -19,10 +19,8 @@ using OpenTelemetry.Internal;
#if PROMETHEUS_ASPNETCORE
namespace OpenTelemetry.Exporter.Prometheus.AspNetCore
#elif PROMETHEUS_HTTPLISTENER
namespace OpenTelemetry.Exporter.Prometheus.HttpListener
#else
namespace OpenTelemetry.Exporter.Prometheus.Shared
namespace OpenTelemetry.Exporter.Prometheus.HttpListener.Shared
#endif
{
/// <summary>

View File

@ -22,7 +22,7 @@ using System.Globalization;
using System.Runtime.CompilerServices;
using OpenTelemetry.Internal;
namespace OpenTelemetry.Exporter.Prometheus.Shared
namespace OpenTelemetry.Exporter.Prometheus
{
/// <summary>
/// Basic PrometheusSerializer which has no OpenTelemetry dependency.

View File

@ -16,7 +16,7 @@
using OpenTelemetry.Metrics;
namespace OpenTelemetry.Exporter.Prometheus.Shared
namespace OpenTelemetry.Exporter.Prometheus
{
/// <summary>
/// OpenTelemetry additions to the PrometheusSerializer.

View File

@ -1,6 +0,0 @@
OpenTelemetry.Exporter.Prometheus.Shared.PrometheusExporterOptions
OpenTelemetry.Exporter.Prometheus.Shared.PrometheusExporterOptions.PrometheusExporterOptions() -> void
OpenTelemetry.Exporter.Prometheus.Shared.PrometheusExporterOptions.ScrapeEndpointPath.get -> string
OpenTelemetry.Exporter.Prometheus.Shared.PrometheusExporterOptions.ScrapeEndpointPath.set -> void
OpenTelemetry.Exporter.Prometheus.Shared.PrometheusExporterOptions.ScrapeResponseCacheDurationMilliseconds.get -> int
OpenTelemetry.Exporter.Prometheus.Shared.PrometheusExporterOptions.ScrapeResponseCacheDurationMilliseconds.set -> void

View File

@ -1,6 +0,0 @@
OpenTelemetry.Exporter.Prometheus.Shared.PrometheusExporterOptions
OpenTelemetry.Exporter.Prometheus.Shared.PrometheusExporterOptions.PrometheusExporterOptions() -> void
OpenTelemetry.Exporter.Prometheus.Shared.PrometheusExporterOptions.ScrapeEndpointPath.get -> string
OpenTelemetry.Exporter.Prometheus.Shared.PrometheusExporterOptions.ScrapeEndpointPath.set -> void
OpenTelemetry.Exporter.Prometheus.Shared.PrometheusExporterOptions.ScrapeResponseCacheDurationMilliseconds.get -> int
OpenTelemetry.Exporter.Prometheus.Shared.PrometheusExporterOptions.ScrapeResponseCacheDurationMilliseconds.set -> void

View File

@ -1,29 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- OmniSharp/VS Code requires TargetFrameworks to be in descending order for IntelliSense and analysis. -->
<TargetFrameworks>netcoreapp3.1;net462</TargetFrameworks>
<Description>Prometheus exporter shared code for both Prometheus exporter HttpListener and Prometheus exporter AspNetCore</Description>
<PackageTags>$(PackageTags);prometheus;metrics</PackageTags>
</PropertyGroup>
<!--Do not run ApiCompat as this package has never released a stable version.
Remove this property once we have released a stable version.-->
<PropertyGroup>
<RunApiCompat>false</RunApiCompat>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry\OpenTelemetry.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\ExceptionExtensions.cs" Link="Includes\ExceptionExtensions.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\Guard.cs" Link="Includes\Guard.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
</Project>

View File

@ -29,6 +29,6 @@
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Zipkin\OpenTelemetry.Exporter.Zipkin.csproj" Aliases="Zipkin" />
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Instrumentation.AspNetCore\OpenTelemetry.Instrumentation.AspNetCore.csproj" />
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Instrumentation.Http\OpenTelemetry.Instrumentation.Http.csproj" />
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.Shared\OpenTelemetry.Exporter.Prometheus.Shared.csproj" />
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.HttpListener\OpenTelemetry.Exporter.Prometheus.HttpListener.csproj" />
</ItemGroup>
</Project>

View File

@ -18,7 +18,7 @@ using System.Collections.Generic;
using System.Diagnostics.Metrics;
using BenchmarkDotNet.Attributes;
using OpenTelemetry;
using OpenTelemetry.Exporter.Prometheus.Shared;
using OpenTelemetry.Exporter.Prometheus;
using OpenTelemetry.Metrics;
using OpenTelemetry.Tests;

View File

@ -21,7 +21,7 @@ using System.Linq;
#endif
using System.Threading;
using System.Threading.Tasks;
using OpenTelemetry.Exporter.Prometheus.Shared;
using OpenTelemetry.Exporter.Prometheus.HttpListener.Shared;
using OpenTelemetry.Metrics;
using OpenTelemetry.Tests;
using Xunit;

View File

@ -20,6 +20,7 @@
<ItemGroup>
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.HttpListener\OpenTelemetry.Exporter.Prometheus.HttpListener.csproj" />
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Exporter.InMemory\OpenTelemetry.Exporter.InMemory.csproj" />
</ItemGroup>
<ItemGroup>

View File

@ -0,0 +1,387 @@
// <copyright file="PrometheusSerializerTests.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
using System.Collections.Generic;
using System.Diagnostics.Metrics;
using System.Text;
using OpenTelemetry.Metrics;
using OpenTelemetry.Tests;
using Xunit;
namespace OpenTelemetry.Exporter.Prometheus
{
public sealed class PrometheusSerializerTests
{
[Fact]
public void GaugeZeroDimension()
{
var buffer = new byte[85000];
var metrics = new List<Metric>();
using var meter = new Meter(Utils.GetCurrentMethodName());
using var provider = Sdk.CreateMeterProviderBuilder()
.AddMeter(meter.Name)
.AddInMemoryExporter(metrics)
.Build();
meter.CreateObservableGauge("test_gauge", () => 123);
provider.ForceFlush();
var cursor = PrometheusSerializer.WriteMetric(buffer, 0, metrics[0]);
Assert.Matches(
("^"
+ "# TYPE test_gauge gauge\n"
+ "test_gauge 123 \\d+\n"
+ "$").Replace('\'', '"'),
Encoding.UTF8.GetString(buffer, 0, cursor));
}
[Fact]
public void GaugeZeroDimensionWithDescription()
{
var buffer = new byte[85000];
var metrics = new List<Metric>();
using var meter = new Meter(Utils.GetCurrentMethodName());
using var provider = Sdk.CreateMeterProviderBuilder()
.AddMeter(meter.Name)
.AddInMemoryExporter(metrics)
.Build();
meter.CreateObservableGauge("test_gauge", () => 123, description: "Hello, world!");
provider.ForceFlush();
var cursor = PrometheusSerializer.WriteMetric(buffer, 0, metrics[0]);
Assert.Matches(
("^"
+ "# HELP test_gauge Hello, world!\n"
+ "# TYPE test_gauge gauge\n"
+ "test_gauge 123 \\d+\n"
+ "$").Replace('\'', '"'),
Encoding.UTF8.GetString(buffer, 0, cursor));
}
[Fact]
public void GaugeZeroDimensionWithUnit()
{
var buffer = new byte[85000];
var metrics = new List<Metric>();
using var meter = new Meter(Utils.GetCurrentMethodName());
using var provider = Sdk.CreateMeterProviderBuilder()
.AddMeter(meter.Name)
.AddInMemoryExporter(metrics)
.Build();
meter.CreateObservableGauge("test_gauge", () => 123, unit: "seconds");
provider.ForceFlush();
var cursor = PrometheusSerializer.WriteMetric(buffer, 0, metrics[0]);
Assert.Matches(
("^"
+ "# TYPE test_gauge_seconds gauge\n"
+ "test_gauge_seconds 123 \\d+\n"
+ "$").Replace('\'', '"'),
Encoding.UTF8.GetString(buffer, 0, cursor));
}
[Fact]
public void GaugeOneDimension()
{
var buffer = new byte[85000];
var metrics = new List<Metric>();
using var meter = new Meter(Utils.GetCurrentMethodName());
using var provider = Sdk.CreateMeterProviderBuilder()
.AddMeter(meter.Name)
.AddInMemoryExporter(metrics)
.Build();
meter.CreateObservableGauge(
"test_gauge",
() => new Measurement<long>(123, new KeyValuePair<string, object>("tagKey", "tagValue")));
provider.ForceFlush();
var cursor = PrometheusSerializer.WriteMetric(buffer, 0, metrics[0]);
Assert.Matches(
("^"
+ "# TYPE test_gauge gauge\n"
+ "test_gauge{tagKey='tagValue'} 123 \\d+\n"
+ "$").Replace('\'', '"'),
Encoding.UTF8.GetString(buffer, 0, cursor));
}
[Fact]
public void GaugeDoubleSubnormal()
{
var buffer = new byte[85000];
var metrics = new List<Metric>();
using var meter = new Meter(Utils.GetCurrentMethodName());
using var provider = Sdk.CreateMeterProviderBuilder()
.AddMeter(meter.Name)
.AddInMemoryExporter(metrics)
.Build();
meter.CreateObservableGauge("test_gauge", () => new List<Measurement<double>>
{
new(double.NegativeInfinity, new("x", "1"), new("y", "2")),
new(double.PositiveInfinity, new("x", "3"), new("y", "4")),
new(double.NaN, new("x", "5"), new("y", "6")),
});
provider.ForceFlush();
var cursor = PrometheusSerializer.WriteMetric(buffer, 0, metrics[0]);
Assert.Matches(
("^"
+ "# TYPE test_gauge gauge\n"
+ "test_gauge{x='1',y='2'} -Inf \\d+\n"
+ "test_gauge{x='3',y='4'} \\+Inf \\d+\n"
+ "test_gauge{x='5',y='6'} Nan \\d+\n"
+ "$").Replace('\'', '"'),
Encoding.UTF8.GetString(buffer, 0, cursor));
}
[Fact]
public void SumDoubleInfinites()
{
var buffer = new byte[85000];
var metrics = new List<Metric>();
using var meter = new Meter(Utils.GetCurrentMethodName());
using var provider = Sdk.CreateMeterProviderBuilder()
.AddMeter(meter.Name)
.AddInMemoryExporter(metrics)
.Build();
var counter = meter.CreateCounter<double>("test_counter");
counter.Add(1.0E308);
counter.Add(1.0E308);
provider.ForceFlush();
var cursor = PrometheusSerializer.WriteMetric(buffer, 0, metrics[0]);
Assert.Matches(
("^"
+ "# TYPE test_counter counter\n"
+ "test_counter \\+Inf \\d+\n"
+ "$").Replace('\'', '"'),
Encoding.UTF8.GetString(buffer, 0, cursor));
}
[Fact]
public void HistogramZeroDimension()
{
var buffer = new byte[85000];
var metrics = new List<Metric>();
using var meter = new Meter(Utils.GetCurrentMethodName());
using var provider = Sdk.CreateMeterProviderBuilder()
.AddMeter(meter.Name)
.AddInMemoryExporter(metrics)
.Build();
var histogram = meter.CreateHistogram<double>("test_histogram");
histogram.Record(18);
histogram.Record(100);
provider.ForceFlush();
var cursor = PrometheusSerializer.WriteMetric(buffer, 0, metrics[0]);
Assert.Matches(
("^"
+ "# TYPE test_histogram histogram\n"
+ "test_histogram_bucket{le='0'} 0 \\d+\n"
+ "test_histogram_bucket{le='5'} 0 \\d+\n"
+ "test_histogram_bucket{le='10'} 0 \\d+\n"
+ "test_histogram_bucket{le='25'} 1 \\d+\n"
+ "test_histogram_bucket{le='50'} 1 \\d+\n"
+ "test_histogram_bucket{le='75'} 1 \\d+\n"
+ "test_histogram_bucket{le='100'} 2 \\d+\n"
+ "test_histogram_bucket{le='250'} 2 \\d+\n"
+ "test_histogram_bucket{le='500'} 2 \\d+\n"
+ "test_histogram_bucket{le='1000'} 2 \\d+\n"
+ "test_histogram_bucket{le='\\+Inf'} 2 \\d+\n"
+ "test_histogram_sum 118 \\d+\n"
+ "test_histogram_count 2 \\d+\n"
+ "$").Replace('\'', '"'),
Encoding.UTF8.GetString(buffer, 0, cursor));
}
[Fact]
public void HistogramOneDimension()
{
var buffer = new byte[85000];
var metrics = new List<Metric>();
using var meter = new Meter(Utils.GetCurrentMethodName());
using var provider = Sdk.CreateMeterProviderBuilder()
.AddMeter(meter.Name)
.AddInMemoryExporter(metrics)
.Build();
var histogram = meter.CreateHistogram<double>("test_histogram");
histogram.Record(18, new KeyValuePair<string, object>("x", "1"));
histogram.Record(100, new KeyValuePair<string, object>("x", "1"));
provider.ForceFlush();
var cursor = PrometheusSerializer.WriteMetric(buffer, 0, metrics[0]);
Assert.Matches(
("^"
+ "# TYPE test_histogram histogram\n"
+ "test_histogram_bucket{x='1',le='0'} 0 \\d+\n"
+ "test_histogram_bucket{x='1',le='5'} 0 \\d+\n"
+ "test_histogram_bucket{x='1',le='10'} 0 \\d+\n"
+ "test_histogram_bucket{x='1',le='25'} 1 \\d+\n"
+ "test_histogram_bucket{x='1',le='50'} 1 \\d+\n"
+ "test_histogram_bucket{x='1',le='75'} 1 \\d+\n"
+ "test_histogram_bucket{x='1',le='100'} 2 \\d+\n"
+ "test_histogram_bucket{x='1',le='250'} 2 \\d+\n"
+ "test_histogram_bucket{x='1',le='500'} 2 \\d+\n"
+ "test_histogram_bucket{x='1',le='1000'} 2 \\d+\n"
+ "test_histogram_bucket{x='1',le='\\+Inf'} 2 \\d+\n"
+ "test_histogram_sum{x='1'} 118 \\d+\n"
+ "test_histogram_count{x='1'} 2 \\d+\n"
+ "$").Replace('\'', '"'),
Encoding.UTF8.GetString(buffer, 0, cursor));
}
[Fact]
public void HistogramTwoDimensions()
{
var buffer = new byte[85000];
var metrics = new List<Metric>();
using var meter = new Meter(Utils.GetCurrentMethodName());
using var provider = Sdk.CreateMeterProviderBuilder()
.AddMeter(meter.Name)
.AddInMemoryExporter(metrics)
.Build();
var histogram = meter.CreateHistogram<double>("test_histogram");
histogram.Record(18, new("x", "1"), new("y", "2"));
histogram.Record(100, new("x", "1"), new("y", "2"));
provider.ForceFlush();
var cursor = PrometheusSerializer.WriteMetric(buffer, 0, metrics[0]);
Assert.Matches(
("^"
+ "# TYPE test_histogram histogram\n"
+ "test_histogram_bucket{x='1',y='2',le='0'} 0 \\d+\n"
+ "test_histogram_bucket{x='1',y='2',le='5'} 0 \\d+\n"
+ "test_histogram_bucket{x='1',y='2',le='10'} 0 \\d+\n"
+ "test_histogram_bucket{x='1',y='2',le='25'} 1 \\d+\n"
+ "test_histogram_bucket{x='1',y='2',le='50'} 1 \\d+\n"
+ "test_histogram_bucket{x='1',y='2',le='75'} 1 \\d+\n"
+ "test_histogram_bucket{x='1',y='2',le='100'} 2 \\d+\n"
+ "test_histogram_bucket{x='1',y='2',le='250'} 2 \\d+\n"
+ "test_histogram_bucket{x='1',y='2',le='500'} 2 \\d+\n"
+ "test_histogram_bucket{x='1',y='2',le='1000'} 2 \\d+\n"
+ "test_histogram_bucket{x='1',y='2',le='\\+Inf'} 2 \\d+\n"
+ "test_histogram_sum{x='1',y='2'} 118 \\d+\n"
+ "test_histogram_count{x='1',y='2'} 2 \\d+\n"
+ "$").Replace('\'', '"'),
Encoding.UTF8.GetString(buffer, 0, cursor));
}
[Fact]
public void HistogramInfinites()
{
var buffer = new byte[85000];
var metrics = new List<Metric>();
using var meter = new Meter(Utils.GetCurrentMethodName());
using var provider = Sdk.CreateMeterProviderBuilder()
.AddMeter(meter.Name)
.AddInMemoryExporter(metrics)
.Build();
var histogram = meter.CreateHistogram<double>("test_histogram");
histogram.Record(18);
histogram.Record(double.PositiveInfinity);
histogram.Record(double.PositiveInfinity);
provider.ForceFlush();
var cursor = PrometheusSerializer.WriteMetric(buffer, 0, metrics[0]);
Assert.Matches(
("^"
+ "# TYPE test_histogram histogram\n"
+ "test_histogram_bucket{le='0'} 0 \\d+\n"
+ "test_histogram_bucket{le='5'} 0 \\d+\n"
+ "test_histogram_bucket{le='10'} 0 \\d+\n"
+ "test_histogram_bucket{le='25'} 1 \\d+\n"
+ "test_histogram_bucket{le='50'} 1 \\d+\n"
+ "test_histogram_bucket{le='75'} 1 \\d+\n"
+ "test_histogram_bucket{le='100'} 1 \\d+\n"
+ "test_histogram_bucket{le='250'} 1 \\d+\n"
+ "test_histogram_bucket{le='500'} 1 \\d+\n"
+ "test_histogram_bucket{le='1000'} 1 \\d+\n"
+ "test_histogram_bucket{le='\\+Inf'} 3 \\d+\n"
+ "test_histogram_sum \\+Inf \\d+\n"
+ "test_histogram_count 3 \\d+\n"
+ "$").Replace('\'', '"'),
Encoding.UTF8.GetString(buffer, 0, cursor));
}
[Fact]
public void HistogramNaN()
{
var buffer = new byte[85000];
var metrics = new List<Metric>();
using var meter = new Meter(Utils.GetCurrentMethodName());
using var provider = Sdk.CreateMeterProviderBuilder()
.AddMeter(meter.Name)
.AddInMemoryExporter(metrics)
.Build();
var histogram = meter.CreateHistogram<double>("test_histogram");
histogram.Record(18);
histogram.Record(double.PositiveInfinity);
histogram.Record(double.NaN);
provider.ForceFlush();
var cursor = PrometheusSerializer.WriteMetric(buffer, 0, metrics[0]);
Assert.Matches(
("^"
+ "# TYPE test_histogram histogram\n"
+ "test_histogram_bucket{le='0'} 0 \\d+\n"
+ "test_histogram_bucket{le='5'} 0 \\d+\n"
+ "test_histogram_bucket{le='10'} 0 \\d+\n"
+ "test_histogram_bucket{le='25'} 1 \\d+\n"
+ "test_histogram_bucket{le='50'} 1 \\d+\n"
+ "test_histogram_bucket{le='75'} 1 \\d+\n"
+ "test_histogram_bucket{le='100'} 1 \\d+\n"
+ "test_histogram_bucket{le='250'} 1 \\d+\n"
+ "test_histogram_bucket{le='500'} 1 \\d+\n"
+ "test_histogram_bucket{le='1000'} 1 \\d+\n"
+ "test_histogram_bucket{le='\\+Inf'} 3 \\d+\n"
+ "test_histogram_sum Nan \\d+\n"
+ "test_histogram_count 3 \\d+\n"
+ "$").Replace('\'', '"'),
Encoding.UTF8.GetString(buffer, 0, cursor));
}
}
}