-
Notifications
You must be signed in to change notification settings - Fork 333
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
Add RAM and threads options to init action #738
Conversation
82fa535
to
0606941
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly looks good, some comments below.
|
||
- 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 🙂
* Get the codeql `--threads` value specified for the `threads` input. | ||
* If no value was specified, all available threads will be used. | ||
* 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
While we are here, there is a code scanning warning that we have the same inputs (
Do you think there is more we can do to simplify or to clarify these different inputs? |
0606941
to
5b67955
Compare
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 |
Which |
A further option - make Obviously for backwards compatibility we still keep the inputs on |
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. |
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? |
Huh, I'm actually not sure. I expected the README in this repository to mention it, but it does not. In the @adityasharad Any ideas where we might be mentioning this? |
That is the right place. I think we have never actually documented |
5b67955
to
e5d6137
Compare
e5d6137
to
9a31e5b
Compare
New snapshot. I think this PR is ready for another look. The main change is that the
Settings propagation for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly looking good, a few comments below.
init/action.yml
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the description based on your excellent suggestions.
analyze/action.yml
Outdated
@@ -29,7 +29,7 @@ inputs: | |||
required: false | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a good suggestion, and I changed the description accordingly.
src/runner.ts
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I removed the catch block from the extracted loadTracerEnvironment()
function so that the behavior of importTracerEnvironment()
remains unchanged.
src/runner.ts
Outdated
@@ -53,11 +55,19 @@ function getToolsDir(userInput: string | undefined): string { | |||
|
|||
const codeqlEnvJsonFilename = "codeql-env.json"; | |||
|
|||
function loadTracerEnvironment(config: Config): any { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a good point. I changed the return type to { [name: string]: string }
.
src/runner.ts
Outdated
) | ||
.option( | ||
"--threads <number>", | ||
"The number of threads to be used by CodeQL extractors." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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!
b1f2597
to
5533fe9
Compare
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 I think this is good to go after that, though. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
CHANGELOG.md
Outdated
@@ -2,7 +2,7 @@ | |||
|
|||
## [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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this mention that the analyze
action will default to the settings from the init
action?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a good point—I added that to the changelog entry.
@@ -18,7 +18,9 @@ inputs: | |||
required: false | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I edited queries/inconsistent-action-input.ql
to exclude inputs named ram
or threads
from the query.
5533fe9
to
69cc9ec
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Thanks for the clear explanations and option descriptions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally good. Just a suggestion on the input description.
analyze/action.yml
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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!
init/action.yml
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the default value for each platform to the description. Thank you for the suggestion!
69cc9ec
to
36e3455
Compare
36e3455
to
c1a269b
Compare
Not sure why the update dependencies workflow failed. I'm triggering it again by adding the label. |
What I was puzzling over was why that workflow ran in the first place when the |
This workflow runs on:
so, it should run in this case, only it should be a noop. |
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... |
I was more wondering why
did not inhibit the |
Let's see if #790 fixes it... It's annoying there's no way to test that workflow in PRs because it runs from |
It looks like for the |
c1a269b
to
aa96b93
Compare
aa96b93
to
70b730e
Compare
This PR adds
ram
andthreads
inputs to theinit
step of the Action to limit resource use of CodeQL extractors.Merge / deployment checklist