Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix rebase creating PR for wrong dependency #10727

Merged
merged 16 commits into from
Oct 16, 2024

Conversation

sachin-sandhu
Copy link
Contributor

@sachin-sandhu sachin-sandhu commented Oct 4, 2024

What are you trying to accomplish?

Preface: This issue is related with :dependabot: closing and creating new pull requests.

Issue: Azure Dev Ops team (likely not limited to) is facing an issue where :dependabot: is closing and recreating an existing PR which is resulting in multiple PRs being generated every day. i.e.

+-------------------------------------------------------------------------------------+
|                         Changes to Dependabot Pull Requests                         |
+------------------------------+------------------------------------------------------+
| closed: dependencies_changed | express,path-to-regexp,react-router,react-router-dom |
| created                      | express ( from 4.18.2 to 4.21.0 )                    |
+------------------------------+------------------------------------------------------+

Here the existing pull request already exists for lead dependency express. This can be seen from job snapshot as following:

job:
  dependencies:
  - express
  - path-to-regexp
  - react-router
  - react-router-dom
  existing-pull-requests:
  - - dependency-name: express
      dependency-version: 4.21.0
    - dependency-name: path-to-regexp
      dependency-version: 0.1.10
    - dependency-name: react-router-doms
      dependency-version: 6.26.2
  security-updates-only: true

On dependabot scanning existing PR, it does not takes the existing PR snapshot into account. i.e. the rerun pr log is as following:

2024/10/07 16:04:22 INFO Checking and updating security pull requests...
2024/10/07 16:04:22 INFO Checking if express 4.18.2 needs updating
2024/10/07 16:04:23 INFO Latest version is 4.21.0
2024/10/07 16:04:30 INFO Requirements to unlock own
2024/10/07 16:04:30 INFO Requirements update strategy bump_versions
2024/10/07 16:04:30 INFO Updating express from 4.18.2 to 4.21.0
2024/10/07 16:04:40 INFO Telling backend to close pull request for express, path-to-regexp, react-router, react-router-dom - dependencies changed
2024/10/07 16:04:40 INFO Submitting express pull request for creation
+-------------------------------------------------------------------------------------+
|                         Changes to Dependabot Pull Requests                         |
+------------------------------+------------------------------------------------------+
| closed: dependencies_changed | express,path-to-regexp,react-router,react-router-dom |
| created                      | express ( from 4.18.2 to 4.21.0 )                    |
+------------------------------+------------------------------------------------------+

Issues:

There are multiple issues with this error which are described as following:

  1. The preceding snapshot is as following:
job:
  dependencies:
  - path-to-regexp
  security-advisories:
  - dependency-name: path-to-regexp
    affected-versions:
    - '>= 0, < 0.1.10'
    - '>= 0.2.0, < 8.0.0'
  security-updates-only: true
  commit-message-options:

Here it can be seen that the lead dependency is mentioned as path-to-regexp as compared to subsequent job (mentioned on top) where the lead dependency is express . Here the dependencies list is sorted alphabetically which is cause of this issue. Due to this mismatch the resulting job creates and erroneous situation that results in closing and creating a new PR. The ideal result in this situation should be to update the existing PR.

  1. A situation where the decision to takes to create/update/close PR has a logical issue. The number of dependencies modified vs initial job list are not compared in logical order (alphabetically) which results in inaccurate results. The error is at line

Solution: The fix intends to stop recreation of PRs if same version update is found in existing PR snapshot. It is seen that this issue exists for lead dependencies (first in the group) right now. The targeted version update can be matched with the one in pr snapshot, if the versions are a match, then a new PR creation can be avoided. i.e.

2024/10/07 17:04:19 INFO Matching entry found in existing PR. Dependency name: express, version: 4.21.0
2024/10/07 17:04:19 INFO Lead dependency (express) version (4.21.0) is  already upto date in pull request, skipping updating pull request.
  1. First part of solution is to take security advisory dependency as a lead dependency, which is primary dependency on which the preceding PR was created. This solves the issue of inaccurate lead dependency.

  2. The comparison of dependencies updated vs initial dependencies in job are now sorted in alphabetical order to accurately compare the two data sets (string array). This should resolve issue of inaccurate results in case same number of dependencies are updated but not in order.

+---------------------------------------------------------------------------------------------------------------------------------+
|                                               Changes to Dependabot Pull Requests                                               |
+---------+-----------------------------------------------------------------------------------------------------------------------+
| updated | path-to-regexp ( from 0.1.7 to 0.1.10 ), react-router-dom ( from 5.3.4 to 6.27.0 ), express ( from 4.18.2 to 4.21.1 ) |
+---------+-----------------------------------------------------------------------------------------------------------------------+

Additional information:

To mitigate any issues that might come up with this fix, a feature flag lead_security_dependency is used to quickly roll back in case of any issues.

Telemetry data collection:
To assess the behaviour, telemetry log has been inserted at various places to collect information on impact of this issue. This is to conduct impact assessment of the issue later and facilitate next steps if required.

