Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@mabartos
Copy link
Contributor

@mabartos mabartos commented Dec 6, 2023

Closes #13113

The intention behind the lazy evaluation of isEnabled() for property mappers is to have the possibility to enable/disable it based on the current configuration with no need to keep the order of property mapper groups.

In that case, we can enable/disable options based on values of other options as f.e. this is enabled only when the property kc.xyz=gold, etc.

@vmuzikar
Copy link
Contributor

vmuzikar commented Dec 6, 2023

CC @shawkins

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@ghost
Copy link

ghost commented Dec 19, 2023

Unreported flaky test detected

If the below flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.adapter.servlet.OfflineServletsAdapterTest#testServlet

Keycloak CI - Base IT (2)

java.lang.AssertionError: 

Expected: not null
     but: was null
	at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
...

Report flaky test

@mabartos mabartos force-pushed the conditionalCli branch 2 times, most recently from 3781ac6 to 18702b9 Compare December 20, 2023 11:07
@mabartos mabartos marked this pull request as ready for review December 20, 2023 11:07
@mabartos mabartos requested review from a team as code owners December 20, 2023 11:07
@mabartos
Copy link
Contributor Author

mabartos commented Dec 20, 2023

@shawkins This PR should be ready for review. I'd be happy if you'd have a chance to look at it.

I still need to finish some additional things:

  • Add description to this PR with the provided functionality (and possibly show some outputs)
  • Add/fix some more tests
  • When the distro is not augmented, the validation of the disabled runtime options is made after the reaugmentation (f.e. when start without --optimized is used; for build works as expected)

Copy link
Contributor

@shawkins shawkins left a comment

Choose a reason for hiding this comment

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

Just a couple of nits in review comments.

If I understand correctly this will handle enablement as long as it's conditional on properties that are set prior to parsing - which most are. But anything that is set as a side effect of the command, such as the StartDev forceDevProfile that won't be known. Is that correct?

I haven't had a chance to run this, but was wondering will this make both help and help-all conditional? That is if you have something like --log=file --help-all will you see any of the file or gelf options?

@mabartos
Copy link
Contributor Author

mabartos commented Dec 21, 2023

@shawkins Thanks for the review! :))

If I understand correctly this will handle enablement as long as it's conditional on properties that are set prior to parsing - which most are. But anything that is set as a side effect of the command, such as the StartDev forceDevProfile that won't be known. Is that correct?

It should handle such situations, but I'll write a test for it and double-check it.

I haven't had a chance to run this, but was wondering will this make both help and help-all conditional? That is if you have something like --log=file --help-all will you see any of the file or gelf options?

Only --help is conditional. If you specify --help-all, all options are printed, even disabled ones with the message when the option is available to the user.

Copy link
Contributor

@vmuzikar vmuzikar left a comment

Choose a reason for hiding this comment

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

@mabartos Thanks for the PR! The general approach LGTM, although I haven't yet reviewed line-by-line.

I think we still need to tackle one more case here: when some option has multiple versions, essentially when we add an option with the same key multiple times. I think it doesn't work yet with this version of the PR, right? This will be required for the hostname stuff when some of the options will have new meaning (descriptions, potentially transformers etc.).

Could you also please rebase to incorporate changes from now merged #24811?

@mabartos
Copy link
Contributor Author

Rebased and added test execution order for the OptionsDistTest. It's not possible to execute start-dev, and then start without explicit build execution. It's the current behavior in Keycloak. We might discuss some improvements around it, but it's out of the scope of this PR.

It was a bit hard to review as it adds a lot of additional complexity.

@vmuzikar Yep, I'm aware of it. But the code should be cleaner now and also catch some minor issues.

Do we have any perf benchmark comparison? I know there's a slight impact on the startup performance. Is there any hit on runtime too?

There should not be any performance degradation even for the startup; I resolved that one I mentioned previously. I made only a small perf analysis and nothing that could impact performance :)) The only thing that has changed is that the initialization of Profile(quite resource-consuming) is done earlier.

I can double-check it.

@shawkins Could you please review the last commit? Thanks!

@mabartos
Copy link
Contributor Author

@shawkins shawkins self-requested a review February 14, 2024 14:42
shawkins
shawkins previously approved these changes Feb 14, 2024
Copy link
Contributor

@shawkins shawkins left a comment

Choose a reason for hiding this comment

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

@mabartos still LGTM. One minor after thought is at what point could or should we be able to clear some of the static state - how big of a footprint does the parsed command have?

@mabartos mabartos force-pushed the conditionalCli branch 2 times, most recently from 36c031d to e0a1e08 Compare March 4, 2024 15:46
@mabartos
Copy link
Contributor Author

mabartos commented Mar 4, 2024

Rebased and resolved conflicts.

@mabartos
Copy link
Contributor Author

mabartos commented Mar 4, 2024

@shawkins @vmuzikar Can you please check it again? Thanks!

@shawkins shawkins self-requested a review March 4, 2024 17:09
Copy link
Contributor

@shawkins shawkins left a comment

Choose a reason for hiding this comment

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

still looks good!

@mabartos
Copy link
Contributor Author

mabartos commented Mar 5, 2024

One minor after thought is at what point could or should we be able to clear some of the static state - how big of a footprint does the parsed command have?

@shawkins Sorry, it seems I've missed your comment.

I assume you mean the static object Environment.parsedCommand. AFAIK pointers/references of static objects are stored in Metaspace, which directs to objects stored in the heap. After getting the heap dump, I noticed that the retained memory for the Environment.parsedCommand is ~28.5kB with the inner CommandSpec objects.

However, as the GC was executed before the heap dump, all other CommandLine#CommandSpecs were still present, so they're not garbage collected either. That means the parent CommandSpec still references the child specs - I assume it's stored even for the reflection capabilities of Picocli. Thus, IMHO, the footprint does not really matter in this case as there should not be any major differences due to the shared references.


@vmuzikar May I ask you for a next round of review? Thanks

@mabartos mabartos requested a review from vmuzikar March 6, 2024 11:54
Copy link
Contributor

@vmuzikar vmuzikar left a comment

Choose a reason for hiding this comment

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

@mabartos LGTM, fantastic work!

I'll rebase it for the last time to be sure we get accurate test results and enable auto-merge.

@vmuzikar vmuzikar enabled auto-merge (squash) March 7, 2024 17:10
@mabartos
Copy link
Contributor Author

mabartos commented Mar 7, 2024

@shawkins @radcortez @vmuzikar Thanks for the reviews! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Conditionally enable and disable CLI options

4 participants