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

Fix exception when unselecting application on metrics page #369

Merged
merged 1 commit into from
Oct 18, 2023
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 @@ -39,6 +39,7 @@ public partial class ChartContainer : ComponentBase, IAsyncDisposable

protected override void OnInitialized()
{
// Update the graph every 200ms. This displays the latest data and moves time forward.
_tickTimer = new PeriodicTimer(TimeSpan.FromSeconds(0.2));
_tickTask = Task.Run(UpdateDataAsync);
}
Expand All @@ -50,22 +51,22 @@ public async ValueTask DisposeAsync()
// Wait for UpdateData to complete.
if (_tickTask is { } t)
{
await t.ConfigureAwait(false);
await t;
}
}

private async Task UpdateDataAsync()
{
var timer = _tickTimer;
while (await timer!.WaitForNextTickAsync().ConfigureAwait(false))
while (await timer!.WaitForNextTickAsync())
{
_instrument = GetInstrument();

if (_instrument.Dimensions.Count > _renderedDimensionsCount)
{
// Re-render the entire control if the number of dimensions has changed.
_renderedDimensionsCount = _instrument.Dimensions.Count;
await InvokeAsync(StateHasChanged).ConfigureAwait(false);
await InvokeAsync(StateHasChanged);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/Aspire.Dashboard/Components/Pages/Metrics.razor
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
</Panel1>
<Panel2>
<div class="metrics-content">
@if (_selectedInstrument != null)
@if (_selectedApplication.Id != null && _selectedMeter != null && _selectedInstrument != null)
{
<ChartContainer ApplicationId="@(_selectedApplication.Id)" MeterName="@(_selectedMeter?.MeterName)" InstrumentName="@(_selectedInstrument.Name)" Duration="_selectedDuration.Duration" />
<ChartContainer ApplicationId="@(_selectedApplication.Id)" MeterName="@(_selectedMeter.MeterName)" InstrumentName="@(_selectedInstrument.Name)" Duration="_selectedDuration.Duration" />
}
else if (_selectedMeter != null)
{
Expand Down
10 changes: 6 additions & 4 deletions src/Aspire.Dashboard/Components/Pages/Metrics.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected override Task OnInitializedAsync()

protected override void OnParametersSet()
{
_selectedApplication = _applications.SingleOrDefault(e => e.Id == ApplicationInstanceId) ?? _applications.ElementAtOrDefault(1) ?? s_selectApplication;
_selectedApplication = _applications.SingleOrDefault(e => e.Id == ApplicationInstanceId) ?? s_selectApplication;
ViewModel.ApplicationServiceId = _selectedApplication.Id;
_instruments = !string.IsNullOrEmpty(_selectedApplication.Id) ? TelemetryRepository.GetInstrumentsSummary(_selectedApplication.Id) : null;

Expand Down Expand Up @@ -105,10 +105,12 @@ private void UpdateApplications()
UpdateSubscription();
}

private Task HandleSelectedApplicationChangedAsync()
private async Task HandleSelectedApplicationChangedAsync()
{
NavigationManager.NavigateTo($"/Metrics/{_selectedApplication.Id}");
return Task.CompletedTask;
var state = new MetricsSelectedState { ApplicationId = _selectedApplication.Id };

NavigateTo(state);
await ProtectedSessionStore.SetAsync(MetricsSelectedState.Key, state);
}

private sealed class MetricsSelectedState
Expand Down