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(CI): properly configure cancel duplicates #12625

Merged
merged 8 commits into from
Jan 29, 2021

Conversation

ktmud
Copy link
Member

@ktmud ktmud commented Jan 20, 2021

SUMMARY

Updating the "Cancel Duplicates" job to use our own Python script, which will try to cancel all duplicate jobs of all workflows:

  1. For each workflow, we keep only the latest run for a given branch + event type (pull_request or push).
  2. Older runs will be cancelled even if they are already running.

The benefit of using a custom Python script instead of a black-box like 3rd party action is that even if the cancel workflow is blocked be other long-running jobs scheduled before it, committers can still run the script locally to trigger the cancellation.

Tried to use https://github.com/potiuk/cancel-workflow-runs#most-often-used-canceling-example
but it's not very easy to configure.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A

TEST PLAN

The job should start correctly and duplicate runs should be properly cancelled.

Tested on my personal fork.

Check https://github.com/ktmud/superset/actions?query=workflow%3A%22Cancel+Duplicates%22 or verification.

ADDITIONAL INFORMATION

@codecov-io
Copy link

codecov-io commented Jan 20, 2021

Codecov Report

Merging #12625 (197e876) into master (32f2c45) will decrease coverage by 0.20%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #12625      +/-   ##
==========================================
- Coverage   67.01%   66.80%   -0.21%     
==========================================
  Files        1022     1022              
  Lines       50102    50102              
  Branches     5191     5191              
==========================================
- Hits        33574    33469     -105     
- Misses      16397    16502     +105     
  Partials      131      131              
