Skip to content

Commit

Permalink
[Rollout] Production rollout 2024-10-25 (#4101)
Browse files Browse the repository at this point in the history
  • Loading branch information
premun authored Oct 24, 2024
2 parents 4bb6117 + dc0a773 commit fc7f00a
Show file tree
Hide file tree
Showing 36 changed files with 305 additions and 147 deletions.
10 changes: 1 addition & 9 deletions .vault-config/maestroprod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,4 @@ keys:

importSecretsFrom: shared/maestro-secrets.yaml

secrets:
# Needed during Maestro rollouts to create GitHub releases in arcade-services
BotAccount-dotnet-bot-repo-PAT:
type: github-access-token
parameters:
gitHubBotAccountSecret:
location: engkeyvault
name: BotAccount-dotnet-bot
gitHubBotAccountName: dotnet-bot
secrets: {}
7 changes: 0 additions & 7 deletions .vault-config/product-construction-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ references:
name: engkeyvault

secrets:
BotAccount-dotnet-bot-repo-PAT:
type: github-access-token
parameters:
gitHubBotAccountSecret:
location: engkeyvault
name: BotAccount-dotnet-bot
gitHubBotAccountName: dotnet-bot

github:
type: github-app-secret
Expand Down
9 changes: 1 addition & 8 deletions .vault-config/product-construction-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,7 @@ references:
name: engkeyvault

secrets:
BotAccount-dotnet-bot-repo-PAT:
type: github-access-token
parameters:
gitHubBotAccountSecret:
location: engkeyvault
name: BotAccount-dotnet-bot
gitHubBotAccountName: dotnet-bot


github:
type: github-app-secret
parameters:
Expand Down
6 changes: 0 additions & 6 deletions .vault-config/vmr-synchronization.1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,3 @@ secrets:
name: dn-bot-dnceng-build
organizations: dnceng
scopes: build_execute code_write

BotAccount-dotnet-bot-repo-PAT:
type: github-access-token
parameters:
gitHubBotAccountSecret: BotAccount-dotnet-bot
gitHubBotAccountName: dotnet-bot
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ resource storageAccountQueue 'Microsoft.Storage/storageAccounts/queueServices/qu
parent: storageAccountQueueService
}

resource codeFlowQueue 'Microsoft.Storage/storageAccounts/queueServices/queues@2022-09-01' = {
name: 'pcs-codeflow-workitems'
parent: storageAccountQueueService
}

// allow storage queue access to the identity used for the aca's
resource pcsStorageQueueAccess 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
scope: storageAccount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
"TableName": "healthreport"
},
"KeyVaultUri": "https://maestroprod.vault.azure.net/",
"FeedCleaner": {
"Enabled": true
},
"BuildAssetRegistry": {
"ConnectionString": "Data Source=tcp:maestro-prod.database.windows.net,1433; Initial Catalog=BuildAssetRegistry; Authentication=Active Directory Managed Identity; Persist Security Info=False; MultipleActiveResultSets=True; Connect Timeout=30; Encrypt=True; TrustServerCertificate=False;"
},
Expand Down
48 changes: 47 additions & 1 deletion src/Maestro/SubscriptionActorService/PullRequestActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Microsoft.Extensions.Logging;
using Microsoft.ServiceFabric.Actors;
using Microsoft.ServiceFabric.Actors.Runtime;
using Microsoft.VisualStudio.Services.Common;
using ProductConstructionService.Client;
using ProductConstructionService.Client.Models;
using SubscriptionActorService.StateModel;
Expand Down Expand Up @@ -872,8 +873,11 @@ await AddDependencyFlowEventsAsync(
MergePolicyCheckResult.PendingPolicies,
pr.Url);

var requiredDescriptionUpdates =
await CalculateOriginalDependencies(darcRemote, targetRepository, targetBranch, targetRepositoryUpdates);

