Skip to content

Commit db6052f

Browse files
committed
Some fixes
1 parent 042c0fb commit db6052f

File tree

21 files changed

+319
-152
lines changed

21 files changed

+319
-152
lines changed

eng/Versions.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<!-- The TFMs of the dotnet-monitor tool. -->
2828
<ToolTargetFrameworks>$(LatestTargetFramework)</ToolTargetFrameworks>
2929
<!-- The TFMs of that the dotnet-monitor tool supports diagnosing. -->
30-
<TestTargetFrameworks>net7.0;net8.0;$(LatestTargetFramework)</TestTargetFrameworks>
30+
<TestTargetFrameworks>net8.0;$(LatestTargetFramework)</TestTargetFrameworks>
3131
<!-- The TFM for generating schema.json and OpenAPI docs. -->
3232
<SchemaTargetFramework>net10.0</SchemaTargetFramework>
3333
</PropertyGroup>

src/Microsoft.Diagnostics.Monitoring.Extension.Common/Microsoft.Diagnostics.Monitoring.Extension.Common.csproj

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
44
<OutputType>Library</OutputType>
55
<PackAsTool>false</PackAsTool>
6-
<TargetFrameworks>$(ToolTargetFrameworks)</TargetFrameworks>
6+
<TargetFrameworks>$(LatestTargetFramework)</TargetFrameworks>
77
<DefineConstants>$(DefineConstants);EXTENSION</DefineConstants>
88
<IsPackable>true</IsPackable>
99
<IsShippingAssembly>true</IsShippingAssembly>
1010
</PropertyGroup>
1111

1212
<ItemGroup>
1313
<Compile Include="..\Tools\dotnet-monitor\DataAnnotationValidateOptions.cs" Link="DataAnnotationValidateOptions.cs" />
14+
<Compile Include="..\Tools\dotnet-monitor\CollectionRules\Options\ValidationHelper.cs" Link="ValidationHelper.cs" />
1415
</ItemGroup>
1516

1617
<ItemGroup>
@@ -20,8 +21,6 @@
2021
</ItemGroup>
2122

2223
<ItemGroup>
23-
<PackageReference Include="Microsoft.Extensions.Logging" />
24-
<PackageReference Include="Microsoft.Extensions.Logging.Console" />
2524
<PackageReference Include="System.CommandLine" />
2625
</ItemGroup>
2726

@@ -40,4 +39,19 @@
4039
<Generator>ResXFileCodeGenerator</Generator>
4140
</EmbeddedResource>
4241
</ItemGroup>
42+
43+
<ItemGroup>
44+
<KnownFrameworkReference
45+
Update="Microsoft.NETCore.App"
46+
TargetingPackVersion="$(NetCoreAppVersion)"
47+
DefaultRuntimeFrameworkVersion="$(NetCoreAppVersion)"
48+
LatestRuntimeFrameworkVersion="$(NetCoreAppVersion)" />
49+
50+
<KnownFrameworkReference
51+
Update="Microsoft.AspNetCore.App"
52+
TargetingPackVersion="$(AspNetCoreAppVersion)"
53+
DefaultRuntimeFrameworkVersion="$(AspNetCoreAppVersion)"
54+
LatestRuntimeFrameworkVersion="$(AspNetCoreAppVersion)" />
55+
</ItemGroup>
56+
4357
</Project>

src/Microsoft.Diagnostics.Monitoring.WebApi/Models/EgressOperationStatus.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class OperationStatus : OperationSummary
6060
public OperationError? Error { get; set; }
6161
}
6262

