-
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.
Fix bug in TextSocketSink to reconnect on socket failure
- Loading branch information
Showing
4 changed files
with
268 additions
and
50 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
53 changes: 53 additions & 0 deletions
53
.../prometheus/src/test/java/org/kairosdb/metrics4jplugin/prometheus/PrometheusSinkTest.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,53 @@ | ||
package org.kairosdb.metrics4jplugin.prometheus; | ||
|
||
|
||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.kairosdb.metrics4j.MetricSourceManager; | ||
import org.kairosdb.metrics4j.configuration.MetricConfig; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.net.http.HttpClient; | ||
import java.net.http.HttpRequest; | ||
import java.net.http.HttpResponse; | ||
import java.util.Collections; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class PrometheusSinkTest | ||
{ | ||
@BeforeEach | ||
void setUp() | ||
{ | ||
|
||
} | ||
|
||
@AfterEach | ||
public void cleanup() | ||
{ | ||
MetricSourceManager.clearConfig(); | ||
} | ||
|
||
@Test | ||
public void testPrometheusServer() throws IOException, InterruptedException, URISyntaxException | ||
{ | ||
MetricConfig metricConfig = MetricConfig.parseConfig("prometheus_test.conf", "not.properties"); | ||
|
||
MetricSourceManager.setMetricConfig(metricConfig); | ||
|
||
MetricSourceManager.addSource("PrometheusSinkTest", "testPrometheusServer", | ||
Collections.emptyMap(), "help", () -> 42); | ||
|
||
HttpClient httpClient = HttpClient.newHttpClient(); | ||
HttpRequest request = HttpRequest.newBuilder(new URI("http://localhost:9666/metrics")).GET().build(); | ||
|
||
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); | ||
|
||
System.out.println(response.body()); | ||
assertThat(response.body()).contains("PrometheusSinkTest_testPrometheusServer_value 42.0"); | ||
|
||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
plugins/prometheus/src/test/resources/prometheus_test.conf
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,27 @@ | ||
metrics4j: { | ||
|
||
collectors: { | ||
#No collectors are needed for JMX | ||
} | ||
|
||
sinks: { | ||
prometheus: { | ||
_class: "org.kairosdb.metrics4jplugin.prometheus.PrometheusSink" | ||
listen-port: 9666 | ||
} | ||
} | ||
|
||
triggers: { | ||
prometheus: { | ||
_class: "org.kairosdb.metrics4jplugin.prometheus.PrometheusTrigger" | ||
_folder: "/home/bhawkins/programs/metrics4j/m4j-prometheus-1.0.1" | ||
} | ||
} | ||
|
||
sources: { | ||
_disabled: false | ||
_trigger: prometheus | ||
_sink: [prometheus] | ||
} | ||
|
||
} |
Oops, something went wrong.