Skip to content

Remove the fallback to the legacy coherency algorithm.#2266

Merged
andriipatsula merged 14 commits intodotnet:mainfrom
andriipatsula:task/apatsula/arcade_6782
Jun 13, 2023
Merged

Remove the fallback to the legacy coherency algorithm.#2266
andriipatsula merged 14 commits intodotnet:mainfrom
andriipatsula:task/apatsula/arcade_6782

Conversation

@andriipatsula
Copy link
Copy Markdown
Member

@andriipatsula andriipatsula self-assigned this Apr 19, 2023
@andriipatsula andriipatsula requested review from a user and premun April 19, 2023 15:28
@premun premun requested a review from mmitche April 19, 2023 16:13
@mmitche
Copy link
Copy Markdown
Member

mmitche commented Apr 19, 2023

We need to implement an alert mechanism when this fails. Right now, Legacy coherency is probably filling some gaps where repos are failing the strict coherency update. Whether it gets it right is unknown, but they're getting updates rather than failing silently.

We should implement this part: #2687 in this PR:

  • We allow coherency to fail and still do an update PR. This is not the case today.
  • In the update PR, we add a new Maestro policy check that is "coherency valid" (sort of like the Do not automerge downgrades). This is always on, regardless of repo policies. If coherency is failing, then we make this check Red

This behavior would not be implemented in local darc, just the subscription actor service. The check, if it could not get info on which dependencies fail coherency, would tell the user to go and run local darc to resolve.

@andriipatsula
Copy link
Copy Markdown
Member Author

andriipatsula commented Apr 25, 2023

I am going to introduce a new merge policy class like:

public class ValidateCoherencyMergePolicy : MergePolicy
{
    public override string DisplayName => "TODO";

    /// overrides `IMergePolicy.EvaluateAsync`
    public override async Task<MergePolicyEvaluationResult> EvaluateAsync(IPullRequest pr, IRemote darc)
    {
        string prBranch = "";
        string repoUrl = "";

        List<DependencyDetail> existingDependencies = (await darc.GetDependenciesAsync(repoUrl, prBranch)).ToList();
        List<DependencyUpdate> coherencyUpdates = new List<DependencyUpdate>();
        try
        {
            // remoteFactory ???
            coherencyUpdates = await darc.GetRequiredCoherencyUpdatesAsync(existingDependencies, remoteFactory, CoherencyMode.Strict);
        }
        catch (DarcCoherencyException)
        {
            return Fail("Is not coherent");
        }

        if (coherencyUpdates.Any())
        {
            return Fail("Is not coherent");
        }

        return Succeed("Is coherent.");

    }
}

and utilize the IRemote.GetRequiredCoherencyUpdatesAsync(IEnumerable<DependencyDetail>, IRemoteFactory, CoherencyMode) to get the list of coherency update and if it empty - the repo + pr branch is coherent.

[!] But we don't have access to IRemoteFactory on the MergePolicy level. What about to modify the interface of the IMergePolicy interface?

public interface IMergePolicy : IMergePolicyInfo
{
-   Task<MergePolicyEvaluationResult> EvaluateAsync(IPullRequest pr, IRemote darc);
+   Task<MergePolicyEvaluationResult> EvaluateAsync(IPullRequest pr, IRemoteFactory remoteFactory);
}

/cc @riarenas , @mmitche

@mmitche
Copy link
Copy Markdown
Member

mmitche commented Apr 25, 2023

I don't think you need to redo the coherency calculation. Instead, GetRequiredUpdates would return whether the coherency update failed: https://github.com/dotnet/arcade-services/blob/main/src/Maestro/SubscriptionActorService/PullRequestActor.cs#L1083-L1088

Then, you modify the IPullRequest interface to include a bit that indicates whether the last coherency update failed or not. It currently just knows about the set of updates in the PR.

The new merge policy would check this bit and let the user know.

@andriipatsula andriipatsula marked this pull request as draft April 26, 2023 15:04
@tkapin
Copy link
Copy Markdown
Member

tkapin commented May 2, 2023

As one of the results of this work, could you please log an issue with proposal to improve our testing capabilities for these scenarios? This might involve anything that you found missing while working on this issue, such as having a local BAR database or resources for integration testing.