63-
[JsonConverter(typeof(JsonStringEnumConverter))]
63+
[JsonConverter(typeof(JsonStringEnumConverter<OperationState>))]
6464
public enum OperationState
6565
{
6666
Starting,

src/Microsoft.Diagnostics.Monitoring.WebApi/MonitorJsonSerializerContext.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,35 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System;
45
using System.Collections.Generic;
56
using System.Text.Json.Serialization;
7+
using Microsoft.AspNetCore.Mvc;
68
using Microsoft.Diagnostics.Monitoring.WebApi.Models;
79
using Microsoft.Diagnostics.Monitoring.Options;
810

911
namespace Microsoft.Diagnostics.Monitoring.WebApi
1012
{
1113
[JsonSerializable(typeof(CaptureParametersConfiguration))]
14+
[JsonSerializable(typeof(CollectionRuleDetailedDescription))]
15+
[JsonSerializable(typeof(Dictionary<string, CollectionRuleDescription>))]
16+
[JsonSerializable(typeof(Dictionary<string, string>))]
17+
[JsonSerializable(typeof(DotnetMonitorInfo))]
18+
[JsonSerializable(typeof(DumpType))]
1219
[JsonSerializable(typeof(EventMetricsConfiguration))]
1320
[JsonSerializable(typeof(EventPipeConfiguration))]
1421
[JsonSerializable(typeof(ExceptionsConfiguration))]
15-
[JsonSerializable(typeof(LogsConfiguration))]
22+
[JsonSerializable(typeof(FileResult))]
23+
[JsonSerializable(typeof(Guid?))]
24+
[JsonSerializable(typeof(IEnumerable<OperationSummary>))]
25+
[JsonSerializable(typeof(IEnumerable<ProcessIdentifier>))]
1626
[JsonSerializable(typeof(IList<ProcessIdentifier>))]
27+
[JsonSerializable(typeof(LogsConfiguration))]
28+
[JsonSerializable(typeof(OperationStatus))]
29+
[JsonSerializable(typeof(ProcessInfo))]
30+
[JsonSerializable(typeof(ProblemDetails))]
31+
[JsonSerializable(typeof(TraceProfile))]
32+
[JsonSerializable(typeof(ValidationProblemDetails))]
1733
partial class MonitorJsonSerializerContext : JsonSerializerContext
1834
{
1935
}

src/Tests/CollectionRuleActions.UnitTests/ExecuteActionTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using Microsoft.AspNetCore.Http.Validation;
45
using Microsoft.Diagnostics.Monitoring.TestCommon;
56
using Microsoft.Diagnostics.Tools.Monitor;
67
using Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Actions;
78
using Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Exceptions;
89
using Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions;
10+
using Microsoft.Extensions.Options;
911
using System;
1012
using System.Globalization;
1113
using System.IO;
@@ -175,7 +177,7 @@ private static void ValidateActionResult(CollectionRuleActionResult result, stri
175177

176178
private static async Task ValidateAction(Action<ExecuteOptions> optionsCallback, Func<ICollectionRuleAction, CancellationToken, Task> actionCallback)
177179
{
178-
ExecuteActionFactory factory = new();
180+
ExecuteActionFactory factory = new(Options.Create<ValidationOptions>(new()));
179181

180182
ExecuteOptions options = new();
181183

src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTests/ActionDependencyAnalyzerTests.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,14 @@ await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions =>
142142
[Fact]
143143
public async Task ProcessInfoTest()
144144
{
145-
PassThroughOptions settings = null;
145+
CollectionRuleActionOptions actionOptions = null;
146146
await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions =>
147147
{
148148
CollectionRuleOptions options = rootOptions.CreateCollectionRule(DefaultRuleName)
149149
.AddPassThroughAction("a1", ConfigurationTokenParser.ProcessNameReference, ConfigurationTokenParser.ProcessIdReference, ConfigurationTokenParser.CommandLineReference)
150150
.SetStartupTrigger();
151151

152-
settings = (PassThroughOptions)options.Actions.Last().Settings;
152+
actionOptions = options.Actions.Last();
153153
}, host =>
154154
{
155155
using CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TimeoutMs);
@@ -166,7 +166,7 @@ await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions =>
166166
CollectionRuleContext context = new(DefaultRuleName, ruleOptions, new TestProcessInfo(instanceId, processId: processId, commandLine: commandLine), HostInfo.GetCurrent(timeProvider), logger);
167167

168168
ActionOptionsDependencyAnalyzer analyzer = ActionOptionsDependencyAnalyzer.Create(context);
169-
PassThroughOptions newSettings = (PassThroughOptions)analyzer.SubstituteOptionValues(new Dictionary<string, CollectionRuleActionResult>(), 1, settings);
169+
PassThroughOptions newSettings = (PassThroughOptions)analyzer.SubstituteOptionValues(new Dictionary<string, CollectionRuleActionResult>(), 1, actionOptions);
170170

171171
Assert.Equal(processName, newSettings.Input1);
172172
Assert.Equal(processId.ToString(CultureInfo.InvariantCulture), newSettings.Input2);
@@ -181,14 +181,14 @@ await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions =>
181181
[Fact]
182182
public async Task HostInfoTest()
183183
{
184-
PassThroughOptions settings = null;
184+
CollectionRuleActionOptions actionOptions = null;
185185
await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions =>
186186
{
187187
CollectionRuleOptions options = rootOptions.CreateCollectionRule(DefaultRuleName)
188188
.AddPassThroughAction("a1", ConfigurationTokenParser.HostNameReference, ConfigurationTokenParser.UnixTimeReference, "test")
189189
.SetStartupTrigger();
190190

191-
settings = (PassThroughOptions)options.Actions.Last().Settings;
191+
actionOptions = options.Actions.Last();
192192
}, host =>
193193
{
194194
using CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TimeoutMs);
@@ -203,7 +203,7 @@ await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions =>
203203
CollectionRuleContext context = new(DefaultRuleName, ruleOptions, new TestProcessInfo(instanceId), hostInfo, logger);
204204

205205
ActionOptionsDependencyAnalyzer analyzer = ActionOptionsDependencyAnalyzer.Create(context);
206-
PassThroughOptions newSettings = (PassThroughOptions)analyzer.SubstituteOptionValues(new Dictionary<string, CollectionRuleActionResult>(), 1, settings);
206+
PassThroughOptions newSettings = (PassThroughOptions)analyzer.SubstituteOptionValues(new Dictionary<string, CollectionRuleActionResult>(), 1, actionOptions);
207207

208208
Assert.Equal(hostName, newSettings.Input1);
209209
Assert.Equal(hostInfo.TimeProvider.GetUtcNow().ToUnixTimeSeconds().ToString(CultureInfo.InvariantCulture), newSettings.Input2);
@@ -223,15 +223,15 @@ public async Task InvalidTokenReferenceTest()
223223
string a2input3 = "$(Actions.a1.MissingResult)";
224224

225225
LogRecord record = new LogRecord();
226-
PassThroughOptions settings = null;
226+
CollectionRuleActionOptions actionOptions = null;
227227
await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions =>
228228
{
229229
CollectionRuleOptions options = rootOptions.CreateCollectionRule(DefaultRuleName)
230230
.AddPassThroughAction("a1", "a1input1", "a1input2", "a1input3")
231231
.AddPassThroughAction("a2", a2input1, a2input2, a2input3)
232232
.SetStartupTrigger();
233233

234-
settings = (PassThroughOptions)options.Actions.Last().Settings;
234+
actionOptions = options.Actions.Last();
235235
}, host =>
236236
{
237237
using CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TimeoutMs);
@@ -245,7 +245,7 @@ await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions =>
245245

246246
ActionOptionsDependencyAnalyzer analyzer = ActionOptionsDependencyAnalyzer.Create(context);
247247
analyzer.GetActionDependencies(1);
248-
analyzer.SubstituteOptionValues(new Dictionary<string, CollectionRuleActionResult>(), 1, settings);
248+
analyzer.SubstituteOptionValues(new Dictionary<string, CollectionRuleActionResult>(), 1, actionOptions);
249249

250250
Assert.Equal(3, record.Events.Count);
251251
Assert.Equal(LoggingEventIds.InvalidActionReferenceToken.Id(), record.Events[0].EventId.Id);
@@ -264,15 +264,15 @@ await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions =>
264264
[Fact]
265265
public async Task RuntimeIdReferenceTest()
266266
{
267-
PassThroughOptions settings = null;
267+
CollectionRuleActionOptions actionOptions = null;
268268
await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions =>
269269
{
270270
CollectionRuleOptions options = rootOptions.CreateCollectionRule(DefaultRuleName)
271271
.AddPassThroughAction("a1", ConfigurationTokenParser.RuntimeIdReference, "test", "test")
272272
.SetStartupTrigger();
273273

274-
settings = (PassThroughOptions)options.Actions.Last().Settings;
275-
}, host =>
274+
actionOptions = options.Actions.Last();
275+
}, host =>
276276
{
277277
using CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TimeoutMs);
278278

@@ -284,7 +284,7 @@ await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions =>
284284
CollectionRuleContext context = new(DefaultRuleName, ruleOptions, new TestProcessInfo(instanceId), HostInfo.GetCurrent(timeProvider), logger);
285285

286286
ActionOptionsDependencyAnalyzer analyzer = ActionOptionsDependencyAnalyzer.Create(context);
287-
PassThroughOptions newSettings = (PassThroughOptions)analyzer.SubstituteOptionValues(new Dictionary<string, CollectionRuleActionResult>(), 1, settings);
287+
PassThroughOptions newSettings = (PassThroughOptions)analyzer.SubstituteOptionValues(new Dictionary<string, CollectionRuleActionResult>(), 1, actionOptions);
288288

289289
Assert.Equal(instanceId.ToString("D"), newSettings.Input1);
290290

src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTests/ExtensionManifestTests.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using Microsoft.AspNetCore.Http.Validation;
45
using Microsoft.Diagnostics.Monitoring.TestCommon;
56
using Microsoft.Diagnostics.Tools.Monitor.Extensibility;
67
using System.IO;
@@ -91,7 +92,7 @@ public void ExtensionManifest_EmptyObject_ThrowOnValidate()
9192
Assert.Null(manifest.AssemblyFileName);
9293
Assert.Null(manifest.ExecutableFileName);
9394

94-
ExtensionException ex = Assert.Throws<ExtensionException>(manifest.Validate);
95+
ExtensionException ex = Assert.Throws<ExtensionException>(() => manifest.Validate(new Microsoft.AspNetCore.Http.Validation.ValidationOptions()));
9596
Assert.Null(ex.InnerException);
9697
}
9798

@@ -115,7 +116,7 @@ public void ExtensionManifest_NameOnly_ThrowOnValidate()
115116
Assert.Null(manifest.AssemblyFileName);
116117
Assert.Null(manifest.ExecutableFileName);
117118

118-
ExtensionException ex = Assert.Throws<ExtensionException>(manifest.Validate);
119+
ExtensionException ex = Assert.Throws<ExtensionException>(() => manifest.Validate(new ValidationOptions()));
119120
Assert.Null(ex.InnerException);
120121
}
121122

@@ -141,7 +142,7 @@ public void ExtensionManifest_ExecutableAndAssembly_ThrowOnValidate()
141142
Assert.Equal(ExpectedAssemblyName, manifest.AssemblyFileName);
142143
Assert.Equal(ExpectedExecutableName, manifest.ExecutableFileName);
143144

144-
ExtensionException ex = Assert.Throws<ExtensionException>(manifest.Validate);
145+
ExtensionException ex = Assert.Throws<ExtensionException>(() => manifest.Validate(new ValidationOptions()));
145146
Assert.Null(ex.InnerException);
146147
}
147148

@@ -166,7 +167,7 @@ public void ExtensionManifest_NameAndAssembly_Valid()
166167
Assert.Equal(ExpectedAssemblyName, manifest.AssemblyFileName);
167168
Assert.Null(manifest.ExecutableFileName);
168169

169-
manifest.Validate();
170+
manifest.Validate(new ValidationOptions());
170171
}
171172

172173
[Fact]
@@ -190,7 +191,7 @@ public void ExtensionManifest_NameAndExecutable_Valid()
190191
Assert.Null(manifest.AssemblyFileName);
191192
Assert.Equal(ExpectedExecutableName, manifest.ExecutableFileName);
192193

193-
manifest.Validate();
194+
manifest.Validate(new ValidationOptions());
194195
}
195196

196197
private static Stream CreateManifestStream(TemporaryDirectory dir, out string path)

src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Microsoft.Diagnostics.Monitoring.UnitTestApp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<Compile Include="..\Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests\ParameterCapturing\SampleMethods.cs" Link="Scenarios\FunctionProbes\SampleMethods.cs"/>
2727
</ItemGroup>
2828

29-
<Import Project="Sdk.targets" Sdk="Microsft.NET.Sdk.Web" />
29+
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk.Web" />
3030

3131
<ItemGroup>
3232
<KnownFrameworkReference

src/Tools/dotnet-monitor/CollectionRules/ActionListExecutor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public async Task<IDictionary<string, CollectionRuleActionResult>> ExecuteAction
9191
));
9292
}
9393

