forked from ConsoleCatzirl/jenkins-logstash-plugin
-
-
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
Open
idohalevi
wants to merge
57
commits into
jenkinsci:master
Choose a base branch
from
idohalevi:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 21 commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
d986d80
first
8a00ac8
queue in workspace
de18b60
deleting comments
4ef9a2f
PR fixes
8c185d6
change dir path
6c7d6a6
using tmp dir
9b7621d
change @timestamp field name
5075433
using stream
fa317c1
Merge pull request #1 from idohalevi/first
idohalevi bf87eec
Update Logzio.java
idohalevi 6d53f29
add debug info
4d9134d
change queue location
54cd262
change const
7a9164d
add debug
959f715
debug prints
03cb931
debug
035fb68
gzip logs
53ffac5
Merge branch 'master' of https://github.com/jenkinsci/logstash-plugin
84aed45
delete debug print
193f057
fixing for travis tests (#2)
idohalevi 4dbe73e
Fix travis (#3)
idohalevi 89a41e9
Use a container for more repeatable builds (#4)
tomwillfixit 25c63b4
sync with upstream
bdab1a3
stream is back
488037f
logzio in memory https client
144e922
adding in memory http sender, local logger and updating README
30ccd6b
remove docker from readme install
bf200ca
delete comma
f2dc75e
Merge pull request #5 from idohalevi/PR
idohalevi ad75e1e
Ranges -> Range
jakub-bochenski 6c27e9b
deleting mail
84d2051
adding static class/fields - travis findbugs
bd0ba73
adding charset - travis findbugs
22d88bc
change reporter class to static class
63647d6
change LOGGER to static member
6a70412
delete unused imports
f57f163
delete unused imports - test
bd062d0
add flatten data explanation
594c37d
send logs before size limit reached
07fcdb4
adding warning about thread safety
e2fb882
move LogzioHttpsClient to a top-level class
74fa7f6
fix spelling
93732e3
change key to token
203eca1
change messages list to Collections.synchronizedList
d31850b
style + typo
b3ffe89
rename help file
77577d9
change to capital
e7b056e
delete run-fast script
1508b3f
Merge branch 'master' of https://github.com/jenkinsci/logstash-plugin…
HananEgbaria 3e37735
Merge pull request #6 from idohalevi/dev
HananEgbaria 605a76c
add close method
HananEgbaria f5e9581
add "synchronized" to push method to resolve multi-threading (multi-j…
HananEgbaria 1aec70e
update maven dependencies versions
HananEgbaria 84c3602
remove unimportant comments
HananEgbaria 93a5cd2
Merge pull request #7 from idohalevi/fix_comments
idohalevi b1dc099
remove unused methods
HananEgbaria 261f22c
Merge pull request #8 from idohalevi/fix_comments
idohalevi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
src/main/java/jenkins/plugins/logstash/configuration/Logzio.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| package jenkins.plugins.logstash.configuration; | ||
|
|
||
| import hudson.Extension; | ||
| import hudson.util.FormValidation; | ||
| import hudson.util.Secret; | ||
|
|
||
| import jenkins.plugins.logstash.persistence.LogzioDao; | ||
| import jenkins.plugins.logstash.Messages; | ||
|
|
||
| import org.apache.commons.lang.StringUtils; | ||
| import org.kohsuke.stapler.DataBoundConstructor; | ||
| import org.kohsuke.stapler.DataBoundSetter; | ||
| import org.kohsuke.stapler.QueryParameter; | ||
|
|
||
| import javax.annotation.Nonnull; | ||
|
|
||
| public class Logzio extends LogstashIndexer<LogzioDao> | ||
| { | ||
| private Secret key; | ||
idohalevi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| private String host; | ||
|
|
||
| @DataBoundConstructor | ||
| public Logzio(){} | ||
|
|
||
| /* | ||
| * We use URL for the setter as stapler can autoconvert a string to a URL but not to a URI | ||
| */ | ||
| public String getHost(){ return this.host; } | ||
|
|
||
| @DataBoundSetter | ||
| public void setHost(String host){ this.host = host; } | ||
|
|
||
| public String getKey() | ||
| { | ||
| return Secret.toString(key); | ||
| } | ||
|
|
||
| @DataBoundSetter | ||
| public void setKey(String key) | ||
| { | ||
| this.key = Secret.fromString(key); | ||
| } | ||
|
|
||
|
|
||
| @Override | ||
| public boolean equals(Object obj) | ||
| { | ||
| if (obj == null) | ||
| return false; | ||
| if (this == obj) | ||
| return true; | ||
| if (getClass() != obj.getClass()) | ||
| return false; | ||
| Logzio other = (Logzio) obj; | ||
| if (!Secret.toString(key).equals(other.getKey())) | ||
| { | ||
| return false; | ||
| } | ||
| if (host == null) | ||
| { | ||
| return other.host == null; | ||
| } | ||
| else return host.equals(other.host); | ||
idohalevi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() | ||
| { | ||
| final int prime = 31; | ||
| int result = super.hashCode(); | ||
| result = prime * result + ((host == null) ? 0 : host.hashCode()); | ||
| result = prime * result + Secret.toString(key).hashCode(); | ||
| return result; | ||
| } | ||
|
|
||
| @Override | ||
| public LogzioDao createIndexerInstance() { return new LogzioDao(host, Secret.toString(key)); } | ||
|
|
||
| @Extension | ||
| public static class LogzioDescriptor extends LogstashIndexerDescriptor | ||
| { | ||
| private static String EU_HOST = "https://listener-eu.logz.io:8071"; | ||
| private static String NONEU_HOST = "https://listener.logz.io:8071"; | ||
|
|
||
| @Nonnull | ||
| @Override | ||
| public String getDisplayName() | ||
| { | ||
| return "Logz.io"; | ||
| } | ||
|
|
||
| @Override | ||
| public int getDefaultPort() | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| public FormValidation doCheckKey(@QueryParameter("value") String value) | ||
| { | ||
| if (StringUtils.isBlank(value)) | ||
| { | ||
| return FormValidation.error(Messages.ValueIsRequired()); | ||
| } | ||
| return FormValidation.ok(); | ||
| } | ||
|
|
||
| public FormValidation doCheckHost(@QueryParameter("value") String value) | ||
idohalevi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| if (StringUtils.isBlank(value)) | ||
| { | ||
| return FormValidation.error(Messages.ValueIsRequired()); | ||
| } | ||
| else if (!(value.equals(EU_HOST) || value.equals(NONEU_HOST))){ | ||
| return FormValidation.error("Please verify your logz.io host is one of the two possible hosts - " | ||
| + EU_HOST + " or " + NONEU_HOST); | ||
| } | ||
| return FormValidation.ok(); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
src/main/java/jenkins/plugins/logstash/persistence/LogzioDao.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| package jenkins.plugins.logstash.persistence; | ||
|
|
||
| import com.github.wnameless.json.flattener.JsonFlattener; | ||
| import com.google.common.io.Files; | ||
|
|
||
| import io.logz.sender.LogzioSender; | ||
| import io.logz.sender.SenderStatusReporter; | ||
| import io.logz.sender.com.google.gson.JsonObject; | ||
| import io.logz.sender.exceptions.LogzioParameterErrorException; | ||
|
|
||
| import java.io.*; | ||
| import java.util.*; | ||
| import java.util.concurrent.Executors; | ||
| import java.util.logging.Level; | ||
| import java.util.logging.Logger; | ||
|
|
||
| import jenkins.model.Jenkins; | ||
| import jenkins.plugins.logstash.LogstashConfiguration; | ||
| import net.sf.json.JSONArray; | ||
| import net.sf.json.JSONObject; | ||
|
|
||
| /** | ||
| * Logz.io Data Access Object. | ||
| * | ||
| * @author Ido Halevi | ||
| */ | ||
|
|
||
| public class LogzioDao extends AbstractLogstashIndexerDao { | ||
| private static final int CONNECT_TIMEOUT = 10*1000; | ||
idohalevi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| private static final int CORE_POOL_SIZE = 2; | ||
| private static final int DRAIN_TIMEOUT = 2; | ||
| private static final int FS_PERCENT_THRESHOLD = 99; | ||
| private static final int GC_PERSISTED_QUEUE_FILE_INTERVAL_SECOND = 30; | ||
| private static final int SOCKET_TIMEOUT = 10*1000; | ||
| private static final String TYPE = "jenkins_plugin"; | ||
idohalevi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| private final LogzioSender logzioSender; | ||
|
|
||
| private String key; | ||
| private String host; | ||
|
|
||
| //primary constructor used by indexer factory | ||
| public LogzioDao(String host, String key){ | ||
| this(null, host, key); | ||
| } | ||
|
|
||
| // Factored for unit testing | ||
| LogzioDao(LogzioSender factory, String host, String key){ | ||
| this.host = host; | ||
| this.key = key; | ||
|
|
||
| // create file for sender queue | ||
| File fp; | ||
| Jenkins jenkins = Jenkins.getInstanceOrNull(); | ||
| if (jenkins == null){ | ||
idohalevi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // for testing (mvn package) | ||
idohalevi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| fp = Files.createTempDir(); | ||
| }else{ | ||
| fp = new File(jenkins.getRootDir() + "/logs/logzio_plugin"); | ||
idohalevi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| boolean folderExisted = fp.mkdirs() || fp.setWritable(true); | ||
| if (!folderExisted) { | ||
| throw new IllegalArgumentException("Unable to create path"); | ||
| } | ||
| } | ||
|
|
||
| try{ | ||
| this.logzioSender = factory == null ? LogzioSender.getOrCreateSenderByType(key, TYPE, DRAIN_TIMEOUT, | ||
| FS_PERCENT_THRESHOLD, fp, host, SOCKET_TIMEOUT, CONNECT_TIMEOUT,false, null, | ||
| Executors.newScheduledThreadPool(CORE_POOL_SIZE),GC_PERSISTED_QUEUE_FILE_INTERVAL_SECOND, true) : factory; | ||
idohalevi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| this.logzioSender.start(); | ||
| }catch (LogzioParameterErrorException e){ | ||
| throw new IllegalArgumentException(e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void push(String data) { | ||
| JSONObject jsonData = JSONObject.fromObject(data); | ||
| JSONArray logMessages = jsonData.getJSONArray("message"); | ||
| for (Object logMsg : logMessages) { | ||
| JsonObject logLine = createLogLine(jsonData, logMsg.toString()); | ||
idohalevi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| this.logzioSender.send(logLine); | ||
| } | ||
| } | ||
|
|
||
| protected JsonObject createLogLine(JSONObject jsonData, String logMsg) { | ||
| JsonObject logLine = new JsonObject(); | ||
| logLine.addProperty("message", logMsg); | ||
| logLine.addProperty("@timestamp", LogstashConfiguration.getInstance().getDateFormatter().format(Calendar.getInstance().getTime())); | ||
idohalevi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| for(Object key : jsonData.keySet()){ | ||
| String keyStr = (String) key; | ||
| if (!keyStr.equals("message")){ | ||
| logLine.addProperty(key.toString(), jsonData.getString(key.toString())); | ||
| } | ||
| } | ||
| return logLine; | ||
| } | ||
|
|
||
| @Override | ||
| public JSONObject buildPayload(BuildData buildData, String jenkinsUrl, List<String> logLines) { | ||
| JSONObject payload = new JSONObject(); | ||
| payload.put("message", logLines); | ||
| payload.put("source", "jenkins"); | ||
| payload.put("source_host", jenkinsUrl); | ||
| payload.put("@buildTimestamp", buildData.getTimestamp()); | ||
| payload.put("@version", 1); | ||
| // flatten build data | ||
| Map<String, Object> flattenJson = JsonFlattener.flattenAsMap(buildData.toString()); | ||
idohalevi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| for (Map.Entry<String, Object> entry : flattenJson.entrySet()) { | ||
| String key = entry.getKey().replace('.','_'); | ||
| Object value = entry.getValue(); | ||
| payload.put(key, value); | ||
| } | ||
|
|
||
| return payload; | ||
| } | ||
|
|
||
| @Override | ||
| public String getDescription(){ return host; } | ||
|
|
||
| public String getHost(){ return host; } | ||
|
|
||
| public String getKey(){ return key; } | ||
|
|
||
| public String getType(){ return TYPE; } | ||
|
|
||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| <div> | ||
| Adds the possibility to push builds logs and build data to a Logstash indexer such as Redis, RabbitMQ, Elastic Search or to Syslog. | ||
| Adds the possibility to push builds logs and build data to a Logstash indexer such as Redis, RabbitMQ, Elastic Search, Logz.io or to Syslog. | ||
| </div> |
9 changes: 9 additions & 0 deletions
9
src/main/resources/jenkins/plugins/logstash/configuration/Logzio/config.jelly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <?jelly escape-by-default='true'?> | ||
| <j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"> | ||
| <f:entry title="${%Logz.io Host}" field="host"> | ||
| <f:textbox default="https://listener.logz.io:8071"/> | ||
| </f:entry> | ||
| <f:entry title="${%Logz.io key}" field="key"> | ||
idohalevi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <f:password/> | ||
| </f:entry> | ||
| </j:jelly> | ||
5 changes: 5 additions & 0 deletions
5
src/main/resources/jenkins/plugins/logstash/configuration/Logzio/help-host.jelly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <div> | ||
| <p>Logz.io listener URL.<br/> | ||
| If you are in the EU region insert https://listener-eu.logz.io:8071. Otherwise, use https://listener.logz.io:8071<br/> | ||
| You can tell which region you are in by checking your login URL</p> | ||
| </div> |
3 changes: 3 additions & 0 deletions
3
src/main/resources/jenkins/plugins/logstash/configuration/Logzio/help-key.jelly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <div> | ||
| <p>The Logz.io account token.</p> | ||
| </div> |
4 changes: 4 additions & 0 deletions
4
src/main/resources/jenkins/plugins/logstash/configuration/Logzio/help.jelly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| <?jelly escape-by-default='true'?> | ||
| <j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler"> | ||
| Push to Logz.io with HTTPs input. | ||
| </j:jelly> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.