forked from logstash-plugins/logstash-input-http
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Setup DropWizard metrics * Add Prometheus port configuration to README * Unit tests for metrics * Add metrics, rewrite MetricTest based on the objects that handle the metrics * Clear changed properties in MetricTest * Change the name of sendLatency metric * Move test classes to the correct packages * Decorate NettyHttpServer with MetricHttpServer * Close server in finally block in MetricHttpServer * Change closing order in MetricHttpServer * Refactor Metrics into Report and split the logic into decorators
- Loading branch information
Showing
26 changed files
with
1,370 additions
and
42 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -22,3 +22,5 @@ lookups.appname.file=etc/appname.json | |
|
||
payload.splitRegex=\n | ||
payload.splitEnabled=false | ||
|
||
prometheus.port=1234 |
This file contains 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 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,25 @@ | ||
/* | ||
logstash-http-input to syslog bridge | ||
Copyright 2024 Suomen Kanuuna Oy | ||
Derivative Work of Elasticsearch | ||
Copyright 2012-2015 Elasticsearch | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package com.teragrep.lsh_01; | ||
|
||
import java.io.Closeable; | ||
|
||
public interface HttpServer extends Runnable, Closeable { | ||
} |
This file contains 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 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,54 @@ | ||
/* | ||
logstash-http-input to syslog bridge | ||
Copyright 2024 Suomen Kanuuna Oy | ||
Derivative Work of Elasticsearch | ||
Copyright 2012-2015 Elasticsearch | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package com.teragrep.lsh_01; | ||
|
||
import com.teragrep.lsh_01.metrics.Report; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Decorator for a HttpServer that applies metrics. | ||
*/ | ||
public class MetricHttpServer implements HttpServer { | ||
|
||
private final HttpServer server; | ||
private final Report report; | ||
|
||
public MetricHttpServer(HttpServer server, Report report) { | ||
this.server = server; | ||
this.report = report; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
report.start(); | ||
server.run(); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
try { | ||
server.close(); | ||
} | ||
finally { | ||
report.close(); | ||
} | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
src/main/java/com/teragrep/lsh_01/MetricRelpConversion.java
This file contains 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,75 @@ | ||
/* | ||
logstash-http-input to syslog bridge | ||
Copyright 2024 Suomen Kanuuna Oy | ||
Derivative Work of Elasticsearch | ||
Copyright 2012-2015 Elasticsearch | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package com.teragrep.lsh_01; | ||
|
||
import com.codahale.metrics.MetricRegistry; | ||
import com.codahale.metrics.SlidingWindowReservoir; | ||
import com.codahale.metrics.Timer; | ||
import com.teragrep.lsh_01.authentication.Subject; | ||
|
||
import java.util.Map; | ||
|
||
import static com.codahale.metrics.MetricRegistry.name; | ||
|
||
/** | ||
* Decorator for IMessageHandler. Responsible for reporting metrics. | ||
*/ | ||
public class MetricRelpConversion implements IMessageHandler { | ||
|
||
private final IMessageHandler relpConversion; | ||
private final MetricRegistry metricRegistry; | ||
private final Timer sendLatency; | ||
|
||
public MetricRelpConversion(IMessageHandler relpConversion, MetricRegistry metricRegistry) { | ||
this.relpConversion = relpConversion; | ||
this.metricRegistry = metricRegistry; | ||
this.sendLatency = metricRegistry | ||
.timer(name(MetricRelpConversion.class, "sendLatency"), () -> new Timer(new SlidingWindowReservoir(10000))); | ||
} | ||
|
||
@Override | ||
public boolean onNewMessage(Subject subject, Map<String, String> headers, String body) { | ||
boolean sent; | ||
try (Timer.Context ctx = sendLatency.time()) { | ||
sent = relpConversion.onNewMessage(subject, headers, body); | ||
} | ||
return sent; | ||
} | ||
|
||
@Override | ||
public IMessageHandler copy() { | ||
return new MetricRelpConversion(relpConversion.copy(), metricRegistry); | ||
} | ||
|
||
@Override | ||
public Subject asSubject(String token) { | ||
return relpConversion.asSubject(token); | ||
} | ||
|
||
@Override | ||
public boolean requiresToken() { | ||
return relpConversion.requiresToken(); | ||
} | ||
|
||
@Override | ||
public Map<String, String> responseHeaders() { | ||
return relpConversion.responseHeaders(); | ||
} | ||
} |
This file contains 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
44 changes: 44 additions & 0 deletions
44
src/main/java/com/teragrep/lsh_01/config/MetricsConfig.java
This file contains 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,44 @@ | ||
/* | ||
logstash-http-input to syslog bridge | ||
Copyright 2024 Suomen Kanuuna Oy | ||
Derivative Work of Elasticsearch | ||
Copyright 2012-2015 Elasticsearch | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package com.teragrep.lsh_01.config; | ||
|
||
public class MetricsConfig implements Validateable { | ||
|
||
public final int prometheusPort; | ||
|
||
public MetricsConfig() { | ||
PropertiesReaderUtilityClass propertiesReader = new PropertiesReaderUtilityClass( | ||
System.getProperty("properties.file", "etc/config.properties") | ||
); | ||
prometheusPort = propertiesReader.getIntProperty("prometheus.port"); | ||
} | ||
|
||
@Override | ||
public void validate() { | ||
if (prometheusPort < 1 || prometheusPort > 65535) { | ||
throw new IllegalArgumentException("prometheus.port wasn't a valid port"); | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "RelpConfig{" + "prometheusPort=" + prometheusPort + "}"; | ||
} | ||
} |
Oops, something went wrong.