Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
Agent: improved template checking after failure
Browse files Browse the repository at this point in the history
Marvel depends on the marvel index template. This commit makes the agent more diligent in checking the existence of the template after error conditions of settings updates. This is relevent, for example, where a dedicated cluster is being stopped, data folder being cleaned and the cluster brought up. Another issue was found when calls to upload the template connected to the monitoring cluster but returned with a non 2XX status code but no Java Exception was thrown.

Closes elastic#335
  • Loading branch information
bleskes committed Nov 12, 2014
1 parent 9d50b5c commit b3d9bff
Show file tree
Hide file tree
Showing 13 changed files with 376 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class AgentModule extends AbstractModule {
@Override
protected void configure() {
Multibinder<Exporter> multibinder = Multibinder.newSetBinder(binder(), Exporter.class);
multibinder.addBinding().to(ESExporter.class);
multibinder.addBinding().to(ESExporter.class).asEagerSingleton();
bind(AgentService.class).asEagerSingleton();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ protected void doClose() {
e.close();
}

// used for testing
public Collection<Exporter> getExporters() {
return exporters;
}

@Override
public void onRefreshSettings(Settings settings) {
TimeValue newSamplingInterval = settings.getAsTime(SETTINGS_INTERVAL, null);
Expand Down
69 changes: 67 additions & 2 deletions agent/src/main/java/org/elasticsearch/marvel/agent/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@
package org.elasticsearch.marvel.agent;

import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.component.Lifecycle;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.transport.BoundTransportAddress;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.http.HttpServer;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.io.UnsupportedEncodingException;
import java.net.*;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Utils {

Expand Down Expand Up @@ -79,4 +85,63 @@ public static String nodeDescription(DiscoveryNode node) {
return builder.toString();
}

public static String[] extractHostsFromHttpServer(HttpServer httpServer, ESLogger logger) {
logger.debug("deriving host setting from httpServer");
BoundTransportAddress boundAddress = httpServer.info().address();
if (httpServer.lifecycleState() != Lifecycle.State.STARTED || boundAddress == null || boundAddress.boundAddress() == null) {
logger.debug("local http server is not yet started. can't connect");
return null;
}
if (boundAddress.boundAddress().uniqueAddressTypeId() != 1) {
logger.error("local node is not bound via the http transport. can't connect");
return null;
}
InetSocketTransportAddress address = (InetSocketTransportAddress) boundAddress.boundAddress();
InetSocketAddress inetSocketAddress = address.address();
InetAddress inetAddress = inetSocketAddress.getAddress();
if (inetAddress == null) {
logger.error("failed to extract the ip address of current node.");
return null;
}

String host = inetAddress.getHostAddress();
if (host.indexOf(":") >= 0) {
// ipv6
host = "[" + host + "]";
}

return new String[]{host + ":" + inetSocketAddress.getPort()};
}

public static URL parseHostWithPath(String host, String path) throws URISyntaxException, MalformedURLException {

if (!host.contains("://")) {
// prefix with http
host = "http://" + host;
}
if (!host.endsWith("/")) {
// make sure we can safely resolves sub paths and not replace parent folders
host = host + "/";
}

URI hostUrl = new URI(host);

if (hostUrl.getPort() == -1) {
// url has no port, default to 9200
hostUrl = new URI(hostUrl.getScheme(), hostUrl.getUserInfo(), hostUrl.getHost(), 9200, hostUrl.getPath(), hostUrl.getQuery(), hostUrl.getFragment());

}
URI hostWithPath = hostUrl.resolve(path);
return hostWithPath.toURL();
}

public static int parseIndexVersionFromTemplate(byte[] template) throws UnsupportedEncodingException {
Pattern versionRegex = Pattern.compile("marvel.index_format\"\\s*:\\s*\"?(\\d+)\"?");
Matcher matcher = versionRegex.matcher(new String(template, "UTF-8"));
if (matcher.find()) {
return Integer.parseInt(matcher.group(1));
} else {
return -1;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/



package org.elasticsearch.marvel.agent.event;
/*
* Licensed to ElasticSearch under one
Expand Down Expand Up @@ -87,7 +86,7 @@ protected String event() {
}

@Override
String conciseDescription() {
public String conciseDescription() {
return (added ? "added" : "removed") + ": [" + block.toString() + "]";
}

Expand Down Expand Up @@ -116,7 +115,7 @@ protected String event() {
}

@Override
String conciseDescription() {
public String conciseDescription() {
return "cluster status is " + clusterHealth.getStatus().name();
}

Expand Down Expand Up @@ -157,7 +156,7 @@ protected String event() {
}

@Override
String conciseDescription() {
public String conciseDescription() {
return description;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public String clusterName() {
/**
* should return a short string based description of the event
*/
abstract String conciseDescription();
public abstract String conciseDescription();

@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/



package org.elasticsearch.marvel.agent.event;
/*
* Licensed to ElasticSearch under one
Expand Down Expand Up @@ -87,7 +86,7 @@ protected String event() {
}

@Override
String conciseDescription() {
public String conciseDescription() {
return "[" + index + "] " + (created ? " created" : " deleted");
}

Expand Down Expand Up @@ -116,7 +115,7 @@ protected String event() {
}

@Override
String conciseDescription() {
public String conciseDescription() {
return "[" + indexHealth.getIndex() + "] status is " + indexHealth.getStatus().name();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/



package org.elasticsearch.marvel.agent.event;
/*
* Licensed to ElasticSearch under one
Expand Down Expand Up @@ -85,7 +84,7 @@ protected String event() {
}

@Override
String conciseDescription() {
public String conciseDescription() {
return Utils.nodeDescription(node) + " became master";
}

Expand All @@ -109,7 +108,7 @@ protected String event() {
}

@Override
String conciseDescription() {
public String conciseDescription() {
return Utils.nodeDescription(node) + (joined ? " joined" : " left");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/



package org.elasticsearch.marvel.agent.event;
/*
* Licensed to ElasticSearch under one
Expand Down Expand Up @@ -107,7 +106,7 @@ public String event() {
}

@Override
String conciseDescription() {
public String conciseDescription() {
return shardDescription(shardRouting) + " initializing on " + Utils.nodeDescription(node);
}
}
Expand All @@ -124,7 +123,7 @@ public String event() {
}

@Override
String conciseDescription() {
public String conciseDescription() {
return shardDescription(shardRouting) + " started on " + Utils.nodeDescription(node);
}
}
Expand All @@ -141,7 +140,7 @@ public String event() {
}

@Override
String conciseDescription() {
public String conciseDescription() {
return shardRouting.shardId() + " promoted to primary on " + Utils.nodeDescription(node);
}
}
Expand All @@ -162,7 +161,7 @@ public String event() {
}

@Override
String conciseDescription() {
public String conciseDescription() {
return shardDescription(shardRouting) + " relocating to " + Utils.nodeDescription(relocatingTo) +
" from " + Utils.nodeDescription(node);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/



package org.elasticsearch.marvel.agent.event;
/*
* Licensed to ElasticSearch under one
Expand Down Expand Up @@ -76,7 +75,7 @@ public String type() {
}

@Override
String conciseDescription() {
public String conciseDescription() {
switch (shardState) {
case CREATED:
// no shard routing
Expand Down
Loading

0 comments on commit b3d9bff

Please sign in to comment.