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

performant multi-run support #169

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

akostadinov
Copy link

@akostadinov akostadinov commented Dec 5, 2017

Hello, I want to be able to run a groovy script many times without needless overhead.
This is needed for me to implement custom log lines processing in Logstash plugin.
At the same time I'd like the convenience and safety of all the magic presently done
by the secure groovy script plugin. This modification is to allow that.

Sorry about white-space changes. It's because of the editor settings. If you don't
want them, I'll go ahead and revert them. Same about the EditorConfig file. Just
thought it is a useful addition.
If you like to keep the removed needless whilte spaces, you could add ?w=1 to url
of the file diff to have them filtered out while reviewing:
https://github.com/jenkinsci/script-security-plugin/pull/169/files?w=1

@akostadinov
Copy link
Author

akostadinov commented Dec 13, 2017

Any thoughts on this one? Would be really useful to know whether such functionality can be eventually accepted and whether this is the right approach for it.

Thank you.

akostadinov added a commit to akostadinov/logstash-plugin that referenced this pull request Dec 18, 2017
akostadinov added a commit to akostadinov/logstash-plugin that referenced this pull request Dec 21, 2017
@jglick jglick self-requested a review January 9, 2018 16:41
@jglick
Copy link
Member

jglick commented Jan 10, 2018

If you don't want them, I'll go ahead and revert them.

Yes please. It is not just about comfort when reviewing diffs; if we ever need to git cherry-pick changes, etc., it is important for changes to be textually minimal.

* You must have used {@link #createSecureCompilerConfiguration} to prepare the Groovy shell.
* @param script a script ready to {@link Script#run}, created for example by {@link GroovyShell#parse(String)}
* @param whitelist the whitelist to use, such as {@link Whitelist#all()}
* @return the sandbox for running this script
Copy link
Member

Choose a reason for hiding this comment

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

Would be helpful to @link to register and unregister so callers can see how to use it.

@@ -277,6 +280,10 @@ private static void cleanUpObjectStreamClassCaches(@Nonnull Class<?> clazz) thro
}
}

public PreparedScript prepare(ClassLoader loader, Binding binding) throws IllegalAccessException, IOException {
Copy link
Member

Choose a reason for hiding this comment

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

Deserves Javadoc at least for the loader parameter, which in evaluate is nontrivial.


} finally {
public void cleanUp() throws IOException {
Copy link
Member

Choose a reason for hiding this comment

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

Better implement Closeable and make this the close method, so PreparedScript can be used in a Java 7+ try block.

} catch (NoSuchFieldException nsme) {
LOGGER.log(Level.FINE, "GroovyShell fields have changed, field loader no longer exists -- memory leak fixes won't work");
/**
* Allows access to execue a script multiple times without preparation and clean-up overhead.
Copy link
Member

Choose a reason for hiding this comment

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

typo


public Object run() throws Exception {
if (sandbox) {
scriptSandbox.register();
Copy link
Member

Choose a reason for hiding this comment

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

Note to self: register and unregister calls should be cheap enough that they contribute no significant overhead.

assertTrue((int) res == 6);
assertTrue((int) b.getVariable("a") == 7);
} catch (Exception e) {
script.cleanUp();
Copy link
Member

Choose a reason for hiding this comment

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

This should be in a finally block, not a catch block (or just use Closeable trick mentioned above).

Copy link
Author

Choose a reason for hiding this comment

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

strange that I did this, I'll check your Closeable suggestion

assertTrue((int) res == 6);
assertTrue((int) b.getVariable("a") == 7);
} catch (Exception e) {
script.cleanUp();
Copy link
Member

Choose a reason for hiding this comment

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

ditto

@akostadinov
Copy link
Author

Hello, updated according to your reasonable comments. Please let me know if you see further possible improvements (or if I missed anything).

One question - would the automatic PR test job deploy a timestamped snapshot or does it have to be deployed in some other way?

@jglick
Copy link
Member

jglick commented Mar 20, 2018

would the automatic PR test job deploy a timestamped snapshot

Afraid not.

does it have to be deployed in some other way?

IIRC you just need a jenkins.io account, then I use a helper script:

mvn clean install source:jar deploy:deploy -DaltDeploymentRepository=maven.jenkins-ci.org::default::https://repo.jenkins-ci.org/snapshots/ -DskipTests

Plain mvn deploy will work well enough in most cases (the above handles some corner cases in Jenkins components released to OSSRH etc.).

@jglick jglick requested review from abayer, jglick and svanoort March 20, 2018 18:24
@jglick
Copy link
Member

jglick commented Jun 26, 2018

would the automatic PR test job deploy a timestamped snapshot

BTW that has been superseded by JEP-305. Docs

Copy link
Member

@jglick jglick left a comment

Choose a reason for hiding this comment

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

Last I checked, the idea sounded fine but I have not looked at the details. Leaving it to plugin owners.

@jglick jglick marked this pull request as draft November 16, 2022 17:23
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.

2 participants