Skip to content

add logstash DAO#29

Closed
vjm wants to merge 5 commits into
jenkinsci:masterfrom
vjm:master
Closed

add logstash DAO#29
vjm wants to merge 5 commits into
jenkinsci:masterfrom
vjm:master

Conversation

@vjm

@vjm vjm commented Jul 2, 2017

Copy link
Copy Markdown

No description provided.

@vjm

vjm commented Jul 2, 2017

Copy link
Copy Markdown
Author

@jakub-bochenski I opened this after discussion on #22 because the elasticsearch plugin option was forcing an http protocol message rather than TCP, which is supported in this PR (as well as the items from #28). Let me know what you think! I am using this build successfully on my Jenkins.

@jakub-bochenski

Copy link
Copy Markdown

If we add separate Logstash backend we should merge #21 too

@jakub-bochenski

Copy link
Copy Markdown

@vjm indeed #22 was only offering support for the HTTP logstash input

Ted Bao and others added 5 commits July 3, 2017 16:20
@jakub-bochenski

Copy link
Copy Markdown

Rebased the branch to make if FF to master

@jakub-bochenski jakub-bochenski left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please add some unit tests to cover the newly added paths
Please update the README with the new backend type

BufferedReader inFromServer = new BufferedReader(new InputStreamReader(logstashClientSocket.getInputStream()));
outToServer.writeBytes(data);
logstashClientSocket.setSoTimeout(10000);
logstashClientSocket.close();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

resources should be closed in finally block, or even better used in try-with-resource block

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is it a good idea to close the Socket before closing the outputstream?
Closing the outputtstream also closes the socket.

StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
exc.printStackTrace(pw);
throw new IOException(sw.toString());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

why not chain the exception?

outToServer.close();
inFromServer.close();
}
catch (Exception exc)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

can you please change this to a multi-catch with specific Exception?

@jakub-bochenski

Copy link
Copy Markdown

It would be ideal if this also supported Logstash HTTP input.
Best solution would be to add new input field to select the protocol. Easy solution would be to check for either http[s]: or tcp: in host (this pattern is already used in ES Dao)

{
logstashClientSocket = new Socket(logstashHost, logstashPort);
DataOutputStream outToServer = new DataOutputStream(logstashClientSocket.getOutputStream());
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(logstashClientSocket.getInputStream()));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why opening a reader when you never read data?


final String logstashHost;
final int logstashPort;
Socket logstashClientSocket;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why is this not private? And why an instance variable?

import com.cloudbees.syslog.Facility;
import com.cloudbees.syslog.MessageFormat;
import com.cloudbees.syslog.Severity;
import com.cloudbees.syslog.sender.UdpSyslogMessageSender;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

These imports from com.cloudbees are not used

logstashClientSocket = new Socket(logstashHost, logstashPort);
DataOutputStream outToServer = new DataOutputStream(logstashClientSocket.getOutputStream());
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(logstashClientSocket.getInputStream()));
outToServer.writeBytes(data);

@mwinter69 mwinter69 Jan 2, 2018

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The javadoc for this method says:

Each character in the string is written out, in sequence, by discarding its high eight bits.

Is this really a good idea? What if we have unicode characters (very likely to happen)?

@jakub-bochenski

Copy link
Copy Markdown

Superseded by #59

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants