Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for some AspNetCoreMetricsInstrumentationOptions #3948

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix MetricTests style warnings
Temppus committed Dec 5, 2022
commit b4ff270b2813dfe1736dc99cf52abf851e8f90d1
Original file line number Diff line number Diff line change
@@ -14,11 +14,7 @@
// limitations under the License.
// </copyright>

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Testing;
@@ -34,11 +30,11 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Tests
public class MetricTests
: IClassFixture<WebApplicationFactory<Program>>, IDisposable
{
private readonly WebApplicationFactory<Program> factory;
private MeterProvider meterProvider = null;

private const int StandardTagsCount = 6;

private readonly WebApplicationFactory<Program> factory;
private MeterProvider meterProvider;

public MetricTests(WebApplicationFactory<Program> factory)
{
this.factory = factory;
@@ -197,6 +193,12 @@ void ConfigureTestServices(IServiceCollection services)
Assert.Contains(tagsToAdd[1], tags);
}

public void Dispose()
{
this.meterProvider?.Dispose();
GC.SuppressFinalize(this);
}

private static List<MetricPoint> GetMetricPoints(Metric metric)
{
Assert.NotNull(metric);
@@ -210,7 +212,8 @@ private static List<MetricPoint> GetMetricPoints(Metric metric)
return metricPoints;
}

private static KeyValuePair<string, object>[] AssertMetricPoint(MetricPoint metricPoint,
private static KeyValuePair<string, object>[] AssertMetricPoint(
MetricPoint metricPoint,
string expectedRoute = "api/Values",
int expectedTagsCount = StandardTagsCount)
{
@@ -220,16 +223,6 @@ private static KeyValuePair<string, object>[] AssertMetricPoint(MetricPoint metr
Assert.Equal(1L, count);
Assert.True(sum > 0);

/*
var bucket = metric.Buckets
.Where(b =>
metric.PopulationSum > b.LowBoundary &&
metric.PopulationSum <= b.HighBoundary)
.FirstOrDefault();
Assert.NotEqual(default, bucket);
Assert.Equal(1, bucket.Count);
*/

var attributes = new KeyValuePair<string, object>[metricPoint.Tags.Count];
int i = 0;
foreach (var tag in metricPoint.Tags)
@@ -253,11 +246,5 @@ private static KeyValuePair<string, object>[] AssertMetricPoint(MetricPoint metr

return attributes;
}

public void Dispose()
{
this.meterProvider?.Dispose();
GC.SuppressFinalize(this);
}
}
}