update promtheus exporter benchmark (#2607)
This commit is contained in:
parent
252437d1ea
commit
5e369a6af1
|
|
@ -1,4 +1,4 @@
|
|||
// <copyright file="PrometheusExporterMetricsHttpServer.cs" company="OpenTelemetry Authors">
|
||||
// <copyright file="PrometheusExporterHttpServer.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
@ -23,9 +23,9 @@ using OpenTelemetry.Internal;
|
|||
namespace OpenTelemetry.Exporter.Prometheus
|
||||
{
|
||||
/// <summary>
|
||||
/// A HTTP listener used to expose Prometheus metrics.
|
||||
/// An HTTP listener used to expose Prometheus metrics.
|
||||
/// </summary>
|
||||
internal sealed class PrometheusExporterMetricsHttpServer : IDisposable
|
||||
internal sealed class PrometheusExporterHttpServer : IDisposable
|
||||
{
|
||||
private readonly PrometheusExporter exporter;
|
||||
private readonly HttpListener httpListener = new HttpListener();
|
||||
|
|
@ -35,10 +35,10 @@ namespace OpenTelemetry.Exporter.Prometheus
|
|||
private Task workerThread;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PrometheusExporterMetricsHttpServer"/> class.
|
||||
/// Initializes a new instance of the <see cref="PrometheusExporterHttpServer"/> class.
|
||||
/// </summary>
|
||||
/// <param name="exporter">The <see cref="PrometheusExporter"/> instance.</param>
|
||||
public PrometheusExporterMetricsHttpServer(PrometheusExporter exporter)
|
||||
public PrometheusExporterHttpServer(PrometheusExporter exporter)
|
||||
{
|
||||
Guard.Null(exporter, nameof(exporter));
|
||||
|
||||
|
|
@ -68,7 +68,7 @@ namespace OpenTelemetry.Exporter.Prometheus
|
|||
/// <summary>
|
||||
/// Start exporter.
|
||||
/// </summary>
|
||||
/// <param name="token">An optional <see cref="CancellationToken"/> that can be used to stop the htto server.</param>
|
||||
/// <param name="token">An optional <see cref="CancellationToken"/> that can be used to stop the HTTP server.</param>
|
||||
public void Start(CancellationToken token = default)
|
||||
{
|
||||
lock (this.syncObject)
|
||||
|
|
@ -32,7 +32,7 @@ namespace OpenTelemetry.Exporter
|
|||
internal readonly PrometheusExporterOptions Options;
|
||||
internal Batch<Metric> Metrics; // TODO: this is no longer needed, we can remove it later
|
||||
private readonly SemaphoreSlim semaphore = new SemaphoreSlim(1, 1);
|
||||
private readonly PrometheusExporterMetricsHttpServer metricsHttpServer;
|
||||
private readonly PrometheusExporterHttpServer metricsHttpServer;
|
||||
private Func<int, bool> funcCollect;
|
||||
private Func<Batch<Metric>, ExportResult> funcExport;
|
||||
private bool disposed;
|
||||
|
|
@ -49,7 +49,7 @@ namespace OpenTelemetry.Exporter
|
|||
{
|
||||
try
|
||||
{
|
||||
this.metricsHttpServer = new PrometheusExporterMetricsHttpServer(this);
|
||||
this.metricsHttpServer = new PrometheusExporterHttpServer(this);
|
||||
this.metricsHttpServer.Start();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// <copyright file="PrometheusExporterMiddlewareBenchmarks.cs" company="OpenTelemetry Authors">
|
||||
// <copyright file="PrometheusSerializerBenchmarks.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
@ -14,17 +14,15 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
#if NETCOREAPP3_1_OR_GREATER
|
||||
extern alias InMemory;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Metrics;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using InMemory::OpenTelemetry.Metrics;
|
||||
using OpenTelemetry;
|
||||
using OpenTelemetry.Exporter;
|
||||
using OpenTelemetry.Exporter.Prometheus;
|
||||
using OpenTelemetry.Metrics;
|
||||
using OpenTelemetry.Tests;
|
||||
|
|
@ -32,67 +30,55 @@ using OpenTelemetry.Tests;
|
|||
namespace Benchmarks.Exporter
|
||||
{
|
||||
[MemoryDiagnoser]
|
||||
public class PrometheusExporterMiddlewareBenchmarks
|
||||
public class PrometheusSerializerBenchmarks
|
||||
{
|
||||
private Meter meter;
|
||||
private MemoryStream responseStream;
|
||||
private MeterProvider meterProvider;
|
||||
private PrometheusExporter exporter;
|
||||
private DefaultHttpContext context;
|
||||
private List<Metric> metrics = new List<Metric>();
|
||||
private byte[] buffer = new byte[85000];
|
||||
|
||||
[Params(1, 1000, 10000)]
|
||||
public int NumberOfExportCalls { get; set; }
|
||||
public int NumberOfSerializeCalls { get; set; }
|
||||
|
||||
[GlobalSetup]
|
||||
public void GlobalSetup()
|
||||
{
|
||||
this.meter = new Meter(Utils.GetCurrentMethodName());
|
||||
this.responseStream = new MemoryStream(1024 * 1024);
|
||||
|
||||
this.meterProvider = Sdk.CreateMeterProviderBuilder()
|
||||
.AddMeter(this.meter.Name)
|
||||
.AddPrometheusExporter()
|
||||
.AddInMemoryExporter(this.metrics)
|
||||
.Build();
|
||||
|
||||
var counter = this.meter.CreateCounter<long>("counter_name_1", "long", "counter_name_1_description");
|
||||
counter.Add(18, new KeyValuePair<string, object>("label1", "value1"), new KeyValuePair<string, object>("label2", "value2"));
|
||||
counter.Add(18, new("label1", "value1"), new("label2", "value2"));
|
||||
|
||||
var gauge = this.meter.CreateObservableGauge("gauge_name_1", () => 18.0D, "long", "gauge_name_1_description");
|
||||
|
||||
var histogram = this.meter.CreateHistogram<long>("histogram_name_1", "long", "histogram_name_1_description");
|
||||
histogram.Record(100, new KeyValuePair<string, object>("label1", "value1"), new KeyValuePair<string, object>("label2", "value2"));
|
||||
histogram.Record(100, new("label1", "value1"), new("label2", "value2"));
|
||||
|
||||
this.context = new DefaultHttpContext();
|
||||
this.context.Response.Body = this.responseStream;
|
||||
|
||||
if (!this.meterProvider.TryFindExporter(out this.exporter))
|
||||
{
|
||||
throw new InvalidOperationException("PrometheusExporter could not be found on MeterProvider.");
|
||||
}
|
||||
|
||||
this.exporter.Collect(Timeout.Infinite);
|
||||
this.meterProvider.ForceFlush();
|
||||
}
|
||||
|
||||
[GlobalCleanup]
|
||||
public void GlobalCleanup()
|
||||
{
|
||||
this.meter?.Dispose();
|
||||
this.responseStream?.Dispose();
|
||||
this.meterProvider?.Dispose();
|
||||
}
|
||||
|
||||
/* TODO: revisit this after PrometheusExporter race condition is solved
|
||||
// TODO: this has a dependency on https://github.com/open-telemetry/opentelemetry-dotnet/issues/2361
|
||||
[Benchmark]
|
||||
public async Task WriteMetricsToResponse()
|
||||
public void WriteMetric()
|
||||
{
|
||||
this.responseStream.Position = 0;
|
||||
|
||||
for (int i = 0; i < this.NumberOfExportCalls; i++)
|
||||
for (int i = 0; i < this.NumberOfSerializeCalls; i++)
|
||||
{
|
||||
await PrometheusExporterMiddleware.WriteMetricsToResponse(this.exporter, this.context.Response).ConfigureAwait(false);
|
||||
int cursor = 0;
|
||||
foreach (var metric in this.metrics)
|
||||
{
|
||||
cursor = PrometheusSerializer.WriteMetric(this.buffer, cursor, metric);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
// <copyright file="PrometheusExporterMetricsHttpServerTests.cs" company="OpenTelemetry Authors">
|
||||
// <copyright file="PrometheusExporterHttpServerTests.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
@ -26,10 +26,10 @@ using Xunit;
|
|||
|
||||
namespace OpenTelemetry.Exporter.Prometheus.Tests
|
||||
{
|
||||
public class PrometheusExporterMetricsHttpServerTests
|
||||
public class PrometheusExporterHttpServerTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task PrometheusExporterMetricsHttpServerIntegration()
|
||||
public async Task PrometheusExporterHttpServerIntegration()
|
||||
{
|
||||
Random random = new Random();
|
||||
int port = 0;
|
||||
Loading…
Reference in New Issue