Flag Coverage Δ
cypress 50.91% <ø> (-0.01%) ⬇️
javascript 61.73% <ø> (ø)
python 63.73% <ø> (-0.35%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
superset/db_engines/hive.py 0.00% <0.00%> (-85.72%) ⬇️
superset/db_engine_specs/hive.py 73.84% <0.00%> (-17.31%) ⬇️
superset/db_engine_specs/presto.py 81.38% <0.00%> (-6.71%) ⬇️
superset/views/database/mixins.py 80.70% <0.00%> (-1.76%) ⬇️
...set-frontend/src/dashboard/util/getDropPosition.js 92.06% <0.00%> (-1.59%) ⬇️
superset/models/core.py 88.04% <0.00%> (-0.82%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 32f2c45...197e876. Read the comment docs.

@ktmud ktmud force-pushed the ci-cancel-duplicates branch from 816db71 to 67861ae Compare January 20, 2021 23:59
@ktmud ktmud force-pushed the ci-cancel-duplicates branch 3 times, most recently from 67bdfdb to 4ad214a Compare January 21, 2021 20:26
@ktmud ktmud changed the title fix(CI): cancel dupliates should not skip pull requests fix(CI): properly configure cancel duplicates Jan 21, 2021
@ktmud ktmud force-pushed the ci-cancel-duplicates branch 3 times, most recently from 0cf38da to bf893a5 Compare January 22, 2021 08:14
Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

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

LGTM. I wish there was a way to avoid copying the action into the codebase 🙁

@ktmud ktmud force-pushed the ci-cancel-duplicates branch from 2a4e5c7 to d918bdc Compare January 24, 2021 07:19
@pull-request-size pull-request-size bot added size/M and removed size/L labels Jan 24, 2021
@ktmud
Copy link
Member Author

ktmud commented Jan 24, 2021

@potiuk, thanks for making the awesome cancel-workflow-runs GitHub action! Could you check here if I used your action correctly?

Much appreciated!

@ktmud ktmud force-pushed the ci-cancel-duplicates branch from d918bdc to c167c98 Compare January 24, 2021 07:36
Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

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

It can be done a bit simpler (and without error state). You can use results of the previous step in the conditional execution of the cancel one.

@potiuk
Copy link
Member

potiuk commented Jan 24, 2021

LGTM. I wish there was a way to avoid copying the action into the codebase

Submodules works great for it!

@ktmud ktmud force-pushed the ci-cancel-duplicates branch 2 times, most recently from 6144c6c to f5218b4 Compare January 24, 2021 08:13
echo "Found $count unfinished jobs."
echo "::set-output name=count::$count"

- uses: potiuk/cancel-workflow-runs@953e057dc81d3458935a18d1184c386b0f6b5738
Copy link
Member

Choose a reason for hiding this comment

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

Just refer to it locally same as for other actions

Copy link
Member

Choose a reason for hiding this comment

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

And add the checkout removed above (otherwise it won't work)

@potiuk
Copy link
Member

potiuk commented Jan 24, 2021

I choose 2 (periodical runs) instead of workflow_run -> requested event type as recommended by potiuk/cancel-workflow-runs's documentation because the cancel_duplicates jobs trigger this way are often put into the back of the workflow queue and therefore won't be able to execute before other jobs are finished anyway. By inserting the cancel job periodically to the queue, it may have a larger chance of being actually executed.

BTW. This is not necessarily true. If you have a lot of jobs in the queue and EACH of the jobs triggers "cancel" on their own, you do not need to add schedule. Whenever any of the scheduled jobs gets in the queue it will cancel all runs. And if there are no jobs in the queue, then ..... you have nothing to cancel because there are no jobs in the queue. So those scheduled cancels will only increase number of jobs but IMHO they will not increase the chance of cancel step actually running.

BTW. Remember that scheduled runs are also put in the queue. If you have a lot of jobs in the queue they will be added at the end of the queue. So there is little point in running them really for this case.

This was the main design decision behind "cancelAllDuplicates" behaviour - to go through all runs and cancel all duplicates.

@ktmud
Copy link
Member Author

ktmud commented Jan 25, 2021

IMHO they will not increase the chance of cancel step actually running.

You are right. It's not like the scheduled run can insert in between the long list of checks once a PR is filed. I'll revise.

@ktmud ktmud force-pushed the ci-cancel-duplicates branch from f5218b4 to dfc623d Compare January 25, 2021 21:05
@mistercrunch
Copy link
Member

@potiuk, good to see you here! and thanks for cancel-workflow-runs

@ktmud ktmud force-pushed the ci-cancel-duplicates branch 3 times, most recently from 6ab5f6f to 29e3713 Compare January 26, 2021 19:27
@ktmud
Copy link
Member Author

ktmud commented Jan 26, 2021

HOLD: current configuration seems to be only cancelling the Cancel Duplicates job itself: https://github.com/ktmud/superset/runs/1771801161?check_suite_focus=true

@junlincc junlincc added the hold! On hold label Jan 27, 2021
@ktmud ktmud force-pushed the ci-cancel-duplicates branch from 597b020 to adf6d70 Compare January 27, 2021 06:30
Copy link
Member

@amitmiran137 amitmiran137 left a comment

Choose a reason for hiding this comment

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

looking forward for this one
CI is a living hell right now

notifyPRCancel: true
skipEventTypes: '["push", "pull_request", "pull_request_target"]'
token: ${{ secrets.GITHUB_TOKEN }}
notifyPRCancel: 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 believe since you are trying to cancel other workflows, you need to specify also
workflowFileName parameter and specify the workflow run file name that you want to cancel.

Copy link
Member

Choose a reason for hiding this comment

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

If you need to cancel more than one worklfow, you need to copy the step and use different workflowFileName,

@ktmud ktmud force-pushed the ci-cancel-duplicates branch from adf6d70 to 98f43c2 Compare January 28, 2021 10:43
@pull-request-size pull-request-size bot added size/L and removed size/M labels Jan 28, 2021
@ktmud ktmud force-pushed the ci-cancel-duplicates branch from 98f43c2 to d6d02c8 Compare January 28, 2021 10:50
@ktmud
Copy link
Member Author

ktmud commented Jan 28, 2021

@potiuk , thanks for the additional information!

I decided to extend a previous Python script I wrote that was intended to use locally.

Now it's working properly: https://github.com/ktmud/superset/runs/1783573660?check_suite_focus=true

Also updated the PR description to include the intended effect.

@ktmud
Copy link
Member Author

ktmud commented Jan 28, 2021

@villebro @amitmiran137 could you take another look on this one? I've completely changed how the jobs are cancelled. More details in PR description.

@@ -23,13 +23,13 @@
export GITHUB_TOKEN=394ba3b48494ab8f930fbc93
Copy link
Member

Choose a reason for hiding this comment

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

Just wondering Is this a real github token here :) ?

Copy link
Member Author

@ktmud ktmud Jan 28, 2021

Choose a reason for hiding this comment

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

Nope. I just randomly typed one that look real.

Copy link
Member Author

Choose a reason for hiding this comment

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

A real token has 40 characters, this one has 24.

Copy link
Member

@amitmiran137 amitmiran137 left a comment

Choose a reason for hiding this comment

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

LGTM

workflows: ["CI"]
types: ["requested"]
workflows:
- "Miscellaneous"
Copy link
Member

Choose a reason for hiding this comment

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

so once merge and will work only with Miscellaneous workflow then we'll add all workflows here right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Only this workflow will trigger the cancel job, but a scheduled cancel job will try to cancel duplicates of all workflows.

@ktmud ktmud merged commit 9c5ec3d into apache:master Jan 29, 2021
@amitmiran137
Copy link
Member

I just tested this
works amazing!

@junlincc
Copy link
Member

many thanks for improving the CI process!

cc @guhan

@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.2.0 labels Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels hold! On hold size/L 🚢 1.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants