Skip to content
This repository has been archived by the owner on Jun 29, 2023. It is now read-only.

Added GelfHTTPSender #68

Closed
wants to merge 5 commits into from
Closed

Added GelfHTTPSender #68

wants to merge 5 commits into from

Conversation

salex89
Copy link
Contributor

@salex89 salex89 commented Feb 19, 2016

Outline

Added HTTP Sender, for situations when the log manager is on a remote location or behind a proxy. Currently TLS and authentication is not supported, only log submission. TLS is the next step.

Motivation

The motivation is to use Graylog for remote logging, with Android devices, IoT and such.

Added configuration

As for the HTTP sender configuration, the host is the complete path to the log manager (i.e Graylog) endpoint, like http://192.168.0.1:12201/gelf . If the port is not added to the host, the one supplied in the configuration file will be inserted into the host. I would gladly document this example, when I am informed where to put it :-) .

Questions and issues

Regarding TLS and auth, additional configuration is needed (not sure which fields for now). I would like to consult with the author, which is the best way to do it? Should new configuration fields be added, available in all of the formats, hence, modifying all of the parsers, or some other way? I have noticed that the GelfSenderConfiguration has the method Map<String, Object> getSpecificConfigurations();, and I suppose this is the way to go, based on the design. However, no example is provided how is this bound to the configuration files, and I'm not sure is it.

Looking forward to continuing this,
Aleksandar

@mp911de
Copy link
Owner

mp911de commented Feb 20, 2016

Thanks for your PR. I'll take a deeper look on it. Could you rebase the PR as there are merge conflicts?

@mp911de mp911de self-assigned this Feb 20, 2016
@Before
public void prepareMocks() throws IOException {
MockitoAnnotations.initMocks(this);
// when(closeableHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 202, "Accepted"));
Copy link
Owner

Choose a reason for hiding this comment

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

An integration test with the sender would be great. Netty is already on the class-path, you can build your own HTTP server, see https://github.com/netty/netty/tree/4.0/example/src/main/java/io/netty/example/http/helloworld

Copy link

Choose a reason for hiding this comment

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

FWIW, using https://github.com/square/okhttp/tree/master/mockwebserver#readme might be useful for those kind of tests without writing everything from scratch. IMHO OkHttp is also quite a good HTTP client library.

Copy link
Owner

Choose a reason for hiding this comment

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

Thx. I'm a bit concerned about pulling in dependencies. With one "lousy" logger appender you're forced to a dependency that might kill your app :(

Copy link

Choose a reason for hiding this comment

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

This might be a good case for optional dependencies (https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html) or using the HTTP client included in the JDK (https://docs.oracle.com/javase/8/docs/api/java/net/HttpURLConnection.html).
The mockwebserver dependency would only be needed in the test scope of this project.

Ignore my remark about OkHttp, that's just an opinion. 😉

@mp911de
Copy link
Owner

mp911de commented Feb 20, 2016

Your change introduces a dependency to Apache's HTTP components which pulls in a couple of other dependencies. The code also requires at least Apache HTTP components 4.3+. Apache HTTP components is widely used and users use various versions. logstash-gelf would force its users to upgrade Apache HTTP components and this is not always easily possible.

I'm also not sure whether to use the deprecated 4.0 API because it could be removed in future versions. Currently, I'd propose to use Java's HttpUrlConnection for data exchange and it supports also HTTPS out of the box.

In general, this is a good approach. Configuring the URL via the host property is currently the best possible way. It is however limited because you can't specify other properties like the timeouts, which should be at least set to some sensible defaults (see Redis/TCP sender).

Documentation for the particular senders is located within the site folder (see https://github.com/mp911de/logstash-gelf/blob/master/src/site/markdown/redis.md for Redis).

Please use the formatter configuration to format your changes.

@salex89
Copy link
Contributor Author

salex89 commented Feb 21, 2016

Got it, I'll address the issues.

On Sat, 20 Feb 2016, 19:53 Mark Paluch notifications@github.com wrote:

Your change introduces a dependency to Apache's HTTP components which
pulls in a couple of other dependencies. The code also requires at least
Apache HTTP components 4.3+. Apache HTTP components is widely used and
users use various versions. logstash-gelf would force its users to upgrade
Apache HTTP components and this is not always easily possible.

I'm also not sure whether to use the deprecated 4.0 API because it could
be removed in future versions. Currently, I'd propose to use Java's
HttpUrlConnection for data exchange and it supports also HTTPS out of the
box.

In general, this is a good approach. Configuring the URL via the host
property is currently the best possible way. It is however limited because
you can't specify other properties like the timeouts, which should be at
least set to some sensible defaults (see Redis/TCP sender).

Documentation for the particular senders is located within the site
folder (see
https://github.com/mp911de/logstash-gelf/blob/master/src/site/markdown/redis.md
for Redis).

Please use the formatter configuration
https://github.com/mp911de/logstash-gelf/blob/master/as7formatter.xml
to format your changes.


Reply to this email directly or view it on GitHub
#68 (comment).

Conflicts:
	src/main/java/biz/paluch/logging/gelf/intern/sender/DefaultGelfSenderProvider.java
	src/main/java/biz/paluch/logging/gelf/intern/sender/GelfHTTPSender.java
	src/test/java/biz/paluch/logging/gelf/GelfUtilTest.java
	src/test/java/biz/paluch/logging/gelf/intern/sender/GelfHTTPSenderTest.java
mp911de pushed a commit that referenced this pull request Mar 20, 2016
logstash-gelf now supports sending log events  using HTTP and HTTPS by using Java's HttpUrlConnection. Payload is sent according to the Graylog specification as JSON with prefixing additional fields with an underscore.

Original pull request: #68.
mp911de added a commit that referenced this pull request Mar 20, 2016
Add author tags. Reformat code. Remove default port fallback in HTTP sender as default ports are specified by the protocol (HTTP/HTTPS). Add documentation for HTTP transport. Extend tests.
@mp911de mp911de added this to the 1.9.0 milestone Mar 20, 2016
@mp911de mp911de added the type: enhancement A general enhancement label Mar 20, 2016
@mp911de
Copy link
Owner

mp911de commented Mar 20, 2016

Thanks. That's rebased, squashed and merged via 3cc5219.

@mp911de mp911de closed this Mar 20, 2016
@salex89
Copy link
Contributor Author

salex89 commented Mar 20, 2016

Damn, I notices I didn't remove the http-client dependency. I noticed but didn't have the time :( . Should I create a new PR?

@mp911de
Copy link
Owner

mp911de commented Mar 21, 2016

Thanks for the hint. I'll take care of it.

mp911de added a commit that referenced this pull request Mar 21, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants