Skip to content
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 @@ -434,7 +434,10 @@ public void UpdateViewModelFromQuery(StructuredLogsPageViewModel viewModel)
if (filters.Count > 0)
{
ViewModel.ClearFilters();
ViewModel.AddFilters(filters);
foreach (var filter in filters)
{
ViewModel.AddFilter(filter);
}
}
}

Expand Down
27 changes: 26 additions & 1 deletion src/Aspire.Dashboard/Model/Otlp/LogFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace Aspire.Dashboard.Model.Otlp;

[DebuggerDisplay("{FilterText,nq}")]
public class LogFilter
public class LogFilter : IEquatable<LogFilter>
{
public const string KnownMessageField = "log.message";
public const string KnownCategoryField = "log.category";
Expand Down Expand Up @@ -142,4 +142,29 @@ public IEnumerable<OtlpLogEntry> Apply(IEnumerable<OtlpLogEntry> input)
}
}
}

public bool Equals(LogFilter? other)
{
if (other == null)
{
return false;
}

if (Field != other.Field)
{
return false;
}

if (Condition != other.Condition)
{
return false;
}

if (!string.Equals(Value, other.Value, StringComparison.OrdinalIgnoreCase))
{
return false;
}

return true;
}
}
17 changes: 11 additions & 6 deletions src/Aspire.Dashboard/Model/StructuredLogsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,21 @@ public void ClearFilters()
_logs = null;
}

public void AddFilters(IEnumerable<LogFilter> filters)
{
_filters.AddRange(filters);
_logs = null;
}

public void AddFilter(LogFilter filter)
{
// Don't add duplicate filters.
foreach (var existingFilter in _filters)
{
if (existingFilter.Equals(filter))
{
return;
}
}

_filters.Add(filter);
_logs = null;
}

public bool RemoveFilter(LogFilter filter)
{
if (_filters.Remove(filter))
Expand All @@ -54,6 +58,7 @@ public bool RemoveFilter(LogFilter filter)
}
return false;
}

public int StartIndex { get => _logsStartIndex; set => SetValue(ref _logsStartIndex, value); }
public int? Count { get => _logsCount; set => SetValue(ref _logsCount, value); }
public LogLevel? LogLevel { get => _logLevel; set => SetValue(ref _logLevel, value); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Aspire.Dashboard.Components.Resize;
using Aspire.Dashboard.Components.Tests.Shared;
using Aspire.Dashboard.Configuration;
using Aspire.Dashboard.Extensions;
using Aspire.Dashboard.Model;
using Aspire.Dashboard.Model.BrowserStorage;
using Aspire.Dashboard.Model.Otlp;
Expand Down Expand Up @@ -64,6 +65,45 @@ public void Render_TraceIdAndSpanId_FilterAdded()
});
}

[Fact]
public void Render_DuplicateFilters_SingleFilterAdded()
{
// Arrange
SetupStructureLogsServices();

var logFilter = new LogFilter { Field = "TestField", Condition = FilterCondition.Contains, Value = "TestValue" };
var serializedFilter = LogFilterFormatter.SerializeLogFiltersToString([logFilter]);

var navigationManager = Services.GetRequiredService<NavigationManager>();
var uri = navigationManager.GetUriWithQueryParameters(new Dictionary<string, object?>
{
["filters"] = serializedFilter + "+" + serializedFilter,
});
navigationManager.NavigateTo(uri);

var viewport = new ViewportInformation(IsDesktop: true, IsUltraLowHeight: false, IsUltraLowWidth: false);

var dimensionManager = Services.GetRequiredService<DimensionManager>();
dimensionManager.InvokeOnBrowserDimensionsChanged(viewport);

// Act
var cut = RenderComponent<StructuredLogs>(builder =>
{
builder.Add(p => p.ViewportInformation, viewport);
});

// Assert
var viewModel = Services.GetRequiredService<StructuredLogsViewModel>();

Assert.Collection(viewModel.Filters,
f =>
{
Assert.Equal(logFilter.Field, f.Field);
Assert.Equal(logFilter.Condition, f.Condition);
Assert.Equal(logFilter.Value, f.Value);
});
}

private void SetupStructureLogsServices()
{
var version = typeof(FluentMain).Assembly.GetName().Version!;
Expand Down