Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Respect proxy settings when streaming the download and extraction of the CodeQL bundle#2624

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

NlightNFotis
Copy link
Member

@NlightNFotisNlightNFotis commentedNov 28, 2024
edited
Loading

Description

This PR is adding support for respecting proxy settings while downloading the CodeQL bundle in streaming mode.

Fixes#2600

Guidance

  • The code changes required to support the feature have been added in0dc76a9.
  • It's introducing ajustfile, which is a script interpreted byhttps://github.com/casey/just, a command action runner. It allows us to create an python virtual environment and run thesync.py to update dependencies in one step, which is very useful for someone trying to interact with it the first time.
    • Ifjust is not present, the file is irrelevant (it's just a text file) but can act as documentation for the steps to invoke manually.
  • I have initially tested this works locally, by settingtinyproxy and writing a function that invokeddownloadAndExtractZstdWithStreaming and observing that we go through the proxy.
    • This function was subsequently thrown away after the first tests locally validated the design.
  • For CI testing, I have made changes to thetest_proxy.yml workflow, so that we download the latest nightly bundle, which by default has the extension.tar.zst which goes through the code path introduced.
    • This can be seen workinghere (latest CI run at the time of writing).
  • This required some changes to thesync.py file in9c48c8b in order to support a step that is being used to initialise the container image (because the Ubuntu container is leaned out and doesn't come with the list of pre-installed software the runners usually come prepared with).
  • The diff (~31k lines) is mostly comprised of a couple of packages added in8f2cb3a. The actual code changes introduced by this PR are in the other commits, and are much smaller in terms of loc changed.

Merge / deployment checklist

  • Confirm this change is backwards compatible with existing workflows.
  • Confirm thereadme has been updated if necessary.
  • Confirm thechangelog has been updated if necessary.

@NlightNFotisNlightNFotisforce-pushed theNlightNFotis/detect_use_proxy_when_streaming branch 2 times, most recently fromc888d44 tof742d6bCompareDecember 3, 2024 16:10
@NlightNFotisNlightNFotisforce-pushed theNlightNFotis/detect_use_proxy_when_streaming branch from326b0f1 to28dd147CompareDecember 3, 2024 17:06
@NlightNFotis
Copy link
MemberAuthor

The streaming of the bundle using the Proxy worked fine in the last CI run:https://github.com/github/codeql-action/actions/runs/12146133664/job/33869336618?pr=2624#step:7:33

I'm now in the process of tidying this up (lots of experimental commits), and incorporating conflicting changes frommain.

aeisenberg reacted with thumbs up emoji

@NlightNFotisNlightNFotisforce-pushed theNlightNFotis/detect_use_proxy_when_streaming branch 3 times, most recently from99f0c0d to2ff0598CompareDecember 4, 2024 18:32
@NlightNFotisNlightNFotisforce-pushed theNlightNFotis/detect_use_proxy_when_streaming branch from2ff0598 to78be2f1CompareDecember 4, 2024 19:29
@NlightNFotisNlightNFotis marked this pull request as ready for reviewDecember 5, 2024 17:00
@NlightNFotisNlightNFotis requested a review froma team as acode ownerDecember 5, 2024 17:00
@NlightNFotisNlightNFotis changed the titlefeat: detect and adjust CodeQL bundle download URL if proxy settings presentRespect proxy settings when streaming the download and extraction of the CodeQL bundleDec 5, 2024
@NlightNFotisNlightNFotis self-assigned thisDec 5, 2024
@NlightNFotis
Copy link
MemberAuthor

Something that I forgot to mention: this PR isnot removing the feature flag: there are 2 references in the code (after this PR gets merged) which are very easy to remove and do not impact functionality.

There are also two more references in a couple of test actions, which would require a bit more thought as to how to handle (we could just remove the environment variable reference in them, or just delete them given that this is more or less tested in the newtest_proxy workflow).

I wanted to do any changes to the feature flag/env var as a different PR, and keep the changes here scoped down to the proxy settings and their handling by the streaming download handler.

Copy link
Contributor

@henrymercerhenrymercer left a comment

Choose a reason for hiding this comment

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

Thanks for this fix! I've added a couple of questions / suggestions:

@@ -1,10 +1,20 @@
name: "Proxy test"
description: "Tests using a proxy specified by the https_proxy environment variable"
versions: ["linked"]
versions: ["linked", "nightly-latest"]
Copy link
Contributor

Choose a reason for hiding this comment

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

This test was passing before when we were streaming zstd bundles with a CodeQL Action version that wasn't respecting proxy settings, presumably because the CodeQL Action could still access the bundle without the proxy.

Can we update the test to ensure that we're downloading the bundle via the proxy?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

In the latest test added as part of this PR, I'm fairly confident we'redownloading the bundle through the proxy.

The reason it worked before is that itdidn't test the streaming of the bundle, because whenlinked is passed as theversion, theprepare-step action was choosing the.tar.gz bundle by default - as example thelatest run from a PR merged recently.

I am not sure though how it makes that selection between the.tar.gz and the.tar.zst one, because in this PR, the same job downloaded the.tar.zst one. But previously, we didn't go through this code because the same job was opting for the.tar.gz when downloading.

Will look more into that and report back any interesting findings.

henrymercer reacted with heart emoji
Comment on lines 127 to 128
core.warning(
`Failed to download and extract CodeQL bundle using streaming. Falling back to downloading the bundle before extracting.`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you tested this fallback? For instance, what happens if we partially extract the CodeQL bundle while streaming, but something goes wrong? Is it worth cleaning up the destination directory in this case or is that handled elsewhere?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Yes, I'm quoting from a previous message of mine that probably got lost because of the volume of messages here:

I'm confident we are good without a flag to manage the risk.

To explain why: because the conflicts introduced by a couple of other PRs were extensive, and I couldn't sort out a clean commit history, I opted to instead just manually recreate the PR on top of main (my code changes are small, so easy to manually replay).

In doing so, I made a mistake: I initialised the HTTP client (the one that respects the proxy settings) and passed it to the headers by accident (instead of the http.get options). What happened ishere, but short story, because of the streaming download now being inside of a fallback try/catch, the failure to download the CodeQL pack with streaming resulted in falling back to downloading it and then extracting it.

I've since fixed this, but this little mistake validated the fallback mechanism working as intended, so I believe that this won't cause an incident like last time - if it fails, worst case scenario is that the mechanism won't work as expected and fall back to the previous mechanism (download and then extract), with the impact being that we lose a few seconds per run (compared to a failed run).

Does this answer your question satisfactorily?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you, that answers the first part of my question. I still wonder if it is worth cleaning up the destination directory as part of thecatch in case we managed to extract some of the CodeQL bundle but not a complete CodeQL bundle.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I agree this is a good idea, and something prudent for us to do before we retry.

Added in4c20d4f.

@NlightNFotis
Copy link
MemberAuthor

Thank you for your reviews@aeisenberg@henrymercer.

I have now implemented all outstanding items on this PR. Would it be possible to have another look at this?

CHANGELOG.md Outdated
@@ -7,7 +7,8 @@ Note that the only difference between `v2` and `v3` of the CodeQL Action is the
## [UNRELEASED]

- We are rolling out a change in December 2024 that will extract the CodeQL bundle directly to the toolcache to improve performance. [#2631](https://github.com/github/codeql-action/pull/2631)
- We have added support for respecting the proxy settings present in environment variables in a runner when streaming the download and extraction of the CodeQL bundle. [#2624](https://github.com/github/codeql-action/pull/2624)
- Fixed an issue where streaming the download and extraction of the CodeQL bundle did not respect proxy settings. [#2624](https://github.com/github/codeql-action/pull/2624)
- Update default CodeQL bundle version to 2.20.0. [#2636](https://github.com/github/codeql-action/pull/2636)
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this line added due to a bad merge?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Hm, I will have a look.

This was reported as a conflict in the GitHub UI, but when I did agit merge locally, it had no problem automatically resolving the conflict. Perhaps it did a weird thing because of my.gitconfig.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I cannot find precisely what went wrong here, as the merge log is past my terminal character limit. I remember it saying that it resolved it automatically using theort method, but it apparently went wrong there.

This is now fixed in9e8cd42.

Going forward I will be more careful validating these merges went right.

@@ -127,7 +127,11 @@ export async function downloadAndExtract(
core.warning(
`Failed to download and extract CodeQL bundle using streaming. Falling back to downloading the bundle before extracting.`,
);
core.warning(getErrorMessage(e));
core.warning(`Error: ${getErrorMessage(e)}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't prefix a warning withError.

Suggested change
core.warning(`Error:${getErrorMessage(e)}`);
core.warning(`Warning:${getErrorMessage(e)}`);

But, do we even need the prefix at all?

Maybe reverting this is better:

Suggested change
core.warning(`Error:${getErrorMessage(e)}`);
core.warning(getErrorMessage(e));

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Thank you for catching this.

Seeing it reported now, I agree it looks a bit silly.

My rationale for changing this was that this was rendering an error that was generated in the process of unpacking as a simple warning, with no other context whatsoever, which could be confusing to a user when interpreting the runner log (example).

I'm still motivated to decorate it somehow, as reverting may not satisfy this concern, but I will think about a cleaner decoration that doesn't look weird/silly.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Okay, this is what I came up with:88bcf64

I've reworded the warnings to flow a bit more naturally for me, and to allow me to embed the error message in an indicative but non-invasive way.

Is this workable for you@aeisenberg ? Or do you have a strong preference for the previous state of affairs?


This folder contains the code supporting the workflows run when a PR is created.

## Update
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can simplify this. I can give some suggestions, but not quite right now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Thank you for this! I agree it looks cleaner.

Willcherry-pick this in.

@henrymercer
Copy link
Contributor

I've merged inmain since we just did a release, and I want to make sure the merge strategy puts the changelog entry in the right place.

NlightNFotis reacted with thumbs up emoji

Copy link
Contributor

@aeisenbergaeisenberg left a comment

Choose a reason for hiding this comment

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

Nice.

NlightNFotis reacted with heart emoji
@NlightNFotisNlightNFotis merged commitc4bbe15 intomainDec 11, 2024
266 checks passed
@NlightNFotisNlightNFotis deleted the NlightNFotis/detect_use_proxy_when_streaming branchDecember 11, 2024 16:26
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@henrymercerhenrymercerhenrymercer left review comments

@aeisenbergaeisenbergaeisenberg approved these changes

@zutshisunakshizutshisunakshiAwaiting requested review from zutshisunakshi

Assignees

@NlightNFotisNlightNFotis

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Enable streaming while respecting proxy settings
3 participants
@NlightNFotis@henrymercer@aeisenberg

[8]ページ先頭

©2009-2025 Movatter.jp