Skip to content

Commit

Permalink
code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
zcodes304 committed Jul 24, 2023
1 parent 7e5216b commit 58b5cf8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
12 changes: 11 additions & 1 deletion tools/code/extractor/Diagnostic.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
using common;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;


namespace extractor;

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

private static bool ShouldExport(DiagnosticName diagnosticName, IEnumerable<string>? diagnosticNamesToExport)
{
return diagnosticNamesToExport is null
|| diagnosticNamesToExport.Any(diagnosticNameToExport => diagnosticNameToExport.Equals(diagnosticName.ToString(), StringComparison.OrdinalIgnoreCase));
}

private static async ValueTask Export(ServiceDirectory serviceDirectory, ServiceUri serviceUri, DiagnosticName diagnosticName, GetRestResource getRestResource, ILogger logger, CancellationToken cancellationToken)
{
var diagnosticsDirectory = new DiagnosticsDirectory(serviceDirectory);
Expand Down
2 changes: 2 additions & 0 deletions tools/code/extractor/Extractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public record Parameters
public required IHostApplicationLifetime ApplicationLifetime { get; init; }
public IEnumerable<string>? ApiNamesToExport { get; init; }
public IEnumerable<string>? LoggerNamesToExport { get; init; }
public IEnumerable<string>? DiagnosticNamesToExport { get; init; }
public IEnumerable<string>? NamedValueNamesToExport { get; init; }
public IEnumerable<string>? ProductNamesToExport { get; init; }
public IEnumerable<string>? BackendNamesToExport { get; init; }
Expand Down Expand Up @@ -70,6 +71,7 @@ await Service.Export(parameters.ServiceDirectory,
parameters.DefaultApiSpecification,
parameters.ApiNamesToExport,
parameters.LoggerNamesToExport,
parameters.DiagnosticNamesToExport,
parameters.NamedValueNamesToExport,
parameters.ProductNamesToExport,
parameters.BackendNamesToExport,
Expand Down
7 changes: 7 additions & 0 deletions tools/code/extractor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ private static Extractor.Parameters GetExtractorParameters(IServiceProvider prov
{
ApiNamesToExport = GetApiNamesToExport(configuration),
LoggerNamesToExport = GetLoggerNamesToExport(configuration),
DiagnosticNamesToExport = GetDiagnosticNamesToExport(configuration),
NamedValueNamesToExport = GetNamedValueNamesToExport(configuration),
ProductNamesToExport = GetProductNamesToExport(configuration),
BackendNamesToExport = GetBackendNamesToExport(configuration),
Expand Down Expand Up @@ -211,6 +212,12 @@ private static Extractor.Parameters GetExtractorParameters(IServiceProvider prov
?.Get<IEnumerable<string>>();
}

private static IEnumerable<string>? GetDiagnosticNamesToExport(IConfiguration configuration)
{
return configuration.TryGetSection("diagnosticNames")
?.Get<IEnumerable<string>>();
}

private static IEnumerable<string>? GetNamedValueNamesToExport(IConfiguration configuration)
{
return configuration.TryGetSection("namedValueNames")
Expand Down
3 changes: 2 additions & 1 deletion tools/code/extractor/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static async ValueTask Export(
DefaultApiSpecification defaultSpecification,
IEnumerable<string>? apiNamesToExport,
IEnumerable<string>? loggerNamesToExport,
IEnumerable<string>? diagnosticNamesToExport,
IEnumerable<string>? namedValueNamesToExport,
IEnumerable<string>? productNamesToExport,
IEnumerable<string>? backendNamesToExport,
Expand All @@ -37,7 +38,7 @@ public static async ValueTask Export(
await Logger.ExportAll(serviceDirectory, serviceUri, listRestResources, getRestResource, logger, loggerNamesToExport, cancellationToken);

logger.LogInformation("Exporting diagnostics...");
await Diagnostic.ExportAll(serviceDirectory, serviceUri, listRestResources, getRestResource, logger, cancellationToken);
await Diagnostic.ExportAll(serviceDirectory, serviceUri, listRestResources, getRestResource, logger, diagnosticNamesToExport, cancellationToken);

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

0 comments on commit 58b5cf8

Please sign in to comment.