94-
object? newSettings = dependencyAnalyzer.SubstituteOptionValues(actionResults, actionIndex, actionOption.Settings);
94+
object? newSettings = dependencyAnalyzer.SubstituteOptionValues(actionResults, actionIndex, actionOption);
9595
ICollectionRuleAction? action = factory.Create(context.ProcessInfo, newSettings);
9696

9797
try

src/Tools/dotnet-monitor/CollectionRules/ActionOptionsDependencyAnalyzer.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ public IList<CollectionRuleActionOptions> GetActionDependencies(int actionIndex)
112112
}
113113
#nullable restore
114114

115-
public object? SubstituteOptionValues(IDictionary<string, CollectionRuleActionResult> actionResults, int actionIndex, object? settings)
115+
public object? SubstituteOptionValues(IDictionary<string, CollectionRuleActionResult> actionResults, int actionIndex, CollectionRuleActionOptions actionOptions)
116116
{
117+
object? settings = actionOptions.Settings;
117118
//Attempt to substitute context properties.
118119
object? originalSettings = settings;
119120

@@ -160,7 +161,7 @@ public IList<CollectionRuleActionOptions> GetActionDependencies(int actionIndex)
160161
}
161162
string? commandLine = _ruleContext.EndpointInfo.CommandLine;
162163

163-
settings = _tokenParser.SubstituteOptionValues(settings, new TokenContext
164+
settings = _tokenParser.SubstituteOptionValues(actionOptions, new TokenContext
164165
{
165166
CloneOnSubstitution = ReferenceEquals(originalSettings, settings),
166167
RuntimeId = _ruleContext.EndpointInfo.RuntimeInstanceCookie,
@@ -289,7 +290,7 @@ private bool GetActionResultReference(string actionReference, int actionIndex,
289290

290291
private static IEnumerable<PropertyInfo> GetDependencyPropertiesFromSettings(CollectionRuleActionOptions options)
291292
{
292-
return ConfigurationTokenParser.GetPropertiesFromSettings(options.Settings, p => p.GetCustomAttributes(typeof(ActionOptionsDependencyPropertyAttribute), inherit: true).Any());
293+
return ConfigurationTokenParser.GetPropertiesFromSettings(options, p => p.GetCustomAttributes(typeof(ActionOptionsDependencyPropertyAttribute), inherit: true).Any());
293294
}
294295
}
295296
}

0 commit comments

Comments
 (0)