Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions eng/packages/General.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<PackageVersion Include="Azure.Storage.Files.DataLake" Version="12.21.0" />
<PackageVersion Include="Azure.AI.Inference" Version="1.0.0-beta.5" />
<PackageVersion Include="ICSharpCode.Decompiler" Version="9.1.0.7988" />
<PackageVersion Include="Microsoft.ApplicationInsights" Version="2.23.0" />
<PackageVersion Include="Microsoft.Bcl.HashCode" Version="1.1.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="$(MicrosoftCodeAnalysisAnalyzersVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="$(MicrosoftCodeAnalysisVersion)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,66 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Azure.Identity;
using Azure.Storage.Files.DataLake;
using Microsoft.Extensions.AI.Evaluation.Console.Telemetry;
using Microsoft.Extensions.AI.Evaluation.Console.Utilities;
using Microsoft.Extensions.AI.Evaluation.Reporting;
using Microsoft.Extensions.AI.Evaluation.Reporting.Storage;
using Microsoft.Extensions.Logging;

namespace Microsoft.Extensions.AI.Evaluation.Console.Commands;

internal sealed class CleanCacheCommand(ILogger logger)
internal sealed class CleanCacheCommand(ILogger logger, TelemetryHelper telemetryHelper)
{
internal async Task<int> InvokeAsync(DirectoryInfo? storageRootDir, Uri? endpointUri, CancellationToken cancellationToken = default)
internal async Task<int> InvokeAsync(
DirectoryInfo? storageRootDir,
Uri? endpointUri,
CancellationToken cancellationToken = default)
{
IEvaluationResponseCacheProvider cacheProvider;

if (storageRootDir is not null)
{
string storageRootPath = storageRootDir.FullName;
logger.LogInformation("Storage root path: {storageRootPath}", storageRootPath);
logger.LogInformation("Deleting expired cache entries...");

cacheProvider = new DiskBasedResponseCacheProvider(storageRootPath);
}
else if (endpointUri is not null)
{
logger.LogInformation("Azure Storage endpoint: {endpointUri}", endpointUri);

var fsClient = new DataLakeDirectoryClient(endpointUri, new DefaultAzureCredential());
cacheProvider = new AzureStorageResponseCacheProvider(fsClient);
}
else
{
throw new InvalidOperationException("Either --path or --endpoint must be specified");
}
var telemetryProperties = new Dictionary<string, string>();

await logger.ExecuteWithCatchAsync(
() => cacheProvider.DeleteExpiredCacheEntriesAsync(cancellationToken)).ConfigureAwait(false);
operation: () =>
telemetryHelper.ReportOperationAsync(
operationName: TelemetryConstants.EventNames.CleanCacheCommand,
operation: () =>
{
IEvaluationResponseCacheProvider cacheProvider;

if (storageRootDir is not null)
{
string storageRootPath = storageRootDir.FullName;
logger.LogInformation("Storage root path: {storageRootPath}", storageRootPath);
logger.LogInformation("Deleting expired cache entries...");

cacheProvider = new DiskBasedResponseCacheProvider(storageRootPath);

telemetryProperties[TelemetryConstants.PropertyNames.StorageType] =
TelemetryConstants.PropertyValues.StorageTypeDisk;
}
else if (endpointUri is not null)
{
logger.LogInformation("Azure Storage endpoint: {endpointUri}", endpointUri);

var fsClient = new DataLakeDirectoryClient(endpointUri, new DefaultAzureCredential());
cacheProvider = new AzureStorageResponseCacheProvider(fsClient);

telemetryProperties[TelemetryConstants.PropertyNames.StorageType] =
TelemetryConstants.PropertyValues.StorageTypeAzure;
}
else
{
throw new InvalidOperationException("Either --path or --endpoint must be specified");
}

return cacheProvider.DeleteExpiredCacheEntriesAsync(cancellationToken);
},
properties: telemetryProperties)).ConfigureAwait(false);

return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,76 +8,98 @@
using System.Threading.Tasks;
using Azure.Identity;
using Azure.Storage.Files.DataLake;
using Microsoft.Extensions.AI.Evaluation.Console.Telemetry;
using Microsoft.Extensions.AI.Evaluation.Console.Utilities;
using Microsoft.Extensions.AI.Evaluation.Reporting;
using Microsoft.Extensions.AI.Evaluation.Reporting.Storage;
using Microsoft.Extensions.Logging;

namespace Microsoft.Extensions.AI.Evaluation.Console.Commands;

internal sealed class CleanResultsCommand(ILogger logger)
internal sealed class CleanResultsCommand(ILogger logger, TelemetryHelper telemetryHelper)
{
internal async Task<int> InvokeAsync(
DirectoryInfo? storageRootDir,
Uri? endpointUri,
int lastN,
CancellationToken cancellationToken = default)
{
IEvaluationResultStore resultStore;

if (storageRootDir is not null)
{
string storageRootPath = storageRootDir.FullName;
logger.LogInformation("Storage root path: {storageRootPath}", storageRootPath);
var telemetryProperties =
new Dictionary<string, string>
{
[TelemetryConstants.PropertyNames.LastN] = lastN.ToTelemetryPropertyValue()
};

resultStore = new DiskBasedResultStore(storageRootPath);
}
else if (endpointUri is not null)
{
logger.LogInformation("Azure Storage endpoint: {endpointUri}", endpointUri);
await logger.ExecuteWithCatchAsync(
operation: () =>
telemetryHelper.ReportOperationAsync(
operationName: TelemetryConstants.EventNames.CleanResultsCommand,
operation: async ValueTask () =>
{
IEvaluationResultStore resultStore;

var fsClient = new DataLakeDirectoryClient(endpointUri, new DefaultAzureCredential());
resultStore = new AzureStorageResultStore(fsClient);
}
else
{
throw new InvalidOperationException("Either --path or --endpoint must be specified");
}
if (storageRootDir is not null)
{
string storageRootPath = storageRootDir.FullName;
logger.LogInformation("Storage root path: {storageRootPath}", storageRootPath);

await logger.ExecuteWithCatchAsync(
async ValueTask () =>
{
if (lastN is 0)
{
logger.LogInformation("Deleting all results...");
resultStore = new DiskBasedResultStore(storageRootPath);

await resultStore.DeleteResultsAsync(cancellationToken: cancellationToken).ConfigureAwait(false);
}
else
{
logger.LogInformation("Deleting all results except the {lastN} most recent ones...", lastN);
telemetryProperties[TelemetryConstants.PropertyNames.StorageType] =
TelemetryConstants.PropertyValues.StorageTypeDisk;
}
else if (endpointUri is not null)
{
logger.LogInformation("Azure Storage endpoint: {endpointUri}", endpointUri);

HashSet<string> toPreserve = [];
var fsClient = new DataLakeDirectoryClient(endpointUri, new DefaultAzureCredential());
resultStore = new AzureStorageResultStore(fsClient);

await foreach (string executionName in
resultStore.GetLatestExecutionNamesAsync(lastN, cancellationToken).ConfigureAwait(false))
{
_ = toPreserve.Add(executionName);
}
telemetryProperties[TelemetryConstants.PropertyNames.StorageType] =
TelemetryConstants.PropertyValues.StorageTypeAzure;
}
else
{
throw new InvalidOperationException("Either --path or --endpoint must be specified");
}

await foreach (string executionName in
resultStore.GetLatestExecutionNamesAsync(
cancellationToken: cancellationToken).ConfigureAwait(false))
{
if (!toPreserve.Contains(executionName))
if (lastN is 0)
{
logger.LogInformation("Deleting all results...");

await resultStore.DeleteResultsAsync(
executionName,
cancellationToken: cancellationToken).ConfigureAwait(false);
}
}
}
}).ConfigureAwait(false);
else
{
logger.LogInformation(
"Deleting all results except the {lastN} most recent ones...",
lastN);

HashSet<string> toPreserve = [];

await foreach (string executionName in
resultStore.GetLatestExecutionNamesAsync(
lastN,
cancellationToken).ConfigureAwait(false))
{
_ = toPreserve.Add(executionName);
}

await foreach (string executionName in
resultStore.GetLatestExecutionNamesAsync(
cancellationToken: cancellationToken).ConfigureAwait(false))
{
if (!toPreserve.Contains(executionName))
{
await resultStore.DeleteResultsAsync(
executionName,
cancellationToken: cancellationToken).ConfigureAwait(false);
}
}
}
},
properties: telemetryProperties)).ConfigureAwait(false);

return 0;
}
Expand Down
Loading
Loading