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

Add option to include causes in the JCasC export, and read causes from it on import. #139

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

allenbenz
Copy link

@allenbenz allenbenz commented Jan 30, 2021

This adds an option to write causes to the JCasC config.
This also allows causes to be read from the JCasC config and is not gated behind enabling the write to JCasC option.

My use case for this is to workaround an issue where how I deploy jenkins causes JCasC to rewrite the plugin configurations - which erases the local knowledge base.
There are other more valid use cases such as wanting to version control the causes list that this provides for

Made it an option as a few dozen causes makes the JCasC export very long.

Some concerns I have that I was unable to resolve:

  • I don't know what this will do to mongodb, I don't have a way to test that meaningfully.
  • The new Date(time) line in FailureCauseModification.java is parsing Date.toString() output. This should be safe as long as the locale of the jenkins master doesn't change.
  • The multilineBuildLogIndication JCasC "pattern" is wrong on export, it's the output of pattern.ToString() instead of the user provided one.

@allenbenz allenbenz changed the title Add feature to optionally include causes in the JCasC export Add option to include causes in the JCasC export Feb 2, 2021
@allenbenz allenbenz changed the title Add option to include causes in the JCasC export Add option to include causes in the JCasC export, and read causes from it on import. Feb 3, 2021
@allenbenz allenbenz force-pushed the add-causes-to-jcasc branch from e737d80 to c5d4228 Compare March 18, 2021 06:53
@olivergondza
Copy link
Member

Looking forward for this feature to be added in the plugin.

I have added some minor review comments.

@allenbenz allenbenz force-pushed the add-causes-to-jcasc branch from d6c622b to c260c2a Compare April 19, 2021 18:34
@olivergondza
Copy link
Member

@rsandell, @TWestling, folks, can you please take a look? Thanks!

* Get if causes from the current knowledge base should be included in the JCasC export is enabled.
* @return exportCausesToJCasCEnabled - on or off. null == off.
*/
public boolean getExportCausesToJCasCEnabled() {
Copy link
Member

Choose a reason for hiding this comment

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

Java bean standard:

Suggested change
public boolean getExportCausesToJCasCEnabled() {
public boolean isExportCausesToJCasCEnabled() {

*/
public Collection<FailureCause> getCauses() {
// The Causes export can be very large so we only include it if enabled.
if (!getExportCausesToJCasCEnabled()) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (!getExportCausesToJCasCEnabled()) {
if (!isExportCausesToJCasCEnabled()) {

Copy link
Author

Choose a reason for hiding this comment

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

Ah, I didn't realize JCasC's reflection would find methods starting with is.

Copy link
Member

Choose a reason for hiding this comment

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

It is the Java bean standard :)

* @param comment the comment of this FailureCause.
* @param lastOccurred the time at which this FailureCause last occurred.
* @param categories the categories of this FailureCause.
* @param indications the list of indications
* @param modifications the modification history of this FailureCause.
*/
@DataBoundConstructor
public FailureCause(String id, String name, String description, String comment,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public FailureCause(String id, String name, String description, String comment,
@Deprecated
public FailureCause(String id, String name, String description, String comment,

Copy link
Author

Choose a reason for hiding this comment

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

I don't know if this is really Deprecated, the fewer parameter DataBoundConstructor and the added DataBoundSetters allow JCasC to handle optional fields, but this constructor is a lot nicer to use in code.

Though if you still want it Deprecated that's fine too.

Copy link
Member

Choose a reason for hiding this comment

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

The deprecation in this scenario would only be a flag to anyone coding against it that it is not the one actually used in runtime. It can still be used in tests, just annotated with something if sportbugs or checkstyle complains.

Copy link
Member

@rsandell rsandell left a comment

Choose a reason for hiding this comment

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

Sorry for the delay in reviewing. So much to do and so little time.

if (knowledgeBase != null) {
for (FailureCause cause:causes) {
try {
knowledgeBase.saveCause(cause);
Copy link
Member

Choose a reason for hiding this comment

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

I am quite certain this will create duplicates for anything else than the file based knowledge base. Unless the id field is set. At least the javadoc should reflect that.

Copy link
Member

Choose a reason for hiding this comment

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

Writing a unit test for that should be relatively easy. There are a couple of integration tests using an embedded mongodb that you can take inspiration from.

Copy link
Author

Choose a reason for hiding this comment

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

I've added a note about duplicates to the javadoc, there isn't much I can do about missing ids short of skipping entries that don't have one, thoughts on the preferred behavior?

@allenbenz allenbenz force-pushed the add-causes-to-jcasc branch from c260c2a to b35c395 Compare October 1, 2021 00:12
@allenbenz allenbenz force-pushed the add-causes-to-jcasc branch from fd9db07 to 39d287f Compare October 1, 2021 20:08
@allenbenz
Copy link
Author

So I'm having a bit of a hygiene problem with the port embedded mongodb runs on.
It would be preferable to allow the OS to provide one to avoid colliding with some other process.

But I'm not able to think of a good way to inject that port number into the config, it's a resource so I can't change it at runtime, and there aren't any hooks in JenkinsConfiguredWithCodeRule or ConfigurationAsCode to apply a transform after it gets loaded but before it's parsed.

Only improvement I could think of would be to swap 27017 with something that's not the mongodb default port to lower the odds of collision but that's not a real solution.

Thoughts?

@olivergondza
Copy link
Member

@allenbenz, use ConfigurationAsCode.get().configure() or ConfigurationAsCode.get().configureWith() without the annotation. You can pre-process the input the way you like.

@yuezhuangshi
Copy link

Looking forward for this feature to be added in the plugin.

@jhaxon
Copy link

jhaxon commented Jun 1, 2023

We're unable to deploy this plugin across our fleet without this functionality.

@rsandell
Copy link
Member

@jhaxon As it seems like the original author has abandoned the change anyone is welcome to continue to work on it to get it over the finish line :)

@carlosgv87
Copy link

@allenbenz@rsandell is there any plan to include this feature on further versions of this plugin?

Thank you in advance 😃

@allenbenz
Copy link
Author

@carlosgv87 unfortunately I have long since stopped working at the place where I was using Jenkins. If someone else wants to pick this up and finish it they should feel welcome to do so. My changes are MIT licensed so ownership isn't a concern for the next person.

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.

6 participants