-
Notifications
You must be signed in to change notification settings - Fork 719
Only display trace menu option for uninstrumented peer resources #9030
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
tests/Aspire.Dashboard.Tests/Model/ResourceMenuItemsTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Aspire.Dashboard.Model; | ||
| using Aspire.Dashboard.Otlp.Model; | ||
| using Aspire.Dashboard.Tests.TelemetryRepositoryTests; | ||
| using Aspire.Tests.Shared.DashboardModel; | ||
| using Aspire.Tests.Shared.Telemetry; | ||
| using Google.Protobuf.Collections; | ||
| using Microsoft.AspNetCore.Components; | ||
| using OpenTelemetry.Proto.Trace.V1; | ||
| using Xunit; | ||
|
|
||
| namespace Aspire.Dashboard.Tests.Model; | ||
|
|
||
| public sealed class ResourceMenuItemsTests | ||
| { | ||
| private static readonly DateTime s_testTime = new(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); | ||
|
|
||
| [Fact] | ||
| public void AddMenuItems_NoTelemetry_NoTelemetryItems() | ||
| { | ||
| // Arrange | ||
| var resource = ModelTestHelpers.CreateResource(); | ||
| var telemetryRespository = TelemetryTestHelpers.CreateRepository(); | ||
|
|
||
| // Act | ||
| var menuItems = new List<MenuButtonItem>(); | ||
| ResourceMenuItems.AddMenuItems( | ||
| menuItems, | ||
| openingMenuButtonId: null, | ||
| resource, | ||
| new TestNavigationManager(), | ||
| telemetryRespository, | ||
| r => r.Name, | ||
| new TestStringLocalizer<Resources.ControlsStrings>(), | ||
| new TestStringLocalizer<Resources.Resources>(), | ||
| _ => Task.CompletedTask, | ||
| _ => Task.CompletedTask, | ||
| (_, _) => false, | ||
| true, | ||
| true); | ||
|
|
||
| // Assert | ||
| Assert.Collection(menuItems, | ||
| e => Assert.Equal("Localized:ActionViewDetailsText", e.Text), | ||
| e => Assert.Equal("Localized:ResourceActionConsoleLogsText", e.Text)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void AddMenuItems_UninstrumentedPeer_TraceItem() | ||
| { | ||
| // Arrange | ||
| var resource = ModelTestHelpers.CreateResource(appName: "test-abc"); | ||
| var outgoingPeerResolver = new TestOutgoingPeerResolver(onResolve: attributes => (resource.Name, resource)); | ||
| var repository = TelemetryTestHelpers.CreateRepository(outgoingPeerResolvers: [outgoingPeerResolver]); | ||
| var addContext = new AddContext(); | ||
| repository.AddTraces(addContext, new RepeatedField<ResourceSpans>() | ||
| { | ||
| new ResourceSpans | ||
| { | ||
| Resource = TelemetryTestHelpers.CreateResource(name: "source", instanceId: "abc"), | ||
| ScopeSpans = | ||
| { | ||
| new ScopeSpans | ||
| { | ||
| Scope = TelemetryTestHelpers.CreateScope(), | ||
| Spans = | ||
| { | ||
| TelemetryTestHelpers.CreateSpan(traceId: "1", spanId: "1-1", startTime: s_testTime.AddMinutes(1), endTime: s_testTime.AddMinutes(10), attributes: [KeyValuePair.Create(OtlpSpan.PeerServiceAttributeKey, "value-1")], kind: Span.Types.SpanKind.Client), | ||
| TelemetryTestHelpers.CreateSpan(traceId: "1", spanId: "1-2", startTime: s_testTime.AddMinutes(5), endTime: s_testTime.AddMinutes(10), parentSpanId: "1-1", attributes: [KeyValuePair.Create(OtlpSpan.PeerServiceAttributeKey, "value-2")], kind: Span.Types.SpanKind.Client) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| // Act | ||
| var menuItems = new List<MenuButtonItem>(); | ||
| ResourceMenuItems.AddMenuItems( | ||
| menuItems, | ||
| openingMenuButtonId: null, | ||
| resource, | ||
| new TestNavigationManager(), | ||
| repository, | ||
| r => r.Name, | ||
| new TestStringLocalizer<Resources.ControlsStrings>(), | ||
| new TestStringLocalizer<Resources.Resources>(), | ||
| _ => Task.CompletedTask, | ||
| _ => Task.CompletedTask, | ||
| (_, _) => false, | ||
| true, | ||
| true); | ||
|
|
||
| // Assert | ||
| Assert.Collection(menuItems, | ||
| e => Assert.Equal("Localized:ActionViewDetailsText", e.Text), | ||
| e => Assert.Equal("Localized:ResourceActionConsoleLogsText", e.Text), | ||
| e => Assert.True(e.IsDivider), | ||
| e => Assert.Equal("Localized:ResourceActionTracesText", e.Text)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void AddMenuItems_HasTelemetry_TelemetryItems() | ||
| { | ||
| // Arrange | ||
| var resource = ModelTestHelpers.CreateResource(appName: "test-abc"); | ||
| var repository = TelemetryTestHelpers.CreateRepository(); | ||
| var addContext = new AddContext(); | ||
| repository.AddTraces(addContext, new RepeatedField<ResourceSpans>() | ||
| { | ||
| new ResourceSpans | ||
| { | ||
| Resource = TelemetryTestHelpers.CreateResource(name: "test", instanceId: "abc"), | ||
| ScopeSpans = | ||
| { | ||
| new ScopeSpans | ||
| { | ||
| Scope = TelemetryTestHelpers.CreateScope(), | ||
| Spans = | ||
| { | ||
| TelemetryTestHelpers.CreateSpan(traceId: "1", spanId: "1-1", startTime: s_testTime.AddMinutes(1), endTime: s_testTime.AddMinutes(10)) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| // Act | ||
| var menuItems = new List<MenuButtonItem>(); | ||
| ResourceMenuItems.AddMenuItems( | ||
| menuItems, | ||
| openingMenuButtonId: null, | ||
| resource, | ||
| new TestNavigationManager(), | ||
| repository, | ||
| r => r.Name, | ||
| new TestStringLocalizer<Resources.ControlsStrings>(), | ||
| new TestStringLocalizer<Resources.Resources>(), | ||
| _ => Task.CompletedTask, | ||
| _ => Task.CompletedTask, | ||
| (_, _) => false, | ||
| true, | ||
| true); | ||
|
|
||
| // Assert | ||
| Assert.Collection(menuItems, | ||
| e => Assert.Equal("Localized:ActionViewDetailsText", e.Text), | ||
| e => Assert.Equal("Localized:ResourceActionConsoleLogsText", e.Text), | ||
| e => Assert.True(e.IsDivider), | ||
| e => Assert.Equal("Localized:ResourceActionStructuredLogsText", e.Text), | ||
| e => Assert.Equal("Localized:ResourceActionTracesText", e.Text), | ||
| e => Assert.Equal("Localized:ResourceActionMetricsText", e.Text)); | ||
| } | ||
|
|
||
| private sealed class TestNavigationManager : NavigationManager | ||
| { | ||
| } | ||
| } |
50 changes: 50 additions & 0 deletions
50
tests/Aspire.Dashboard.Tests/TelemetryRepositoryTests/TestOutgoingPeerResolver.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Aspire.Dashboard.Model; | ||
| using Aspire.Tests.Shared.DashboardModel; | ||
|
|
||
| namespace Aspire.Dashboard.Tests.TelemetryRepositoryTests; | ||
|
|
||
| public sealed class TestOutgoingPeerResolver : IOutgoingPeerResolver, IDisposable | ||
| { | ||
| private readonly Func<KeyValuePair<string, string>[], (string? Name, ResourceViewModel? Resource)>? _onResolve; | ||
| private readonly List<Func<Task>> _callbacks; | ||
|
|
||
| public TestOutgoingPeerResolver(Func<KeyValuePair<string, string>[], (string? Name, ResourceViewModel? Resource)>? onResolve = null) | ||
| { | ||
| _onResolve = onResolve; | ||
| _callbacks = new(); | ||
| } | ||
|
|
||
| public void Dispose() | ||
| { | ||
| } | ||
|
|
||
| public IDisposable OnPeerChanges(Func<Task> callback) | ||
| { | ||
| _callbacks.Add(callback); | ||
| return this; | ||
| } | ||
|
|
||
| public async Task InvokePeerChanges() | ||
| { | ||
| foreach (var callback in _callbacks) | ||
| { | ||
| await callback(); | ||
| } | ||
| } | ||
|
|
||
| public bool TryResolvePeer(KeyValuePair<string, string>[] attributes, out string? name, out ResourceViewModel? matchedResourced) | ||
| { | ||
| if (_onResolve != null) | ||
| { | ||
| (name, matchedResourced) = _onResolve(attributes); | ||
| return (name != null); | ||
| } | ||
|
|
||
| name = "TestPeer"; | ||
| matchedResourced = ModelTestHelpers.CreateResource(appName: "TestPeer"); | ||
| return true; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.