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

[release/8.0] Update table every second, reuse existing metric values if possible #3774

Merged
merged 3 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
}

<div id="metric-table-container" style="height: 40vh; overflow-y: auto; margin-bottom: 20px; max-width:1200px;">
<FluentDataGrid Items="@_metricsView" ItemSize="35" Virtualize="true" GridTemplateColumns="@string.Join(" ", Enumerable.Repeat("1fr", columnCount))">
@* ItemKey is to preserve row focus by associating rows with their associated time *@
<FluentDataGrid
Items="@_metricsView"
ItemSize="35"
Virtualize="true"
GridTemplateColumns="@string.Join(" ", Enumerable.Repeat("1fr", columnCount))"
ItemKey="@(item => item.DateTime)">
<ChildContent>
<TemplateColumn Title="@Loc[nameof(ControlsStrings.MetricTableStartColumnHeader)]" TooltipText="@(context => FormatHelpers.FormatDateTime(TimeProvider, TimeProvider.ToLocal(context.DateTime), MillisecondsDisplay.None, CultureInfo.CurrentCulture))" Tooltip="true">
@FormatHelpers.FormatTimeWithOptionalDate(TimeProvider, TimeProvider.ToLocal(context.DateTime))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public partial class MetricTable : ChartBase
private OtlpInstrument? _instrument;
private bool _showCount;
private bool _onlyShowValueChanges = true;
private DateTimeOffset? _lastUpdate;

private readonly CancellationTokenSource _waitTaskCancellationTokenSource = new();

Expand All @@ -31,6 +32,14 @@ public partial class MetricTable : ChartBase

protected override async Task OnChartUpdated(List<ChartTrace> traces, List<DateTimeOffset> xValues, bool tickUpdate, DateTimeOffset inProgressDataTime)
{
// Only update table every second to batch updates. New data coming every 200ms may be disorienting for screen-reader users.
if (inProgressDataTime - _lastUpdate < TimeSpan.FromSeconds(1))
{
return;
}

_lastUpdate = inProgressDataTime;

if (!Equals(_instrument?.Name, InstrumentViewModel.Instrument?.Name) || _showCount != InstrumentViewModel.ShowCount)
{
_metrics.Clear();
Expand All @@ -43,8 +52,6 @@ protected override async Task OnChartUpdated(List<ChartTrace> traces, List<DateT

_metrics = UpdateMetrics(out var xValuesToAnnounce, traces, xValues);

await InvokeAsync(StateHasChanged);

if (xValuesToAnnounce.Count == 0)
{
return;
Expand Down