diff --git a/src/Aspire.Dashboard/Otlp/Storage/Subscription.cs b/src/Aspire.Dashboard/Otlp/Storage/Subscription.cs index 9c1e9a4624d..cb50f7a9e9b 100644 --- a/src/Aspire.Dashboard/Otlp/Storage/Subscription.cs +++ b/src/Aspire.Dashboard/Otlp/Storage/Subscription.cs @@ -47,10 +47,11 @@ private async Task 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); } } diff --git a/tests/Aspire.Dashboard.Tests/CustomAssert.cs b/tests/Aspire.Dashboard.Tests/CustomAssert.cs index 78ba6286a84..b8ff4c73273 100644 --- a/tests/Aspire.Dashboard.Tests/CustomAssert.cs +++ b/tests/Aspire.Dashboard.Tests/CustomAssert.cs @@ -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}."); } } diff --git a/tests/Aspire.Dashboard.Tests/TelemetryRepositoryTests/LogTests.cs b/tests/Aspire.Dashboard.Tests/TelemetryRepositoryTests/LogTests.cs index 4412081581b..70f047cb199 100644 --- a/tests/Aspire.Dashboard.Tests/TelemetryRepositoryTests/LogTests.cs +++ b/tests/Aspire.Dashboard.Tests/TelemetryRepositoryTests/LogTests.cs @@ -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; @@ -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() { @@ -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(); diff --git a/tests/Shared/Telemetry/TelemetryTestHelpers.cs b/tests/Shared/Telemetry/TelemetryTestHelpers.cs index 25f4f020155..96394008c04 100644 --- a/tests/Shared/Telemetry/TelemetryTestHelpers.cs +++ b/tests/Shared/Telemetry/TelemetryTestHelpers.cs @@ -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; @@ -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) @@ -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;