Skip to content

Commit

Permalink
Add logging to min execute interval test (#5701)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK authored Sep 13, 2024
1 parent c18fedf commit f2d447f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/Aspire.Dashboard/Otlp/Storage/Subscription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ private async Task<bool> TryQueueAsync(CancellationToken cancellationToken)
var lastExecute = _lastExecute;
if (lastExecute != null)
{
var s = lastExecute.Value.Add(_telemetryRepository._subscriptionMinExecuteInterval) - DateTime.UtcNow;
var minExecuteInterval = _telemetryRepository._subscriptionMinExecuteInterval;
var s = lastExecute.Value.Add(minExecuteInterval) - DateTime.UtcNow;
if (s > TimeSpan.Zero)
{
Logger.LogTrace("Subscription '{Name}' minimum execute interval hit. Waiting {DelayInterval}.", Name, s);
Logger.LogTrace("Subscription '{Name}' minimum execute interval of {MinExecuteInterval} hit. Waiting {DelayInterval}.", Name, minExecuteInterval, s);
await Task.Delay(s, cancellationToken).ConfigureAwait(false);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Aspire.Dashboard.Tests/CustomAssert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public static class CustomAssert
public static void AssertExceedsMinInterval(TimeSpan duration, TimeSpan minInterval)
{
// Timers are not precise, so we allow for a small margin of error.
Assert.True(duration >= minInterval.Subtract(TimeSpan.FromMilliseconds(20)), $"Elapsed time {duration} should be greater than min interval {minInterval}.");
Assert.True(duration >= minInterval.Subtract(TimeSpan.FromMilliseconds(30)), $"Elapsed time {duration} should be greater than min interval {minInterval}.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
using Aspire.Dashboard.Model.Otlp;
using Aspire.Dashboard.Otlp.Model;
using Aspire.Dashboard.Otlp.Storage;
using Aspire.Dashboard.Tests.Integration;
using Google.Protobuf.Collections;
using OpenTelemetry.Proto.Logs.V1;
using Xunit;
using Xunit.Abstractions;
using static Aspire.Tests.Shared.Telemetry.TelemetryTestHelpers;

namespace Aspire.Dashboard.Tests.TelemetryRepositoryTests;
Expand All @@ -17,6 +19,13 @@ public class LogTests
{
private static readonly DateTime s_testTime = new(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

private readonly ITestOutputHelper _testOutputHelper;

public LogTests(ITestOutputHelper testOutputHelper)
{
_testOutputHelper = testOutputHelper;
}

[Fact]
public void AddLogs()
{
Expand Down Expand Up @@ -652,7 +661,8 @@ public async Task Subscription_MultipleUpdates_MinExecuteIntervalApplied()
{
// Arrange
var minExecuteInterval = TimeSpan.FromMilliseconds(500);
var repository = CreateRepository(subscriptionMinExecuteInterval: minExecuteInterval);
var loggerFactory = IntegrationTestHelpers.CreateLoggerFactory(_testOutputHelper);
var repository = CreateRepository(subscriptionMinExecuteInterval: minExecuteInterval, loggerFactory: loggerFactory);

var callCount = 0;
var resultChannel = Channel.CreateUnbounded<int>();
Expand Down
8 changes: 6 additions & 2 deletions tests/Shared/Telemetry/TelemetryTestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Aspire.Dashboard.Otlp.Model;
using Aspire.Dashboard.Otlp.Storage;
using Google.Protobuf;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using OpenTelemetry.Proto.Common.V1;
Expand Down Expand Up @@ -222,7 +223,8 @@ public static TelemetryRepository CreateRepository(
int? maxAttributeLength = null,
int? maxSpanEventCount = null,
int? maxTraceCount = null,
TimeSpan? subscriptionMinExecuteInterval = null)
TimeSpan? subscriptionMinExecuteInterval = null,
ILoggerFactory? loggerFactory = null)
{
var options = new TelemetryLimitOptions();
if (maxMetricsCount != null)
Expand All @@ -246,7 +248,9 @@ public static TelemetryRepository CreateRepository(
options.MaxTraceCount = maxTraceCount.Value;
}

var repository = new TelemetryRepository(NullLoggerFactory.Instance, Options.Create(new DashboardOptions { TelemetryLimits = options }));
var repository = new TelemetryRepository(
loggerFactory ?? NullLoggerFactory.Instance,
Options.Create(new DashboardOptions { TelemetryLimits = options }));
if (subscriptionMinExecuteInterval != null)
{
repository._subscriptionMinExecuteInterval = subscriptionMinExecuteInterval.Value;
Expand Down

0 comments on commit f2d447f

Please sign in to comment.