-
-
Notifications
You must be signed in to change notification settings - Fork 107
Add Logz.io support #74
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
base: master
Are you sure you want to change the base?
Changes from all commits
d986d80
8a00ac8
de18b60
4ef9a2f
8c185d6
6c7d6a6
9b7621d
5075433
fa317c1
bf87eec
6d53f29
4d9134d
54cd262
7a9164d
959f715
03cb931
035fb68
53ffac5
84aed45
193f057
4dbe73e
89a41e9
25c63b4
bdab1a3
488037f
144e922
30ccd6b
bf200ca
f2dc75e
ad75e1e
6c27e9b
84d2051
bd0ba73
22d88bc
63647d6
6a70412
f57f163
bd062d0
594c37d
07fcdb4
e2fb882
74fa7f6
93732e3
203eca1
d31850b
b3ffe89
77577d9
e7b056e
1508b3f
3e37735
605a76c
f5e9581
1aec70e
84c3602
93a5cd2
b1dc099
261f22c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,60 +48,60 @@ | |
| public class LogstashBuildWrapper extends BuildWrapper | ||
| { | ||
|
|
||
| /** | ||
| * Create a new {@link LogstashBuildWrapper}. | ||
| */ | ||
| @DataBoundConstructor | ||
| public LogstashBuildWrapper() | ||
| {} | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| public Environment setUp(AbstractBuild build, Launcher launcher, BuildListener listener) | ||
| throws IOException, InterruptedException | ||
| { | ||
| return new Environment() | ||
| { | ||
| }; | ||
| } | ||
|
|
||
| @Override | ||
| public DescriptorImpl getDescriptor() | ||
| { | ||
| return (DescriptorImpl)super.getDescriptor(); | ||
| } | ||
|
|
||
| /** | ||
| * Registers {@link LogstashBuildWrapper} as a {@link BuildWrapper}. | ||
| */ | ||
| @Extension | ||
| public static class DescriptorImpl extends BuildWrapperDescriptor | ||
| { | ||
|
|
||
| public DescriptorImpl() | ||
| { | ||
| super(LogstashBuildWrapper.class); | ||
| load(); | ||
| } | ||
| /** | ||
| * Create a new {@link LogstashBuildWrapper}. | ||
| */ | ||
| @DataBoundConstructor | ||
| public LogstashBuildWrapper() | ||
| {} | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| public String getDisplayName() | ||
| public Environment setUp(AbstractBuild build, Launcher launcher, BuildListener listener) | ||
| throws IOException, InterruptedException | ||
| { | ||
| return Messages.DisplayName(); | ||
| return new Environment() | ||
| { | ||
| }; | ||
| } | ||
|
|
||
| @Override | ||
| public DescriptorImpl getDescriptor() | ||
| { | ||
| return (DescriptorImpl)super.getDescriptor(); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| * Registers {@link LogstashBuildWrapper} as a {@link BuildWrapper}. | ||
| */ | ||
| @Override | ||
| public boolean isApplicable(AbstractProject<?, ?> item) | ||
| @Extension | ||
| public static class DescriptorImpl extends BuildWrapperDescriptor | ||
| { | ||
| return false; | ||
|
|
||
| public DescriptorImpl() | ||
| { | ||
| super(LogstashBuildWrapper.class); | ||
| load(); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| public String getDisplayName() | ||
| { | ||
| return Messages.DisplayName(); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| public boolean isApplicable(AbstractProject<?, ?> item) | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please revert the complete file to its original state. You just changed indentation. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * The MIT License | ||
| * | ||
| * Copyright 2017 Red Hat inc, and individual contributors | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| * THE SOFTWARE. | ||
| */ | ||
|
|
||
| package jenkins.plugins.logstash; | ||
|
|
||
| import net.sf.json.JSONObject; | ||
|
|
||
| /** | ||
| * Interface describing processors of persisted payload. | ||
| */ | ||
| public interface LogstashPayloadProcessor { | ||
| /** | ||
| * Modifies a JSON payload compatible with the Logstash schema. | ||
| * | ||
| * @param payload the JSON payload that has been constructed so far. | ||
| * @return The formatted JSON object, can be null to ignore this payload. | ||
| */ | ||
| JSONObject process(JSONObject payload) throws Exception; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we actually only need the finish() method, not process().
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jakub-bochenski There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAIR finish only uses process to call it with null arg. Anyhow check the comment above (#74 (comment)) it might make this point moot |
||
|
|
||
| /** | ||
| * Finalizes any operations, for example returns cashed lines at end of build. | ||
| * | ||
| * @return A formatted JSON object, can be null when it has nothing. | ||
| */ | ||
| JSONObject finish() throws Exception; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| /* | ||
| * The MIT License | ||
| * | ||
| * Copyright 2017 Red Hat inc. and individual contributors | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| * THE SOFTWARE. | ||
| */ | ||
|
|
||
| package jenkins.plugins.logstash; | ||
|
|
||
| import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
| import groovy.lang.Binding; | ||
| import jenkins.model.Jenkins; | ||
| import net.sf.json.JSONObject; | ||
| import org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript; | ||
| import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted; | ||
|
|
||
| import javax.annotation.Nonnull; | ||
| import java.io.IOException; | ||
| import java.io.OutputStream; | ||
|
|
||
| /** | ||
| * This class is handling custom groovy script processing of JSON payload. | ||
| * Each call to process executes the script provided in job configuration. | ||
| * Script is executed under the same binding each time so that it has ability | ||
| * to persist data during build execution if desired by script author. | ||
| * When build is finished, script will receive null as the payload and can | ||
| * return any cached but non-sent data back for persisting. | ||
| * The return value of script is the payload to be persisted unless null. | ||
| */ | ||
| public class LogstashScriptProcessor implements LogstashPayloadProcessor{ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you need this implmentation, just the interface There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even the interface is not needed. Actually the complete #71 should be taken out of here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need a close hook for the build. It's not available on master, so I suggested to use the same approach as #71 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What helps an interface when there is no implementation?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do you suggest we should continue with this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me try to explain again. Maybe at this point the best way to proceed is to forget about #71 and just add a way to notify the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #71 added a feature to close the LogstashWriter, which is specific to a build but it is not interacting with the Dao as the scriptprocessor is only used in the writer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I think I meant the LogstashWriter instead of IndexerDao On a different note: I'm rather busy lately and don't want to block it. I would be happy to accept whatever solution you and @idohalevi can agree on
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jakub-bochenski @mwinter69 |
||
| @Nonnull | ||
| private final SecureGroovyScript script; | ||
|
|
||
| @Nonnull | ||
| private final OutputStream consoleOut; | ||
|
|
||
| /** Groovy binding for script execution */ | ||
| @Nonnull | ||
| private final Binding binding; | ||
|
|
||
| /** Classloader for script execution */ | ||
| @Nonnull | ||
| private final ClassLoader classLoader; | ||
|
|
||
| public LogstashScriptProcessor(SecureGroovyScript script, OutputStream consoleOut) { | ||
| this.script = script; | ||
| this.consoleOut = consoleOut; | ||
|
|
||
| // TODO: should we put variables in the binding like manager, job, etc.? | ||
| binding = new Binding(); | ||
| binding.setVariable("console", new BuildConsoleWrapper()); | ||
|
|
||
| // not sure what the diff is compared to getClass().getClassLoader(); | ||
| final Jenkins jenkins = Jenkins.getInstance(); | ||
| classLoader = jenkins.getPluginManager().uberClassLoader; | ||
| } | ||
|
|
||
| /** | ||
| * Helper method to allow logging to build console. | ||
| */ | ||
| @SuppressFBWarnings( | ||
| value="DM_DEFAULT_ENCODING", | ||
| justification="TODO: not sure how to fix this") | ||
| private void buildLogPrintln(Object o) throws IOException { | ||
| consoleOut.write(o.toString().getBytes()); | ||
| consoleOut.write("\n".getBytes()); | ||
| consoleOut.flush(); | ||
| } | ||
|
|
||
| @Override | ||
| public JSONObject process(JSONObject payload) throws Exception { | ||
| binding.setVariable("payload", payload); | ||
| script.evaluate(classLoader, binding); | ||
| return (JSONObject) binding.getVariable("payload"); | ||
| } | ||
|
|
||
| @Override | ||
| public JSONObject finish() throws Exception { | ||
| buildLogPrintln("Tearing down Script Log Processor.."); | ||
| return process(null); | ||
| } | ||
|
|
||
| /** | ||
| * Helper to allow access from sandboxed script to output messages to console. | ||
| */ | ||
| private class BuildConsoleWrapper { | ||
| @Whitelisted | ||
| public void println(Object o) throws IOException { | ||
| buildLogPrintln(o); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.