| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
There was a problem hiding this comment.
Mostly looks good, some comments below.
Sorry, something went wrong.
|
|
||
| - name: Run init | ||
| run: | | ||
| runner/dist/codeql-runner-linux init --ram=230 --threads=1 --repository $GITHUB_REPOSITORY --languages java --github-url $GITHUB_SERVER_URL --github-auth ${{ github.token }} |
There was a problem hiding this comment.
I think I'd slightly prefer this to use something other than 1 for the threads as 1 could very easily be a default in which case we wouldn't really be checking anything. Maybe 3 as that seems very unlikely to ever be the default value.
Sorry, something went wrong.
There was a problem hiding this comment.
This is a decision that I struggled with.
The main challenge here is that the number of threads used defaults to (and is capped at) the number of CPU cores available on the machine. GitHub action runners have 2 CPUs, so both the default and the cap would be 2. Passing any value larger than 1 means that the test will break if it runs on a system with different number of CPUs.
I would love to hear your thoughts. For example, maybe we could assume that the runner will always have at least 2 CPUs and have two tests with threads set to 1 and 2?
Sorry, something went wrong.
There was a problem hiding this comment.
Aha, this is a good point. As I mentioned below, I'm actually not sure that capping this is a good idea, but for now let's leave this test as is 🙂
Sorry, something went wrong.
| * Get the value of the codeql `--threads` flag specified for the `threads` | ||
| * input. If no value was specified, all available threads will be used. | ||
| * | ||
| * The value will be capped to the number of available CPUs. |
There was a problem hiding this comment.
I don't know how I feel about capping this. I note that the RAM is not capped and the user can request more RAM than is available on the machine thus causing an OOM. On the other hand, the threads are capped even though using more threads than there are cores wouldn't cause us to crash (just give suboptimal performance). Additionally, there are valid reasons to have more threads than cores - for instance in CPUs with hyperthreading there is a benefit to having 2x the number of threads as cores.
If we do indeed want to cap the number of threads, it should definitely be documented in the user-facing description of the threads input rather than in a comment on the code.
Sorry, something went wrong.
There was a problem hiding this comment.
I want to note that this PR refactors the implementation of getMemoryFlag() and getThreadsFlag() but does not change their behavior. What you say makes sense; perhaps we can continue the discussion (and invite wider participation that just the two of us) outside this PR?
Sorry, something went wrong.
There was a problem hiding this comment.
I agree that we should invite a wider discussion on this outside the PR as it is technically a breaking behaviour change - some users might be passing 99 in and relying on the capping which would cause them to experience massive performance issues if we remove it.
Given this wasn't introduced by this PR, I don't think we need to block on it.
Sorry, something went wrong.
|
While we are here, there is a code scanning warning that we have the same inputs (ram and threads) in different actions (init and analyze) with different help texts. In this case, they are indeed different:
Do you think there is more we can do to simplify or to clarify these different inputs? |
Sorry, something went wrong.
|
Regarding your final point, I think I agree with Code Scanning that having the same option name of different steps and serving a different purpose may invite user confusion. It's too late to change the options on analyze as these are shipped but maybe these new options could be extractor-{ram,threads} instead? |
Sorry, something went wrong.
|
Which threads argument gets passed to database finalize? |
Sorry, something went wrong.
|
finalize shares the arguments in the analyze step. A further option - make init the place where these should be specified and then use the ones from init everywhere when they are available (storing them in the config for the analyze step to use later). Obviously for backwards compatibility we still keep the inputs on analyze in the code, but we amend our documentation to remove all mention of them. |
Sorry, something went wrong.
|
That sounds good. We could respect the analyze arguments if they are provided separately (might be handy for debugging), but if they are absent just respect the values passed to init. |
Sorry, something went wrong.
Sounds like a plan. I will revise this PR to do so.
Can you point me to the documentation that need to be amended, just so that I do not miss it? |
Sorry, something went wrong.
Huh, I'm actually not sure. I expected the README in this repository to mention it, but it does not. In the github/docs-internal repository, I expected the page corresponding to https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning to mention this but actually it seems that it also does not. @adityasharad Any ideas where we might be mentioning this? |
Sorry, something went wrong.
|
That is the right place. I think we have never actually documented ram and threads outside this repo, though that is more by omission than by design. |
Sorry, something went wrong.
|
New snapshot. I think this PR is ready for another look. The main change is that the analyze action and runner command now by default use the same RAM and threads options as the init action and runner command. Explicit RAM and threads settings for analyze still take precedence.
Settings propagation for the analyze action is tested with newly added unit tests. Settings propagation for the analyze runner command has no tests and could use a more careful review. |
Sorry, something went wrong.
There was a problem hiding this comment.
Mostly looking good, a few comments below.
Sorry, something went wrong.
| description: Override the amount of memory in MB to be used by CodeQL extractors. By default, almost all the memory of the machine is used. | ||
| required: false | ||
| threads: | ||
| description: The number of threads to be used by CodeQL extractors. |
There was a problem hiding this comment.
I think this description and the one above should clarify that this is also the threads and RAM used for analysis unless they are overidden. Also, we explain what the default for ram is but we do not explain the default value of threads - I think we should say something about that. (I haven't got to that bit of the code yet, but I assume it defaults to the number of cores on the runner?)
Sorry, something went wrong.
There was a problem hiding this comment.
I updated the description based on your excellent suggestions.
Sorry, something went wrong.
| default: "false" | ||
| threads: | ||
| description: The number of threads to be used by CodeQL. | ||
| description: The number of threads to be used by CodeQL. By default, this action will use the same number of threads as the init action. |
There was a problem hiding this comment.
Here and above, instead of just saying used by CodeQL, I would say used by CodeQL for database finalization and query execution, to distinguish from the values in init that are used for extraction.
Sorry, something went wrong.
There was a problem hiding this comment.
That is a good suggestion, and I changed the description accordingly.
Sorry, something went wrong.
| const jsonEnvFile = path.join(config.tempDir, codeqlEnvJsonFilename); | ||
| return JSON.parse(fs.readFileSync(jsonEnvFile).toString("utf-8")); | ||
| } catch (err) { | ||
| return {}; |
There was a problem hiding this comment.
We do we now silently fail if we can't load this file? If this is indeed a deliberate change and is necessary, I think we should have a comment here explaining why.
Sorry, something went wrong.
There was a problem hiding this comment.
Good catch! I removed the catch block from the extracted loadTracerEnvironment() function so that the behavior of importTracerEnvironment() remains unchanged.
Sorry, something went wrong.
|
|
||
| const codeqlEnvJsonFilename = "codeql-env.json"; | ||
|
|
||
| function loadTracerEnvironment(config: Config): any { |
There was a problem hiding this comment.
I think there should be a more specific return type than any that we can use here. I expect it to always be a map from strings to strings?
Sorry, something went wrong.
There was a problem hiding this comment.
That is a good point. I changed the return type to { [name: string]: string }.
Sorry, something went wrong.
| ) | ||
| .option( | ||
| "--threads <number>", | ||
| "The number of threads to be used by CodeQL extractors." |
There was a problem hiding this comment.
The same comments I made to the Action's input descriptions also apply here. Note that since the runner is being deprecated, I personally think we can omit adding these flags to it - we're committed to maintaining it till March but I don't think we need to be adding new functionality to it.
Sorry, something went wrong.
There was a problem hiding this comment.
I updated the runner option help text to match the descriptions of the action inputs.
Your point about the runner being deprecated is well taken, and I will keep that in mind for any future work in this area. Thanks!
Sorry, something went wrong.
|
Thanks for addressing my comments! It's my understanding (@adityasharad can confirm) that we don't want to merge anything until we've bumped the default CLI version to 2.6.4 and released that to v1. I think this is good to go after that, though. |
Sorry, something went wrong.
There was a problem hiding this comment.
A few clarifying questions, overall looks sensible. No objection to merging into main, though we can hold off on v1 until the upcoming CLI release.
Sorry, something went wrong.
| ## [UNRELEASED] | ||
|
|
||
| No user facing changes. | ||
| - The `init` step of the Action now supports `ram` and `threads` inputs to limit resource use of CodeQL extractors. [#738](https://github.com/github/codeql-action/pull/738) |
There was a problem hiding this comment.
Should this mention that the analyze action will default to the settings from the init action?
Sorry, something went wrong.
There was a problem hiding this comment.
That is a good point—I added that to the changelog entry.
Sorry, something went wrong.
| default: "brutal" | ||
| ram: | ||
| description: Override the amount of memory in MB to be used by CodeQL. By default, almost all the memory of the machine is used. | ||
| description: >- |
There was a problem hiding this comment.
Since the input descriptions here are going to vary between the two actions, we should add an exception to the custom query that's producing the code scanning warning on this file.
Sorry, something went wrong.
There was a problem hiding this comment.
I edited queries/inconsistent-action-input.ql to exclude inputs named ram or threads from the query.
Sorry, something went wrong.
There was a problem hiding this comment.
Nice! Thanks for the clear explanations and option descriptions.
Sorry, something went wrong.
There was a problem hiding this comment.
Generally good. Just a suggestion on the input description.
Sorry, something went wrong.
| The number of threads that can be used by CodeQL for database finalization and query execution. | ||
| By default, this action will use the same number of threads as previously set in the "init" action. | ||
| If the "init" action also does not have an explicit "threads" input, this action will use all the | ||
| hardware threads available in the system. |
There was a problem hiding this comment.
Maybe good to specify what the default values are. Something like this?
| hardware threads available in the system. | |
| hardware threads available in the system. The default runners on GitHub Actions have two cores. |
Sorry, something went wrong.
There was a problem hiding this comment.
Yes, that would indeed be very useful to users. I added the default value for each platform to the description. Thank you for the suggestion!
Sorry, something went wrong.
| threads: | ||
| description: >- | ||
| The number of threads that can be used by CodeQL extractors. | ||
| By default, CodeQL extractors will use all the hardware threads available in the system. |
There was a problem hiding this comment.
Same comment as above.
Sorry, something went wrong.
There was a problem hiding this comment.
I added the default value for each platform to the description. Thank you for the suggestion!
Sorry, something went wrong.
|
Not sure why the update dependencies workflow failed. I'm triggering it again by adding the label. |
Sorry, something went wrong.
What I was puzzling over was why that workflow ran in the first place when the Update dependencies label was absent. Shouldn't the absence of the label prevent the workflow from running in the first place? |
Sorry, something went wrong.
This workflow runs on: pull_request_target:
types: [opened, synchronize, reopened, ready_for_review, labeled]
so, it should run in this case, only it should be a noop. |
Sorry, something went wrong.
Hmm, something definitely did go wrong in this run, though, because it continued and failed even though there was no label: https://github.com/github/codeql-action/actions/runs/1372901091 I think I must've broken something in #789... |
Sorry, something went wrong.
I was more wondering why did not inhibit the update job, which I would have expected it to when the Update dependencies label was absent. |
Sorry, something went wrong.
|
Let's see if #790 fixes it... It's annoying there's no way to test that workflow in PRs because it runs from main. |
Sorry, something went wrong.
It looks like for the if conditional you should either omit ${{ ... }} entirely or use it to cover the entire conditional. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
This PR adds ram and threads inputs to the init step of the Action to limit resource use of CodeQL extractors.
Merge / deployment checklist