From 0e735d2960201d9022f6d5dfd3736c90d49ee6f5 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 30 Jan 2024 17:52:21 -0800 Subject: [PATCH] [release/8.0-preview3] Fix histogram chart calculation (#1993) * Fix histogram chart calculation * Comment * Update src/Aspire.Dashboard/Components/Controls/ChartContainer.razor.cs Co-authored-by: Drew Noakes * Update src/Aspire.Dashboard/Components/Controls/ChartContainer.razor.cs --------- Co-authored-by: James Newton-King Co-authored-by: Drew Noakes --- .../Components/Controls/ChartContainer.razor.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Aspire.Dashboard/Components/Controls/ChartContainer.razor.cs b/src/Aspire.Dashboard/Components/Controls/ChartContainer.razor.cs index 43e929f330..9b3cbba2be 100644 --- a/src/Aspire.Dashboard/Components/Controls/ChartContainer.razor.cs +++ b/src/Aspire.Dashboard/Components/Controls/ChartContainer.razor.cs @@ -170,13 +170,18 @@ protected override async Task OnParametersSetAsync() private OtlpInstrument? GetInstrument() { + var endDate = DateTime.UtcNow; + // Get more data than is being displayed. Histogram graph uses some historical data to calculate bucket counts. + // It's ok to get more data than is needed here. An additional date filter is applied when building chart values. + var startDate = endDate.Subtract(Duration + TimeSpan.FromSeconds(30)); + var instrument = TelemetryRepository.GetInstrument(new GetInstrumentRequest { ApplicationServiceId = ApplicationId, MeterName = MeterName, InstrumentName = InstrumentName, - StartTime = DateTime.UtcNow.Subtract(Duration), - EndTime = DateTime.UtcNow, + StartTime = startDate, + EndTime = endDate, }); if (instrument == null)