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

JAVAFICATION: Move env/secret variable substitution to java #9619

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

andrewvc
Copy link
Contributor

@andrewvc andrewvc commented May 19, 2018

This is a partial port of the string substitution code that required writing our own version of ruby's gsub.

Java has String#replaceAll, but that doesn't let you pass in a function to do the replacement.

Porting the whole SubstitutionVariables class is a little tricky without also replacing the Settings class.

@@ -0,0 +1,64 @@
package org.logstash.secret;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved from being an inner class in the secret store tests

@andrewvc andrewvc force-pushed the port-substitution-variables branch 3 times, most recently from feef05b to 254557a Compare May 19, 2018 14:46
@andrewvc andrewvc force-pushed the port-substitution-variables branch 2 times, most recently from d29e02b to 068a515 Compare May 19, 2018 23:29
org.logstash.common.SubstitutionVariables.replacePlaceholders(
value, ENV, LogStash::Util::SecretStore.get_if_exists
);
rescue org.logstash.common.SubstitutionVariables::MissingSubstitutionVariableError => e
Copy link
Member

Choose a reason for hiding this comment

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

@andrewvc are you sure this is caught here? Instinctively I'd say now actually. Maybe simply throw that ConfigurationError on the Java side in the first place?

Syntax for that would be:

                throw RubyUtil.RUBY.newRaiseException(
                    RubyUtil.CONFIGURATION_ERROR_CLASS,
                    "Your Message"
                );

:)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean by "am I sure that is caught?" As in, is the thrown exception caught, or is the rescue block here doing its work?

I'd prefer not to wrap this with a JRuby ext wrapper that throws ruby exceptions unless we need it.

This does work correctly today and is caught by https://github.com/elastic/logstash/blob/master/logstash-core/lib/logstash/util/settings_helper.rb#L41

I verified this manually.

Copy link
Member

Choose a reason for hiding this comment

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

@andrewvc yea that's what I meant, all good then :)

@original-brownbear
Copy link
Member

@original-brownbear
Copy link
Member

Jenkins test this

@andrewvc
Copy link
Contributor Author

@original-brownbear Yup, I'll take a look today.

@andrewvc
Copy link
Contributor Author

jenkins, please retest this

1 similar comment
@andrewvc
Copy link
Contributor Author

jenkins, please retest this

@andrewvc andrewvc force-pushed the port-substitution-variables branch 4 times, most recently from e9ad847 to c10283e Compare May 31, 2018 02:56
@andrewvc
Copy link
Contributor Author

Jenkins, test this please

@andrewvc
Copy link
Contributor Author

OK, so I pushed up a new commit that makes us load the secret store once per substitution vs. once per invocation of the substitution function.

The secret store, on my laptop, takes 300ms to start up. This is long enough to cause the test to time out. In the future we should find some way to cache it and invalidate it if the file contents change. That's more work than appropriate for this PR however.

@andrewvc
Copy link
Contributor Author

andrewvc commented Jun 1, 2018

jenkins, test this please

andrewvc and others added 5 commits March 29, 2022 19:12
This is a partial port that required writing our own version of ruby's gsub.

Java has `String#replaceAll`, but that doesn't let you pass in a function to do the replacement.
These exceptions are non-fatal per the specs
This is very slow and caused some specs to time out
@andsel andsel force-pushed the port-substitution-variables branch from 4ca7845 to 9664be5 Compare March 29, 2022 17:21
@andsel andsel self-assigned this Mar 30, 2022
@andsel
Copy link
Contributor

andsel commented Mar 30, 2022

Aligned with main and fixed some compiler warning to make ti run but fails the CI.
Needs more investigation on how to fix this.

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.

4 participants