Skip to content

Commit 58b5cf8

Browse files
committed
code changes
1 parent 7e5216b commit 58b5cf8

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

tools/code/extractor/Diagnostic.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
using common;
22
using Microsoft.Extensions.Logging;
33
using System.Collections.Generic;
4+
using System;
45
using System.Linq;
56
using System.Threading;
67
using System.Threading.Tasks;
78

9+
810
namespace extractor;
911

1012
internal static class Diagnostic
1113
{
12-
public static async ValueTask ExportAll(ServiceDirectory serviceDirectory, ServiceUri serviceUri, ListRestResources listRestResources, GetRestResource getRestResource, ILogger logger, CancellationToken cancellationToken)
14+
public static async ValueTask ExportAll(ServiceDirectory serviceDirectory, ServiceUri serviceUri, ListRestResources listRestResources, GetRestResource getRestResource, ILogger logger, IEnumerable<string>? diagnosticNamesToExport, CancellationToken cancellationToken)
1315
{
1416
await List(serviceUri, listRestResources, cancellationToken)
17+
// Filter out diagnostics that should not be exported
18+
.Where(diagnosticName => ShouldExport(diagnosticName, diagnosticNamesToExport))
1519
.ForEachParallel(async diagnosticName => await Export(serviceDirectory, serviceUri, diagnosticName, getRestResource, logger, cancellationToken),
1620
cancellationToken);
1721
}
@@ -25,6 +29,12 @@ private static IAsyncEnumerable<DiagnosticName> List(ServiceUri serviceUri, List
2529
.Select(name => new DiagnosticName(name));
2630
}
2731

32+
private static bool ShouldExport(DiagnosticName diagnosticName, IEnumerable<string>? diagnosticNamesToExport)
33+
{
34+
return diagnosticNamesToExport is null
35+
|| diagnosticNamesToExport.Any(diagnosticNameToExport => diagnosticNameToExport.Equals(diagnosticName.ToString(), StringComparison.OrdinalIgnoreCase));
36+
}
37+
2838
private static async ValueTask Export(ServiceDirectory serviceDirectory, ServiceUri serviceUri, DiagnosticName diagnosticName, GetRestResource getRestResource, ILogger logger, CancellationToken cancellationToken)
2939
{
3040
var diagnosticsDirectory = new DiagnosticsDirectory(serviceDirectory);

tools/code/extractor/Extractor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public record Parameters
2222
public required IHostApplicationLifetime ApplicationLifetime { get; init; }
2323
public IEnumerable<string>? ApiNamesToExport { get; init; }
2424
public IEnumerable<string>? LoggerNamesToExport { get; init; }
25+
public IEnumerable<string>? DiagnosticNamesToExport { get; init; }
2526
public IEnumerable<string>? NamedValueNamesToExport { get; init; }
2627
public IEnumerable<string>? ProductNamesToExport { get; init; }
2728
public IEnumerable<string>? BackendNamesToExport { get; init; }
@@ -70,6 +71,7 @@ await Service.Export(parameters.ServiceDirectory,
7071
parameters.DefaultApiSpecification,
7172
parameters.ApiNamesToExport,
7273
parameters.LoggerNamesToExport,
74+
parameters.DiagnosticNamesToExport,
7375
parameters.NamedValueNamesToExport,
7476
parameters.ProductNamesToExport,
7577
parameters.BackendNamesToExport,

tools/code/extractor/Program.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ private static Extractor.Parameters GetExtractorParameters(IServiceProvider prov
184184
{
185185
ApiNamesToExport = GetApiNamesToExport(configuration),
186186
LoggerNamesToExport = GetLoggerNamesToExport(configuration),
187+
DiagnosticNamesToExport = GetDiagnosticNamesToExport(configuration),
187188
NamedValueNamesToExport = GetNamedValueNamesToExport(configuration),
188189
ProductNamesToExport = GetProductNamesToExport(configuration),
189190
BackendNamesToExport = GetBackendNamesToExport(configuration),
@@ -211,6 +212,12 @@ private static Extractor.Parameters GetExtractorParameters(IServiceProvider prov
211212
?.Get<IEnumerable<string>>();
212213
}
213214

215+
private static IEnumerable<string>? GetDiagnosticNamesToExport(IConfiguration configuration)
216+
{
217+
return configuration.TryGetSection("diagnosticNames")
218+
?.Get<IEnumerable<string>>();
219+
}
220+
214221
private static IEnumerable<string>? GetNamedValueNamesToExport(IConfiguration configuration)
215222
{
216223
return configuration.TryGetSection("namedValueNames")

tools/code/extractor/Service.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public static async ValueTask Export(
1414
DefaultApiSpecification defaultSpecification,
1515
IEnumerable<string>? apiNamesToExport,
1616
IEnumerable<string>? loggerNamesToExport,
17+
IEnumerable<string>? diagnosticNamesToExport,
1718
IEnumerable<string>? namedValueNamesToExport,
1819
IEnumerable<string>? productNamesToExport,
1920
IEnumerable<string>? backendNamesToExport,
@@ -37,7 +38,7 @@ public static async ValueTask Export(
3738
await Logger.ExportAll(serviceDirectory, serviceUri, listRestResources, getRestResource, logger, loggerNamesToExport, cancellationToken);
3839

3940
logger.LogInformation("Exporting diagnostics...");
40-
await Diagnostic.ExportAll(serviceDirectory, serviceUri, listRestResources, getRestResource, logger, cancellationToken);
41+
await Diagnostic.ExportAll(serviceDirectory, serviceUri, listRestResources, getRestResource, logger, diagnosticNamesToExport, cancellationToken);
4142

4243
logger.LogInformation("Exporting backends...");
4344
await Backend.ExportAll(serviceDirectory, serviceUri, listRestResources, getRestResource, logger, backendNamesToExport, cancellationToken);

0 commit comments

Comments
 (0)