pullRequest.Description = await _pullRequestBuilder.CalculatePRDescriptionAndCommitUpdatesAsync(
targetRepositoryUpdates.RequiredUpdates,
requiredDescriptionUpdates,
pullRequest.Description,
targetRepository,
pullRequest.HeadBranch);
Expand Down Expand Up @@ -1075,6 +1079,48 @@ private async Task<RepositoryBranchUpdate> GetRepositoryBranchUpdate()

private static string GetNewBranchName(string targetBranch) => $"darc-{targetBranch}-{Guid.NewGuid()}";

/// <summary>
/// Given a set of updates, replace the `from` version of every dependency update with the corresponding version
/// from the target branch
/// </summary>
/// <param name="darcRemote">Darc client used to fetch target branch dependencies.</param>
/// <param name="targetRepository">Target repository to fetch the dependencies from.</param>
/// <param name="targetBranch">Target branch to fetch the dependencies from.</param>
/// <param name="targetRepositoryUpdates">Incoming updates to the repository</param>
/// <returns>
/// Asset update and the corresponding list of altered dependencies
/// </returns>
/// <remarks>
/// This method is intended for use in situations where we want to keep the information about the original dependency
/// version, such as when updating PR descriptions.
/// </remarks>
private static async Task<List<(UpdateAssetsParameters update, List<DependencyUpdate> deps)>> CalculateOriginalDependencies(
IRemote darcRemote,
string targetRepository,
string targetBranch,
TargetRepoDependencyUpdate targetRepositoryUpdates)
{
List<DependencyDetail> targetBranchDeps = [..await darcRemote.GetDependenciesAsync(targetRepository, targetBranch)];

List<(UpdateAssetsParameters update, List<DependencyUpdate> deps)> alteredUpdates = [];
foreach (var requiredUpdate in targetRepositoryUpdates.RequiredUpdates)
{
var updatedDependencies = requiredUpdate.deps
.Select(dependency => new DependencyUpdate()
{
From = targetBranchDeps
.Where(replace => dependency.From.Name == replace.Name)
.FirstOrDefault(dependency.From),
To = dependency.To,
})
.ToList();

alteredUpdates.Add((requiredUpdate.update, updatedDependencies));
}

return alteredUpdates;
}