Plan of execution:

  • The feature will be turned on only for Azure Dev Ops related PRs. Feature flag handling will be by ADO team.
  • Afterwards, logs will be observed for sample repos set to ensure that fix is working as intended
  • If there is not breaking impact, then telemetry data will be collected from AWS CloudWatch logs.
  • Data collected will be analyzed to see the impact of this behaviour.
  • Post analysis steps can be taken if required.

Anything you want to highlight for special attention from reviewers?

How will you know you've accomplished your goal?

We should see a larger drop in dropping and recreating new PRs on affected repos.

Checklist

  • I have run the complete test suite to ensure all tests and linters pass.
  • I have thoroughly tested my code changes to ensure they work as expected, including adding additional tests for new functionality.
  • I have written clear and descriptive commit messages.
  • I have provided a detailed description of the changes in the pull request, including the problem it addresses, how it fixes the problem, and any relevant details about the implementation.
  • I have ensured that the code is well-documented and easy to understand.

@sachin-sandhu sachin-sandhu self-assigned this Oct 4, 2024
@sachin-sandhu sachin-sandhu changed the title draft for dep change issues Fixes issue related with dependencies_changed on existing pr scan Oct 7, 2024
@sachin-sandhu sachin-sandhu marked this pull request as ready for review October 7, 2024 17:22
@sachin-sandhu sachin-sandhu requested a review from a team as a code owner October 7, 2024 17:22
@abdulapopoola
Copy link
Member

thanks @sachin-sandhu , please let's get @jakecoffman , @Nishnha , and @landongrindheim to review this as they worked on this area a bit.

Copy link
Contributor

@kbukum1 kbukum1 left a comment

Choose a reason for hiding this comment

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

I left some comments.

@jakecoffman
Copy link
Member

jakecoffman commented Oct 8, 2024

I'm not entirely sure what the problem is. Customer has Dependabot run daily and so it does, and finds an update to an existing PR:
created                      | express ( from 4.18.2 to 4.21.0 ) 

So it supersedes the PR. That seems like the behavior Dependabot has always had.

Is that a correct summary of the issue?

If the dependencies are updating too frequently the solution would be to have Dependabot run less frequent than daily, maybe weekly.

Edit: Ah ok this repo makes the problem pretty clear: https://github.com/brettfo/dependabot-npm-closing

@jakecoffman
Copy link
Member

jakecoffman commented Oct 8, 2024

It appears this PR will break rebases. We do need Dependabot to rebase jobs even if an existing PR exists with the same version, that's a feature of rebasing.

For example: Dependabot posts the PR, and new commits go to the main branch. Users will want to @dependabot rebase the PR before merging. With this change it seems like that will no longer work assuming the dependency version hasn't changed.

It seems the bug here is that a rebase job is producing different results from the job that created it, probably because of the grouped nature of the update. So we need to track down why that is happening instead of preventing the rebase.

@jakecoffman jakecoffman changed the title Fixes issue related with dependencies_changed on existing pr scan fix rebase creating PR for wrong dependency Oct 14, 2024
updater/lib/dependabot/job.rb Outdated Show resolved Hide resolved
updater/lib/dependabot/job.rb Outdated Show resolved Hide resolved
@@ -1172,6 +1172,122 @@ def expect_update_checker_with_ignored_versions(versions, dependency_matcher: an
end
end

context "when the security advisory job is used as lead dependency" do
Copy link
Member

Choose a reason for hiding this comment

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

The top of this file has a comment:

DO NOT ADD NEW TESTS TO THIS FILE

This would be a perfect candidate for a "silent test" for multidir-rebase. Here's a multidir-create test you can modify to add a rebase: https://github.com/dependabot/dependabot-core/blob/e63dc2cf45f6d2d6ca29ed49433a26eb74c5fcfc/silent/tests/testdata/su-multidir.txt

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have moved tests cases to relevant file and also added silent tests for security rebases

@@ -113,6 +113,7 @@

before do
allow(Dependabot::Experiments).to receive(:enabled?).with(:bundler_v1_unsupported_error).and_return(false)
allow(Dependabot::Experiments).to receive(:enabled?).with(:lead_security_dependency).and_return(false)
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest turning the experiment on in these tests as we believe this is the right way to do security updates with a single dependency going forward.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added a new test for single dependency update, this particular test case is intended towards deprecation notices

@sachin-sandhu sachin-sandhu requested review from jakecoffman and removed request for landongrindheim October 15, 2024 01:41
Copy link
Member

@jakecoffman jakecoffman left a comment

Choose a reason for hiding this comment

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

Nice work!

@sachin-sandhu sachin-sandhu force-pushed the ssandhu/dependency-changed-issue-fix branch from 6d5e3ce to 9baebdd Compare October 16, 2024 13:52
@sachin-sandhu sachin-sandhu merged commit 420e9ff into main Oct 16, 2024
124 checks passed
@sachin-sandhu sachin-sandhu deleted the ssandhu/dependency-changed-issue-fix branch October 16, 2024 14:48
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.

5 participants