From 717db3a0dff44f2e3b3341f6177a57ec8c81efd9 Mon Sep 17 00:00:00 2001 From: Boaz Leskes Date: Sat, 20 Dec 2014 09:39:56 +0100 Subject: [PATCH] Agent: make http server injection optional It should be OK to run the agent when http.enabled is set to false, shipping to another cluster. Closes #374 --- .../marvel/agent/exporter/ESExporter.java | 4 ++-- .../marvel/agent/exporter/ESExporterTests.java | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/agent/src/main/java/org/elasticsearch/marvel/agent/exporter/ESExporter.java b/agent/src/main/java/org/elasticsearch/marvel/agent/exporter/ESExporter.java index ad976458e3f07..6936c9985ce8a 100644 --- a/agent/src/main/java/org/elasticsearch/marvel/agent/exporter/ESExporter.java +++ b/agent/src/main/java/org/elasticsearch/marvel/agent/exporter/ESExporter.java @@ -161,7 +161,7 @@ public String name() { return "es_exporter"; } - @Inject + @Inject(optional = true) public void setHttpServer(HttpServer httpServer) { this.httpServer = httpServer; } @@ -337,7 +337,7 @@ private HttpURLConnection openAndValidateConnection(String method, String path) private HttpURLConnection openAndValidateConnection(String method, String path, String contentType) { if (hosts.length == 0) { if (httpServer == null) { - logger.debug("local http server is not yet injected. can't connect."); + logger.warn("http server is not enabled no hosts are manually configured"); return null; } diff --git a/agent/src/test/java/org/elasticsearch/marvel/agent/exporter/ESExporterTests.java b/agent/src/test/java/org/elasticsearch/marvel/agent/exporter/ESExporterTests.java index 428109e435aa8..abf3fd176a5ad 100644 --- a/agent/src/test/java/org/elasticsearch/marvel/agent/exporter/ESExporterTests.java +++ b/agent/src/test/java/org/elasticsearch/marvel/agent/exporter/ESExporterTests.java @@ -51,6 +51,19 @@ @ClusterScope(transportClientRatio = 0.0, scope = ElasticsearchIntegrationTest.Scope.TEST, numNodes = 0) public class ESExporterTests extends ElasticsearchIntegrationTest { + @Test + public void testHttpServerOff() { + ImmutableSettings.Builder builder = ImmutableSettings.builder() + .put(AgentService.SETTINGS_INTERVAL, "200m") + .put("http.enabled", "false"); + cluster().startNode(builder); + ESExporter esExporter = getEsExporter(); + logger.info("trying exporting despite of no target"); + esExporter.exportEvents(new Event[]{ + new TestEvent() + }); + } + @Test public void testLargeClusterStateSerialization() throws InterruptedException { // make sure no other exporting is done (quicker)..