#region Code flow subscriptions

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,19 @@ protected async Task<NativePath> PrepareCloneInternal(string remoteUri, string d
else
{
_logger.LogDebug("Clone of {repo} found in {clonePath}", remoteUri, clonePath);
var remote = await _localGitRepo.AddRemoteIfMissingAsync(clonePath, remoteUri, cancellationToken);

string remote;

try
{
remote = await _localGitRepo.AddRemoteIfMissingAsync(clonePath, remoteUri, cancellationToken);
}
catch (Exception e) when (e.Message.Contains("fatal: not a git repository"))
{
_logger.LogWarning("Clone at {clonePath} is not a git repository, re-cloning", clonePath);
_fileSystem.DeleteDirectory(clonePath, recursive: true);
return await PrepareCloneInternal(remoteUri, dirName, cancellationToken);
}

// We cannot do `fetch --all` as tokens might be needed but fetch +refs/heads/*:+refs/remotes/origin/* doesn't fetch new refs
// So we need to call `remote update origin` to fetch everything
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ where sub.Enabled

if (subscriptionToUpdate != null)
{
await _workItemProducerFactory.CreateProducer<SubscriptionTriggerWorkItem>().ProduceWorkItemAsync(new()
await _workItemProducerFactory.CreateProducer<SubscriptionTriggerWorkItem>(subscriptionToUpdate.SourceEnabled).ProduceWorkItemAsync(new()
{
SubscriptionId = subscriptionToUpdate.Id,
BuildId = buildId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,20 @@ public async Task<IActionResult> StopPcsWorkItemProcessors()
{
return Ok(await PerformActionOnAllProcessors(async stateCache =>
{
await stateCache.SetStateAsync(WorkItemProcessorState.Stopping);
return (stateCache.ReplicaName, WorkItemProcessorState.Stopping);
var state = await stateCache.GetStateAsync();
switch (state)
{
case WorkItemProcessorState.Stopping:
case WorkItemProcessorState.Working:
await stateCache.SetStateAsync(WorkItemProcessorState.Stopping);
return (stateCache.ReplicaName, WorkItemProcessorState.Stopping);
case WorkItemProcessorState.Initializing:
throw new BadHttpRequestException("Can't stop the service while initializing, try again later");
case WorkItemProcessorState.Stopped:
return (stateCache.ReplicaName, WorkItemProcessorState.Stopped);
default:
throw new Exception("PCS is in an unsupported state");
}
}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static PcsStartup()
{
var context = (BuildAssetRegistryContext)entry.Context;
ILogger<BuildAssetRegistryContext> logger = context.GetService<ILogger<BuildAssetRegistryContext>>();
var workItemProducer = context.GetService<IWorkItemProducerFactory>().CreateProducer<SubscriptionTriggerWorkItem>();
var workItemProducerFactory = context.GetService<IWorkItemProducerFactory>();
var subscriptionIdGenerator = context.GetService<SubscriptionIdGenerator>();
BuildChannel entity = entry.Entity;

Expand Down Expand Up @@ -118,6 +118,7 @@ static PcsStartup()

foreach (Subscription subscription in subscriptionsToUpdate)
{
var workItemProducer = workItemProducerFactory.CreateProducer<SubscriptionTriggerWorkItem>(subscription.SourceEnabled);
workItemProducer.ProduceWorkItemAsync(new()
{
BuildId = entity.BuildId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ await builder.ConfigurePcs(
if (isDevelopment)
{
app.UseDeveloperExceptionPage();
await app.Services.UseLocalWorkItemQueues(
app.Configuration.GetRequiredValue(WorkItemConfiguration.WorkItemQueueNameConfigurationKey));
await app.Services.UseLocalWorkItemQueues([
app.Configuration.GetRequiredValue(WorkItemConfiguration.DefaultWorkItemQueueNameConfigurationKey),
app.Configuration.GetRequiredValue(WorkItemConfiguration.CodeFlowWorkItemQueueNameConfigurationKey)]);

if (useSwagger)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
}
},
"AllowedHosts": "*",
"WorkItemQueueName": "pcs-workitems",
"WorkItemConsumerCount": 5,
"DefaultWorkItemQueueName": "pcs-workitems",
"DefaultWorkItemConsumerCount": 4,
"CodeFlowWorkItemQueueName": "pcs-codeflow-workitems",
"WorkItemConsumerOptions": {
"QueuePollTimeout": "00:01:00",
"MaxWorkItemRetries": 3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ public NonBatchedPullRequestUpdater(
Subscription? subscription = await _context.Subscriptions.FindAsync(SubscriptionId);
if (subscription == null)
{
await _pullRequestCheckReminders.UnsetReminderAsync();
await _pullRequestUpdateReminders.UnsetReminderAsync();
// We don't know if the subscription was a code flow one, so just unset both
await _pullRequestCheckReminders.UnsetReminderAsync(isCodeFlow: true);
await _pullRequestCheckReminders.UnsetReminderAsync(isCodeFlow: false);
await _pullRequestUpdateReminders.UnsetReminderAsync(isCodeFlow: true);
await _pullRequestUpdateReminders.UnsetReminderAsync(isCodeFlow: false);

return null;
}

Expand Down Expand Up @@ -98,14 +102,15 @@ protected override async Task<IReadOnlyList<MergePolicyDefinition>> GetMergePoli
}

protected override async Task<bool> CheckInProgressPullRequestAsync(
InProgressPullRequest pullRequestCheck)
InProgressPullRequest pullRequestCheck,
bool isCodeFlow)
{
Subscription? subscription = await GetSubscription();
if (subscription == null)
{
return false;
}

return await base.CheckInProgressPullRequestAsync(pullRequestCheck);
return await base.CheckInProgressPullRequestAsync(pullRequestCheck, isCodeFlow);
}
}
Loading

0 comments on commit fc7f00a

Please sign in to comment.