Skip to content
Closed
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
6 changes: 4 additions & 2 deletions src/ImageBuilder/AcrContentClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ namespace Microsoft.DotNet.ImageBuilder;

internal class AcrContentClientFactory(
IAzureTokenCredentialProvider tokenCredentialProvider,
IOptions<PublishConfiguration> publishConfigOptions)
IOptions<PublishConfiguration> publishConfigOptions,
ILoggerService loggerService)
: IAcrContentClientFactory
{
private readonly IAzureTokenCredentialProvider _tokenCredentialProvider = tokenCredentialProvider;
private readonly PublishConfiguration _publishConfig = publishConfigOptions.Value;
private readonly ILoggerService _loggerService = loggerService;

public IAcrContentClient Create(Acr acr, string repositoryName)
{
Expand All @@ -33,7 +35,7 @@ public IAcrContentClient Create(Acr acr, string repositoryName)
AzureScopes.ContainerRegistryScope);

var client = new ContainerRegistryContentClient(acr.RegistryUri, repositoryName, tokenCredential);
var wrapper = new AcrContentClientWrapper(client);
var wrapper = new AcrContentClientWrapper(client, _loggerService);
return wrapper;
}
}
11 changes: 10 additions & 1 deletion src/ImageBuilder/AcrContentClientWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
Expand All @@ -10,15 +11,23 @@
namespace Microsoft.DotNet.ImageBuilder;

#nullable enable
public class AcrContentClientWrapper(ContainerRegistryContentClient innerClient) : IAcrContentClient
public class AcrContentClientWrapper(ContainerRegistryContentClient innerClient, ILoggerService loggerService) : IAcrContentClient
{
private readonly ContainerRegistryContentClient _innerClient = innerClient;
private readonly ILoggerService _loggerService = loggerService;

public string RepositoryName => _innerClient.RepositoryName;

public async Task<ManifestQueryResult> GetManifestAsync(string tagOrDigest)
{
_loggerService.WriteMessage($"[{nameof(GetManifestAsync)}] {RepositoryName}:{tagOrDigest}");
Stopwatch stopwatch = Stopwatch.StartNew();

Response<GetManifestResult> result = await _innerClient.GetManifestAsync(tagOrDigest);

stopwatch.Stop();
_loggerService.WriteMessage($"[{nameof(GetManifestAsync)}] {RepositoryName}:{tagOrDigest} -> {result.Value.Digest} ({stopwatch.ElapsedMilliseconds}ms)");

JsonObject manifestData = (JsonObject)(JsonNode.Parse(result.Value.Manifest.ToString()) ?? throw new JsonException($"Unable to deserialize result: {result.Value.Manifest}"));
return new ManifestQueryResult(result.Value.Digest, manifestData);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -69,20 +70,25 @@ protected async Task<IEnumerable<EolDigestData>> GetAllImageDigestsFromRegistryA

IAcrClient acrClient = _acrClientFactory.Create(Options.RegistryOptions.Registry);


Stopwatch totalStopwatch = Stopwatch.StartNew();
IAsyncEnumerable<string> repositoryNames =
acrClient.GetRepositoryNamesAsync()
.Where(repo => repoNameFilter is null || repoNameFilter(repo));

ConcurrentBag<(string Digest, string? Tag)> digests = [];
await foreach (string repositoryName in repositoryNames)
{
Stopwatch repoStopwatch = Stopwatch.StartNew();

IAcrContentClient contentClient =
_acrContentClientFactory.Create(
Acr.Parse(Options.RegistryOptions.Registry),
repositoryName);

ContainerRepository repo = acrClient.GetRepository(repositoryName);
IAsyncEnumerable<ArtifactManifestProperties> manifests = repo.GetAllManifestPropertiesAsync();
int manifestCount = 0;
await foreach (ArtifactManifestProperties manifestProps in manifests)
{
ManifestQueryResult manifestResult = await contentClient.GetManifestAsync(manifestProps.Digest);
Expand All @@ -99,9 +105,16 @@ protected async Task<IEnumerable<EolDigestData>> GetAllImageDigestsFromRegistryA
digest: manifestProps.Digest);
digests.Add((imageName, GetLongestTag(manifestProps.Tags)));
}
manifestCount++;
}

repoStopwatch.Stop();
LoggerService.WriteMessage($"Processed repository '{repositoryName}' with {manifestCount} manifests in {repoStopwatch.ElapsedMilliseconds}ms");
}

totalStopwatch.Stop();
LoggerService.WriteMessage($"Completed querying all image digests. Total digests: {digests.Count}, Total time: {totalStopwatch.Elapsed}");

return digests
.Select(val => new EolDigestData(val.Digest) { Tag = val.Tag });
}
Expand Down
Loading