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

Enable Custom Artifact Names with New Tokens #6675

Merged
merged 26 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0081dfd
Initial design
wsugarman May 18, 2024
1408cf6
Add proper unix seconds support
wsugarman May 18, 2024
8020845
Fix default
wsugarman May 18, 2024
82e7193
Merge branch 'main' into dotnet-dump-template
wsugarman May 18, 2024
2ae837f
Merge remote-tracking branch 'origin/main' into dotnet-dump-template
wsugarman Jun 2, 2024
38c3071
Add host and time
wsugarman Jun 2, 2024
29fd72a
Revert "Fix default"
wsugarman Jun 2, 2024
4b46fde
Revert "Add proper unix seconds support"
wsugarman Jun 2, 2024
40024fb
Revert "Initial design"
wsugarman Jun 2, 2024
680381e
Change pattern
wsugarman Jun 3, 2024
ab86bd5
Merge branch 'main' into dotnet-dump-template
wsugarman Jun 3, 2024
ccad5c3
Use default artifact name for API
wsugarman Jun 3, 2024
adf6cc8
Merge branch 'dotnet-dump-template' of https://github.com/wsugarman/d…
wsugarman Jun 3, 2024
42224a7
Merge branch 'main' into dotnet-dump-template
wsugarman Jun 21, 2024
562d0b6
Create HostInfo
wsugarman Jul 5, 2024
b1e300c
Merge main
wsugarman Jul 6, 2024
501f6c2
Fix nullability
wsugarman Jul 6, 2024
adb22ef
Add E2E tests for most actions
wsugarman Jul 7, 2024
463aa7c
Nit
wsugarman Jul 7, 2024
1c3d0bb
Merge in main
wsugarman Jul 27, 2024
c23a94f
Update schema.json
wsugarman Jul 27, 2024
b6a7693
Nit
wsugarman Jul 27, 2024
40ea154
Merge branch 'main' into dotnet-dump-template
wsugarman Aug 1, 2024
092c607
nit: spelling mistake
wsugarman Aug 1, 2024
91a7c2d
Merge branch 'main' into dotnet-dump-template
wsugarman Aug 1, 2024
f9b2e4b
Merge branch 'main' into dotnet-dump-template
wsugarman Aug 1, 2024
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
49 changes: 49 additions & 0 deletions documentation/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1700,6 +1700,13 @@
"type": "string",
"description": "The name of the egress provider to which the artifact is egressed.",
"minLength": 1
},
"ArtifactName": {
"type": [
"null",
"string"
],
"description": "The name of the generated artifact."
}
}
},
Expand Down Expand Up @@ -1750,6 +1757,13 @@
"$ref": "#/definitions/ExceptionsConfiguration"
}
]
},
"ArtifactName": {
"type": [
"null",
"string"
],
"description": "The name of the generated artifact."
}
}
},
Expand All @@ -1776,6 +1790,13 @@
"type": "string",
"description": "The name of the egress provider to which the artifact is egressed.",
"minLength": 1
},
"ArtifactName": {
"type": [
"null",
"string"
],
"description": "The name of the generated artifact."
}
}
},
Expand Down Expand Up @@ -1825,6 +1846,13 @@
"type": "string",
"description": "The name of the egress provider to which the artifact is egressed.",
"minLength": 1
},
"ArtifactName": {
"type": [
"null",
"string"
],
"description": "The name of the generated artifact."
}
}
},
Expand Down Expand Up @@ -1939,6 +1967,13 @@
"$ref": "#/definitions/LogFormat"
}
]
},
"ArtifactName": {
"type": [
"null",
"string"
],
"description": "The name of the generated artifact."
}
}
},
Expand Down Expand Up @@ -1976,6 +2011,13 @@
"$ref": "#/definitions/CallStackFormat"
}
]
},
"ArtifactName": {
"type": [
"null",
"string"
],
"description": "The name of the generated artifact."
}
}
},
Expand Down Expand Up @@ -2062,6 +2104,13 @@
"$ref": "#/definitions/TraceEventFilter"
}
]
},
"ArtifactName": {
"type": [
"null",
"string"
],
"description": "The name of the generated artifact."
}
}
},
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -773,4 +773,7 @@
<value>The expected value of the 'iss' or Issuer field in the JWT (JSON Web Token).</value>
<comment>The description provided for the Issuer parameter on MonitorApiKeyOptions.</comment>
</data>
</root>
<data name="DisplayAttributeDescription_CollectArtifactOptions_ArtifactName" xml:space="preserve">
<value>The name of the generated artifact.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ protected async Task<ActionResult> Result(
return await SendToEgress(new EgressOperation(
operation,
providerName,
default, // Use default artifact name
processInfo,
scope,
tags),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ internal class EgressOperation : IEgressOperation

private readonly IArtifactOperation _operation;

public EgressOperation(IArtifactOperation operation, string endpointName, IProcessInfo processInfo, KeyValueLogScope scope, string? tags, CollectionRuleMetadata? collectionRuleMetadata = null)
public EgressOperation(IArtifactOperation operation, string endpointName, string? artifactName, IProcessInfo processInfo, KeyValueLogScope scope, string? tags, CollectionRuleMetadata? collectionRuleMetadata = null)
{
_egress = (service, token) => service.EgressAsync(
endpointName,
operation.ExecuteAsync,
operation.GenerateFileName(),
artifactName ?? operation.GenerateFileName(),
operation.ContentType,
processInfo.EndpointInfo,
collectionRuleMetadata,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions =>
ILogger<CollectionRuleService> logger = host.Services.GetRequiredService<ILogger<CollectionRuleService>>();
TimeProvider timeProvider = host.Services.GetRequiredService<TimeProvider>();

CollectionRuleContext context = new(DefaultRuleName, ruleOptions, CreateTestProcess(), logger, timeProvider);
CollectionRuleContext context = new(DefaultRuleName, ruleOptions, CreateTestProcess(), HostInfo.GetCurrent(timeProvider), logger);

int callbackCount = 0;
Action startCallback = () => callbackCount++;
Expand Down Expand Up @@ -106,7 +106,7 @@ await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions =>
ILogger<CollectionRuleService> logger = host.Services.GetRequiredService<ILogger<CollectionRuleService>>();
TimeProvider timeProvider = host.Services.GetRequiredService<TimeProvider>();

CollectionRuleContext context = new(DefaultRuleName, ruleOptions, CreateTestProcess(), logger, timeProvider);
CollectionRuleContext context = new(DefaultRuleName, ruleOptions, CreateTestProcess(), HostInfo.GetCurrent(timeProvider), logger);

int callbackCount = 0;
Action startCallback = () => callbackCount++;
Expand Down Expand Up @@ -152,7 +152,7 @@ await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions =>
ILogger<CollectionRuleService> logger = host.Services.GetRequiredService<ILogger<CollectionRuleService>>();
TimeProvider timeProvider = host.Services.GetRequiredService<TimeProvider>();

CollectionRuleContext context = new(DefaultRuleName, ruleOptions, CreateTestProcess(), logger, timeProvider);
CollectionRuleContext context = new(DefaultRuleName, ruleOptions, CreateTestProcess(), HostInfo.GetCurrent(timeProvider), logger);

int callbackCount = 0;
Action startCallback = () => callbackCount++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.Diagnostics.Monitoring.WebApi.Models;
using Microsoft.Diagnostics.Tools.Monitor.CollectionRules;
using Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Actions;
using Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options;
using Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions;
using Microsoft.Extensions.DependencyInjection;
using System;
Expand Down Expand Up @@ -45,7 +46,17 @@ public Task CollectDumpAction_Success(TargetFrameworkMoniker tfm, DumpType dumpT
outputHelper: _outputHelper);
}

private async Task CollectDumpAction_SuccessCore(TargetFrameworkMoniker tfm, DumpType dumpType)
[Fact]
public Task CollectDumpAction_CustomArtifactName()
{
// Code path should be unchanged between TFM and dump type
return RetryUtilities.RetryAsync(
func: () => CollectDumpAction_SuccessCore(TargetFrameworkMoniker.Current, DumpType.Mini, artifactName: Guid.NewGuid().ToString("n")),
shouldRetry: (Exception ex) => ex is TaskCanceledException,
outputHelper: _outputHelper);
}

private async Task CollectDumpAction_SuccessCore(TargetFrameworkMoniker tfm, DumpType dumpType, string artifactName = null)
{
// MacOS dumps inconsistently segfault the runtime on .NET 5: https://github.com/dotnet/dotnet-monitor/issues/174
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && tfm == TargetFrameworkMoniker.Net50)
Expand All @@ -59,8 +70,12 @@ await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions =>
{
rootOptions.AddFileSystemEgress(ActionTestsConstants.ExpectedEgressProvider, tempDirectory.FullName);

rootOptions.CreateCollectionRule(DefaultRuleName)
.AddCollectDumpAction(ActionTestsConstants.ExpectedEgressProvider, dumpType)
CollectionRuleOptions options = rootOptions.CreateCollectionRule(DefaultRuleName)
.AddCollectDumpAction(ActionTestsConstants.ExpectedEgressProvider, o =>
{
o.ArtifactName = artifactName;
o.Type = dumpType;
})
.SetStartupTrigger();
}, async host =>
{
Expand All @@ -84,7 +99,7 @@ await runner.ExecuteAsync(async () =>

CollectionRuleActionResult result = await ActionTestsHelper.ExecuteAndDisposeAsync(action, CommonTestTimeouts.DumpTimeout);

string egressPath = ActionTestsHelper.ValidateEgressPath(result);
string egressPath = ActionTestsHelper.ValidateEgressPath(result, artifactName);

using FileStream dumpStream = new(egressPath, FileMode.Open, FileAccess.Read);
Assert.NotNull(dumpStream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,18 @@ ex is TaskCanceledException ||
outputHelper: _outputHelper);
}

private async Task CollectGCDumpAction_SuccessCore(TargetFrameworkMoniker tfm)
[Fact]
public Task CollectGCDumpAction_CustomArtifactName()
{
return RetryUtilities.RetryAsync(
func: () => CollectGCDumpAction_SuccessCore(TargetFrameworkMoniker.Current, artifactName: Guid.NewGuid().ToString("n")),
shouldRetry: (Exception ex) => (
ex is TaskCanceledException ||
(ex is CollectionRuleActionException && ex.InnerException is InvalidOperationException)),
outputHelper: _outputHelper);
}

private async Task CollectGCDumpAction_SuccessCore(TargetFrameworkMoniker tfm, string artifactName = null)
{
using TemporaryDirectory tempDirectory = new(_outputHelper);

Expand All @@ -60,7 +71,7 @@ await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions =>
rootOptions.AddFileSystemEgress(ActionTestsConstants.ExpectedEgressProvider, tempDirectory.FullName);

rootOptions.CreateCollectionRule(DefaultRuleName)
.AddCollectGCDumpAction(ActionTestsConstants.ExpectedEgressProvider)
.AddCollectGCDumpAction(ActionTestsConstants.ExpectedEgressProvider, o => o.ArtifactName = artifactName)
.SetStartupTrigger();
}, async host =>
{
Expand All @@ -84,7 +95,7 @@ await runner.ExecuteAsync(async () =>

CollectionRuleActionResult result = await ActionTestsHelper.ExecuteAndDisposeAsync(action, CommonTestTimeouts.GCDumpTimeout);

string egressPath = ActionTestsHelper.ValidateEgressPath(result);
string egressPath = ActionTestsHelper.ValidateEgressPath(result, artifactName);

using FileStream gcdumpStream = new(egressPath, FileMode.Open, FileAccess.Read);
Assert.NotNull(gcdumpStream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ public CollectLiveMetricsActionTests(ITestOutputHelper outputHelper)

[Theory]
[MemberData(nameof(ActionTestsHelper.GetTfms), MemberType = typeof(ActionTestsHelper))]
public async Task CollectLiveMetricsAction_CustomProviders(TargetFrameworkMoniker tfm)
public Task CollectLiveMetricsAction_CustomProviders(TargetFrameworkMoniker tfm) =>
CollectLiveMetricsAction_CustomProvidersCore(tfm);

[Fact]
public Task CollectLiveMetricsAction_CustomArtifactName() =>
CollectLiveMetricsAction_CustomProvidersCore(TargetFrameworkMoniker.Current, artifactName: Guid.NewGuid().ToString("n"));

private async Task CollectLiveMetricsAction_CustomProvidersCore(TargetFrameworkMoniker tfm, string artifactName = null)
{
using TemporaryDirectory tempDirectory = new(_outputHelper);

Expand All @@ -55,16 +62,17 @@ await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions =>
rootOptions.CreateCollectionRule(DefaultRuleName)
.AddCollectLiveMetricsAction(ActionTestsConstants.ExpectedEgressProvider, options =>
{
options.ArtifactName = artifactName;
options.Duration = TimeSpan.FromSeconds(CommonTestTimeouts.LiveMetricsDurationSeconds);
options.IncludeDefaultProviders = false;
options.Providers = new[]
{
options.Providers =
[
new EventMetricsProvider
{
ProviderName = providerName,
CounterNames = counterNames,
}
};
];
})
.SetStartupTrigger();
}, async host =>
Expand All @@ -89,7 +97,7 @@ await runner.ExecuteAsync(async () =>

CollectionRuleActionResult result = await ActionTestsHelper.ExecuteAndDisposeAsync(action, CommonTestTimeouts.LiveMetricsTimeout);

string egressPath = ActionTestsHelper.ValidateEgressPath(result);
string egressPath = ActionTestsHelper.ValidateEgressPath(result, artifactName);

using FileStream liveMetricsStream = new(egressPath, FileMode.Open, FileAccess.Read);
Assert.NotNull(liveMetricsStream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions =>
[MemberData(nameof(ActionTestsHelper.GetTfms), MemberType = typeof(ActionTestsHelper))]
public async Task CollectTraceAction_ProvidersSuccess(TargetFrameworkMoniker tfm)
{
List<EventPipeProvider> ExpectedProviders = new()
{
List<EventPipeProvider> ExpectedProviders =
[
new() { Name = "Microsoft-Extensions-Logging" }
};
];

using TemporaryDirectory tempDirectory = new(_outputHelper);

Expand All @@ -79,13 +79,30 @@ await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions =>
options.Duration = TimeSpan.FromSeconds(2);
})
.SetStartupTrigger();
}, async host =>
}, host => PerformTrace(host, tfm));
}

[Fact]
public async Task CollectTraceAction_CustomArtifactName()
{
string artifactName = Guid.NewGuid().ToString("n");
using TemporaryDirectory tempDirectory = new(_outputHelper);

await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions =>
{
await PerformTrace(host, tfm);
});
rootOptions.AddFileSystemEgress(ActionTestsConstants.ExpectedEgressProvider, tempDirectory.FullName);

rootOptions.CreateCollectionRule(DefaultRuleName)
.AddCollectTraceAction(TraceProfile.Logs, ActionTestsConstants.ExpectedEgressProvider, options =>
{
options.ArtifactName = artifactName;
options.Duration = TimeSpan.FromSeconds(2);
})
.SetStartupTrigger();
}, host => PerformTrace(host, TargetFrameworkMoniker.Current, artifactName));
}

private async Task PerformTrace(IHost host, TargetFrameworkMoniker tfm)
private async Task PerformTrace(IHost host, TargetFrameworkMoniker tfm, string artifactName = null)
{
CollectTraceOptions options = ActionTestsHelper.GetActionOptions<CollectTraceOptions>(host, DefaultRuleName);

Expand All @@ -107,7 +124,7 @@ await runner.ExecuteAsync(async () =>

CollectionRuleActionResult result = await ActionTestsHelper.ExecuteAndDisposeAsync(action, CommonTestTimeouts.TraceTimeout);

string egressPath = ActionTestsHelper.ValidateEgressPath(result);
string egressPath = ActionTestsHelper.ValidateEgressPath(result, artifactName);

using FileStream traceStream = new(egressPath, FileMode.Open, FileAccess.Read);
Assert.NotNull(traceStream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private static MethodInfo GetMethodInfo(string methodName)
methodName = methodName[..methodName.IndexOf('[')];
}

// Return null on psuedo frames (e.g. [NativeFrame])
// Return null on pseudo frames (e.g. [NativeFrame])
if (methodName.Length == 0)
{
return null;
Expand Down Expand Up @@ -380,7 +380,7 @@ private void CollectStacksActionConfigureTool(MonitorCollectRunner runner, out T
options.GreaterThan = 0.0;
options.SlidingWindowDuration = TimeSpan.FromSeconds(5);
})
.AddCollectStacksAction(fileEgress, Tools.Monitor.CollectionRules.Options.Actions.CallStackFormat.Json);
.AddCollectStacksAction(fileEgress, o => o.Format = Tools.Monitor.CollectionRules.Options.Actions.CallStackFormat.Json);

ruleCompletedTask = runner.WaitForCollectionRuleActionsCompletedAsync("StacksCounterRule");
}
Expand Down
Loading