@andriipatsula
Copy link
Copy Markdown
Member Author

@riarenas , @mmitche could you please short feedback about the latest changes in the PR. @riarenas , we can have a call and discuss next steps.

  1. Example of a test PR with a failing coherency check: https://github.com/maestro-auth-test/maestro-test3/pull/2059/checks?check_run_id=13442834926
  2. I am going to add one more test scenario to ScenarioTests_GitHubFlow.cs
  3. As we are going to remove fallback and introduce new check, this new Github check won't be available in existing subscription (as I understand). Do I need to update all existing subscriptions? Write a data change script?

@ghost
Copy link
Copy Markdown

ghost commented May 17, 2023

  1. Example of a test PR with a failing coherency check: https://github.com/maestro-auth-test/maestro-test3/pull/2059/checks?check_run_id=13442834926

Yay! a check! Is it possible to add instructions to the error message on how to fix the coherency issue? I believe the Exception can capture some more details that would be helpful to add. I'll see if I can track which ones I'm talking about.

  1. I am going to add one more test scenario to ScenarioTests_GitHubFlow.cs

Sounds good

  1. As we are going to remove fallback and introduce new check, this new Github check won't be available in existing subscription (as I understand). Do I need to update all existing subscriptions? Write a data change script?

We could add the check to the standard merge policy, which is already an aggregation of policies that we suggest everyone should have: https://github.com/dotnet/arcade-services/blob/main/src/Maestro/Maestro.MergePolicies/StandardMergePolicy.cs

For subscriptions not using the standard policy I see a few options:

  • we just inform partners that this is a new check and to please add it to their subscriptions.
  • We update every subscription (ideally through the API or through darc, not through the database) to include the new policy
  • We inject the policy and check to every subscription, regardless of how they have them configured.

@andriipatsula andriipatsula force-pushed the task/apatsula/arcade_6782 branch from bb0f578 to 0ed4b8f Compare May 24, 2023 10:15
@andriipatsula andriipatsula marked this pull request as ready for review May 24, 2023 10:17
@andriipatsula
Copy link
Copy Markdown
Member Author

andriipatsula commented May 24, 2023

PR has been updated. Here are a few examples:

I did refactor/rewrite the ScenarioTests_GitHubFlow::Darc_GitHubFlow_NonBatched_WithCoherency test, since the Strick algorithm consistently failed and it always fall back to the Legacy algorithm.

Copy link
Copy Markdown
Member

@mmitche mmitche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking generally good. I haven't taken a very close look at the tests yet.

The only downside to the approach taken is that if a repo doesn't enable a merge policy, either using standard or including this specifically, they won't the direct feedback that there is an issue. IMO this isn't a blocker as standard is heavily used.

It would be good to eventually divide the merge policies into optional ones that enable auto-merge, and ones that are required to evaluate the dependency update.

@andriipatsula andriipatsula requested review from a user and mmitche May 29, 2023 15:11
andriipatsula and others added 2 commits June 5, 2023 13:48
Co-authored-by: Matt Mitchell <mmitche@microsoft.com>
Co-authored-by: Matt Mitchell <mmitche@microsoft.com>
StringBuilder description = new StringBuilder("Coherency update failed for the following dependencies:");
foreach (CoherencyErrorDetails error in pr.CoherencyErrors)
{
description.Append("\n * ").Append(error.Error);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use AppendLine instead of Append so you can save yourself adding the \n manually

ghost
ghost previously approved these changes Jun 8, 2023
Copy link
Copy Markdown

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM pretty much. Just make sure to run all of the scenario test suite to make sure there are no problems there, and to keep in mind the necessary followups described in the issue.

Copy link
Copy Markdown

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not look at the latest changes.

@andriipatsula andriipatsula merged commit 4b3f187 into dotnet:main Jun 13, 2023
andriipatsula added a commit to andriipatsula/arcade-services that referenced this pull request Jun 27, 2023
andriipatsula added a commit to andriipatsula/arcade-services that referenced this pull request Aug 25, 2023
Co-authored-by: Matt Mitchell <mmitche@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants