Merge branch 'master' into feature/shield-ui

Original commit: elastic/x-pack-elasticsearch@71d5f800d9
This commit is contained in:
Lukas Olson 2016-04-22 14:24:01 -07:00
commit 064a1eb961
298 changed files with 2542 additions and 2052 deletions

View File

@ -13,7 +13,6 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilderString;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
@ -315,23 +314,23 @@ public class License implements ToXContent {
version = this.version;
}
if (restViewMode) {
builder.field(XFields.STATUS, status().label());
builder.field(Fields.STATUS, status().label());
}
builder.field(XFields.UID, uid);
builder.field(XFields.TYPE, type);
builder.field(Fields.UID, uid);
builder.field(Fields.TYPE, type);
if (version == VERSION_START) {
builder.field(XFields.SUBSCRIPTION_TYPE, subscriptionType);
builder.field(Fields.SUBSCRIPTION_TYPE, subscriptionType);
}
builder.dateValueField(XFields.ISSUE_DATE_IN_MILLIS, XFields.ISSUE_DATE, issueDate);
builder.dateValueField(Fields.ISSUE_DATE_IN_MILLIS, Fields.ISSUE_DATE, issueDate);
if (version == VERSION_START) {
builder.field(XFields.FEATURE, feature);
builder.field(Fields.FEATURE, feature);
}
builder.dateValueField(XFields.EXPIRY_DATE_IN_MILLIS, XFields.EXPIRY_DATE, expiryDate);
builder.field(XFields.MAX_NODES, maxNodes);
builder.field(XFields.ISSUED_TO, issuedTo);
builder.field(XFields.ISSUER, issuer);
builder.dateValueField(Fields.EXPIRY_DATE_IN_MILLIS, Fields.EXPIRY_DATE, expiryDate);
builder.field(Fields.MAX_NODES, maxNodes);
builder.field(Fields.ISSUED_TO, issuedTo);
builder.field(Fields.ISSUER, issuer);
if (!licenseSpecMode && !restViewMode && signature != null) {
builder.field(XFields.SIGNATURE, signature);
builder.field(Fields.SIGNATURE, signature);
}
if (restViewMode) {
builder.humanReadable(previouslyHumanReadable);
@ -504,43 +503,27 @@ public class License implements ToXContent {
return result;
}
final static class Fields {
static final String STATUS = "status";
static final String UID = "uid";
static final String TYPE = "type";
static final String SUBSCRIPTION_TYPE = "subscription_type";
static final String ISSUE_DATE_IN_MILLIS = "issue_date_in_millis";
static final String ISSUE_DATE = "issue_date";
static final String FEATURE = "feature";
static final String EXPIRY_DATE_IN_MILLIS = "expiry_date_in_millis";
static final String EXPIRY_DATE = "expiry_date";
static final String MAX_NODES = "max_nodes";
static final String ISSUED_TO = "issued_to";
static final String ISSUER = "issuer";
static final String VERSION = "version";
static final String SIGNATURE = "signature";
public final static class Fields {
public static final String STATUS = "status";
public static final String UID = "uid";
public static final String TYPE = "type";
public static final String SUBSCRIPTION_TYPE = "subscription_type";
public static final String ISSUE_DATE_IN_MILLIS = "issue_date_in_millis";
public static final String ISSUE_DATE = "issue_date";
public static final String FEATURE = "feature";
public static final String EXPIRY_DATE_IN_MILLIS = "expiry_date_in_millis";
public static final String EXPIRY_DATE = "expiry_date";
public static final String MAX_NODES = "max_nodes";
public static final String ISSUED_TO = "issued_to";
public static final String ISSUER = "issuer";
public static final String VERSION = "version";
public static final String SIGNATURE = "signature";
static final String LICENSES = "licenses";
static final String LICENSE = "license";
public static final String LICENSES = "licenses";
public static final String LICENSE = "license";
}
public interface XFields {
XContentBuilderString STATUS = new XContentBuilderString(Fields.STATUS);
XContentBuilderString UID = new XContentBuilderString(Fields.UID);
XContentBuilderString TYPE = new XContentBuilderString(Fields.TYPE);
XContentBuilderString SUBSCRIPTION_TYPE = new XContentBuilderString(Fields.SUBSCRIPTION_TYPE);
XContentBuilderString ISSUE_DATE_IN_MILLIS = new XContentBuilderString(Fields.ISSUE_DATE_IN_MILLIS);
XContentBuilderString ISSUE_DATE = new XContentBuilderString(Fields.ISSUE_DATE);
XContentBuilderString FEATURE = new XContentBuilderString(Fields.FEATURE);
XContentBuilderString EXPIRY_DATE_IN_MILLIS = new XContentBuilderString(Fields.EXPIRY_DATE_IN_MILLIS);
XContentBuilderString EXPIRY_DATE = new XContentBuilderString(Fields.EXPIRY_DATE);
XContentBuilderString MAX_NODES = new XContentBuilderString(Fields.MAX_NODES);
XContentBuilderString ISSUED_TO = new XContentBuilderString(Fields.ISSUED_TO);
XContentBuilderString ISSUER = new XContentBuilderString(Fields.ISSUER);
XContentBuilderString SIGNATURE = new XContentBuilderString(Fields.SIGNATURE);
}
private static long parseDate(XContentParser parser, String description, boolean endOfTheDay) throws IOException {
if (parser.currentToken() == XContentParser.Token.VALUE_NUMBER) {
return parser.longValue();

View File

@ -16,7 +16,7 @@ import org.elasticsearch.watcher.condition.script.ExecutableScriptCondition;
import org.elasticsearch.watcher.condition.script.ScriptCondition;
import org.elasticsearch.watcher.execution.WatchExecutionContext;
import org.elasticsearch.watcher.support.Script;
import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy;
import org.elasticsearch.watcher.support.ScriptServiceProxy;
import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTestCase;
import org.elasticsearch.watcher.watch.Payload;
import org.junit.AfterClass;

View File

@ -5,21 +5,17 @@
*/
package org.elasticsearch.messy.tests;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
import org.elasticsearch.cluster.metadata.MappingMetaData;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse;
import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.FieldMappingMetaData;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.script.groovy.GroovyPlugin;
import org.elasticsearch.watcher.execution.ExecutionState;
import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTestCase;
import org.elasticsearch.watcher.transport.actions.put.PutWatchResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import static org.elasticsearch.common.xcontent.support.XContentMapValues.extractValue;
import static org.elasticsearch.watcher.actions.ActionBuilders.loggingAction;
import static org.elasticsearch.watcher.client.WatchSourceBuilders.watchBuilder;
import static org.elasticsearch.watcher.condition.ConditionBuilders.alwaysCondition;
@ -27,13 +23,9 @@ import static org.elasticsearch.watcher.input.InputBuilders.simpleInput;
import static org.elasticsearch.watcher.transform.TransformBuilders.scriptTransform;
import static org.elasticsearch.watcher.trigger.TriggerBuilders.schedule;
import static org.elasticsearch.watcher.trigger.schedule.Schedules.interval;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
/**
* This test makes sure that the http host and path fields in the watch_record action result are
* not analyzed so they can be used in aggregations
*/
public class HistoryTemplateTransformMappingsIT extends AbstractWatcherIntegrationTestCase {
@Override
@ -91,29 +83,16 @@ public class HistoryTemplateTransformMappingsIT extends AbstractWatcherIntegrati
refresh();
assertBusy(new Runnable() {
@Override
public void run() {
GetMappingsResponse mappingsResponse = client().admin().indices().prepareGetMappings().get();
assertThat(mappingsResponse, notNullValue());
assertThat(mappingsResponse.getMappings().isEmpty(), is(false));
for (ObjectObjectCursor<String, ImmutableOpenMap<String, MappingMetaData>> metadatas : mappingsResponse.getMappings()) {
if (!metadatas.key.startsWith(".watcher-history")) {
continue;
}
MappingMetaData metadata = metadatas.value.get("watch_record");
assertThat(metadata, notNullValue());
try {
Map<String, Object> source = metadata.getSourceAsMap();
logger.info("checking index [{}] with metadata:\n[{}]", metadatas.key, metadata.source().toString());
assertThat(extractValue("properties.result.properties.transform.properties.payload.enabled", source),
is((Object) false));
String path = "properties.result.properties.actions.properties.transform.properties.payload.enabled";
assertThat(extractValue(path, source), is((Object) false));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
assertBusy(() -> {
GetFieldMappingsResponse getFieldMappingsResponse = client().admin().indices()
.prepareGetFieldMappings(".watcher-history*").setFields("result.actions.transform.payload")
.setTypes("watch_record").includeDefaults(true).get();
for (Map<String, Map<String, FieldMappingMetaData>> map : getFieldMappingsResponse.mappings().values()) {
Map<String, FieldMappingMetaData> watchRecord = map.get("watch_record");
assertThat(watchRecord, hasKey("result.actions.transform.payload"));
FieldMappingMetaData fieldMappingMetaData = watchRecord.get("result.actions.transform.payload");
assertThat(fieldMappingMetaData.isNull(), is(true));
}
});
}

View File

@ -6,6 +6,9 @@
package org.elasticsearch.messy.tests;
import org.apache.lucene.util.LuceneTestCase;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.SuppressForbidden;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
@ -17,8 +20,9 @@ import org.elasticsearch.script.ScriptSettings;
import org.elasticsearch.script.groovy.GroovyScriptEngineService;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.watcher.ResourceWatcherService;
import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy;
import org.elasticsearch.watcher.support.ScriptServiceProxy;
import org.junit.Ignore;
import org.mockito.Mockito;
import java.util.Arrays;
import java.util.HashSet;
@ -43,8 +47,11 @@ public final class MessyTestUtils {
);
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Arrays.asList(ScriptServiceProxy.INSTANCE));
ClusterService clusterService = Mockito.mock(ClusterService.class);
Mockito.when(clusterService.state()).thenReturn(ClusterState.builder(new ClusterName("_name")).build());
ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
return ScriptServiceProxy.of(new ScriptService(settings, new Environment(settings), engineServiceSet,
new ResourceWatcherService(settings, tp), scriptEngineRegistry, scriptContextRegistry, scriptSettings));
new ResourceWatcherService(settings, tp), scriptEngineRegistry, scriptContextRegistry, scriptSettings),
clusterService);
}
}

View File

@ -23,7 +23,7 @@ import org.elasticsearch.watcher.condition.script.ExecutableScriptCondition;
import org.elasticsearch.watcher.condition.script.ScriptCondition;
import org.elasticsearch.watcher.execution.WatchExecutionContext;
import org.elasticsearch.watcher.support.Script;
import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy;
import org.elasticsearch.watcher.support.ScriptServiceProxy;
import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTestCase;
import org.elasticsearch.watcher.watch.Payload;
import org.junit.After;

View File

@ -14,7 +14,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.script.ScriptException;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.script.ScriptService.ScriptType;
import org.elasticsearch.search.internal.InternalSearchResponse;
import org.elasticsearch.test.ESTestCase;
@ -25,7 +24,7 @@ import org.elasticsearch.watcher.condition.script.ScriptCondition;
import org.elasticsearch.watcher.condition.script.ScriptConditionFactory;
import org.elasticsearch.watcher.execution.WatchExecutionContext;
import org.elasticsearch.watcher.support.Script;
import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy;
import org.elasticsearch.watcher.support.ScriptServiceProxy;
import org.elasticsearch.watcher.watch.Payload;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
@ -124,7 +123,7 @@ public class ScriptConditionTests extends ESTestCase {
ScriptType scriptType = randomFrom(ScriptType.values());
String script;
switch (scriptType) {
case INDEXED:
case STORED:
case FILE:
script = "nonExisting_script";
break;
@ -212,7 +211,7 @@ public class ScriptConditionTests extends ESTestCase {
case FILE:
builder.field("file", script);
break;
case INDEXED:
case STORED:
builder.field("id", script);
break;
default:

View File

@ -7,6 +7,7 @@ package org.elasticsearch.messy.tests;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.settings.Settings;
@ -77,7 +78,10 @@ public class TransformIT extends AbstractWatcherIntegrationTestCase {
script = Script.inline("return [key3 : ctx.payload.key1 + ctx.payload.key2]").lang("groovy").build();
} else if (randomBoolean()) {
logger.info("testing script transform with an indexed script");
client().preparePutIndexedScript("groovy", "_id", "{\"script\" : \"return [key3 : ctx.payload.key1 + ctx.payload.key2]\"}")
client().admin().cluster().preparePutStoredScript()
.setId("_id")
.setScriptLang("groovy")
.setSource(new BytesArray("{\"script\" : \"return [key3 : ctx.payload.key1 + ctx.payload.key2]\"}"))
.get();
script = Script.indexed("_id").lang("groovy").build();
} else {

View File

@ -13,10 +13,10 @@ import org.elasticsearch.script.mustache.MustachePlugin;
import org.elasticsearch.test.junit.annotations.Network;
import org.elasticsearch.test.junit.annotations.TestLogging;
import org.elasticsearch.watcher.actions.hipchat.HipChatAction;
import org.elasticsearch.watcher.actions.hipchat.service.HipChatAccount;
import org.elasticsearch.watcher.actions.hipchat.service.HipChatMessage;
import org.elasticsearch.watcher.actions.hipchat.service.HipChatService;
import org.elasticsearch.watcher.actions.hipchat.service.SentMessages;
import org.elasticsearch.xpack.notification.hipchat.HipChatAccount;
import org.elasticsearch.xpack.notification.hipchat.HipChatMessage;
import org.elasticsearch.xpack.notification.hipchat.HipChatService;
import org.elasticsearch.xpack.notification.hipchat.SentMessages;
import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTestCase;
import org.elasticsearch.watcher.transport.actions.put.PutWatchResponse;
@ -72,18 +72,18 @@ public class HipChatServiceIT extends AbstractWatcherIntegrationTestCase {
.put(super.nodeSettings(nodeOrdinal))
// this is for the `test-watcher-integration` group level integration in HipChat
.put("xpack.watcher.actions.hipchat.service.account.integration_account.profile", "integration")
.put("xpack.watcher.actions.hipchat.service.account.integration_account.auth_token",
.put("xpack.notification.hipchat.service.account.integration_account.profile", "integration")
.put("xpack.notification.hipchat.service.account.integration_account.auth_token",
"huuS9v7ccuOy3ZBWWWr1vt8Lqu3sQnLUE81nrLZU")
.put("xpack.watcher.actions.hipchat.service.account.integration_account.room", "test-watcher")
.put("xpack.notification.hipchat.service.account.integration_account.room", "test-watcher")
// this is for the Watcher Test account in HipChat
.put("xpack.watcher.actions.hipchat.service.account.user_account.profile", "user")
.put("xpack.watcher.actions.hipchat.service.account.user_account.auth_token", "FYVx16oDH78ZW9r13wtXbcszyoyA7oX5tiMWg9X0")
.put("xpack.notification.hipchat.service.account.user_account.profile", "user")
.put("xpack.notification.hipchat.service.account.user_account.auth_token", "FYVx16oDH78ZW9r13wtXbcszyoyA7oX5tiMWg9X0")
// this is for the `test-watcher-v1` notification token
.put("xpack.watcher.actions.hipchat.service.account.v1_account.profile", "v1")
.put("xpack.watcher.actions.hipchat.service.account.v1_account.auth_token", "a734baf62df618b96dda55b323fc30")
.put("xpack.notification.hipchat.service.account.v1_account.profile", "v1")
.put("xpack.notification.hipchat.service.account.v1_account.auth_token", "a734baf62df618b96dda55b323fc30")
.build();
}

View File

@ -12,11 +12,11 @@ import org.elasticsearch.script.MockMustacheScriptEngine;
import org.elasticsearch.script.mustache.MustachePlugin;
import org.elasticsearch.test.junit.annotations.Network;
import org.elasticsearch.watcher.actions.pagerduty.PagerDutyAction;
import org.elasticsearch.watcher.actions.pagerduty.service.IncidentEvent;
import org.elasticsearch.watcher.actions.pagerduty.service.IncidentEventContext;
import org.elasticsearch.watcher.actions.pagerduty.service.PagerDutyAccount;
import org.elasticsearch.watcher.actions.pagerduty.service.PagerDutyService;
import org.elasticsearch.watcher.actions.pagerduty.service.SentEvent;
import org.elasticsearch.xpack.notification.pagerduty.IncidentEvent;
import org.elasticsearch.xpack.notification.pagerduty.IncidentEventContext;
import org.elasticsearch.xpack.notification.pagerduty.PagerDutyAccount;
import org.elasticsearch.xpack.notification.pagerduty.PagerDutyService;
import org.elasticsearch.xpack.notification.pagerduty.SentEvent;
import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTestCase;
import org.elasticsearch.watcher.transport.actions.put.PutWatchResponse;
import org.elasticsearch.watcher.watch.Payload;
@ -72,7 +72,7 @@ public class PagerDutyServiceIT extends AbstractWatcherIntegrationTestCase {
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put("xpack.watcher.actions.pagerduty.service.account.test_account.service_api_key", "fc082467005d4072a914e0bb041882d0")
.put("xpack.notification.pagerduty.service.account.test_account.service_api_key", "fc082467005d4072a914e0bb041882d0")
.build();
}

View File

@ -5,9 +5,10 @@
*/
package org.elasticsearch.messy.tests;
import org.elasticsearch.action.indexedscripts.put.PutIndexedScriptRequest;
import org.elasticsearch.action.admin.cluster.storedscripts.PutStoredScriptRequest;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
@ -192,14 +193,17 @@ public class SearchInputIT extends ESIntegTestCase {
public void testSearchIndexedTemplate() throws Exception {
WatchExecutionContext ctx = createContext();
PutIndexedScriptRequest indexedScriptRequest = client().preparePutIndexedScript("mustache","test-template",
TEMPLATE_QUERY).request();
assertThat(client().putIndexedScript(indexedScriptRequest).actionGet().isCreated(), is(true));
PutStoredScriptRequest indexedScriptRequest = client().admin().cluster().preparePutStoredScript()
.setId("test-template")
.setScriptLang("mustache")
.setSource(new BytesArray(TEMPLATE_QUERY))
.request();
assertThat(client().admin().cluster().putStoredScript(indexedScriptRequest).actionGet().isAcknowledged(), is(true));
Map<String, Object> params = new HashMap<>();
params.put("seconds_param", "30s");
Template template = new Template("test-template", ScriptType.INDEXED, null, null, params);
Template template = new Template("test-template", ScriptType.STORED, null, null, params);
jsonBuilder().value(TextTemplate.indexed("test-template").params(params).build()).bytes();
SearchRequest request = client().prepareSearch().setSearchType(ExecutableSearchInput.DEFAULT_SEARCH_TYPE)
@ -209,7 +213,7 @@ public class SearchInputIT extends ESIntegTestCase {
Template resultTemplate = executedResult.executedRequest().template();
assertThat(resultTemplate, notNullValue());
assertThat(resultTemplate.getScript(), equalTo("test-template"));
assertThat(resultTemplate.getType(), equalTo(ScriptType.INDEXED));
assertThat(resultTemplate.getType(), equalTo(ScriptType.STORED));
}
public void testSearchOnDiskTemplate() throws Exception {

View File

@ -5,12 +5,13 @@
*/
package org.elasticsearch.messy.tests;
import org.elasticsearch.action.indexedscripts.put.PutIndexedScriptRequest;
import org.elasticsearch.action.admin.cluster.storedscripts.PutStoredScriptRequest;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.client.Requests;
import org.elasticsearch.common.Base64;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.settings.Settings;
@ -388,8 +389,12 @@ public class SearchTransformIT extends ESIntegTestCase {
"{\"from\":\"{{ctx.trigger.scheduled_time}}||-{{seconds_param}}\",\"to\":\"{{ctx.trigger.scheduled_time}}\"," +
"\"include_lower\":true,\"include_upper\":true}}}]}}}";
PutIndexedScriptRequest indexedScriptRequest = client().preparePutIndexedScript("mustache", "test-script", templateQuery).request();
assertThat(client().putIndexedScript(indexedScriptRequest).actionGet().isCreated(), is(true));
PutStoredScriptRequest indexedScriptRequest = client().admin().cluster().preparePutStoredScript()
.setId("test-script")
.setScriptLang("mustache")
.setSource(new BytesArray(templateQuery))
.request();
assertThat(client().admin().cluster().putStoredScript(indexedScriptRequest).actionGet().isAcknowledged(), is(true));
Map<String, Object> params = new HashMap<>();
params.put("seconds_param", "30s");
@ -397,13 +402,13 @@ public class SearchTransformIT extends ESIntegTestCase {
BytesReference templateSource = jsonBuilder()
.value(TextTemplate.indexed("test-script").params(params).build())
.bytes();
Template template = new Template("test-script", ScriptType.INDEXED, null, null, null);
Template template = new Template("test-script", ScriptType.STORED, null, null, null);
SearchRequest request = client()
.prepareSearch()
.setSearchType(ExecutableSearchTransform.DEFAULT_SEARCH_TYPE)
.setIndices("test-search-index")
.setTemplate(template)
.setTemplate(template)
.request();
SearchTransform.Result result = executeSearchTransform(request, ctx);
@ -411,7 +416,7 @@ public class SearchTransformIT extends ESIntegTestCase {
Template resultTemplate = result.executedRequest().template();
assertThat(resultTemplate, notNullValue());
assertThat(resultTemplate.getScript(), equalTo("test-script"));
assertThat(resultTemplate.getType(), equalTo(ScriptType.INDEXED));
assertThat(resultTemplate.getType(), equalTo(ScriptType.STORED));
}
public void testSearchOnDiskTemplate() throws Exception {
@ -466,7 +471,7 @@ public class SearchTransformIT extends ESIntegTestCase {
new ExecutableAlwaysCondition(logger),
null,
null,
new ExecutableActions(new ArrayList<ActionWrapper>()),
new ExecutableActions(new ArrayList<>()),
null,
new WatchStatus( new DateTime(40000, UTC), emptyMap())),
new DateTime(60000, UTC),

View File

@ -9,6 +9,7 @@ import org.elasticsearch.Version;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.search.SearchPhaseExecutionException;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.indices.TermsLookup;
import org.elasticsearch.plugins.Plugin;
@ -72,7 +73,7 @@ public class ShieldCachePermissionIT extends ShieldIntegTestCase {
public void loadData() {
index("data", "a", "1", "{ \"name\": \"John\", \"token\": \"token1\" }");
index("tokens", "tokens", "1", "{ \"group\": \"1\", \"tokens\": [\"token1\", \"token2\"] }");
client().preparePutIndexedScript().setOpType(IndexRequest.OpType.CREATE).setSource("{\n" +
client().admin().cluster().preparePutStoredScript().setSource(new BytesArray("{\n" +
"\"template\": {\n" +
" \"query\": {\n" +
" \"exists\": {\n" +
@ -80,7 +81,7 @@ public class ShieldCachePermissionIT extends ShieldIntegTestCase {
" }\n" +
" }\n" +
" }\n" +
"}")
"}"))
.setScriptLang("mustache")
.setId("testTemplate")
.execute().actionGet();
@ -110,7 +111,7 @@ public class ShieldCachePermissionIT extends ShieldIntegTestCase {
public void testThatScriptServiceDoesntLeakData() {
SearchResponse response = client().prepareSearch("data").setTypes("a")
.setTemplate(new Template("testTemplate", ScriptService.ScriptType.INDEXED, MustacheScriptEngineService.NAME, null,
.setTemplate(new Template("testTemplate", ScriptService.ScriptType.STORED, MustacheScriptEngineService.NAME, null,
Collections.<String, Object>singletonMap("name", "token")))
.execute().actionGet();
assertThat(response.isTimedOut(), is(false));
@ -121,7 +122,7 @@ public class ShieldCachePermissionIT extends ShieldIntegTestCase {
response = client().filterWithHeader(Collections.singletonMap("Authorization", basicAuthHeaderValue(READ_ONE_IDX_USER,
new SecuredString("changeme".toCharArray()))))
.prepareSearch("data").setTypes("a")
.setTemplate(new Template("testTemplate", ScriptService.ScriptType.INDEXED, MustacheScriptEngineService.NAME, null,
.setTemplate(new Template("testTemplate", ScriptService.ScriptType.STORED, MustacheScriptEngineService.NAME, null,
Collections.<String, Object>singletonMap("name", "token")))
.execute().actionGet();
fail("search phase exception should have been thrown! response was:\n" + response.toString());

View File

@ -12,11 +12,11 @@ import org.elasticsearch.script.MockMustacheScriptEngine;
import org.elasticsearch.script.mustache.MustachePlugin;
import org.elasticsearch.test.junit.annotations.Network;
import org.elasticsearch.watcher.actions.slack.SlackAction;
import org.elasticsearch.watcher.actions.slack.service.SentMessages;
import org.elasticsearch.watcher.actions.slack.service.SlackAccount;
import org.elasticsearch.watcher.actions.slack.service.SlackService;
import org.elasticsearch.watcher.actions.slack.service.message.Attachment;
import org.elasticsearch.watcher.actions.slack.service.message.SlackMessage;
import org.elasticsearch.xpack.notification.slack.SentMessages;
import org.elasticsearch.xpack.notification.slack.SlackAccount;
import org.elasticsearch.xpack.notification.slack.SlackService;
import org.elasticsearch.xpack.notification.slack.message.Attachment;
import org.elasticsearch.xpack.notification.slack.message.SlackMessage;
import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTestCase;
import org.elasticsearch.watcher.transport.actions.put.PutWatchResponse;
@ -71,7 +71,7 @@ public class SlackServiceIT extends AbstractWatcherIntegrationTestCase {
.put(super.nodeSettings(nodeOrdinal))
// this is for the `test-watcher-integration` group level integration in HipChat
.put("xpack.watcher.actions.slack.service.account.test_account.url",
.put("xpack.notification.slack.service.account.test_account.url",
"https://hooks.slack.com/services/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")
.build();
}

View File

@ -6,6 +6,9 @@
package org.elasticsearch.smoketest;
import com.fasterxml.jackson.core.io.JsonStringEncoder;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentType;
@ -18,7 +21,7 @@ import org.elasticsearch.script.ScriptSettings;
import org.elasticsearch.script.mustache.MustacheScriptEngineService;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.watcher.ResourceWatcherService;
import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy;
import org.elasticsearch.watcher.support.ScriptServiceProxy;
import org.elasticsearch.watcher.support.text.DefaultTextTemplateEngine;
import org.elasticsearch.watcher.support.text.TextTemplate;
import org.elasticsearch.watcher.support.text.TextTemplateEngine;
@ -59,7 +62,9 @@ public class WatcherTemplateTests extends ESTestCase {
ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, registry);
ScriptService scriptService = new ScriptService(setting, environment, engines, resourceWatcherService, scriptEngineRegistry,
registry, scriptSettings);
engine = new DefaultTextTemplateEngine(Settings.EMPTY, ScriptServiceProxy.of(scriptService));
ClusterService clusterService = Mockito.mock(ClusterService.class);
Mockito.when(clusterService.state()).thenReturn(ClusterState.builder(new ClusterName("_name")).build());
engine = new DefaultTextTemplateEngine(Settings.EMPTY, ScriptServiceProxy.of(scriptService, clusterService));
}
public void testEscaping() throws Exception {

View File

@ -11,7 +11,7 @@ esplugin {
}
ext.versions = [
okhttp: '2.3.0'
okhttp: '2.7.5'
]
// TODO: fix this! https://github.com/elastic/x-plugins/issues/1066
@ -32,9 +32,10 @@ dependencies {
// watcher deps
compile 'com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:r239'
compile 'com.google.guava:guava:16.0.1' // needed by watcher for the html sanitizer and shield tests for jimfs
compile 'com.google.code.findbugs:jsr305:3.0.1' // TODO: remove this
compile 'com.sun.mail:javax.mail:1.5.3'
testCompile 'org.subethamail:subethasmtp:3.1.7'
// needed for subethasmtp, has @GuardedBy annotation
testCompile 'com.google.code.findbugs:jsr305:3.0.1'
// common test deps
testCompile 'org.elasticsearch:securemock:1.2'
@ -45,7 +46,7 @@ dependencies {
testCompile "com.squareup.okhttp:mockwebserver:${versions.okhttp}"
testCompile "com.squareup.okhttp:okhttp:${versions.okhttp}"
testCompile "com.squareup.okhttp:okhttp-ws:${versions.okhttp}"
testCompile 'com.squareup.okio:okio:1.3.0'
testCompile 'com.squareup.okio:okio:1.6.0'
testCompile 'org.bouncycastle:bcprov-jdk15on:1.50'
}
@ -187,14 +188,18 @@ modifyPom { MavenPom pom ->
// find the 'base' dependency and replace it with the correct name because the project name is
// always used even when the pom of the other project is correct
for (Node depNode : depsNodes.get(0).children()) {
Iterator<Node> childNodeIter = depsNodes.get(0).children().iterator()
while (childNodeIter.hasNext()) {
Node depNode = childNodeIter.next()
String groupId = depNode.get('groupId').get(0).text()
Node artifactIdNode = depNode.get('artifactId').get(0)
String artifactId = artifactIdNode.text()
String scope = depNode.get("scope").get(0).text()
if (groupId.equals('org.elasticsearch') && artifactId.equals('base')) {
artifactIdNode.replaceNode(new Node(null, 'artifactId', 'license-core'))
return
} else if ('test'.equals(scope)) {
childNodeIter.remove()
}
}
}
}
}

View File

@ -5,10 +5,6 @@
*/
package org.elasticsearch.graph;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import org.elasticsearch.action.ActionModule;
import org.elasticsearch.common.component.LifecycleComponent;
import org.elasticsearch.common.inject.Module;
@ -18,12 +14,13 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsModule;
import org.elasticsearch.graph.action.GraphExploreAction;
import org.elasticsearch.graph.action.TransportGraphExploreAction;
import org.elasticsearch.graph.license.GraphLicensee;
import org.elasticsearch.graph.license.GraphModule;
import org.elasticsearch.graph.rest.action.RestGraphAction;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.xpack.XPackPlugin;
import java.util.Collection;
import java.util.Collections;
public class Graph extends Plugin {
public static final String NAME = "graph";
@ -48,8 +45,20 @@ public class Graph extends Plugin {
public static boolean enabled(Settings settings) {
return XPackPlugin.featureEnabled(settings, NAME, true);
}
}
public Collection<Module> nodeModules() {
return Collections.singletonList(new GraphModule(enabled, transportClientMode));
}
@Override
public Collection<Class<? extends LifecycleComponent>> nodeServices() {
if (enabled == false|| transportClientMode) {
return Collections.emptyList();
}
return Collections.singletonList(GraphLicensee.class);
}
public void onModule(ActionModule actionModule) {
if (enabled) {
actionModule.registerAction(GraphExploreAction.INSTANCE, TransportGraphExploreAction.class);
@ -65,23 +74,5 @@ public class Graph extends Plugin {
public void onModule(SettingsModule module) {
module.registerSetting(Setting.boolSetting(XPackPlugin.featureEnabledSetting(NAME), true, Setting.Property.NodeScope));
}
public Collection<Module> nodeModules() {
if (enabled == false|| transportClientMode) {
return Collections.emptyList();
}
return Arrays.<Module> asList(new GraphModule());
}
@Override
public Collection<Class<? extends LifecycleComponent>> nodeServices() {
if (enabled == false|| transportClientMode) {
return Collections.emptyList();
}
return Arrays.<Class<? extends LifecycleComponent>>asList(
GraphLicensee.class
);
}
}

View File

@ -0,0 +1,46 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.graph;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.xpack.XPackFeatureSet;
/**
*
*/
public class GraphFeatureSet implements XPackFeatureSet {
private final boolean enabled;
private final GraphLicensee licensee;
@Inject
public GraphFeatureSet(Settings settings, @Nullable GraphLicensee licensee) {
this.enabled = Graph.enabled(settings);
this.licensee = licensee;
}
@Override
public String name() {
return Graph.NAME;
}
@Override
public String description() {
return "Graph Data Exploration for the Elastic Stack";
}
@Override
public boolean available() {
return licensee != null && licensee.isAvailable();
}
@Override
public boolean enabled() {
return enabled;
}
}

View File

@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.graph.license;
package org.elasticsearch.graph;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject;
@ -13,7 +13,6 @@ import org.elasticsearch.license.core.License.OperationMode;
import org.elasticsearch.license.plugin.core.AbstractLicenseeComponent;
import org.elasticsearch.license.plugin.core.LicenseState;
import org.elasticsearch.license.plugin.core.LicenseeRegistry;
import org.elasticsearch.graph.Graph;
public class GraphLicensee extends AbstractLicenseeComponent<GraphLicensee> {
@ -60,7 +59,7 @@ public class GraphLicensee extends AbstractLicenseeComponent<GraphLicensee> {
*
* @return {@code true} as long as the license is valid. Otherwise {@code false}.
*/
public boolean isGraphExploreEnabled() {
public boolean isAvailable() {
// status is volatile
Status localStatus = status;
OperationMode operationMode = localStatus.getMode();

View File

@ -0,0 +1,35 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.graph;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.inject.util.Providers;
import org.elasticsearch.xpack.XPackPlugin;
/**
*
*/
public class GraphModule extends AbstractModule {
private final boolean enabled;
private final boolean transportClientNode;
public GraphModule(boolean enabled, boolean transportClientNode) {
this.enabled = enabled;
this.transportClientNode = transportClientNode;
}
@Override
protected void configure() {
XPackPlugin.bindFeatureSet(binder(), GraphFeatureSet.class);
if (enabled && transportClientNode == false) {
bind(GraphLicensee.class).asEagerSingleton();
} else {
bind(GraphLicensee.class).toProvider(Providers.of(null));
}
}
}

View File

@ -15,7 +15,6 @@ import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilderString;
import org.elasticsearch.graph.action.Connection.ConnectionId;
import org.elasticsearch.graph.action.Vertex.VertexId;
@ -149,12 +148,12 @@ public class GraphExploreResponse extends ActionResponse implements ToXContent {
}
static final class Fields {
static final XContentBuilderString TOOK = new XContentBuilderString("took");
static final XContentBuilderString TIMED_OUT = new XContentBuilderString("timed_out");
static final XContentBuilderString INDICES = new XContentBuilderString("_indices");
static final XContentBuilderString FAILURES = new XContentBuilderString("failures");
static final XContentBuilderString VERTICES = new XContentBuilderString("vertices");
static final XContentBuilderString CONNECTIONS = new XContentBuilderString("connections");
static final String TOOK = "took";
static final String TIMED_OUT = "timed_out";
static final String INDICES = "_indices";
static final String FAILURES = "failures";
static final String VERTICES = "vertices";
static final String CONNECTIONS = "connections";
}

View File

@ -21,22 +21,22 @@ import java.util.List;
* A Hop represents one of potentially many stages in a graph exploration.
* Each Hop identifies one or more fields in which it will attempt to find
* terms that are significantly connected to the previous Hop. Each field is identified
* using a {@link VertexRequest}
*
* using a {@link VertexRequest}
*
* <p>An example series of Hops on webserver logs would be:
* <ol>
* <li>an initial Hop to find
* <li>an initial Hop to find
* the top ten IPAddresses trying to access urls containing the word "admin"</li>
* <li>a secondary Hop to see which other URLs those IPAddresses were trying to access</li>
* </ol>
*
* </ol>
*
* <p>
* Optionally, each hop can contain a "guiding query" that further limits the set of documents considered.
* In our weblog example above we might choose to constrain the second hop to only look at log records that
* In our weblog example above we might choose to constrain the second hop to only look at log records that
* had a reponse code of 404.
* </p>
* <p>
* If absent, the list of {@link VertexRequest}s is inherited from the prior Hop's list to avoid repeating
* If absent, the list of {@link VertexRequest}s is inherited from the prior Hop's list to avoid repeating
* the fields that will be examined at each stage.
* </p>
*
@ -64,12 +64,7 @@ public class Hop {
}
void writeTo(StreamOutput out) throws IOException {
if (guidingQuery == null) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
out.writeQuery(guidingQuery);
}
out.writeOptionalNamedWriteable(guidingQuery);
if (vertices == null) {
out.writeVInt(0);
} else {
@ -81,9 +76,7 @@ public class Hop {
}
void readFrom(StreamInput in) throws IOException {
if (in.readBoolean()) {
guidingQuery = in.readQuery();
}
guidingQuery = in.readOptionalNamedWriteable(QueryBuilder.class);
int size = in.readVInt();
if (size > 0) {
vertices = new ArrayList<>();
@ -103,9 +96,9 @@ public class Hop {
}
/**
* Add a field in which this {@link Hop} will look for terms that are highly linked to
* previous hops and optionally the guiding query.
*
* Add a field in which this {@link Hop} will look for terms that are highly linked to
* previous hops and optionally the guiding query.
*
* @param fieldName a field in the chosen index
*/
public VertexRequest addVertexRequest(String fieldName) {
@ -120,8 +113,8 @@ public class Hop {
/**
* An optional parameter that focuses the exploration on documents that
* match the given query.
*
* match the given query.
*
* @param queryBuilder any query
*/
public void guidingQuery(QueryBuilder<?> queryBuilder) {
@ -146,4 +139,4 @@ public class Hop {
VertexRequest getVertexRequest(int requestNumber) {
return getEffectiveVertexRequests().get(requestNumber);
}
}
}

View File

@ -24,7 +24,7 @@ import org.elasticsearch.common.util.CollectionUtils;
import org.elasticsearch.graph.action.Connection.ConnectionId;
import org.elasticsearch.graph.action.GraphExploreRequest.TermBoost;
import org.elasticsearch.graph.action.Vertex.VertexId;
import org.elasticsearch.graph.license.GraphLicensee;
import org.elasticsearch.graph.GraphLicensee;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.license.plugin.core.LicenseUtils;
@ -85,7 +85,7 @@ public class TransportGraphExploreAction extends HandledTransportAction<GraphExp
@Override
protected void doExecute(GraphExploreRequest request, ActionListener<GraphExploreResponse> listener) {
if (licensee.isGraphExploreEnabled()) {
if (licensee.isAvailable()) {
new AsyncGraphAction(request, listener).start();
} else {
listener.onFailure(LicenseUtils.newComplianceException(GraphLicensee.ID));

View File

@ -6,6 +6,7 @@
package org.elasticsearch.graph.license;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.graph.GraphLicensee;
import org.elasticsearch.license.core.License.OperationMode;
import org.elasticsearch.license.plugin.core.AbstractLicenseeTestCase;
@ -95,10 +96,10 @@ public class LicenseTests extends AbstractLicenseeTestCase {
}
private void assertLicensePlatinumTrialBehaviour(GraphLicensee graphLicensee) {
assertThat("Expected graph exploration to be allowed", graphLicensee.isGraphExploreEnabled(), is(true));
assertThat("Expected graph exploration to be allowed", graphLicensee.isAvailable(), is(true));
}
private void assertLicenseBasicOrGoldOrNoneOrExpiredBehaviour(GraphLicensee graphLicensee) {
assertThat("Expected graph exploration not to be allowed", graphLicensee.isGraphExploreEnabled(), is(false));
assertThat("Expected graph exploration not to be allowed", graphLicensee.isAvailable(), is(false));
}
}

View File

@ -19,7 +19,7 @@ import org.elasticsearch.graph.action.Vertex;
import org.elasticsearch.graph.action.VertexRequest;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.ScriptQueryBuilder;
import org.elasticsearch.marvel.Marvel;
import org.elasticsearch.marvel.Monitoring;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.script.AbstractSearchScript;
import org.elasticsearch.script.ExecutableScript;
@ -126,7 +126,7 @@ public class GraphTests extends ESSingleNodeTestCase {
// Disable Shield otherwise authentication failures happen creating indices.
Builder newSettings = Settings.builder();
newSettings.put(XPackPlugin.featureEnabledSetting(Security.NAME), false);
newSettings.put(XPackPlugin.featureEnabledSetting(Marvel.NAME), false);
newSettings.put(XPackPlugin.featureEnabledSetting(Monitoring.NAME), false);
newSettings.put(XPackPlugin.featureEnabledSetting(Watcher.NAME), false);
return newSettings.build();
}

View File

@ -24,7 +24,7 @@ import org.elasticsearch.license.plugin.core.LicenseState;
import org.elasticsearch.license.plugin.core.LicensesManagerService;
import org.elasticsearch.license.plugin.core.LicensesMetaData;
import org.elasticsearch.license.plugin.core.LicensesStatus;
import org.elasticsearch.marvel.Marvel;
import org.elasticsearch.marvel.Monitoring;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.shield.Security;
import org.elasticsearch.test.ESIntegTestCase;
@ -49,7 +49,7 @@ public abstract class AbstractLicensesIntegrationTestCase extends ESIntegTestCas
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(XPackPlugin.featureEnabledSetting(Security.NAME), false)
.put(XPackPlugin.featureEnabledSetting(Marvel.NAME), false)
.put(XPackPlugin.featureEnabledSetting(Monitoring.NAME), false)
.put(XPackPlugin.featureEnabledSetting(Watcher.NAME), false)
.put(XPackPlugin.featureEnabledSetting(Graph.NAME), false)
.build();

View File

@ -1,20 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.marvel;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.marvel.agent.AgentService;
import org.elasticsearch.marvel.cleaner.CleanerService;
public class MarvelModule extends AbstractModule {
@Override
protected void configure() {
bind(MarvelSettings.class).asEagerSingleton();
bind(AgentService.class).asEagerSingleton();
bind(CleanerService.class).asEagerSingleton();
}
}

View File

@ -18,16 +18,16 @@ import org.elasticsearch.marvel.agent.collector.CollectorModule;
import org.elasticsearch.marvel.agent.exporter.ExporterModule;
import org.elasticsearch.marvel.cleaner.CleanerService;
import org.elasticsearch.marvel.client.MonitoringClientModule;
import org.elasticsearch.marvel.license.LicenseModule;
import org.elasticsearch.marvel.license.MarvelLicensee;
import org.elasticsearch.marvel.rest.action.RestMonitoringBulkAction;
import org.elasticsearch.marvel.support.init.proxy.MonitoringClientProxy;
import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.common.init.LazyInitializationModule;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
/**
* This class activates/deactivates the monitoring modules depending if we're running a node client, transport client or tribe client:
@ -35,7 +35,7 @@ import java.util.Collections;
* - transport clients: only action/transport actions are binded
* - tribe clients: everything is disables by default but can be enabled per tribe cluster
*/
public class Marvel {
public class Monitoring {
public static final String NAME = "monitoring";
@ -43,9 +43,9 @@ public class Marvel {
private final boolean enabled;
private final boolean transportClientMode;
public Marvel(Settings settings) {
public Monitoring(Settings settings) {
this.settings = settings;
this.enabled = MarvelSettings.ENABLED.get(settings);
this.enabled = MonitoringSettings.ENABLED.get(settings);
this.transportClientMode = XPackPlugin.transportClientMode(settings);
}
@ -58,29 +58,27 @@ public class Marvel {
}
public Collection<Module> nodeModules() {
if (enabled == false || transportClientMode) {
return Collections.emptyList();
List<Module> modules = new ArrayList<>();
modules.add(new MonitoringModule(enabled, transportClientMode));
if (enabled && transportClientMode == false) {
modules.add(new CollectorModule());
modules.add(new ExporterModule(settings));
modules.add(new MonitoringClientModule());
}
return Arrays.<Module>asList(
new MarvelModule(),
new LicenseModule(),
new CollectorModule(),
new ExporterModule(settings),
new MonitoringClientModule());
return modules;
}
public Collection<Class<? extends LifecycleComponent>> nodeServices() {
if (enabled == false || transportClientMode) {
return Collections.emptyList();
}
return Arrays.<Class<? extends LifecycleComponent>>asList(MarvelLicensee.class,
return Arrays.<Class<? extends LifecycleComponent>>asList(MonitoringLicensee.class,
AgentService.class,
CleanerService.class);
}
public void onModule(SettingsModule module) {
MarvelSettings.register(module);
MonitoringSettings.register(module);
}
public void onModule(ActionModule module) {

View File

@ -0,0 +1,46 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.marvel;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.xpack.XPackFeatureSet;
/**
*
*/
public class MonitoringFeatureSet implements XPackFeatureSet {
private final boolean enabled;
private final MonitoringLicensee licensee;
@Inject
public MonitoringFeatureSet(Settings settings, @Nullable MonitoringLicensee licensee) {
this.enabled = MonitoringSettings.ENABLED.get(settings);
this.licensee = licensee;
}
@Override
public String name() {
return Monitoring.NAME;
}
@Override
public String description() {
return "Monitoring for the Elastic Stack";
}
@Override
public boolean available() {
return licensee != null && licensee.available();
}
@Override
public boolean enabled() {
return enabled;
}
}

View File

@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.marvel.license;
package org.elasticsearch.marvel;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject;
@ -15,8 +15,6 @@ import org.elasticsearch.license.plugin.core.AbstractLicenseeComponent;
import org.elasticsearch.license.plugin.core.LicenseState;
import org.elasticsearch.license.plugin.core.Licensee;
import org.elasticsearch.license.plugin.core.LicenseeRegistry;
import org.elasticsearch.marvel.Marvel;
import org.elasticsearch.marvel.MarvelSettings;
/**
* {@code MarvelLicensee} determines whether certain features of Monitoring are enabled or disabled.
@ -27,11 +25,11 @@ import org.elasticsearch.marvel.MarvelSettings;
* <li>Cleaning up (deleting) older indices.</li>
* </ul>
*/
public class MarvelLicensee extends AbstractLicenseeComponent<MarvelLicensee> implements Licensee {
public class MonitoringLicensee extends AbstractLicenseeComponent<MonitoringLicensee> implements Licensee {
@Inject
public MarvelLicensee(Settings settings, LicenseeRegistry clientService) {
super(settings, Marvel.NAME, clientService);
public MonitoringLicensee(Settings settings, LicenseeRegistry clientService) {
super(settings, Monitoring.NAME, clientService);
}
/**
@ -67,7 +65,7 @@ public class MarvelLicensee extends AbstractLicenseeComponent<MarvelLicensee> im
newLicense.type(), newLicense.type(), newLicense.type()),
LoggerMessageFormat.format(
"Automatic index cleanup is locked to {} days for clusters with [{}] license.",
MarvelSettings.HISTORY_DURATION.getDefault(Settings.EMPTY).days(), newLicense.type())
MonitoringSettings.HISTORY_DURATION.getDefault(Settings.EMPTY).days(), newLicense.type())
};
}
}
@ -76,6 +74,15 @@ public class MarvelLicensee extends AbstractLicenseeComponent<MarvelLicensee> im
return Strings.EMPTY_ARRAY;
}
/**
* Monitoring is always available regardless of the license type (operation mode)
*
* @return true
*/
public boolean available() {
return true;
}
/**
* Determine if the index cleaning service is enabled.
* <p>

View File

@ -0,0 +1,37 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.marvel;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.inject.util.Providers;
import org.elasticsearch.marvel.agent.AgentService;
import org.elasticsearch.marvel.cleaner.CleanerService;
import org.elasticsearch.xpack.XPackPlugin;
public class MonitoringModule extends AbstractModule {
private final boolean enabled;
private final boolean transportClientMode;
public MonitoringModule(boolean enabled, boolean transportClientMode) {
this.enabled = enabled;
this.transportClientMode = transportClientMode;
}
@Override
protected void configure() {
XPackPlugin.bindFeatureSet(binder(), MonitoringFeatureSet.class);
if (enabled && transportClientMode == false) {
bind(MonitoringLicensee.class).asEagerSingleton();
bind(MonitoringSettings.class).asEagerSingleton();
bind(AgentService.class).asEagerSingleton();
bind(CleanerService.class).asEagerSingleton();
} else {
bind(MonitoringLicensee.class).toProvider(Providers.of(null));
}
}
}

View File

@ -25,7 +25,7 @@ import static org.elasticsearch.common.settings.Setting.groupSetting;
import static org.elasticsearch.common.settings.Setting.listSetting;
import static org.elasticsearch.common.settings.Setting.timeSetting;
public class MarvelSettings extends AbstractComponent {
public class MonitoringSettings extends AbstractComponent {
public static final String LEGACY_DATA_INDEX_NAME = ".marvel-es-data";
@ -40,7 +40,7 @@ public class MarvelSettings extends AbstractComponent {
* Determines whether monitoring is enabled/disabled
*/
public static final Setting<Boolean> ENABLED =
new Setting<>(XPackPlugin.featureEnabledSetting(Marvel.NAME),
new Setting<>(XPackPlugin.featureEnabledSetting(Monitoring.NAME),
// By default, marvel is disabled on tribe nodes
(s) -> String.valueOf(!XPackPlugin.isTribeNode(s) && !XPackPlugin.isTribeClientNode(s)),
@ -153,7 +153,7 @@ public class MarvelSettings extends AbstractComponent {
private volatile String[] indices;
@Inject
public MarvelSettings(Settings settings, ClusterSettings clusterSettings) {
public MonitoringSettings(Settings settings, ClusterSettings clusterSettings) {
super(settings);
setIndexStatsTimeout(INDEX_STATS_TIMEOUT.get(settings));
@ -233,7 +233,7 @@ public class MarvelSettings extends AbstractComponent {
* @return The key prefixed by the product prefixes.
*/
static String key(String key) {
return XPackPlugin.featureSettingPrefix(Marvel.NAME) + "." + key;
return XPackPlugin.featureSettingPrefix(Monitoring.NAME) + "." + key;
}
}

View File

@ -24,6 +24,9 @@ public class MonitoringBulkDoc extends MonitoringDoc {
super(monitoringId, monitoringVersion);
}
/**
* Read from a stream.
*/
public MonitoringBulkDoc(StreamInput in) throws IOException {
super(in);
index = in.readOptionalString();
@ -32,6 +35,15 @@ public class MonitoringBulkDoc extends MonitoringDoc {
source = in.readBytesReference();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeOptionalString(index);
out.writeOptionalString(type);
out.writeOptionalString(id);
out.writeBytesReference(source);
}
public String getIndex() {
return index;
}
@ -63,18 +75,4 @@ public class MonitoringBulkDoc extends MonitoringDoc {
public void setSource(BytesReference source) {
this.source = source;
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeOptionalString(index);
out.writeOptionalString(type);
out.writeOptionalString(id);
out.writeBytesReference(source);
}
@Override
public MonitoringBulkDoc readFrom(StreamInput in) throws IOException {
return new MonitoringBulkDoc(in);
}
}

View File

@ -73,7 +73,7 @@ public class MonitoringBulkResponse extends ActionResponse {
out.writeOptionalWriteable(error);
}
public static class Error implements Writeable<Error>, ToXContent {
public static class Error implements Writeable, ToXContent {
private final Throwable cause;
private final RestStatus status;
@ -87,6 +87,11 @@ public class MonitoringBulkResponse extends ActionResponse {
this(in.<Throwable>readThrowable());
}
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeThrowable(getCause());
}
/**
* The failure message.
*/
@ -108,16 +113,6 @@ public class MonitoringBulkResponse extends ActionResponse {
return cause;
}
@Override
public Error readFrom(StreamInput in) throws IOException {
return new Error(in);
}
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeThrowable(getCause());
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();

View File

@ -16,7 +16,7 @@ import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.CollectionUtils;
import org.elasticsearch.common.util.concurrent.EsExecutors;
import org.elasticsearch.common.util.concurrent.ReleasableLock;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.agent.collector.Collector;
import org.elasticsearch.marvel.agent.collector.cluster.ClusterStatsCollector;
import org.elasticsearch.marvel.agent.exporter.ExportException;
@ -54,12 +54,12 @@ public class AgentService extends AbstractLifecycleComponent<AgentService> {
@Inject
public AgentService(Settings settings, ClusterSettings clusterSettings, Set<Collector> collectors, Exporters exporters) {
super(settings);
this.samplingIntervalMillis = MarvelSettings.INTERVAL.get(settings).millis();
this.settingsCollectors = MarvelSettings.COLLECTORS.get(settings).toArray(new String[0]);
this.samplingIntervalMillis = MonitoringSettings.INTERVAL.get(settings).millis();
this.settingsCollectors = MonitoringSettings.COLLECTORS.get(settings).toArray(new String[0]);
this.collectors = Collections.unmodifiableSet(filterCollectors(collectors, settingsCollectors));
this.exporters = exporters;
clusterSettings.addSettingsUpdateConsumer(MarvelSettings.INTERVAL, this::setInterval);
clusterSettings.addSettingsUpdateConsumer(MonitoringSettings.INTERVAL, this::setInterval);
}
private void setInterval(TimeValue interval) {

View File

@ -12,10 +12,10 @@ import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.component.AbstractLifecycleComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.MonitoredSystem;
import org.elasticsearch.marvel.agent.exporter.MonitoringDoc;
import org.elasticsearch.marvel.license.MarvelLicensee;
import org.elasticsearch.marvel.MonitoringLicensee;
import java.util.Collection;
@ -24,16 +24,16 @@ public abstract class AbstractCollector<T> extends AbstractLifecycleComponent<T>
private final String name;
protected final ClusterService clusterService;
protected final MarvelSettings marvelSettings;
protected final MarvelLicensee licensee;
protected final MonitoringSettings monitoringSettings;
protected final MonitoringLicensee licensee;
@Inject
public AbstractCollector(Settings settings, String name, ClusterService clusterService,
MarvelSettings marvelSettings, MarvelLicensee licensee) {
MonitoringSettings monitoringSettings, MonitoringLicensee licensee) {
super(settings);
this.name = name;
this.clusterService = clusterService;
this.marvelSettings = marvelSettings;
this.monitoringSettings = monitoringSettings;
this.licensee = licensee;
}

View File

@ -13,10 +13,10 @@ import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.agent.collector.AbstractCollector;
import org.elasticsearch.marvel.agent.exporter.MonitoringDoc;
import org.elasticsearch.marvel.license.MarvelLicensee;
import org.elasticsearch.marvel.MonitoringLicensee;
import org.elasticsearch.shield.InternalClient;
import java.util.ArrayList;
@ -38,8 +38,8 @@ public class ClusterStateCollector extends AbstractCollector<ClusterStateCollect
@Inject
public ClusterStateCollector(Settings settings, ClusterService clusterService,
MarvelSettings marvelSettings, MarvelLicensee marvelLicensee, InternalClient client) {
super(settings, NAME, clusterService, marvelSettings, marvelLicensee);
MonitoringSettings monitoringSettings, MonitoringLicensee licensee, InternalClient client) {
super(settings, NAME, clusterService, monitoringSettings, licensee);
this.client = client;
}
@ -58,7 +58,7 @@ public class ClusterStateCollector extends AbstractCollector<ClusterStateCollect
long timestamp = System.currentTimeMillis();
DiscoveryNode sourceNode = localNode();
ClusterHealthResponse clusterHealth = client.admin().cluster().prepareHealth().get(marvelSettings.clusterStateTimeout());
ClusterHealthResponse clusterHealth = client.admin().cluster().prepareHealth().get(monitoringSettings.clusterStateTimeout());
// Adds a cluster_state document with associated status
ClusterStateMonitoringDoc clusterStateDoc = new ClusterStateMonitoringDoc(monitoringId(), monitoringVersion());

View File

@ -16,10 +16,10 @@ import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.plugin.core.LicenseUtils;
import org.elasticsearch.license.plugin.core.LicensesManagerService;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.agent.collector.AbstractCollector;
import org.elasticsearch.marvel.agent.exporter.MonitoringDoc;
import org.elasticsearch.marvel.license.MarvelLicensee;
import org.elasticsearch.marvel.MonitoringLicensee;
import org.elasticsearch.shield.InternalClient;
import java.util.ArrayList;
@ -47,9 +47,9 @@ public class ClusterStatsCollector extends AbstractCollector<ClusterStatsCollect
@Inject
public ClusterStatsCollector(Settings settings, ClusterService clusterService,
MarvelSettings marvelSettings, MarvelLicensee marvelLicensee, InternalClient client,
MonitoringSettings monitoringSettings, MonitoringLicensee licensee, InternalClient client,
LicensesManagerService licensesManagerService, ClusterName clusterName) {
super(settings, NAME, clusterService, marvelSettings, marvelLicensee);
super(settings, NAME, clusterService, monitoringSettings, licensee);
this.client = client;
this.clusterName = clusterName;
this.licensesManagerService = licensesManagerService;
@ -68,7 +68,7 @@ public class ClusterStatsCollector extends AbstractCollector<ClusterStatsCollect
// Retrieves cluster stats
ClusterStatsResponse clusterStats = null;
try {
clusterStats = client.admin().cluster().prepareClusterStats().get(marvelSettings.clusterStatsTimeout());
clusterStats = client.admin().cluster().prepareClusterStats().get(monitoringSettings.clusterStatsTimeout());
} catch (ElasticsearchSecurityException e) {
if (LicenseUtils.isLicenseExpiredException(e)) {
logger.trace("collector [{}] - unable to collect data because of expired license", e, name());

View File

@ -13,10 +13,10 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.agent.collector.AbstractCollector;
import org.elasticsearch.marvel.agent.exporter.MonitoringDoc;
import org.elasticsearch.marvel.license.MarvelLicensee;
import org.elasticsearch.marvel.MonitoringLicensee;
import org.elasticsearch.shield.InternalClient;
import org.elasticsearch.shield.Security;
@ -40,8 +40,8 @@ public class IndexRecoveryCollector extends AbstractCollector<IndexRecoveryColle
@Inject
public IndexRecoveryCollector(Settings settings, ClusterService clusterService,
MarvelSettings marvelSettings, MarvelLicensee marvelLicensee, InternalClient client) {
super(settings, NAME, clusterService, marvelSettings, marvelLicensee);
MonitoringSettings monitoringSettings, MonitoringLicensee licensee, InternalClient client) {
super(settings, NAME, clusterService, monitoringSettings, licensee);
this.client = client;
}
@ -55,10 +55,10 @@ public class IndexRecoveryCollector extends AbstractCollector<IndexRecoveryColle
List<MonitoringDoc> results = new ArrayList<>(1);
try {
RecoveryResponse recoveryResponse = client.admin().indices().prepareRecoveries()
.setIndices(marvelSettings.indices())
.setIndices(monitoringSettings.indices())
.setIndicesOptions(IndicesOptions.lenientExpandOpen())
.setActiveOnly(marvelSettings.recoveryActiveOnly())
.get(marvelSettings.recoveryTimeout());
.setActiveOnly(monitoringSettings.recoveryActiveOnly())
.get(monitoringSettings.recoveryTimeout());
if (recoveryResponse.hasRecoveries()) {
IndexRecoveryMonitoringDoc indexRecoveryDoc = new IndexRecoveryMonitoringDoc(monitoringId(), monitoringVersion());
@ -69,7 +69,7 @@ public class IndexRecoveryCollector extends AbstractCollector<IndexRecoveryColle
results.add(indexRecoveryDoc);
}
} catch (IndexNotFoundException e) {
if (Security.enabled(settings) && IndexNameExpressionResolver.isAllIndices(Arrays.asList(marvelSettings.indices()))) {
if (Security.enabled(settings) && IndexNameExpressionResolver.isAllIndices(Arrays.asList(monitoringSettings.indices()))) {
logger.debug("collector [{}] - unable to collect data for missing index [{}]", name(), e.getIndex());
} else {
throw e;

View File

@ -15,10 +15,10 @@ import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.agent.collector.AbstractCollector;
import org.elasticsearch.marvel.agent.exporter.MonitoringDoc;
import org.elasticsearch.marvel.license.MarvelLicensee;
import org.elasticsearch.marvel.MonitoringLicensee;
import org.elasticsearch.shield.InternalClient;
import org.elasticsearch.shield.Security;
@ -42,8 +42,8 @@ public class IndexStatsCollector extends AbstractCollector<IndexStatsCollector>
@Inject
public IndexStatsCollector(Settings settings, ClusterService clusterService,
MarvelSettings marvelSettings, MarvelLicensee marvelLicensee, InternalClient client) {
super(settings, NAME, clusterService, marvelSettings, marvelLicensee);
MonitoringSettings monitoringSettings, MonitoringLicensee licensee, InternalClient client) {
super(settings, NAME, clusterService, monitoringSettings, licensee);
this.client = client;
}
@ -57,7 +57,7 @@ public class IndexStatsCollector extends AbstractCollector<IndexStatsCollector>
List<MonitoringDoc> results = new ArrayList<>();
try {
IndicesStatsResponse indicesStats = client.admin().indices().prepareStats()
.setIndices(marvelSettings.indices())
.setIndices(monitoringSettings.indices())
.setIndicesOptions(IndicesOptions.lenientExpandOpen())
.clear()
.setDocs(true)
@ -68,7 +68,7 @@ public class IndexStatsCollector extends AbstractCollector<IndexStatsCollector>
.setSegments(true)
.setStore(true)
.setRefresh(true)
.get(marvelSettings.indexStatsTimeout());
.get(monitoringSettings.indexStatsTimeout());
long timestamp = System.currentTimeMillis();
String clusterUUID = clusterUUID();
@ -83,7 +83,7 @@ public class IndexStatsCollector extends AbstractCollector<IndexStatsCollector>
results.add(indexStatsDoc);
}
} catch (IndexNotFoundException e) {
if (Security.enabled(settings) && IndexNameExpressionResolver.isAllIndices(Arrays.asList(marvelSettings.indices()))) {
if (Security.enabled(settings) && IndexNameExpressionResolver.isAllIndices(Arrays.asList(monitoringSettings.indices()))) {
logger.debug("collector [{}] - unable to collect data for missing index [{}]", name(), e.getIndex());
} else {
throw e;

View File

@ -13,10 +13,10 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.agent.collector.AbstractCollector;
import org.elasticsearch.marvel.agent.exporter.MonitoringDoc;
import org.elasticsearch.marvel.license.MarvelLicensee;
import org.elasticsearch.marvel.MonitoringLicensee;
import org.elasticsearch.shield.InternalClient;
import org.elasticsearch.shield.Security;
@ -37,8 +37,8 @@ public class IndicesStatsCollector extends AbstractCollector<IndicesStatsCollect
@Inject
public IndicesStatsCollector(Settings settings, ClusterService clusterService,
MarvelSettings marvelSettings, MarvelLicensee marvelLicensee, InternalClient client) {
super(settings, NAME, clusterService, marvelSettings, marvelLicensee);
MonitoringSettings monitoringSettings, MonitoringLicensee licensee, InternalClient client) {
super(settings, NAME, clusterService, monitoringSettings, licensee);
this.client = client;
}
@ -51,14 +51,14 @@ public class IndicesStatsCollector extends AbstractCollector<IndicesStatsCollect
protected Collection<MonitoringDoc> doCollect() throws Exception {
try {
IndicesStatsResponse indicesStats = client.admin().indices().prepareStats()
.setIndices(marvelSettings.indices())
.setIndices(monitoringSettings.indices())
.setIndicesOptions(IndicesOptions.lenientExpandOpen())
.clear()
.setDocs(true)
.setIndexing(true)
.setSearch(true)
.setStore(true)
.get(marvelSettings.indicesStatsTimeout());
.get(monitoringSettings.indicesStatsTimeout());
IndicesStatsMonitoringDoc indicesStatsDoc = new IndicesStatsMonitoringDoc(monitoringId(), monitoringVersion());
indicesStatsDoc.setClusterUUID(clusterUUID());
@ -68,7 +68,7 @@ public class IndicesStatsCollector extends AbstractCollector<IndicesStatsCollect
return Collections.singletonList(indicesStatsDoc);
} catch (IndexNotFoundException e) {
if (Security.enabled(settings) && IndexNameExpressionResolver.isAllIndices(Arrays.asList(marvelSettings.indices()))) {
if (Security.enabled(settings) && IndexNameExpressionResolver.isAllIndices(Arrays.asList(monitoringSettings.indices()))) {
logger.debug("collector [{}] - unable to collect data for missing index [{}]", name(), e.getIndex());
return Collections.emptyList();
}

View File

@ -17,10 +17,10 @@ import org.elasticsearch.cluster.routing.allocation.decider.DiskThresholdDecider
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.agent.collector.AbstractCollector;
import org.elasticsearch.marvel.agent.exporter.MonitoringDoc;
import org.elasticsearch.marvel.license.MarvelLicensee;
import org.elasticsearch.marvel.MonitoringLicensee;
import org.elasticsearch.shield.InternalClient;
import java.util.Collection;
@ -42,10 +42,10 @@ public class NodeStatsCollector extends AbstractCollector<NodeStatsCollector> {
private final DiskThresholdDecider diskThresholdDecider;
@Inject
public NodeStatsCollector(Settings settings, ClusterService clusterService, MarvelSettings marvelSettings,
MarvelLicensee marvelLicensee, InternalClient client,
public NodeStatsCollector(Settings settings, ClusterService clusterService, MonitoringSettings monitoringSettings,
MonitoringLicensee licensee, InternalClient client,
NodeEnvironment nodeEnvironment, DiskThresholdDecider diskThresholdDecider) {
super(settings, NAME, clusterService, marvelSettings, marvelLicensee);
super(settings, NAME, clusterService, monitoringSettings, licensee);
this.client = client;
this.nodeEnvironment = nodeEnvironment;
this.diskThresholdDecider = diskThresholdDecider;
@ -71,7 +71,17 @@ public class NodeStatsCollector extends AbstractCollector<NodeStatsCollector> {
request.process(true);
request.threadPool(true);
request.fs(true);
NodeStats nodeStats = client.admin().cluster().nodesStats(request).actionGet().getAt(0);
NodeStats[] nodesStatsResponses = client.admin().cluster().nodesStats(request).actionGet().getNodes();
// In unusual scenarios, node stats can be empty (e.g., closing an index in the middle of the request)
// Note: NodesStatsResponse does not currently override failures, so we cannot log the actual reason
if (nodesStatsResponses.length == 0) {
logger.debug("_local NodesStatsResponse is empty");
return null;
}
NodeStats nodeStats = nodesStatsResponses[0];
// Here we are calling directly the DiskThresholdDecider to retrieve the high watermark value
// It would be nicer to use a settings API like documented in #6732

View File

@ -13,10 +13,10 @@ import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.agent.collector.AbstractCollector;
import org.elasticsearch.marvel.agent.exporter.MonitoringDoc;
import org.elasticsearch.marvel.license.MarvelLicensee;
import org.elasticsearch.marvel.MonitoringLicensee;
import java.util.ArrayList;
import java.util.Arrays;
@ -36,8 +36,8 @@ public class ShardsCollector extends AbstractCollector<ShardsCollector> {
@Inject
public ShardsCollector(Settings settings, ClusterService clusterService,
MarvelSettings marvelSettings, MarvelLicensee marvelLicensee) {
super(settings, NAME, clusterService, marvelSettings, marvelLicensee);
MonitoringSettings monitoringSettings, MonitoringLicensee licensee) {
super(settings, NAME, clusterService, monitoringSettings, licensee);
}
@Override
@ -82,7 +82,8 @@ public class ShardsCollector extends AbstractCollector<ShardsCollector> {
}
private boolean match(String indexName) {
String[] indices = marvelSettings.indices();
return IndexNameExpressionResolver.isAllIndices(Arrays.asList(marvelSettings.indices())) || Regex.simpleMatch(indices, indexName);
String[] indices = monitoringSettings.indices();
return IndexNameExpressionResolver
.isAllIndices(Arrays.asList(monitoringSettings.indices())) || Regex.simpleMatch(indices, indexName);
}
}

View File

@ -10,7 +10,7 @@ import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import java.util.concurrent.atomic.AtomicBoolean;
@ -65,7 +65,7 @@ public abstract class Exporter implements AutoCloseable {
protected abstract void doClose();
protected String settingFQN(String setting) {
return MarvelSettings.EXPORTERS_SETTINGS.getKey() + config.name + "." + setting;
return MonitoringSettings.EXPORTERS_SETTINGS.getKey() + config.name + "." + setting;
}
public static class Config {

View File

@ -13,7 +13,7 @@ import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsException;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.agent.exporter.local.LocalExporter;
import org.elasticsearch.node.Node;
@ -48,7 +48,7 @@ public class Exporters extends AbstractLifecycleComponent<Exporters> implements
this.factories = factories;
this.clusterService = clusterService;
this.exporters = new AtomicReference<>(emptyMap());
clusterSettings.addSettingsUpdateConsumer(MarvelSettings.EXPORTERS_SETTINGS, this::setExportersSetting);
clusterSettings.addSettingsUpdateConsumer(MonitoringSettings.EXPORTERS_SETTINGS, this::setExportersSetting);
}
private void setExportersSetting(Settings exportersSetting) {
@ -63,7 +63,7 @@ public class Exporters extends AbstractLifecycleComponent<Exporters> implements
@Override
protected void doStart() {
exporters.set(initExporters(MarvelSettings.EXPORTERS_SETTINGS.get(settings)));
exporters.set(initExporters(MonitoringSettings.EXPORTERS_SETTINGS.get(settings)));
}
@Override

View File

@ -5,16 +5,8 @@
*/
package org.elasticsearch.marvel.agent.exporter;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.compress.NotXContentException;
import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.xpack.template.TemplateUtils;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Locale;
import java.util.regex.Pattern;
@ -29,56 +21,8 @@ public final class MarvelTemplateUtils {
private MarvelTemplateUtils() {
}
/**
* Loads a built-in template and returns its source.
*/
public static String loadTemplate(String id, Integer version) {
public static String loadTemplate(String id) {
String resource = String.format(Locale.ROOT, TEMPLATE_FILE, id);
try {
BytesReference source = load(resource);
validate(source);
return filter(source, version);
} catch (Exception e) {
throw new IllegalArgumentException("Unable to load monitoring template [" + resource + "]", e);
}
}
/**
* Loads a resource from the classpath and returns it as a {@link BytesReference}
*/
static BytesReference load(String name) throws IOException {
try (InputStream is = MarvelTemplateUtils.class.getResourceAsStream(name)) {
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
Streams.copy(is, out);
return new BytesArray(out.toByteArray());
}
}
}
/**
* Parses and validates that the source is not empty.
*/
static void validate(BytesReference source) {
if (source == null) {
throw new ElasticsearchParseException("Monitoring template must not be null");
}
try {
XContentHelper.convertToMap(source, false).v2();
} catch (NotXContentException e) {
throw new ElasticsearchParseException("Monitoring template must not be empty");
} catch (Exception e) {
throw new ElasticsearchParseException("Invalid monitoring template", e);
}
}
/**
* Filters the source: replaces any template version property with the version number
*/
static String filter(BytesReference source, Integer version) {
return Pattern.compile(TEMPLATE_VERSION_PROPERTY)
.matcher(source.toUtf8())
.replaceAll(String.valueOf(version));
return TemplateUtils.loadTemplate(resource, String.valueOf(TEMPLATE_VERSION), TEMPLATE_VERSION_PROPERTY);
}
}

View File

@ -11,7 +11,6 @@ import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilderString;
import java.io.IOException;
import java.util.Collections;
@ -21,7 +20,7 @@ import java.util.Map;
/**
* Base class for all monitoring documents.
*/
public class MonitoringDoc implements Writeable<MonitoringDoc> {
public class MonitoringDoc implements Writeable {
private final String monitoringId;
private final String monitoringVersion;
@ -35,6 +34,9 @@ public class MonitoringDoc implements Writeable<MonitoringDoc> {
this.monitoringVersion = monitoringVersion;
}
/**
* Read from a stream.
*/
public MonitoringDoc(StreamInput in) throws IOException {
this(in.readOptionalString(), in.readOptionalString());
clusterUUID = in.readOptionalString();
@ -42,6 +44,15 @@ public class MonitoringDoc implements Writeable<MonitoringDoc> {
sourceNode = in.readOptionalWriteable(Node::new);
}
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeOptionalString(getMonitoringId());
out.writeOptionalString(getMonitoringVersion());
out.writeOptionalString(getClusterUUID());
out.writeVLong(getTimestamp());
out.writeOptionalWriteable(getSourceNode());
}
public String getClusterUUID() {
return clusterUUID;
}
@ -87,21 +98,7 @@ public class MonitoringDoc implements Writeable<MonitoringDoc> {
"]";
}
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeOptionalString(getMonitoringId());
out.writeOptionalString(getMonitoringVersion());
out.writeOptionalString(getClusterUUID());
out.writeVLong(getTimestamp());
out.writeOptionalWriteable(getSourceNode());
}
@Override
public MonitoringDoc readFrom(StreamInput in) throws IOException {
return new MonitoringDoc(in);
}
public static class Node implements Writeable<Node>, ToXContent {
public static class Node implements Writeable, ToXContent {
private String uuid;
private String host;
@ -124,6 +121,9 @@ public class MonitoringDoc implements Writeable<MonitoringDoc> {
}
}
/**
* Read from a stream.
*/
public Node(StreamInput in) throws IOException {
uuid = in.readOptionalString();
host = in.readOptionalString();
@ -137,6 +137,25 @@ public class MonitoringDoc implements Writeable<MonitoringDoc> {
}
}
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeOptionalString(uuid);
out.writeOptionalString(host);
out.writeOptionalString(transportAddress);
out.writeOptionalString(ip);
out.writeOptionalString(name);
if (attributes != null) {
out.writeVInt(attributes.size());
for (Map.Entry<String, String> entry : attributes.entrySet()) {
out.writeString(entry.getKey());
out.writeString(entry.getValue());
}
} else {
out.writeVInt(0);
}
}
public String getUUID() {
return uuid;
}
@ -178,29 +197,6 @@ public class MonitoringDoc implements Writeable<MonitoringDoc> {
return builder.endObject();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeOptionalString(uuid);
out.writeOptionalString(host);
out.writeOptionalString(transportAddress);
out.writeOptionalString(ip);
out.writeOptionalString(name);
if (attributes != null) {
out.writeVInt(attributes.size());
for (Map.Entry<String, String> entry : attributes.entrySet()) {
out.writeString(entry.getKey());
out.writeString(entry.getValue());
}
} else {
out.writeVInt(0);
}
}
@Override
public Node readFrom(StreamInput in) throws IOException {
return new Node(in);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
@ -229,12 +225,12 @@ public class MonitoringDoc implements Writeable<MonitoringDoc> {
}
static final class Fields {
static final XContentBuilderString UUID = new XContentBuilderString("uuid");
static final XContentBuilderString HOST = new XContentBuilderString("host");
static final XContentBuilderString TRANSPORT_ADDRESS = new XContentBuilderString("transport_address");
static final XContentBuilderString IP = new XContentBuilderString("ip");
static final XContentBuilderString NAME = new XContentBuilderString("name");
static final XContentBuilderString ATTRIBUTES = new XContentBuilderString("attributes");
static final String UUID = "uuid";
static final String HOST = "host";
static final String TRANSPORT_ADDRESS = "transport_address";
static final String IP = "ip";
static final String NAME = "name";
static final String ATTRIBUTES = "attributes";
}
}
}

View File

@ -13,7 +13,6 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsException;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilderString;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.marvel.MonitoredSystem;
import org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils;
@ -36,12 +35,6 @@ public abstract class MonitoringIndexNameResolver<T extends MonitoringDoc> {
public static final String PREFIX = ".monitoring";
public static final String DELIMITER = "-";
private final int version;
protected MonitoringIndexNameResolver(int version) {
this.version = version;
}
/**
* Returns the name of the index in which the monitoring document must be indexed.
*
@ -112,10 +105,6 @@ public abstract class MonitoringIndexNameResolver<T extends MonitoringDoc> {
*/
public abstract String template();
int getVersion() {
return version;
}
/**
* @return the filters used when rendering the document.
* If null or empty, no filtering is applied.
@ -128,9 +117,9 @@ public abstract class MonitoringIndexNameResolver<T extends MonitoringDoc> {
protected abstract void buildXContent(T document, XContentBuilder builder, ToXContent.Params params) throws IOException;
public static final class Fields {
public static final XContentBuilderString CLUSTER_UUID = new XContentBuilderString("cluster_uuid");
public static final XContentBuilderString TIMESTAMP = new XContentBuilderString("timestamp");
public static final XContentBuilderString SOURCE_NODE = new XContentBuilderString("source_node");
public static final String CLUSTER_UUID = "cluster_uuid";
public static final String TIMESTAMP = "timestamp";
public static final String SOURCE_NODE = "source_node";
}
/**
@ -143,9 +132,8 @@ public abstract class MonitoringIndexNameResolver<T extends MonitoringDoc> {
private final String index;
public Data(int version) {
super(version);
this.index = String.join(DELIMITER, PREFIX, DATA, String.valueOf(version));
public Data() {
this.index = String.join(DELIMITER, PREFIX, DATA, String.valueOf(MarvelTemplateUtils.TEMPLATE_VERSION));
}
@Override
@ -160,12 +148,12 @@ public abstract class MonitoringIndexNameResolver<T extends MonitoringDoc> {
@Override
public String templateName() {
return String.format(Locale.ROOT, "%s-%s-%d", PREFIX, DATA, getVersion());
return String.format(Locale.ROOT, "%s-%s-%d", PREFIX, DATA, MarvelTemplateUtils.TEMPLATE_VERSION);
}
@Override
public String template() {
return MarvelTemplateUtils.loadTemplate(DATA, getVersion());
return MarvelTemplateUtils.loadTemplate(DATA);
}
}
@ -182,10 +170,9 @@ public abstract class MonitoringIndexNameResolver<T extends MonitoringDoc> {
private final DateTimeFormatter formatter;
private final String index;
public Timestamped(MonitoredSystem system, int version, Settings settings) {
super(version);
public Timestamped(MonitoredSystem system, Settings settings) {
this.system = system;
this.index = String.join(DELIMITER, PREFIX, system.getSystem(), String.valueOf(getVersion()));
this.index = String.join(DELIMITER, PREFIX, system.getSystem(), String.valueOf(MarvelTemplateUtils.TEMPLATE_VERSION));
String format = INDEX_NAME_TIME_FORMAT_SETTING.get(settings);
try {
this.formatter = DateTimeFormat.forPattern(format).withZoneUTC();
@ -212,12 +199,12 @@ public abstract class MonitoringIndexNameResolver<T extends MonitoringDoc> {
@Override
public String templateName() {
return String.format(Locale.ROOT, "%s-%s-%d", PREFIX, getId(), getVersion());
return String.format(Locale.ROOT, "%s-%s-%d", PREFIX, getId(), MarvelTemplateUtils.TEMPLATE_VERSION);
}
@Override
public String template() {
return MarvelTemplateUtils.loadTemplate(getId(), getVersion());
return MarvelTemplateUtils.loadTemplate(getId());
}
String getId() {

View File

@ -19,7 +19,6 @@ import org.elasticsearch.marvel.agent.collector.indices.IndexStatsMonitoringDoc;
import org.elasticsearch.marvel.agent.collector.indices.IndicesStatsMonitoringDoc;
import org.elasticsearch.marvel.agent.collector.node.NodeStatsMonitoringDoc;
import org.elasticsearch.marvel.agent.collector.shards.ShardMonitoringDoc;
import org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils;
import org.elasticsearch.marvel.agent.exporter.MonitoringDoc;
import org.elasticsearch.marvel.agent.resolver.bulk.MonitoringBulkResolver;
import org.elasticsearch.marvel.agent.resolver.cluster.ClusterInfoResolver;
@ -43,40 +42,37 @@ import static org.elasticsearch.marvel.MonitoredSystem.ES;
public class ResolversRegistry implements Iterable<MonitoringIndexNameResolver> {
private static final int ES_TEMPLATE_VERSION = MarvelTemplateUtils.TEMPLATE_VERSION;
private static final int KIBANA_TEMPLATE_VERSION = MarvelTemplateUtils.TEMPLATE_VERSION;
private final List<Registration> registrations = new ArrayList<>();
public ResolversRegistry(Settings settings) {
// register built-in defaults resolvers
registerBuiltIn(ES, ES_TEMPLATE_VERSION, settings);
registerBuiltIn(ES, settings);
// register resolvers for monitored systems
registerMonitoredSystem(MonitoredSystem.KIBANA, KIBANA_TEMPLATE_VERSION, settings);
registerMonitoredSystem(MonitoredSystem.KIBANA, settings);
}
/**
* Registers resolvers for elasticsearch documents collected by the monitoring plugin
*/
private void registerBuiltIn(MonitoredSystem id, int version, Settings settings) {
registrations.add(resolveByClass(ClusterInfoMonitoringDoc.class, new ClusterInfoResolver(version)));
registrations.add(resolveByClass(ClusterStateNodeMonitoringDoc.class, new ClusterStateNodeResolver(id, version, settings)));
registrations.add(resolveByClass(ClusterStateMonitoringDoc.class, new ClusterStateResolver(id, version, settings)));
registrations.add(resolveByClass(ClusterStatsMonitoringDoc.class, new ClusterStatsResolver(id, version, settings)));
registrations.add(resolveByClass(DiscoveryNodeMonitoringDoc.class, new DiscoveryNodeResolver(version)));
registrations.add(resolveByClass(IndexRecoveryMonitoringDoc.class, new IndexRecoveryResolver(id, version, settings)));
registrations.add(resolveByClass(IndexStatsMonitoringDoc.class, new IndexStatsResolver(id, version, settings)));
registrations.add(resolveByClass(IndicesStatsMonitoringDoc.class, new IndicesStatsResolver(id, version, settings)));
registrations.add(resolveByClass(NodeStatsMonitoringDoc.class, new NodeStatsResolver(id, version, settings)));
registrations.add(resolveByClass(ShardMonitoringDoc.class, new ShardsResolver(id, version, settings)));
private void registerBuiltIn(MonitoredSystem id, Settings settings) {
registrations.add(resolveByClass(ClusterInfoMonitoringDoc.class, new ClusterInfoResolver()));
registrations.add(resolveByClass(ClusterStateNodeMonitoringDoc.class, new ClusterStateNodeResolver(id, settings)));
registrations.add(resolveByClass(ClusterStateMonitoringDoc.class, new ClusterStateResolver(id, settings)));
registrations.add(resolveByClass(ClusterStatsMonitoringDoc.class, new ClusterStatsResolver(id, settings)));
registrations.add(resolveByClass(DiscoveryNodeMonitoringDoc.class, new DiscoveryNodeResolver()));
registrations.add(resolveByClass(IndexRecoveryMonitoringDoc.class, new IndexRecoveryResolver(id, settings)));
registrations.add(resolveByClass(IndexStatsMonitoringDoc.class, new IndexStatsResolver(id, settings)));
registrations.add(resolveByClass(IndicesStatsMonitoringDoc.class, new IndicesStatsResolver(id, settings)));
registrations.add(resolveByClass(NodeStatsMonitoringDoc.class, new NodeStatsResolver(id, settings)));
registrations.add(resolveByClass(ShardMonitoringDoc.class, new ShardsResolver(id, settings)));
}
/**
* Registers resolvers for monitored systems
*/
private void registerMonitoredSystem(MonitoredSystem id, int version, Settings settings) {
final MonitoringBulkResolver resolver = new MonitoringBulkResolver(id, version, settings);
private void registerMonitoredSystem(MonitoredSystem id, Settings settings) {
final MonitoringBulkResolver resolver = new MonitoringBulkResolver(id, settings);
registrations.add(resolveByClassSystemVersion(MonitoringBulkDoc.class, id, Version.CURRENT, resolver));
}

View File

@ -17,8 +17,8 @@ import java.io.IOException;
public class MonitoringBulkResolver extends MonitoringIndexNameResolver.Timestamped<MonitoringBulkDoc> {
public MonitoringBulkResolver(MonitoredSystem id, int version, Settings settings) {
super(id, version, settings);
public MonitoringBulkResolver(MonitoredSystem id, Settings settings) {
super(id, settings);
}
@Override

View File

@ -10,7 +10,6 @@ import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.hash.MessageDigests;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilderString;
import org.elasticsearch.license.core.License;
import org.elasticsearch.marvel.agent.collector.cluster.ClusterInfoMonitoringDoc;
import org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolver;
@ -23,10 +22,6 @@ public class ClusterInfoResolver extends MonitoringIndexNameResolver.Data<Cluste
public static final String TYPE = "cluster_info";
public ClusterInfoResolver(int version) {
super(version);
}
@Override
public String type(ClusterInfoMonitoringDoc document) {
return TYPE;
@ -72,14 +67,14 @@ public class ClusterInfoResolver extends MonitoringIndexNameResolver.Data<Cluste
}
static final class Fields {
static final XContentBuilderString CLUSTER_NAME = new XContentBuilderString("cluster_name");
static final XContentBuilderString LICENSE = new XContentBuilderString("license");
static final XContentBuilderString VERSION = new XContentBuilderString("version");
static final XContentBuilderString CLUSTER_STATS = new XContentBuilderString("cluster_stats");
static final String CLUSTER_NAME = "cluster_name";
static final String LICENSE = "license";
static final String VERSION = "version";
static final String CLUSTER_STATS = "cluster_stats";
static final XContentBuilderString HKEY = new XContentBuilderString("hkey");
static final String HKEY = "hkey";
static final XContentBuilderString UID = new XContentBuilderString("uid");
static final XContentBuilderString TYPE = new XContentBuilderString("type");
static final String UID = "uid";
static final String TYPE = "type";
}
}

View File

@ -8,7 +8,6 @@ package org.elasticsearch.marvel.agent.resolver.cluster;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilderString;
import org.elasticsearch.marvel.MonitoredSystem;
import org.elasticsearch.marvel.agent.collector.cluster.ClusterStateNodeMonitoringDoc;
import org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolver;
@ -19,8 +18,8 @@ public class ClusterStateNodeResolver extends MonitoringIndexNameResolver.Timest
public static final String TYPE = "node";
public ClusterStateNodeResolver(MonitoredSystem id, int version, Settings settings) {
super(id, version, settings);
public ClusterStateNodeResolver(MonitoredSystem id, Settings settings) {
super(id, settings);
}
@Override
@ -38,8 +37,8 @@ public class ClusterStateNodeResolver extends MonitoringIndexNameResolver.Timest
}
static final class Fields {
static final XContentBuilderString STATE_UUID = new XContentBuilderString("state_uuid");
static final XContentBuilderString NODE = new XContentBuilderString("node");
static final XContentBuilderString ID = new XContentBuilderString("id");
static final String STATE_UUID = "state_uuid";
static final String NODE = "node";
static final String ID = "id";
}
}

View File

@ -9,7 +9,6 @@ import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilderString;
import org.elasticsearch.marvel.MonitoredSystem;
import org.elasticsearch.marvel.agent.collector.cluster.ClusterStateMonitoringDoc;
import org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolver;
@ -32,8 +31,8 @@ public class ClusterStateResolver extends MonitoringIndexNameResolver.Timestampe
"cluster_state.nodes",
};
public ClusterStateResolver(MonitoredSystem id, int version, Settings settings) {
super(id, version, settings);
public ClusterStateResolver(MonitoredSystem id, Settings settings) {
super(id, settings);
}
@Override
@ -58,7 +57,7 @@ public class ClusterStateResolver extends MonitoringIndexNameResolver.Timestampe
}
static final class Fields {
static final XContentBuilderString CLUSTER_STATE = new XContentBuilderString(TYPE);
static final XContentBuilderString STATUS = new XContentBuilderString("status");
static final String CLUSTER_STATE = TYPE;
static final String STATUS = "status";
}
}

View File

@ -9,7 +9,6 @@ import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilderString;
import org.elasticsearch.marvel.MonitoredSystem;
import org.elasticsearch.marvel.agent.collector.cluster.ClusterStatsMonitoringDoc;
import org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolver;
@ -39,8 +38,8 @@ public class ClusterStatsResolver extends MonitoringIndexNameResolver.Timestampe
"cluster_stats.nodes.versions",
};
public ClusterStatsResolver(MonitoredSystem id, int version, Settings settings) {
super(id, version, settings);
public ClusterStatsResolver(MonitoredSystem id, Settings settings) {
super(id, settings);
}
@Override
@ -64,6 +63,6 @@ public class ClusterStatsResolver extends MonitoringIndexNameResolver.Timestampe
}
static final class Fields {
static final XContentBuilderString CLUSTER_STATS = new XContentBuilderString(TYPE);
static final String CLUSTER_STATS = TYPE;
}
}

View File

@ -8,7 +8,6 @@ package org.elasticsearch.marvel.agent.resolver.cluster;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilderString;
import org.elasticsearch.marvel.agent.collector.cluster.DiscoveryNodeMonitoringDoc;
import org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolver;
@ -19,10 +18,6 @@ public class DiscoveryNodeResolver extends MonitoringIndexNameResolver.Data<Disc
public static final String TYPE = "node";
public DiscoveryNodeResolver(int version) {
super(version);
}
@Override
public String type(DiscoveryNodeMonitoringDoc document) {
return TYPE;
@ -55,10 +50,10 @@ public class DiscoveryNodeResolver extends MonitoringIndexNameResolver.Data<Disc
}
static final class Fields {
static final XContentBuilderString NODE = new XContentBuilderString(TYPE);
static final XContentBuilderString NAME = new XContentBuilderString("name");
static final XContentBuilderString TRANSPORT_ADDRESS = new XContentBuilderString("transport_address");
static final XContentBuilderString ATTRIBUTES = new XContentBuilderString("attributes");
static final XContentBuilderString ID = new XContentBuilderString("id");
static final String NODE = TYPE;
static final String NAME = "name";
static final String TRANSPORT_ADDRESS = "transport_address";
static final String ATTRIBUTES = "attributes";
static final String ID = "id";
}
}

View File

@ -9,7 +9,6 @@ import org.elasticsearch.action.admin.indices.recovery.RecoveryResponse;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilderString;
import org.elasticsearch.indices.recovery.RecoveryState;
import org.elasticsearch.marvel.MonitoredSystem;
import org.elasticsearch.marvel.agent.collector.indices.IndexRecoveryMonitoringDoc;
@ -23,8 +22,8 @@ public class IndexRecoveryResolver extends MonitoringIndexNameResolver.Timestamp
public static final String TYPE = "index_recovery";
public IndexRecoveryResolver(MonitoredSystem id, int version, Settings settings) {
super(id, version, settings);
public IndexRecoveryResolver(MonitoredSystem id, Settings settings) {
super(id, settings);
}
@Override
@ -62,8 +61,8 @@ public class IndexRecoveryResolver extends MonitoringIndexNameResolver.Timestamp
}
static final class Fields {
static final XContentBuilderString INDEX_RECOVERY = new XContentBuilderString(TYPE);
static final XContentBuilderString SHARDS = new XContentBuilderString("shards");
static final XContentBuilderString INDEX_NAME = new XContentBuilderString("index_name");
static final String INDEX_RECOVERY = TYPE;
static final String SHARDS = "shards";
static final String INDEX_NAME = "index_name";
}
}

View File

@ -9,7 +9,6 @@ import org.elasticsearch.action.admin.indices.stats.IndexStats;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilderString;
import org.elasticsearch.marvel.MonitoredSystem;
import org.elasticsearch.marvel.agent.collector.indices.IndexStatsMonitoringDoc;
import org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolver;
@ -67,8 +66,8 @@ public class IndexStatsResolver extends MonitoringIndexNameResolver.Timestamped<
"index_stats.total.refresh.total_time_in_millis",
};
public IndexStatsResolver(MonitoredSystem id, int version, Settings settings) {
super(id, version, settings);
public IndexStatsResolver(MonitoredSystem id, Settings settings) {
super(id, settings);
}
@Override
@ -106,9 +105,9 @@ public class IndexStatsResolver extends MonitoringIndexNameResolver.Timestamped<
}
static final class Fields {
static final XContentBuilderString INDEX_STATS = new XContentBuilderString(TYPE);
static final XContentBuilderString INDEX = new XContentBuilderString("index");
static final XContentBuilderString TOTAL = new XContentBuilderString("total");
static final XContentBuilderString PRIMARIES = new XContentBuilderString("primaries");
static final String INDEX_STATS = TYPE;
static final String INDEX = "index";
static final String TOTAL = "total";
static final String PRIMARIES = "primaries";
}
}

View File

@ -9,7 +9,6 @@ import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilderString;
import org.elasticsearch.marvel.MonitoredSystem;
import org.elasticsearch.marvel.agent.collector.indices.IndicesStatsMonitoringDoc;
import org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolver;
@ -42,8 +41,8 @@ public class IndicesStatsResolver extends MonitoringIndexNameResolver.Timestampe
"indices_stats._all.total.store.size_in_bytes",
};
public IndicesStatsResolver(MonitoredSystem id, int version, Settings settings) {
super(id, version, settings);
public IndicesStatsResolver(MonitoredSystem id, Settings settings) {
super(id, settings);
}
@Override
@ -67,6 +66,6 @@ public class IndicesStatsResolver extends MonitoringIndexNameResolver.Timestampe
}
static final class Fields {
static final XContentBuilderString INDICES_STATS = new XContentBuilderString(TYPE);
static final String INDICES_STATS = TYPE;
}
}

View File

@ -9,7 +9,6 @@ import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilderString;
import org.elasticsearch.marvel.MonitoredSystem;
import org.elasticsearch.marvel.agent.collector.node.NodeStatsMonitoringDoc;
import org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolver;
@ -88,8 +87,8 @@ public class NodeStatsResolver extends MonitoringIndexNameResolver.Timestamped<N
"node_stats.thread_pool.watcher.rejected",
};
public NodeStatsResolver(MonitoredSystem id, int version, Settings settings) {
super(id, version, settings);
public NodeStatsResolver(MonitoredSystem id, Settings settings) {
super(id, settings);
}
@Override
@ -121,11 +120,11 @@ public class NodeStatsResolver extends MonitoringIndexNameResolver.Timestamped<N
}
static final class Fields {
static final XContentBuilderString NODE_STATS = new XContentBuilderString(TYPE);
static final XContentBuilderString NODE_ID = new XContentBuilderString("node_id");
static final XContentBuilderString NODE_MASTER = new XContentBuilderString("node_master");
static final XContentBuilderString MLOCKALL = new XContentBuilderString("mlockall");
static final XContentBuilderString DISK_THRESHOLD_ENABLED = new XContentBuilderString("disk_threshold_enabled");
static final XContentBuilderString DISK_THRESHOLD_WATERMARK_HIGH = new XContentBuilderString("disk_threshold_watermark_high");
static final String NODE_STATS = TYPE;
static final String NODE_ID = "node_id";
static final String NODE_MASTER = "node_master";
static final String MLOCKALL = "mlockall";
static final String DISK_THRESHOLD_ENABLED = "disk_threshold_enabled";
static final String DISK_THRESHOLD_WATERMARK_HIGH = "disk_threshold_watermark_high";
}
}

View File

@ -9,7 +9,6 @@ import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilderString;
import org.elasticsearch.marvel.MonitoredSystem;
import org.elasticsearch.marvel.agent.collector.shards.ShardMonitoringDoc;
import org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolver;
@ -33,8 +32,8 @@ public class ShardsResolver extends MonitoringIndexNameResolver.Timestamped<Shar
"shard.index",
};
public ShardsResolver(MonitoredSystem id, int version, Settings settings) {
super(id, version, settings);
public ShardsResolver(MonitoredSystem id, Settings settings) {
super(id, settings);
}
@Override
@ -60,13 +59,13 @@ public class ShardsResolver extends MonitoringIndexNameResolver.Timestamped<Shar
if (shardRouting != null) {
// ShardRouting is rendered inside a startObject() / endObject() but without a name,
// so we must use XContentBuilder.field(String, ToXContent, ToXContent.Params) here
builder.field(Fields.SHARD.underscore().toString(), shardRouting, params);
builder.field(Fields.SHARD, shardRouting, params);
}
}
static final class Fields {
static final XContentBuilderString SHARD = new XContentBuilderString("shard");
static final XContentBuilderString STATE_UUID = new XContentBuilderString("state_uuid");
static final String SHARD = "shard";
static final String STATE_UUID = "state_uuid";
}
/**

View File

@ -13,8 +13,8 @@ import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.concurrent.AbstractLifecycleRunnable;
import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException;
import org.elasticsearch.common.util.concurrent.FutureUtils;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.license.MarvelLicensee;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.MonitoringLicensee;
import org.elasticsearch.threadpool.ThreadPool;
import org.joda.time.DateTime;
import org.joda.time.chrono.ISOChronology;
@ -28,7 +28,7 @@ import java.util.concurrent.ScheduledFuture;
*/
public class CleanerService extends AbstractLifecycleComponent<CleanerService> {
private final MarvelLicensee licensee;
private final MonitoringLicensee licensee;
private final ThreadPool threadPool;
private final ExecutionScheduler executionScheduler;
private final List<Listener> listeners = new CopyOnWriteArrayList<>();
@ -36,21 +36,21 @@ public class CleanerService extends AbstractLifecycleComponent<CleanerService> {
private volatile TimeValue globalRetention;
CleanerService(Settings settings, ClusterSettings clusterSettings, MarvelLicensee licensee, ThreadPool threadPool,
CleanerService(Settings settings, ClusterSettings clusterSettings, MonitoringLicensee licensee, ThreadPool threadPool,
ExecutionScheduler executionScheduler) {
super(settings);
this.licensee = licensee;
this.threadPool = threadPool;
this.executionScheduler = executionScheduler;
this.globalRetention = MarvelSettings.HISTORY_DURATION.get(settings);
this.globalRetention = MonitoringSettings.HISTORY_DURATION.get(settings);
this.runnable = new IndicesCleaner();
// the validation is performed by the setting's object itself
clusterSettings.addSettingsUpdateConsumer(MarvelSettings.HISTORY_DURATION, this::setGlobalRetention);
clusterSettings.addSettingsUpdateConsumer(MonitoringSettings.HISTORY_DURATION, this::setGlobalRetention);
}
@Inject
public CleanerService(Settings settings, ClusterSettings clusterSettings, ThreadPool threadPool, MarvelLicensee licensee) {
public CleanerService(Settings settings, ClusterSettings clusterSettings, ThreadPool threadPool, MonitoringLicensee licensee) {
this(settings, clusterSettings, licensee,threadPool, new DefaultExecutionScheduler());
}
@ -85,7 +85,7 @@ public class CleanerService extends AbstractLifecycleComponent<CleanerService> {
* This will ignore the global retention if the license does not allow retention updates.
*
* @return Never {@code null}
* @see MarvelLicensee#allowUpdateRetention()
* @see MonitoringLicensee#allowUpdateRetention()
*/
public TimeValue getRetention() {
// we only care about their value if they are allowed to set it
@ -93,7 +93,7 @@ public class CleanerService extends AbstractLifecycleComponent<CleanerService> {
return globalRetention;
}
else {
return MarvelSettings.HISTORY_DURATION.getDefault(Settings.EMPTY);
return MonitoringSettings.HISTORY_DURATION.getDefault(Settings.EMPTY);
}
}
@ -108,7 +108,8 @@ public class CleanerService extends AbstractLifecycleComponent<CleanerService> {
public void setGlobalRetention(TimeValue globalRetention) {
// notify the user that their setting will be ignored until they get the right license
if (licensee.allowUpdateRetention() == false) {
logger.warn("[{}] setting will be ignored until an appropriate license is applied", MarvelSettings.HISTORY_DURATION.getKey());
logger.warn("[{}] setting will be ignored until an appropriate license is applied",
MonitoringSettings.HISTORY_DURATION.getKey());
}
this.globalRetention = globalRetention;

View File

@ -1,17 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.marvel.license;
import org.elasticsearch.common.inject.AbstractModule;
public class LicenseModule extends AbstractModule {
@Override
protected void configure() {
bind(MarvelLicensee.class).asEagerSingleton();
}
}

View File

@ -11,7 +11,6 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilderString;
import org.elasticsearch.marvel.action.MonitoringBulkRequestBuilder;
import org.elasticsearch.marvel.action.MonitoringBulkResponse;
import org.elasticsearch.marvel.client.MonitoringClient;
@ -79,8 +78,8 @@ public class RestMonitoringBulkAction extends MonitoringRestHandler {
}
static final class Fields {
static final XContentBuilderString TOOK = new XContentBuilderString("took");
static final XContentBuilderString ERRORS = new XContentBuilderString("errors");
static final XContentBuilderString ERROR = new XContentBuilderString("error");
static final String TOOK = "took";
static final String ERRORS = "errors";
static final String ERROR = "error";
}
}

View File

@ -16,16 +16,15 @@ import java.util.Collection;
import static org.hamcrest.Matchers.is;
public class MarvelPluginClientTests extends ESTestCase {
public void testModulesWithClientSettings() {
Settings settings = Settings.builder()
.put(Client.CLIENT_TYPE_SETTING_S.getKey(), TransportClient.CLIENT_TYPE)
.build();
Marvel plugin = new Marvel(settings);
Monitoring plugin = new Monitoring(settings);
assertThat(plugin.isEnabled(), is(true));
assertThat(plugin.isTransportClient(), is(true));
Collection<Module> modules = plugin.nodeModules();
assertThat(modules.size(), is(0));
}
public void testModulesWithNodeSettings() {
@ -33,10 +32,8 @@ public class MarvelPluginClientTests extends ESTestCase {
Settings settings = Settings.builder()
.put(Client.CLIENT_TYPE_SETTING_S.getKey(), "node")
.build();
Marvel plugin = new Marvel(settings);
Monitoring plugin = new Monitoring(settings);
assertThat(plugin.isEnabled(), is(true));
assertThat(plugin.isTransportClient(), is(false));
Collection<Module> modules = plugin.nodeModules();
assertThat(modules.size(), is(5));
}
}

View File

@ -35,13 +35,13 @@ public class MarvelPluginTests extends MarvelIntegTestCase {
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(MarvelSettings.INTERVAL.getKey(), "-1")
.put(MonitoringSettings.INTERVAL.getKey(), "-1")
.build();
}
public void testMarvelEnabled() {
internalCluster().startNode(Settings.builder()
.put(XPackPlugin.featureEnabledSetting(Marvel.NAME), true)
.put(XPackPlugin.featureEnabledSetting(Monitoring.NAME), true)
.build());
assertPluginIsLoaded();
assertServiceIsBound(AgentService.class);
@ -49,7 +49,7 @@ public class MarvelPluginTests extends MarvelIntegTestCase {
public void testMarvelDisabled() {
internalCluster().startNode(Settings.builder()
.put(XPackPlugin.featureEnabledSetting(Marvel.NAME), false)
.put(XPackPlugin.featureEnabledSetting(Monitoring.NAME), false)
.build());
assertPluginIsLoaded();
assertServiceIsNotBound(AgentService.class);
@ -57,7 +57,7 @@ public class MarvelPluginTests extends MarvelIntegTestCase {
public void testMarvelEnabledOnTribeNode() {
internalCluster().startNode(Settings.builder()
.put(XPackPlugin.featureEnabledSetting(Marvel.NAME), true)
.put(XPackPlugin.featureEnabledSetting(Monitoring.NAME), true)
.put("tribe.name", "t1")
.build());
assertPluginIsLoaded();

View File

@ -13,7 +13,7 @@ import org.junit.Rule;
import org.junit.rules.ExpectedException;
/**
* Tests {@link MarvelSettings}
* Tests {@link MonitoringSettings}
*/
public class MarvelSettingsTests extends ESTestCase {
@Rule
@ -23,24 +23,24 @@ public class MarvelSettingsTests extends ESTestCase {
TimeValue sevenDays = TimeValue.timeValueHours(7 * 24);
// 7 days
assertEquals(sevenDays, MarvelSettings.HISTORY_DURATION.get(Settings.EMPTY));
assertEquals(sevenDays, MonitoringSettings.HISTORY_DURATION.get(Settings.EMPTY));
// Note: this verifies the semantics because this is taken for granted that it never returns null!
assertEquals(sevenDays, MarvelSettings.HISTORY_DURATION.get(buildSettings(MarvelSettings.HISTORY_DURATION.getKey(), null)));
assertEquals(sevenDays, MonitoringSettings.HISTORY_DURATION.get(buildSettings(MonitoringSettings.HISTORY_DURATION.getKey(), null)));
}
public void testHistoryDurationMinimum24Hours() {
// hit the minimum
assertEquals(MarvelSettings.HISTORY_DURATION_MINIMUM,
MarvelSettings.HISTORY_DURATION.get(buildSettings(MarvelSettings.HISTORY_DURATION.getKey(), "24h")));
assertEquals(MonitoringSettings.HISTORY_DURATION_MINIMUM,
MonitoringSettings.HISTORY_DURATION.get(buildSettings(MonitoringSettings.HISTORY_DURATION.getKey(), "24h")));
}
public void testHistoryDurationMinimum24HoursBlocksLower() {
expectedException.expect(IllegalArgumentException.class);
// 1 ms early!
String oneSecondEarly = (MarvelSettings.HISTORY_DURATION_MINIMUM.millis() - 1) + "ms";
String oneSecondEarly = (MonitoringSettings.HISTORY_DURATION_MINIMUM.millis() - 1) + "ms";
MarvelSettings.HISTORY_DURATION.get(buildSettings(MarvelSettings.HISTORY_DURATION.getKey(), oneSecondEarly));
MonitoringSettings.HISTORY_DURATION.get(buildSettings(MonitoringSettings.HISTORY_DURATION.getKey(), oneSecondEarly));
}
private Settings buildSettings(String key, String value) {

View File

@ -58,9 +58,9 @@ public class MonitoringBulkTests extends MarvelIntegTestCase {
for (SearchHit searchHit : searchResponse.getHits()) {
Map<String, Object> source = searchHit.sourceAsMap();
assertNotNull(source.get(MonitoringBulkResolver.Fields.CLUSTER_UUID.underscore().toString()));
assertNotNull(source.get(MonitoringBulkResolver.Fields.TIMESTAMP.underscore().toString()));
assertNotNull(source.get(MonitoringBulkResolver.Fields.SOURCE_NODE.underscore().toString()));
assertNotNull(source.get(MonitoringBulkResolver.Fields.CLUSTER_UUID));
assertNotNull(source.get(MonitoringBulkResolver.Fields.TIMESTAMP));
assertNotNull(source.get(MonitoringBulkResolver.Fields.SOURCE_NODE));
}
}

View File

@ -23,7 +23,7 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.DummyTransportAddress;
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
import org.elasticsearch.discovery.DiscoverySettings;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.MonitoredSystem;
import org.elasticsearch.marvel.agent.exporter.ExportException;
import org.elasticsearch.marvel.agent.exporter.Exporters;
@ -257,7 +257,7 @@ public class TransportMonitoringBulkActionTests extends ESTestCase {
public CapturingExporters() {
super(Settings.EMPTY, Collections.emptyMap(), clusterService,
new ClusterSettings(Settings.EMPTY, Collections.singleton(MarvelSettings.EXPORTERS_SETTINGS)));
new ClusterSettings(Settings.EMPTY, Collections.singleton(MonitoringSettings.EXPORTERS_SETTINGS)));
}
@Override
@ -279,7 +279,7 @@ public class TransportMonitoringBulkActionTests extends ESTestCase {
public ConsumingExporters(Consumer<Collection<? extends MonitoringDoc>> consumer) {
super(Settings.EMPTY, Collections.emptyMap(), clusterService,
new ClusterSettings(Settings.EMPTY, Collections.singleton(MarvelSettings.EXPORTERS_SETTINGS)));
new ClusterSettings(Settings.EMPTY, Collections.singleton(MonitoringSettings.EXPORTERS_SETTINGS)));
this.consumer = consumer;
}

View File

@ -23,7 +23,7 @@ import org.elasticsearch.license.plugin.core.LicenseState;
import org.elasticsearch.license.plugin.core.Licensee;
import org.elasticsearch.license.plugin.core.LicenseeRegistry;
import org.elasticsearch.license.plugin.core.LicensesManagerService;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.test.MarvelIntegTestCase;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.shield.InternalClient;
@ -54,7 +54,7 @@ public abstract class AbstractCollectorTestCase extends MarvelIntegTestCase {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(NetworkModule.HTTP_ENABLED.getKey(), false)
.put(MarvelSettings.INTERVAL.getKey(), "-1")
.put(MonitoringSettings.INTERVAL.getKey(), "-1")
.build();
}
@ -126,7 +126,7 @@ public abstract class AbstractCollectorTestCase extends MarvelIntegTestCase {
}
protected static void endGracefulPeriod() {
long expiryDate = System.currentTimeMillis() - MarvelSettings.MAX_LICENSE_GRACE_PERIOD.millis() - timeValueMinutes(10).millis();
long expiryDate = System.currentTimeMillis() - MonitoringSettings.MAX_LICENSE_GRACE_PERIOD.millis() - timeValueMinutes(10).millis();
long issueDate = expiryDate - randomDaysInMillis();
final License license = createTestingLicense(issueDate, expiryDate);
@ -139,7 +139,7 @@ public abstract class AbstractCollectorTestCase extends MarvelIntegTestCase {
}
protected static void disableLicense() {
long expiryDate = System.currentTimeMillis() - MarvelSettings.MAX_LICENSE_GRACE_PERIOD.millis() - randomDaysInMillis();
long expiryDate = System.currentTimeMillis() - MonitoringSettings.MAX_LICENSE_GRACE_PERIOD.millis() - randomDaysInMillis();
long issueDate = expiryDate - randomDaysInMillis();
final License license = createTestingLicense(issueDate, expiryDate);

View File

@ -10,11 +10,11 @@ import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.MonitoredSystem;
import org.elasticsearch.marvel.agent.collector.AbstractCollectorTestCase;
import org.elasticsearch.marvel.agent.exporter.MonitoringDoc;
import org.elasticsearch.marvel.license.MarvelLicensee;
import org.elasticsearch.marvel.MonitoringLicensee;
import java.util.ArrayList;
import java.util.Collection;
@ -153,8 +153,8 @@ public class ClusterStateCollectorTests extends AbstractCollectorTestCase {
assertNotNull(nodeId);
return new ClusterStateCollector(internalCluster().getInstance(Settings.class, nodeId),
internalCluster().getInstance(ClusterService.class, nodeId),
internalCluster().getInstance(MarvelSettings.class, nodeId),
internalCluster().getInstance(MarvelLicensee.class, nodeId),
internalCluster().getInstance(MonitoringSettings.class, nodeId),
internalCluster().getInstance(MonitoringLicensee.class, nodeId),
securedClient(nodeId));
}

View File

@ -11,12 +11,12 @@ import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.plugin.core.LicensesManagerService;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.MonitoredSystem;
import org.elasticsearch.marvel.agent.collector.AbstractCollector;
import org.elasticsearch.marvel.agent.collector.AbstractCollectorTestCase;
import org.elasticsearch.marvel.agent.exporter.MonitoringDoc;
import org.elasticsearch.marvel.license.MarvelLicensee;
import org.elasticsearch.marvel.MonitoringLicensee;
import java.util.Collection;
@ -131,8 +131,8 @@ public class ClusterStatsCollectorTests extends AbstractCollectorTestCase {
assertNotNull(nodeId);
return new ClusterStatsCollector(internalCluster().getInstance(Settings.class, nodeId),
internalCluster().getInstance(ClusterService.class, nodeId),
internalCluster().getInstance(MarvelSettings.class, nodeId),
internalCluster().getInstance(MarvelLicensee.class, nodeId),
internalCluster().getInstance(MonitoringSettings.class, nodeId),
internalCluster().getInstance(MonitoringLicensee.class, nodeId),
securedClient(nodeId),
internalCluster().getInstance(LicensesManagerService.class, nodeId),
internalCluster().getInstance(ClusterName.class, nodeId));

View File

@ -13,11 +13,11 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.indices.recovery.RecoveryState;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.MonitoredSystem;
import org.elasticsearch.marvel.agent.collector.AbstractCollectorTestCase;
import org.elasticsearch.marvel.agent.exporter.MonitoringDoc;
import org.elasticsearch.marvel.license.MarvelLicensee;
import org.elasticsearch.marvel.MonitoringLicensee;
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import java.util.Collection;
@ -47,8 +47,8 @@ public class IndexRecoveryCollectorTests extends AbstractCollectorTestCase {
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(MarvelSettings.INDEX_RECOVERY_ACTIVE_ONLY.getKey(), activeOnly)
.put(MarvelSettings.INDICES.getKey(), indexName)
.put(MonitoringSettings.INDEX_RECOVERY_ACTIVE_ONLY.getKey(), activeOnly)
.put(MonitoringSettings.INDICES.getKey(), indexName)
.build();
}
@ -85,8 +85,8 @@ public class IndexRecoveryCollectorTests extends AbstractCollectorTestCase {
waitForNoBlocksOnNode(node2);
waitForRelocation();
for (MarvelSettings marvelSettings : internalCluster().getInstances(MarvelSettings.class)) {
assertThat(marvelSettings.recoveryActiveOnly(), equalTo(activeOnly));
for (MonitoringSettings monitoringSettings : internalCluster().getInstances(MonitoringSettings.class)) {
assertThat(monitoringSettings.recoveryActiveOnly(), equalTo(activeOnly));
}
logger.info("--> collect index recovery data");
@ -168,7 +168,7 @@ public class IndexRecoveryCollectorTests extends AbstractCollectorTestCase {
}
public void testEmptyCluster() throws Exception {
final String node = internalCluster().startNode(Settings.builder().put(MarvelSettings.INDICES.getKey(),
final String node = internalCluster().startNode(Settings.builder().put(MonitoringSettings.INDICES.getKey(),
Strings.EMPTY_ARRAY));
waitForNoBlocksOnNode(node);
@ -180,7 +180,7 @@ public class IndexRecoveryCollectorTests extends AbstractCollectorTestCase {
}
public void testEmptyClusterAllIndices() throws Exception {
final String node = internalCluster().startNode(Settings.builder().put(MarvelSettings.INDICES.getKey(), MetaData.ALL));
final String node = internalCluster().startNode(Settings.builder().put(MonitoringSettings.INDICES.getKey(), MetaData.ALL));
waitForNoBlocksOnNode(node);
try {
@ -191,7 +191,7 @@ public class IndexRecoveryCollectorTests extends AbstractCollectorTestCase {
}
public void testEmptyClusterMissingIndex() throws Exception {
final String node = internalCluster().startNode(Settings.builder().put(MarvelSettings.INDICES.getKey(), "unknown"));
final String node = internalCluster().startNode(Settings.builder().put(MonitoringSettings.INDICES.getKey(), "unknown"));
waitForNoBlocksOnNode(node);
try {
@ -207,8 +207,8 @@ public class IndexRecoveryCollectorTests extends AbstractCollectorTestCase {
}
return new IndexRecoveryCollector(internalCluster().getInstance(Settings.class, nodeId),
internalCluster().getInstance(ClusterService.class, nodeId),
internalCluster().getInstance(MarvelSettings.class, nodeId),
internalCluster().getInstance(MarvelLicensee.class, nodeId),
internalCluster().getInstance(MonitoringSettings.class, nodeId),
internalCluster().getInstance(MonitoringLicensee.class, nodeId),
securedClient(nodeId));
}
}

View File

@ -11,11 +11,11 @@ import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.MonitoredSystem;
import org.elasticsearch.marvel.agent.collector.AbstractCollectorTestCase;
import org.elasticsearch.marvel.agent.exporter.MonitoringDoc;
import org.elasticsearch.marvel.license.MarvelLicensee;
import org.elasticsearch.marvel.MonitoringLicensee;
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import java.util.Collection;
@ -52,7 +52,7 @@ public class IndexStatsCollectorTests extends AbstractCollectorTestCase {
}
public void testEmptyClusterAllIndices() throws Exception {
final String node = internalCluster().startNode(Settings.builder().put(MarvelSettings.INDICES.getKey(), MetaData.ALL));
final String node = internalCluster().startNode(Settings.builder().put(MonitoringSettings.INDICES.getKey(), MetaData.ALL));
waitForNoBlocksOnNode(node);
try {
@ -63,7 +63,7 @@ public class IndexStatsCollectorTests extends AbstractCollectorTestCase {
}
public void testEmptyClusterMissingIndex() throws Exception {
final String node = internalCluster().startNode(Settings.builder().put(MarvelSettings.INDICES.getKey(), "unknown"));
final String node = internalCluster().startNode(Settings.builder().put(MonitoringSettings.INDICES.getKey(), "unknown"));
waitForNoBlocksOnNode(node);
try {
@ -240,8 +240,8 @@ public class IndexStatsCollectorTests extends AbstractCollectorTestCase {
assertNotNull(nodeId);
return new IndexStatsCollector(internalCluster().getInstance(Settings.class, nodeId),
internalCluster().getInstance(ClusterService.class, nodeId),
internalCluster().getInstance(MarvelSettings.class, nodeId),
internalCluster().getInstance(MarvelLicensee.class, nodeId),
internalCluster().getInstance(MonitoringSettings.class, nodeId),
internalCluster().getInstance(MonitoringLicensee.class, nodeId),
securedClient(nodeId));
}
}

View File

@ -13,11 +13,11 @@ import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.MonitoredSystem;
import org.elasticsearch.marvel.agent.collector.AbstractCollectorTestCase;
import org.elasticsearch.marvel.agent.exporter.MonitoringDoc;
import org.elasticsearch.marvel.license.MarvelLicensee;
import org.elasticsearch.marvel.MonitoringLicensee;
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import java.util.Collection;
@ -52,7 +52,7 @@ public class IndicesStatsCollectorTests extends AbstractCollectorTestCase {
}
public void testEmptyClusterAllIndices() throws Exception {
final String node = internalCluster().startNode(Settings.builder().put(MarvelSettings.INDICES.getKey(), MetaData.ALL));
final String node = internalCluster().startNode(Settings.builder().put(MonitoringSettings.INDICES.getKey(), MetaData.ALL));
waitForNoBlocksOnNode(node);
try {
@ -63,7 +63,7 @@ public class IndicesStatsCollectorTests extends AbstractCollectorTestCase {
}
public void testEmptyClusterMissingIndex() throws Exception {
final String node = internalCluster().startNode(Settings.builder().put(MarvelSettings.INDICES.getKey(), "unknown"));
final String node = internalCluster().startNode(Settings.builder().put(MonitoringSettings.INDICES.getKey(), "unknown"));
waitForNoBlocksOnNode(node);
try {
@ -215,8 +215,8 @@ public class IndicesStatsCollectorTests extends AbstractCollectorTestCase {
}
return new IndicesStatsCollector(internalCluster().getInstance(Settings.class, nodeId),
internalCluster().getInstance(ClusterService.class, nodeId),
internalCluster().getInstance(MarvelSettings.class, nodeId),
internalCluster().getInstance(MarvelLicensee.class, nodeId),
internalCluster().getInstance(MonitoringSettings.class, nodeId),
internalCluster().getInstance(MonitoringLicensee.class, nodeId),
securedClient(nodeId));
}
}

View File

@ -11,11 +11,11 @@ import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.cluster.routing.allocation.decider.DiskThresholdDecider;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.MonitoredSystem;
import org.elasticsearch.marvel.agent.collector.AbstractCollectorTestCase;
import org.elasticsearch.marvel.agent.exporter.MonitoringDoc;
import org.elasticsearch.marvel.license.MarvelLicensee;
import org.elasticsearch.marvel.MonitoringLicensee;
import org.elasticsearch.shield.InternalClient;
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
@ -96,8 +96,8 @@ public class NodeStatsCollectorTests extends AbstractCollectorTestCase {
private NodeStatsCollector newNodeStatsCollector(final String nodeId) {
return new NodeStatsCollector(internalCluster().getInstance(Settings.class, nodeId),
internalCluster().getInstance(ClusterService.class, nodeId),
internalCluster().getInstance(MarvelSettings.class, nodeId),
internalCluster().getInstance(MarvelLicensee.class, nodeId),
internalCluster().getInstance(MonitoringSettings.class, nodeId),
internalCluster().getInstance(MonitoringLicensee.class, nodeId),
internalCluster().getInstance(InternalClient.class, nodeId),
internalCluster().getInstance(NodeEnvironment.class, nodeId),
internalCluster().getInstance(DiskThresholdDecider.class, nodeId));

View File

@ -10,11 +10,11 @@ import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.MonitoredSystem;
import org.elasticsearch.marvel.agent.collector.AbstractCollectorTestCase;
import org.elasticsearch.marvel.agent.exporter.MonitoringDoc;
import org.elasticsearch.marvel.license.MarvelLicensee;
import org.elasticsearch.marvel.MonitoringLicensee;
import java.util.Collection;
@ -39,7 +39,7 @@ public class ShardsCollectorTests extends AbstractCollectorTestCase {
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(MarvelSettings.INDICES.getKey(), "test-shards*")
.put(MonitoringSettings.INDICES.getKey(), "test-shards*")
.build();
}
@ -207,7 +207,7 @@ public class ShardsCollectorTests extends AbstractCollectorTestCase {
assertNotNull(nodeId);
return new ShardsCollector(internalCluster().getInstance(Settings.class, nodeId),
internalCluster().getInstance(ClusterService.class, nodeId),
internalCluster().getInstance(MarvelSettings.class, nodeId),
internalCluster().getInstance(MarvelLicensee.class, nodeId));
internalCluster().getInstance(MonitoringSettings.class, nodeId),
internalCluster().getInstance(MonitoringLicensee.class, nodeId));
}
}

View File

@ -8,8 +8,8 @@ package org.elasticsearch.marvel.agent.exporter;
import org.elasticsearch.Version;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoredSystem;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.agent.collector.Collector;
import org.elasticsearch.marvel.agent.collector.cluster.ClusterStatsCollector;
import org.elasticsearch.marvel.test.MarvelIntegTestCase;
@ -25,13 +25,11 @@ import static org.hamcrest.Matchers.notNullValue;
@ClusterScope(scope = TEST, numDataNodes = 0, numClientNodes = 0, transportClientRatio = 0.0)
public abstract class AbstractExporterTemplateTestCase extends MarvelIntegTestCase {
private final Integer currentVersion = MarvelTemplateUtils.TEMPLATE_VERSION;
@Override
protected Settings nodeSettings(int nodeOrdinal) {
Settings.Builder settings = Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(MarvelSettings.INTERVAL.getKey(), "-1");
.put(MonitoringSettings.INTERVAL.getKey(), "-1");
for (Map.Entry<String, String> setting : exporterSettings().getAsMap().entrySet()) {
settings.put("xpack.monitoring.agent.exporters._exporter." + setting.getKey(), setting.getValue());
@ -43,7 +41,7 @@ public abstract class AbstractExporterTemplateTestCase extends MarvelIntegTestCa
protected abstract void deleteTemplates() throws Exception;
protected abstract void putTemplate(String name, int version) throws Exception;
protected abstract void putTemplate(String name) throws Exception;
protected abstract void assertTemplateExist(String name) throws Exception;
@ -70,15 +68,14 @@ public abstract class AbstractExporterTemplateTestCase extends MarvelIntegTestCa
public void testCreateWhenExistingTemplatesAreOld() throws Exception {
internalCluster().startNode();
final Integer version = randomIntBetween(0, currentVersion - 1);
putTemplate(indexTemplateName(version), version);
putTemplate(dataTemplateName(version), version);
putTemplate(indexTemplateName());
putTemplate(dataTemplateName());
doExporting();
logger.debug("--> existing templates are old");
assertTemplateExist(dataTemplateName(version));
assertTemplateExist(indexTemplateName(version));
assertTemplateExist(dataTemplateName());
assertTemplateExist(indexTemplateName());
logger.debug("--> existing templates are old: new templates should be created");
for (String template : monitoringTemplates().keySet()) {
@ -95,8 +92,8 @@ public abstract class AbstractExporterTemplateTestCase extends MarvelIntegTestCa
public void testCreateWhenExistingTemplateAreUpToDate() throws Exception {
internalCluster().startNode();
putTemplate(indexTemplateName(currentVersion), currentVersion);
putTemplate(dataTemplateName(currentVersion), currentVersion);
putTemplate(indexTemplateName());
putTemplate(dataTemplateName());
doExporting();
@ -106,8 +103,8 @@ public abstract class AbstractExporterTemplateTestCase extends MarvelIntegTestCa
}
logger.debug("--> existing templates has the same version: they should not be changed");
assertTemplateNotUpdated(indexTemplateName(currentVersion));
assertTemplateNotUpdated(dataTemplateName(currentVersion));
assertTemplateNotUpdated(indexTemplateName());
assertTemplateNotUpdated(dataTemplateName());
doExporting();
@ -116,47 +113,6 @@ public abstract class AbstractExporterTemplateTestCase extends MarvelIntegTestCa
awaitIndexExists(currentTimestampedIndexName());
}
public void testRandomTemplates() throws Exception {
internalCluster().startNode();
int previousIndexTemplateVersion = rarely() ? currentVersion : randomIntBetween(0, currentVersion - 1);
boolean previousIndexTemplateExist = randomBoolean();
if (previousIndexTemplateExist) {
logger.debug("--> creating index template in version [{}]", previousIndexTemplateVersion);
putTemplate(indexTemplateName(previousIndexTemplateVersion), previousIndexTemplateVersion);
}
int previousDataTemplateVersion = rarely() ? currentVersion : randomIntBetween(0, currentVersion - 1);
boolean previousDataTemplateExist = randomBoolean();
if (previousDataTemplateExist) {
logger.debug("--> creating data template in version [{}]", previousDataTemplateVersion);
putTemplate(dataTemplateName(previousDataTemplateVersion), previousDataTemplateVersion);
}
doExporting();
logger.debug("--> templates should exist in current version");
for (String template : monitoringTemplates().keySet()) {
assertTemplateExist(template);
}
if (previousIndexTemplateExist) {
logger.debug("--> index template should exist in version [{}]", previousIndexTemplateVersion);
assertTemplateExist(indexTemplateName(previousIndexTemplateVersion));
}
if (previousDataTemplateExist) {
logger.debug("--> data template should exist in version [{}]", previousDataTemplateVersion);
assertTemplateExist(dataTemplateName(previousDataTemplateVersion));
}
doExporting();
logger.debug("--> indices should exist in current version");
awaitIndexExists(currentDataIndexName());
awaitIndexExists(currentTimestampedIndexName());
}
protected void doExporting() throws Exception {
Collector collector = internalCluster().getInstance(ClusterStatsCollector.class);
assertNotNull(collector);
@ -169,18 +125,18 @@ public abstract class AbstractExporterTemplateTestCase extends MarvelIntegTestCa
exporters.export(collector.collect());
}
private String dataTemplateName(Integer version) {
MockDataIndexNameResolver resolver = new MockDataIndexNameResolver(version);
private String dataTemplateName() {
MockDataIndexNameResolver resolver = new MockDataIndexNameResolver();
return resolver.templateName();
}
private String indexTemplateName(Integer version) {
MockTimestampedIndexNameResolver resolver = new MockTimestampedIndexNameResolver(MonitoredSystem.ES, version, exporterSettings());
private String indexTemplateName() {
MockTimestampedIndexNameResolver resolver = new MockTimestampedIndexNameResolver(MonitoredSystem.ES, exporterSettings());
return resolver.templateName();
}
private String currentDataIndexName() {
MockDataIndexNameResolver resolver = new MockDataIndexNameResolver(currentVersion);
MockDataIndexNameResolver resolver = new MockDataIndexNameResolver();
return resolver.index(null);
}
@ -188,13 +144,12 @@ public abstract class AbstractExporterTemplateTestCase extends MarvelIntegTestCa
MonitoringDoc doc = new MonitoringDoc(MonitoredSystem.ES.getSystem(), Version.CURRENT.toString());
doc.setTimestamp(System.currentTimeMillis());
MockTimestampedIndexNameResolver resolver = new MockTimestampedIndexNameResolver(MonitoredSystem.ES, currentVersion,
exporterSettings());
MockTimestampedIndexNameResolver resolver = new MockTimestampedIndexNameResolver(MonitoredSystem.ES, exporterSettings());
return resolver.index(doc);
}
/** Generates a basic template **/
protected static BytesReference generateTemplateSource(String name, Integer version) throws IOException {
protected static BytesReference generateTemplateSource(String name) throws IOException {
return jsonBuilder().startObject()
.field("template", name)
.startObject("settings")

View File

@ -15,7 +15,7 @@ import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsException;
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.MonitoredSystem;
import org.elasticsearch.marvel.agent.exporter.local.LocalExporter;
import org.elasticsearch.marvel.cleaner.CleanerService;
@ -71,8 +71,8 @@ public class ExportersTests extends ESTestCase {
// we always need to have the local exporter as it serves as the default one
factories.put(LocalExporter.TYPE, new LocalExporter.Factory(MonitoringClientProxy.of(client), clusterService,
mock(CleanerService.class)));
clusterSettings = new ClusterSettings(Settings.EMPTY, new HashSet<>(Arrays.asList(MarvelSettings.COLLECTORS,
MarvelSettings.INTERVAL, MarvelSettings.EXPORTERS_SETTINGS)));
clusterSettings = new ClusterSettings(Settings.EMPTY, new HashSet<>(Arrays.asList(MonitoringSettings.COLLECTORS,
MonitoringSettings.INTERVAL, MonitoringSettings.EXPORTERS_SETTINGS)));
exporters = new Exporters(Settings.EMPTY, factories, clusterService, clusterSettings);
}
@ -179,7 +179,7 @@ public class ExportersTests extends ESTestCase {
.put("xpack.monitoring.agent.exporters._name0.type", "_type")
.put("xpack.monitoring.agent.exporters._name1.type", "_type")
.build();
clusterSettings = new ClusterSettings(nodeSettings, new HashSet<>(Arrays.asList(MarvelSettings.EXPORTERS_SETTINGS)));
clusterSettings = new ClusterSettings(nodeSettings, new HashSet<>(Arrays.asList(MonitoringSettings.EXPORTERS_SETTINGS)));
exporters = new Exporters(nodeSettings, factories, clusterService, clusterSettings) {
@Override

View File

@ -5,100 +5,31 @@
*/
package org.elasticsearch.marvel.agent.exporter;
import org.apache.lucene.util.Constants;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.test.ESTestCase;
import org.hamcrest.Matcher;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
import java.io.IOException;
import static org.elasticsearch.xpack.template.TemplateUtilsTests.assertTemplate;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.notNullValue;
public class MarvelTemplateUtilsTests extends ESTestCase {
private static final String TEST_TEMPLATE = "/monitoring-test.json";
@Rule
public ExpectedException expectedException = ExpectedException.none();
public void testLoadTemplate() throws IOException {
final int version = randomIntBetween(0, 10_000);
String source = MarvelTemplateUtils.loadTemplate("test", version);
String source = MarvelTemplateUtils.loadTemplate("test");
assertThat(source, notNullValue());
assertThat(source.length(), greaterThan(0));
assertTemplate(source, equalTo("{\n" +
" \"template\": \".monitoring-data-" + version + "\",\n" +
" \"template\": \".monitoring-data-" + MarvelTemplateUtils.TEMPLATE_VERSION + "\",\n" +
" \"mappings\": {\n" +
" \"type_1\": {\n" +
" \"_meta\": {\n" +
" \"template.version\": \"" + version + "\"\n" +
" \"template.version\": \"" + MarvelTemplateUtils.TEMPLATE_VERSION + "\"\n" +
" }\n" +
" }\n" +
" }\n" +
"}"));
}
public void testLoad() throws IOException {
BytesReference source = MarvelTemplateUtils.load(TEST_TEMPLATE);
assertThat(source, notNullValue());
assertThat(source.length(), greaterThan(0));
}
public void testValidateNullSource() {
expectedException.expect(ElasticsearchParseException.class);
expectedException.expectMessage("Monitoring template must not be null");
MarvelTemplateUtils.validate(null);
}
public void testValidateEmptySource() {
expectedException.expect(ElasticsearchParseException.class);
expectedException.expectMessage("Monitoring template must not be empty");
MarvelTemplateUtils.validate(new BytesArray(""));
}
public void testValidateInvalidSource() {
expectedException.expect(ElasticsearchParseException.class);
expectedException.expectMessage("Invalid monitoring template");
MarvelTemplateUtils.validate(new BytesArray("{\"foo\": \"bar"));
}
public void testValidate() {
try {
MarvelTemplateUtils.validate(MarvelTemplateUtils.load(TEST_TEMPLATE));
} catch (Exception e) {
fail("failed to validate test template: " + e.getMessage());
}
}
public void testFilter() {
assertTemplate(MarvelTemplateUtils.filter(new BytesArray("${monitoring.template.version}"), 0), equalTo("0"));
assertTemplate(MarvelTemplateUtils.filter(new BytesArray("{\"template\": \"test-${monitoring.template.version}\"}"), 1),
equalTo("{\"template\": \"test-1\"}"));
assertTemplate(MarvelTemplateUtils.filter(new BytesArray("{\"template\": \"${monitoring.template.version}-test\"}"), 2),
equalTo("{\"template\": \"2-test\"}"));
assertTemplate(MarvelTemplateUtils.filter(new BytesArray("{\"template\": \"test-${monitoring.template.version}-test\"}"), 3),
equalTo("{\"template\": \"test-3-test\"}"));
final int version = randomIntBetween(0, 100);
assertTemplate(MarvelTemplateUtils.filter(new BytesArray("{\"foo-${monitoring.template.version}\": " +
"\"bar-${monitoring.template.version}\"}"), version),
equalTo("{\"foo-" + version + "\": \"bar-" + version + "\"}"));
}
public static void assertTemplate(String actual, Matcher<? super String> matcher) {
if (Constants.WINDOWS) {
// translate Windows line endings (\r\n) to standard ones (\n)
actual = Strings.replace(actual, System.lineSeparator(), "\n");
}
assertThat(actual, matcher);
}
}

View File

@ -74,8 +74,8 @@ public class HttpExporterTemplateTests extends AbstractExporterTemplateTestCase
}
@Override
protected void putTemplate(String name, int version) throws Exception {
dispatcher.templates.put(name, generateTemplateSource(name, version));
protected void putTemplate(String name) throws Exception {
dispatcher.templates.put(name, generateTemplateSource(name));
}
@Override

View File

@ -24,7 +24,7 @@ import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.DummyTransportAddress;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.MonitoredSystem;
import org.elasticsearch.marvel.agent.collector.cluster.ClusterStateMonitoringDoc;
import org.elasticsearch.marvel.agent.collector.indices.IndexRecoveryMonitoringDoc;
@ -94,7 +94,7 @@ public class HttpExporterTests extends MarvelIntegTestCase {
enqueueResponse(200, "{\"errors\": false, \"msg\": \"successful bulk request\"}");
Settings.Builder builder = Settings.builder()
.put(MarvelSettings.INTERVAL.getKey(), "-1")
.put(MonitoringSettings.INTERVAL.getKey(), "-1")
.put("xpack.monitoring.agent.exporters._http.type", "http")
.put("xpack.monitoring.agent.exporters._http.host", webServer.getHostName() + ":" + webServer.getPort())
.put("xpack.monitoring.agent.exporters._http.connection.keep_alive", false)
@ -132,7 +132,7 @@ public class HttpExporterTests extends MarvelIntegTestCase {
public void testDynamicHostChange() {
// disable exporting to be able to use non valid hosts
Settings.Builder builder = Settings.builder()
.put(MarvelSettings.INTERVAL.getKey(), "-1")
.put(MonitoringSettings.INTERVAL.getKey(), "-1")
.put("xpack.monitoring.agent.exporters._http.type", "http")
.put("xpack.monitoring.agent.exporters._http.host", "test0");
@ -156,7 +156,7 @@ public class HttpExporterTests extends MarvelIntegTestCase {
public void testHostChangeReChecksTemplate() throws Exception {
Settings.Builder builder = Settings.builder()
.put(MarvelSettings.INTERVAL.getKey(), "-1")
.put(MonitoringSettings.INTERVAL.getKey(), "-1")
.put("xpack.monitoring.agent.exporters._http.type", "http")
.put("xpack.monitoring.agent.exporters._http.host", webServer.getHostName() + ":" + webServer.getPort())
.put("xpack.monitoring.agent.exporters._http.connection.keep_alive", false)
@ -273,7 +273,7 @@ public class HttpExporterTests extends MarvelIntegTestCase {
public void testUnsupportedClusterVersion() throws Exception {
Settings.Builder builder = Settings.builder()
.put(MarvelSettings.INTERVAL.getKey(), "-1")
.put(MonitoringSettings.INTERVAL.getKey(), "-1")
.put("xpack.monitoring.agent.exporters._http.type", "http")
.put("xpack.monitoring.agent.exporters._http.host", webServer.getHostName() + ":" + webServer.getPort())
.put("xpack.monitoring.agent.exporters._http.connection.keep_alive", false);
@ -301,7 +301,7 @@ public class HttpExporterTests extends MarvelIntegTestCase {
public void testDynamicIndexFormatChange() throws Exception {
Settings.Builder builder = Settings.builder()
.put(MarvelSettings.INTERVAL.getKey(), "-1")
.put(MonitoringSettings.INTERVAL.getKey(), "-1")
.put("xpack.monitoring.agent.exporters._http.type", "http")
.put("xpack.monitoring.agent.exporters._http.host", webServer.getHostName() + ":" + webServer.getPort())
.put("xpack.monitoring.agent.exporters._http.connection.keep_alive", false)
@ -401,7 +401,7 @@ public class HttpExporterTests extends MarvelIntegTestCase {
final String host = webServer.getHostName() + ":" + webServer.getPort();
Settings.Builder builder = Settings.builder()
.put(MarvelSettings.INTERVAL.getKey(), "-1")
.put(MonitoringSettings.INTERVAL.getKey(), "-1")
.put("xpack.monitoring.agent.exporters._http.type", "http")
.put("xpack.monitoring.agent.exporters._http.host", host)
.put("xpack.monitoring.agent.exporters._http.connection.keep_alive", false);

View File

@ -26,9 +26,9 @@ public class LocalExporterTemplateTests extends AbstractExporterTemplateTestCase
}
@Override
protected void putTemplate(String name, int version) throws Exception {
protected void putTemplate(String name) throws Exception {
waitNoPendingTasksOnAll();
assertAcked(client().admin().indices().preparePutTemplate(name).setSource(generateTemplateSource(name, version)).get());
assertAcked(client().admin().indices().preparePutTemplate(name).setSource(generateTemplateSource(name)).get());
}
@Override

View File

@ -14,7 +14,7 @@ import org.elasticsearch.cluster.health.ClusterHealthStatus;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.DummyTransportAddress;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.MonitoredSystem;
import org.elasticsearch.marvel.agent.collector.cluster.ClusterStateMonitoringDoc;
import org.elasticsearch.marvel.agent.collector.indices.IndexRecoveryMonitoringDoc;
@ -53,7 +53,7 @@ public class LocalExporterTests extends MarvelIntegTestCase {
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(MarvelSettings.INTERVAL.getKey(), "-1")
.put(MonitoringSettings.INTERVAL.getKey(), "-1")
.build();
}

View File

@ -10,6 +10,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.transport.DummyTransportAddress;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils;
import org.elasticsearch.marvel.agent.exporter.MonitoringDoc;
import java.io.IOException;
@ -20,11 +21,9 @@ import static org.hamcrest.Matchers.equalTo;
public class DataResolverTests extends MonitoringIndexNameResolverTestCase {
private int randomVersion = randomIntBetween(0, 100);
@Override
protected MonitoringIndexNameResolver<MonitoringDoc> newResolver() {
return newDataResolver(randomVersion);
return newDataResolver();
}
@Override
@ -52,12 +51,11 @@ public class DataResolverTests extends MonitoringIndexNameResolverTestCase {
}
public void testDataResolver() {
assertThat(newDataResolver(randomVersion).index(newMarvelDoc()), equalTo(".monitoring-data-" + randomVersion));
assertThat(newDataResolver(42).index(newMarvelDoc()), equalTo(".monitoring-data-42"));
assertThat(newDataResolver().index(newMarvelDoc()), equalTo(".monitoring-data-" + MarvelTemplateUtils.TEMPLATE_VERSION));
}
private MonitoringIndexNameResolver.Data<MonitoringDoc> newDataResolver(int randomVersion) {
return new MonitoringIndexNameResolver.Data<MonitoringDoc>(randomVersion) {
private MonitoringIndexNameResolver.Data<MonitoringDoc> newDataResolver() {
return new MonitoringIndexNameResolver.Data<MonitoringDoc>() {
@Override
public String type(MonitoringDoc document) {
return null;

View File

@ -11,6 +11,7 @@ import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.marvel.MonitoredSystem;
import org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils;
import org.elasticsearch.marvel.agent.exporter.MonitoringDoc;
import org.elasticsearch.test.ESTestCase;
@ -128,18 +129,17 @@ public abstract class MonitoringIndexNameResolverTestCase<M extends MonitoringDo
public void testResolver() {
MonitoringIndexNameResolver resolver = newResolver();
assertThat(resolver, notNullValue());
assertThat(resolver.getVersion(), greaterThanOrEqualTo(0));
if (resolver instanceof MonitoringIndexNameResolver.Timestamped) {
MonitoringIndexNameResolver.Timestamped timestamped = (MonitoringIndexNameResolver.Timestamped) resolver;
assertThat(resolver.index(newMarvelDoc()),
startsWith(PREFIX + DELIMITER + timestamped.getId() + DELIMITER + timestamped.getVersion() + DELIMITER));
startsWith(PREFIX + DELIMITER + timestamped.getId() + DELIMITER + MarvelTemplateUtils.TEMPLATE_VERSION + DELIMITER));
}
if (resolver instanceof MonitoringIndexNameResolver.Data) {
MonitoringIndexNameResolver.Data data = (MonitoringIndexNameResolver.Data) resolver;
assertThat(resolver.index(newMarvelDoc()),
equalTo(PREFIX + DELIMITER + MonitoringIndexNameResolver.Data.DATA + DELIMITER + String.valueOf(data.getVersion())));
equalTo(PREFIX + DELIMITER + MonitoringIndexNameResolver.Data.DATA + DELIMITER + MarvelTemplateUtils.TEMPLATE_VERSION));
}
}
@ -148,9 +148,9 @@ public abstract class MonitoringIndexNameResolverTestCase<M extends MonitoringDo
assertNotNull(sourceFields);
String[] commons = new String[]{
CLUSTER_UUID.underscore().getValue(),
TIMESTAMP.underscore().getValue(),
SOURCE_NODE.underscore().getValue(),
CLUSTER_UUID,
TIMESTAMP,
SOURCE_NODE,
};
assertThat("source must contains default fields", sourceFields.keySet(), hasItems(commons));

View File

@ -12,6 +12,7 @@ import org.elasticsearch.common.transport.DummyTransportAddress;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.marvel.MonitoredSystem;
import org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils;
import org.elasticsearch.marvel.agent.exporter.MonitoringDoc;
import org.joda.time.format.DateTimeFormat;
@ -28,11 +29,10 @@ import static org.hamcrest.Matchers.notNullValue;
public class TimestampedResolverTests extends MonitoringIndexNameResolverTestCase {
private MonitoredSystem randomId = randomFrom(MonitoredSystem.values());
private int randomVersion = randomIntBetween(0, 100);
@Override
protected MonitoringIndexNameResolver<MonitoringDoc> newResolver() {
return newTimestampedResolver(randomId, randomVersion, Settings.EMPTY);
return newTimestampedResolver(randomId, Settings.EMPTY);
}
@Override
@ -72,19 +72,17 @@ public class TimestampedResolverTests extends MonitoringIndexNameResolverTestCas
.build();
}
MonitoringIndexNameResolver.Timestamped resolver = newTimestampedResolver(randomId, randomVersion, settings);
MonitoringIndexNameResolver.Timestamped resolver = newTimestampedResolver(randomId, settings);
assertThat(resolver, notNullValue());
assertThat(resolver.getId(), equalTo(randomId.getSystem()));
assertThat(resolver.getVersion(), equalTo(randomVersion));
assertThat(resolver.index(doc),
equalTo(PREFIX + DELIMITER + resolver.getId() + DELIMITER + String.valueOf(resolver.getVersion())
equalTo(PREFIX + DELIMITER + resolver.getId() + DELIMITER + String.valueOf(MarvelTemplateUtils.TEMPLATE_VERSION)
+ DELIMITER + DateTimeFormat.forPattern(format).withZoneUTC().print(1437580442979L)));
}
}
private MonitoringIndexNameResolver.Timestamped<MonitoringDoc> newTimestampedResolver(MonitoredSystem id, int version,
Settings settings) {
return new MonitoringIndexNameResolver.Timestamped<MonitoringDoc>(id, version, settings) {
private MonitoringIndexNameResolver.Timestamped<MonitoringDoc> newTimestampedResolver(MonitoredSystem id, Settings settings) {
return new MonitoringIndexNameResolver.Timestamped<MonitoringDoc>(id, settings) {
@Override
public String type(MonitoringDoc document) {
return null;

View File

@ -11,7 +11,7 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.license.core.License;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.agent.collector.cluster.ClusterStatsCollector;
import org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils;
import org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolver;
@ -39,8 +39,8 @@ public class ClusterInfoTests extends MarvelIntegTestCase {
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(MarvelSettings.INTERVAL.getKey(), "-1")
.put(MarvelSettings.COLLECTORS.getKey(), ClusterStatsCollector.NAME)
.put(MonitoringSettings.INTERVAL.getKey(), "-1")
.put(MonitoringSettings.COLLECTORS.getKey(), ClusterStatsCollector.NAME)
.build();
}
@ -77,42 +77,42 @@ public class ClusterInfoTests extends MarvelIntegTestCase {
assertThat(response.getId(), equalTo(clusterUUID));
Map<String, Object> source = response.getSource();
assertThat(source.get(MonitoringIndexNameResolver.Fields.CLUSTER_UUID.underscore().toString()), notNullValue());
assertThat(source.get(MonitoringIndexNameResolver.Fields.TIMESTAMP.underscore().toString()), notNullValue());
assertThat(source.get(MonitoringIndexNameResolver.Fields.SOURCE_NODE.underscore().toString()), notNullValue());
assertThat(source.get(ClusterInfoResolver.Fields.CLUSTER_NAME.underscore().toString()), equalTo(cluster().getClusterName()));
assertThat(source.get(ClusterInfoResolver.Fields.VERSION.underscore().toString()), equalTo(Version.CURRENT.toString()));
assertThat(source.get(MonitoringIndexNameResolver.Fields.CLUSTER_UUID), notNullValue());
assertThat(source.get(MonitoringIndexNameResolver.Fields.TIMESTAMP), notNullValue());
assertThat(source.get(MonitoringIndexNameResolver.Fields.SOURCE_NODE), notNullValue());
assertThat(source.get(ClusterInfoResolver.Fields.CLUSTER_NAME), equalTo(cluster().getClusterName()));
assertThat(source.get(ClusterInfoResolver.Fields.VERSION), equalTo(Version.CURRENT.toString()));
logger.debug("--> checking that the document contains license information");
Object licenseObj = source.get(ClusterInfoResolver.Fields.LICENSE.underscore().toString());
Object licenseObj = source.get(ClusterInfoResolver.Fields.LICENSE);
assertThat(licenseObj, instanceOf(Map.class));
Map license = (Map) licenseObj;
assertThat(license, instanceOf(Map.class));
String uid = (String) license.get(ClusterInfoResolver.Fields.UID.underscore().toString());
String uid = (String) license.get(ClusterInfoResolver.Fields.UID);
assertThat(uid, not(isEmptyOrNullString()));
String type = (String) license.get(ClusterInfoResolver.Fields.TYPE.underscore().toString());
String type = (String) license.get(ClusterInfoResolver.Fields.TYPE);
assertThat(type, not(isEmptyOrNullString()));
String status = (String) license.get(License.XFields.STATUS.underscore().toString());
String status = (String) license.get(License.Fields.STATUS);
assertThat(status, not(isEmptyOrNullString()));
Long expiryDate = (Long) license.get(License.XFields.EXPIRY_DATE_IN_MILLIS.underscore().toString());
Long expiryDate = (Long) license.get(License.Fields.EXPIRY_DATE_IN_MILLIS);
assertThat(expiryDate, greaterThan(0L));
// We basically recompute the hash here
String hkey = (String) license.get(ClusterInfoResolver.Fields.HKEY.underscore().toString());
String hkey = (String) license.get(ClusterInfoResolver.Fields.HKEY);
String recalculated = ClusterInfoResolver.hash(status, uid, type, String.valueOf(expiryDate), clusterUUID);
assertThat(hkey, equalTo(recalculated));
assertThat((String) license.get(License.XFields.ISSUER.underscore().toString()), not(isEmptyOrNullString()));
assertThat((String) license.get(License.XFields.ISSUED_TO.underscore().toString()), not(isEmptyOrNullString()));
assertThat((Long) license.get(License.XFields.ISSUE_DATE_IN_MILLIS.underscore().toString()), greaterThan(0L));
assertThat((Integer) license.get(License.XFields.MAX_NODES.underscore().toString()), greaterThan(0));
assertThat((String) license.get(License.Fields.ISSUER), not(isEmptyOrNullString()));
assertThat((String) license.get(License.Fields.ISSUED_TO), not(isEmptyOrNullString()));
assertThat((Long) license.get(License.Fields.ISSUE_DATE_IN_MILLIS), greaterThan(0L));
assertThat((Integer) license.get(License.Fields.MAX_NODES), greaterThan(0));
Object clusterStats = source.get(ClusterInfoResolver.Fields.CLUSTER_STATS.underscore().toString());
Object clusterStats = source.get(ClusterInfoResolver.Fields.CLUSTER_STATS);
assertNotNull(clusterStats);
assertThat(clusterStats, instanceOf(Map.class));
assertThat(((Map) clusterStats).size(), greaterThan(0));
@ -128,10 +128,10 @@ public class ClusterInfoTests extends MarvelIntegTestCase {
.setTypes(ClusterInfoResolver.TYPE)
.setQuery(
QueryBuilders.boolQuery()
.should(QueryBuilders.matchQuery(License.XFields.STATUS.underscore().toString(), License.Status.ACTIVE.label()))
.should(QueryBuilders.matchQuery(License.XFields.STATUS.underscore().toString(), License.Status.INVALID.label()))
.should(QueryBuilders.matchQuery(License.XFields.STATUS.underscore().toString(), License.Status.EXPIRED.label()))
.should(QueryBuilders.matchQuery(ClusterInfoResolver.Fields.CLUSTER_NAME.underscore().toString(),
.should(QueryBuilders.matchQuery(License.Fields.STATUS, License.Status.ACTIVE.label()))
.should(QueryBuilders.matchQuery(License.Fields.STATUS, License.Status.INVALID.label()))
.should(QueryBuilders.matchQuery(License.Fields.STATUS, License.Status.EXPIRED.label()))
.should(QueryBuilders.matchQuery(ClusterInfoResolver.Fields.CLUSTER_NAME,
cluster().getClusterName()))
.minimumNumberShouldMatch(1)
).get(), 0L);

View File

@ -10,7 +10,7 @@ import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.agent.collector.cluster.ClusterStateCollector;
import org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolver;
import org.elasticsearch.marvel.test.MarvelIntegTestCase;
@ -43,8 +43,8 @@ public class ClusterStateTests extends MarvelIntegTestCase {
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(MarvelSettings.INTERVAL.getKey(), "-1")
.put(MarvelSettings.COLLECTORS.getKey(), ClusterStateCollector.NAME)
.put(MonitoringSettings.INTERVAL.getKey(), "-1")
.put(MonitoringSettings.COLLECTORS.getKey(), ClusterStateCollector.NAME)
.put("xpack.monitoring.agent.exporters.default_local.type", "local")
.put("node.attr.custom", randomInt)
.build();
@ -107,7 +107,7 @@ public class ClusterStateTests extends MarvelIntegTestCase {
public void testClusterStateNodes() throws Exception {
final long nbNodes = internalCluster().size();
MonitoringIndexNameResolver.Timestamped timestampedResolver = new MockTimestampedIndexNameResolver(ES, TEMPLATE_VERSION);
MonitoringIndexNameResolver.Timestamped timestampedResolver = new MockTimestampedIndexNameResolver(ES);
assertNotNull(timestampedResolver);
String timestampedIndex = timestampedResolver.indexPattern();
@ -122,13 +122,13 @@ public class ClusterStateTests extends MarvelIntegTestCase {
logger.debug("--> checking that every document contains the expected fields");
String[] filters = {
MonitoringIndexNameResolver.Fields.CLUSTER_UUID.underscore().toString(),
MonitoringIndexNameResolver.Fields.TIMESTAMP.underscore().toString(),
SOURCE_NODE.underscore().toString(),
ClusterStateNodeResolver.Fields.STATE_UUID.underscore().toString(),
ClusterStateNodeResolver.Fields.NODE.underscore().toString(),
ClusterStateNodeResolver.Fields.NODE.underscore().toString() + "."
+ ClusterStateNodeResolver.Fields.ID.underscore().toString(),
MonitoringIndexNameResolver.Fields.CLUSTER_UUID,
MonitoringIndexNameResolver.Fields.TIMESTAMP,
SOURCE_NODE,
ClusterStateNodeResolver.Fields.STATE_UUID,
ClusterStateNodeResolver.Fields.NODE,
ClusterStateNodeResolver.Fields.NODE + "."
+ ClusterStateNodeResolver.Fields.ID,
};
for (SearchHit searchHit : response.getHits().getHits()) {
@ -143,7 +143,7 @@ public class ClusterStateTests extends MarvelIntegTestCase {
assertThat(client().prepareSearch().setSize(0)
.setIndices(timestampedIndex)
.setTypes(ClusterStateNodeResolver.TYPE)
.setQuery(QueryBuilders.matchQuery(SOURCE_NODE.underscore().toString() + ".attributes.custom", randomInt))
.setQuery(QueryBuilders.matchQuery(SOURCE_NODE + ".attributes.custom", randomInt))
.get().getHits().getTotalHits(), greaterThan(0L));
logger.debug("--> cluster state nodes successfully collected");
@ -152,7 +152,7 @@ public class ClusterStateTests extends MarvelIntegTestCase {
public void testDiscoveryNodes() throws Exception {
final long nbNodes = internalCluster().size();
MonitoringIndexNameResolver.Data dataResolver = new MockDataIndexNameResolver(TEMPLATE_VERSION);
MonitoringIndexNameResolver.Data dataResolver = new MockDataIndexNameResolver();
assertNotNull(dataResolver);
String dataIndex = dataResolver.indexPattern();
@ -167,18 +167,18 @@ public class ClusterStateTests extends MarvelIntegTestCase {
logger.debug("--> checking that every document contains the expected fields");
String[] filters = {
MonitoringIndexNameResolver.Fields.CLUSTER_UUID.underscore().toString(),
MonitoringIndexNameResolver.Fields.TIMESTAMP.underscore().toString(),
MonitoringIndexNameResolver.Fields.SOURCE_NODE.underscore().toString(),
DiscoveryNodeResolver.Fields.NODE.underscore().toString(),
DiscoveryNodeResolver.Fields.NODE.underscore().toString() + "."
+ DiscoveryNodeResolver.Fields.ID.underscore().toString(),
DiscoveryNodeResolver.Fields.NODE.underscore().toString() + "."
+ DiscoveryNodeResolver.Fields.NAME.underscore().toString(),
DiscoveryNodeResolver.Fields.NODE.underscore().toString() + "."
+ DiscoveryNodeResolver.Fields.ATTRIBUTES.underscore().toString(),
DiscoveryNodeResolver.Fields.NODE.underscore().toString() + "."
+ DiscoveryNodeResolver.Fields.TRANSPORT_ADDRESS.underscore().toString(),
MonitoringIndexNameResolver.Fields.CLUSTER_UUID,
MonitoringIndexNameResolver.Fields.TIMESTAMP,
MonitoringIndexNameResolver.Fields.SOURCE_NODE,
DiscoveryNodeResolver.Fields.NODE,
DiscoveryNodeResolver.Fields.NODE + "."
+ DiscoveryNodeResolver.Fields.ID,
DiscoveryNodeResolver.Fields.NODE + "."
+ DiscoveryNodeResolver.Fields.NAME,
DiscoveryNodeResolver.Fields.NODE + "."
+ DiscoveryNodeResolver.Fields.ATTRIBUTES,
DiscoveryNodeResolver.Fields.NODE + "."
+ DiscoveryNodeResolver.Fields.TRANSPORT_ADDRESS,
};
for (SearchHit searchHit : response.getHits().getHits()) {

View File

@ -8,7 +8,7 @@ package org.elasticsearch.marvel.agent.resolver.cluster;
import org.elasticsearch.action.admin.cluster.stats.ClusterStatsNodes;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.agent.collector.cluster.ClusterStatsCollector;
import org.elasticsearch.marvel.test.MarvelIntegTestCase;
import org.elasticsearch.search.SearchHit;
@ -30,8 +30,8 @@ public class ClusterStatsTests extends MarvelIntegTestCase {
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(MarvelSettings.INTERVAL.getKey(), "-1")
.put(MarvelSettings.COLLECTORS.getKey(), ClusterStatsCollector.NAME)
.put(MonitoringSettings.INTERVAL.getKey(), "-1")
.put(MonitoringSettings.COLLECTORS.getKey(), ClusterStatsCollector.NAME)
.put("xpack.monitoring.agent.exporters.default_local.type", "local")
.build();
}

View File

@ -9,7 +9,7 @@ import org.elasticsearch.action.admin.indices.recovery.RecoveryResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.agent.collector.indices.IndexRecoveryCollector;
import org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolver;
import org.elasticsearch.marvel.test.MarvelIntegTestCase;
@ -35,9 +35,9 @@ public class IndexRecoveryTests extends MarvelIntegTestCase {
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(MarvelSettings.INTERVAL.getKey(), "-1")
.put(MarvelSettings.INDICES.getKey(), INDEX_PREFIX + "*")
.put(MarvelSettings.COLLECTORS.getKey(), IndexRecoveryCollector.NAME)
.put(MonitoringSettings.INTERVAL.getKey(), "-1")
.put(MonitoringSettings.INDICES.getKey(), INDEX_PREFIX + "*")
.put(MonitoringSettings.COLLECTORS.getKey(), IndexRecoveryCollector.NAME)
.put("xpack.monitoring.agent.exporters.default_local.type", "local")
.build();
}
@ -80,12 +80,12 @@ public class IndexRecoveryTests extends MarvelIntegTestCase {
logger.debug("--> checking that every document contains the expected fields");
String[] filters = {
MonitoringIndexNameResolver.Fields.CLUSTER_UUID.underscore().toString(),
MonitoringIndexNameResolver.Fields.TIMESTAMP.underscore().toString(),
MonitoringIndexNameResolver.Fields.SOURCE_NODE.underscore().toString(),
IndexRecoveryResolver.Fields.INDEX_RECOVERY.underscore().toString(),
IndexRecoveryResolver.Fields.INDEX_RECOVERY.underscore().toString() + "."
+ IndexRecoveryResolver.Fields.SHARDS.underscore().toString(),
MonitoringIndexNameResolver.Fields.CLUSTER_UUID,
MonitoringIndexNameResolver.Fields.TIMESTAMP,
MonitoringIndexNameResolver.Fields.SOURCE_NODE,
IndexRecoveryResolver.Fields.INDEX_RECOVERY,
IndexRecoveryResolver.Fields.INDEX_RECOVERY + "."
+ IndexRecoveryResolver.Fields.SHARDS,
};
for (SearchHit searchHit : response.getHits().getHits()) {

View File

@ -8,7 +8,7 @@ package org.elasticsearch.marvel.agent.resolver.indices;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.agent.collector.indices.IndexStatsCollector;
import org.elasticsearch.marvel.test.MarvelIntegTestCase;
import org.elasticsearch.search.SearchHit;
@ -28,8 +28,8 @@ public class IndexStatsTests extends MarvelIntegTestCase {
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(MarvelSettings.INTERVAL.getKey(), "-1")
.put(MarvelSettings.COLLECTORS.getKey(), IndexStatsCollector.NAME)
.put(MonitoringSettings.INTERVAL.getKey(), "-1")
.put(MonitoringSettings.COLLECTORS.getKey(), IndexStatsCollector.NAME)
.put("xpack.monitoring.agent.exporters.default_local.type", "local")
.build();
}

View File

@ -8,9 +8,8 @@ package org.elasticsearch.marvel.agent.resolver.indices;
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.agent.collector.indices.IndicesStatsCollector;
import org.elasticsearch.marvel.agent.resolver.indices.IndicesStatsResolver;
import org.elasticsearch.marvel.test.MarvelIntegTestCase;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
@ -29,8 +28,8 @@ public class IndicesStatsTests extends MarvelIntegTestCase {
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(MarvelSettings.INTERVAL.getKey(), "-1")
.put(MarvelSettings.COLLECTORS.getKey(), IndicesStatsCollector.NAME)
.put(MonitoringSettings.INTERVAL.getKey(), "-1")
.put(MonitoringSettings.COLLECTORS.getKey(), IndicesStatsCollector.NAME)
.put("xpack.monitoring.agent.exporters.default_local.type", "local")
.build();
}

View File

@ -8,7 +8,7 @@ package org.elasticsearch.marvel.agent.resolver.node;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.test.MarvelIntegTestCase;
import org.elasticsearch.node.Node;
import org.elasticsearch.search.aggregations.Aggregation;
@ -34,7 +34,7 @@ public class MultiNodesStatsTests extends MarvelIntegTestCase {
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(MarvelSettings.INTERVAL.getKey(), "-1")
.put(MonitoringSettings.INTERVAL.getKey(), "-1")
.put("xpack.monitoring.agent.exporters.default_local.type", "local")
.build();
}

View File

@ -8,7 +8,7 @@ package org.elasticsearch.marvel.agent.resolver.node;
import org.apache.lucene.util.Constants;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.agent.collector.node.NodeStatsCollector;
import org.elasticsearch.marvel.agent.exporter.local.LocalExporter;
import org.elasticsearch.marvel.test.MarvelIntegTestCase;
@ -31,8 +31,8 @@ public class NodeStatsTests extends MarvelIntegTestCase {
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(MarvelSettings.INTERVAL.getKey(), "-1")
.put(MarvelSettings.COLLECTORS.getKey(), NodeStatsCollector.NAME)
.put(MonitoringSettings.INTERVAL.getKey(), "-1")
.put(MonitoringSettings.COLLECTORS.getKey(), NodeStatsCollector.NAME)
.put("xpack.monitoring.agent.exporters.default_local.type", LocalExporter.TYPE)
.build();
}

View File

@ -11,9 +11,8 @@ import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.agent.collector.shards.ShardsCollector;
import org.elasticsearch.marvel.agent.resolver.shards.ShardsResolver;
import org.elasticsearch.marvel.test.MarvelIntegTestCase;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.aggregations.Aggregation;
@ -43,9 +42,9 @@ public class ShardsTests extends MarvelIntegTestCase {
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(MarvelSettings.INTERVAL.getKey(), "-1")
.put(MarvelSettings.COLLECTORS.getKey(), ShardsCollector.NAME)
.put(MarvelSettings.INDICES.getKey(), INDEX_PREFIX + "*")
.put(MonitoringSettings.INTERVAL.getKey(), "-1")
.put(MonitoringSettings.COLLECTORS.getKey(), ShardsCollector.NAME)
.put(MonitoringSettings.INDICES.getKey(), INDEX_PREFIX + "*")
.put("xpack.monitoring.agent.exporters.default_local.type", "local")
.build();
}

View File

@ -10,7 +10,7 @@ import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.agent.AgentService;
import org.elasticsearch.marvel.test.MarvelIntegTestCase;
import org.elasticsearch.test.ESIntegTestCase;
@ -46,28 +46,28 @@ public class MarvelSettingsTests extends MarvelIntegTestCase {
private Settings marvelSettings() {
return Settings.builder()
.put(MarvelSettings.INTERVAL.getKey(), interval)
.put(MarvelSettings.INDEX_STATS_TIMEOUT.getKey(), indexStatsTimeout)
.put(MarvelSettings.INDICES_STATS_TIMEOUT.getKey(), indicesStatsTimeout)
.putArray(MarvelSettings.INDICES.getKey(), indices)
.put(MarvelSettings.CLUSTER_STATE_TIMEOUT.getKey(), clusterStateTimeout)
.put(MarvelSettings.CLUSTER_STATS_TIMEOUT.getKey(), clusterStatsTimeout)
.put(MarvelSettings.INDEX_RECOVERY_TIMEOUT.getKey(), recoveryTimeout)
.put(MarvelSettings.INDEX_RECOVERY_ACTIVE_ONLY.getKey(), recoveryActiveOnly)
.putArray(MarvelSettings.COLLECTORS.getKey(), collectors)
.put(MonitoringSettings.INTERVAL.getKey(), interval)
.put(MonitoringSettings.INDEX_STATS_TIMEOUT.getKey(), indexStatsTimeout)
.put(MonitoringSettings.INDICES_STATS_TIMEOUT.getKey(), indicesStatsTimeout)
.putArray(MonitoringSettings.INDICES.getKey(), indices)
.put(MonitoringSettings.CLUSTER_STATE_TIMEOUT.getKey(), clusterStateTimeout)
.put(MonitoringSettings.CLUSTER_STATS_TIMEOUT.getKey(), clusterStatsTimeout)
.put(MonitoringSettings.INDEX_RECOVERY_TIMEOUT.getKey(), recoveryTimeout)
.put(MonitoringSettings.INDEX_RECOVERY_ACTIVE_ONLY.getKey(), recoveryActiveOnly)
.putArray(MonitoringSettings.COLLECTORS.getKey(), collectors)
.build();
}
public void testMarvelSettings() throws Exception {
logger.info("--> testing monitoring settings service initialization");
for (final MarvelSettings marvelSettings : internalCluster().getInstances(MarvelSettings.class)) {
assertThat(marvelSettings.indexStatsTimeout().millis(), equalTo(indexStatsTimeout.millis()));
assertThat(marvelSettings.indicesStatsTimeout().millis(), equalTo(indicesStatsTimeout.millis()));
assertArrayEquals(marvelSettings.indices(), indices);
assertThat(marvelSettings.clusterStateTimeout().millis(), equalTo(clusterStateTimeout.millis()));
assertThat(marvelSettings.clusterStatsTimeout().millis(), equalTo(clusterStatsTimeout.millis()));
assertThat(marvelSettings.recoveryTimeout().millis(), equalTo(recoveryTimeout.millis()));
assertThat(marvelSettings.recoveryActiveOnly(), equalTo(recoveryActiveOnly));
for (final MonitoringSettings monitoringSettings : internalCluster().getInstances(MonitoringSettings.class)) {
assertThat(monitoringSettings.indexStatsTimeout().millis(), equalTo(indexStatsTimeout.millis()));
assertThat(monitoringSettings.indicesStatsTimeout().millis(), equalTo(indicesStatsTimeout.millis()));
assertArrayEquals(monitoringSettings.indices(), indices);
assertThat(monitoringSettings.clusterStateTimeout().millis(), equalTo(clusterStateTimeout.millis()));
assertThat(monitoringSettings.clusterStatsTimeout().millis(), equalTo(clusterStatsTimeout.millis()));
assertThat(monitoringSettings.recoveryTimeout().millis(), equalTo(recoveryTimeout.millis()));
assertThat(monitoringSettings.recoveryActiveOnly(), equalTo(recoveryActiveOnly));
}
for (final AgentService service : internalCluster().getInstances(AgentService.class)) {
@ -79,15 +79,15 @@ public class MarvelSettingsTests extends MarvelIntegTestCase {
logger.info("--> testing monitoring dynamic settings update");
Settings.Builder transientSettings = Settings.builder();
final Setting[] marvelSettings = new Setting[] {
MarvelSettings.INDICES,
MarvelSettings.INTERVAL,
MarvelSettings.INDEX_RECOVERY_TIMEOUT,
MarvelSettings.INDEX_STATS_TIMEOUT,
MarvelSettings.INDICES_STATS_TIMEOUT,
MarvelSettings.INDEX_RECOVERY_ACTIVE_ONLY,
MarvelSettings.COLLECTORS,
MarvelSettings.CLUSTER_STATE_TIMEOUT,
MarvelSettings.CLUSTER_STATS_TIMEOUT };
MonitoringSettings.INDICES,
MonitoringSettings.INTERVAL,
MonitoringSettings.INDEX_RECOVERY_TIMEOUT,
MonitoringSettings.INDEX_STATS_TIMEOUT,
MonitoringSettings.INDICES_STATS_TIMEOUT,
MonitoringSettings.INDEX_RECOVERY_ACTIVE_ONLY,
MonitoringSettings.COLLECTORS,
MonitoringSettings.CLUSTER_STATE_TIMEOUT,
MonitoringSettings.CLUSTER_STATS_TIMEOUT };
for (Setting<?> setting : marvelSettings) {
if (setting.isDynamic()) {
Object updated = null;
@ -115,26 +115,26 @@ public class MarvelSettingsTests extends MarvelIntegTestCase {
if (setting.isDynamic() == false) {
continue;
}
if (setting == MarvelSettings.INTERVAL) {
if (setting == MonitoringSettings.INTERVAL) {
for (final AgentService service : internalCluster().getInstances(AgentService.class)) {
assertEquals(service.getSamplingInterval(), setting.get(updatedSettings));
}
} else {
for (final MarvelSettings marvelSettings1 : internalCluster().getInstances(MarvelSettings.class)) {
if (setting == MarvelSettings.INDEX_STATS_TIMEOUT) {
assertEquals(marvelSettings1.indexStatsTimeout(), setting.get(updatedSettings));
} else if (setting == MarvelSettings.INDICES_STATS_TIMEOUT) {
assertEquals(marvelSettings1.indicesStatsTimeout(), setting.get(updatedSettings));
} else if (setting == MarvelSettings.CLUSTER_STATS_TIMEOUT) {
assertEquals(marvelSettings1.clusterStatsTimeout(), setting.get(updatedSettings));
} else if (setting == MarvelSettings.CLUSTER_STATE_TIMEOUT) {
assertEquals(marvelSettings1.clusterStateTimeout(), setting.get(updatedSettings));
} else if (setting == MarvelSettings.INDEX_RECOVERY_TIMEOUT) {
assertEquals(marvelSettings1.recoveryTimeout(), setting.get(updatedSettings));
} else if (setting == MarvelSettings.INDEX_RECOVERY_ACTIVE_ONLY) {
assertEquals(Boolean.valueOf(marvelSettings1.recoveryActiveOnly()), setting.get(updatedSettings));
} else if (setting == MarvelSettings.INDICES) {
assertEquals(Arrays.asList(marvelSettings1.indices()), setting.get(updatedSettings));
for (final MonitoringSettings monitoringSettings1 : internalCluster().getInstances(MonitoringSettings.class)) {
if (setting == MonitoringSettings.INDEX_STATS_TIMEOUT) {
assertEquals(monitoringSettings1.indexStatsTimeout(), setting.get(updatedSettings));
} else if (setting == MonitoringSettings.INDICES_STATS_TIMEOUT) {
assertEquals(monitoringSettings1.indicesStatsTimeout(), setting.get(updatedSettings));
} else if (setting == MonitoringSettings.CLUSTER_STATS_TIMEOUT) {
assertEquals(monitoringSettings1.clusterStatsTimeout(), setting.get(updatedSettings));
} else if (setting == MonitoringSettings.CLUSTER_STATE_TIMEOUT) {
assertEquals(monitoringSettings1.clusterStateTimeout(), setting.get(updatedSettings));
} else if (setting == MonitoringSettings.INDEX_RECOVERY_TIMEOUT) {
assertEquals(monitoringSettings1.recoveryTimeout(), setting.get(updatedSettings));
} else if (setting == MonitoringSettings.INDEX_RECOVERY_ACTIVE_ONLY) {
assertEquals(Boolean.valueOf(monitoringSettings1.recoveryActiveOnly()), setting.get(updatedSettings));
} else if (setting == MonitoringSettings.INDICES) {
assertEquals(Arrays.asList(monitoringSettings1.indices()), setting.get(updatedSettings));
} else {
fail("unable to check value for unknown dynamic setting [" + setting + "]");
}

View File

@ -7,7 +7,7 @@ package org.elasticsearch.marvel.cleaner;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.MonitoredSystem;
import org.elasticsearch.marvel.agent.exporter.Exporter;
import org.elasticsearch.marvel.agent.exporter.Exporters;
@ -19,6 +19,8 @@ import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import org.elasticsearch.test.VersionUtils;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import java.util.Locale;
@ -31,7 +33,7 @@ public abstract class AbstractIndicesCleanerTestCase extends MarvelIntegTestCase
protected Settings nodeSettings(int nodeOrdinal) {
Settings.Builder settings = Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(MarvelSettings.INTERVAL.getKey(), "-1");
.put(MonitoringSettings.INTERVAL.getKey(), "-1");
return settings.build();
}
@ -46,7 +48,7 @@ public abstract class AbstractIndicesCleanerTestCase extends MarvelIntegTestCase
public void testDeleteIndex() throws Exception {
internalCluster().startNode();
createTimestampedIndex(MarvelTemplateUtils.TEMPLATE_VERSION, now().minusDays(10));
createTimestampedIndex(now().minusDays(10));
assertIndicesCount(1);
CleanerService.Listener listener = getListener();
@ -57,7 +59,7 @@ public abstract class AbstractIndicesCleanerTestCase extends MarvelIntegTestCase
public void testIgnoreCurrentDataIndex() throws Exception {
internalCluster().startNode();
createDataIndex(MarvelTemplateUtils.TEMPLATE_VERSION, now().minusDays(10));
createDataIndex(now().minusDays(10));
assertIndicesCount(1);
CleanerService.Listener listener = getListener();
@ -68,9 +70,12 @@ public abstract class AbstractIndicesCleanerTestCase extends MarvelIntegTestCase
public void testIgnoreDataIndicesInOtherVersions() throws Exception {
internalCluster().startNode();
createIndex(MarvelSettings.LEGACY_DATA_INDEX_NAME, now().minusYears(1));
createDataIndex(0, now().minusDays(10));
createDataIndex(Integer.MAX_VALUE, now().minusDays(20));
createIndex(MonitoringSettings.LEGACY_DATA_INDEX_NAME, now().minusYears(1));
createDataIndex(now().minusDays(10));
String olderIndex = String.join(MonitoringIndexNameResolver.DELIMITER, MonitoringIndexNameResolver.PREFIX,
MonitoringIndexNameResolver.Data.DATA, "1");
createIndex(olderIndex, now().minusDays(20));
assertIndicesCount(3);
CleanerService.Listener listener = getListener();
@ -81,8 +86,8 @@ public abstract class AbstractIndicesCleanerTestCase extends MarvelIntegTestCase
public void testIgnoreCurrentTimestampedIndex() throws Exception {
internalCluster().startNode();
createTimestampedIndex(MarvelTemplateUtils.TEMPLATE_VERSION, now().minusDays(10));
createTimestampedIndex(MarvelTemplateUtils.TEMPLATE_VERSION, now());
createTimestampedIndex(now().minusDays(10));
createTimestampedIndex(now());
assertIndicesCount(2);
CleanerService.Listener listener = getListener();
@ -93,8 +98,13 @@ public abstract class AbstractIndicesCleanerTestCase extends MarvelIntegTestCase
public void testIgnoreTimestampedIndicesInOtherVersions() throws Exception {
internalCluster().startNode();
createTimestampedIndex(0, now().minusDays(10));
createTimestampedIndex(Integer.MAX_VALUE, now().minusDays(10));
createTimestampedIndex(now().minusDays(10));
// create an older index based on an older template
DateTimeFormatter formatter = DateTimeFormat.forPattern("YYYY.MM.dd").withZoneUTC();
String index = String.join(MonitoringIndexNameResolver.DELIMITER, MonitoringIndexNameResolver.PREFIX,
MonitoredSystem.ES.getSystem(), "1");
String timestampedIndex = String.join("-", index, formatter.print(now().minusDays(10)));
createIndex(timestampedIndex, now().minusDays(10));
assertIndicesCount(2);
CleanerService.Listener listener = getListener();
@ -108,11 +118,11 @@ public abstract class AbstractIndicesCleanerTestCase extends MarvelIntegTestCase
CleanerService.Listener listener = getListener();
final DateTime now = now();
createTimestampedIndex(MarvelTemplateUtils.TEMPLATE_VERSION, now.minusYears(1));
createTimestampedIndex(MarvelTemplateUtils.TEMPLATE_VERSION, now.minusMonths(6));
createTimestampedIndex(MarvelTemplateUtils.TEMPLATE_VERSION, now.minusMonths(1));
createTimestampedIndex(MarvelTemplateUtils.TEMPLATE_VERSION, now.minusDays(10));
createTimestampedIndex(MarvelTemplateUtils.TEMPLATE_VERSION, now.minusDays(1));
createTimestampedIndex(now.minusYears(1));
createTimestampedIndex(now.minusMonths(6));
createTimestampedIndex(now.minusMonths(1));
createTimestampedIndex(now.minusDays(10));
createTimestampedIndex(now.minusDays(1));
assertIndicesCount(5);
// Clean indices that have expired two years ago
@ -143,12 +153,12 @@ public abstract class AbstractIndicesCleanerTestCase extends MarvelIntegTestCase
public void testRetentionAsGlobalSetting() throws Exception {
final int max = 10;
final int retention = randomIntBetween(1, max);
internalCluster().startNode(Settings.builder().put(MarvelSettings.HISTORY_DURATION.getKey(),
internalCluster().startNode(Settings.builder().put(MonitoringSettings.HISTORY_DURATION.getKey(),
String.format(Locale.ROOT, "%dd", retention)));
final DateTime now = now();
for (int i = 0; i < max; i++) {
createTimestampedIndex(MarvelTemplateUtils.TEMPLATE_VERSION, now.minusDays(i));
createTimestampedIndex(now.minusDays(i));
}
assertIndicesCount(max);
@ -175,18 +185,18 @@ public abstract class AbstractIndicesCleanerTestCase extends MarvelIntegTestCase
/**
* Creates a monitoring data index in a given version.
*/
protected void createDataIndex(int version, DateTime creationDate) {
createIndex(new MockDataIndexNameResolver(version).index(randomMonitoringDoc()), creationDate);
protected void createDataIndex(DateTime creationDate) {
createIndex(new MockDataIndexNameResolver().index(randomMonitoringDoc()), creationDate);
}
/**
* Creates a monitoring timestamped index in a given version.
*/
protected void createTimestampedIndex(int version, DateTime creationDate) {
protected void createTimestampedIndex(DateTime creationDate) {
MonitoringDoc monitoringDoc = randomMonitoringDoc();
monitoringDoc.setTimestamp(creationDate.getMillis());
MonitoringIndexNameResolver.Timestamped resolver = new MockTimestampedIndexNameResolver(MonitoredSystem.ES, version);
MonitoringIndexNameResolver.Timestamped resolver = new MockTimestampedIndexNameResolver(MonitoredSystem.ES);
createIndex(resolver.index(monitoringDoc), creationDate);
}

View File

@ -8,8 +8,8 @@ package org.elasticsearch.marvel.cleaner;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.license.MarvelLicensee;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.MonitoringLicensee;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.joda.time.DateTime;
@ -33,13 +33,13 @@ public class CleanerServiceTests extends ESTestCase {
@Rule
public ExpectedException expectedException = ExpectedException.none();
private final MarvelLicensee licensee = mock(MarvelLicensee.class);
private final MonitoringLicensee licensee = mock(MonitoringLicensee.class);
private ClusterSettings clusterSettings;
private ThreadPool threadPool;
@Before
public void start() {
clusterSettings = new ClusterSettings(Settings.EMPTY, Collections.singleton(MarvelSettings.HISTORY_DURATION));
clusterSettings = new ClusterSettings(Settings.EMPTY, Collections.singleton(MonitoringSettings.HISTORY_DURATION));
threadPool = new ThreadPool("CleanerServiceTests");
}
@ -53,14 +53,14 @@ public class CleanerServiceTests extends ESTestCase {
expectedException.expect(IllegalArgumentException.class);
TimeValue expected = TimeValue.timeValueHours(1);
Settings settings = Settings.builder().put(MarvelSettings.HISTORY_DURATION.getKey(), expected.getStringRep()).build();
Settings settings = Settings.builder().put(MonitoringSettings.HISTORY_DURATION.getKey(), expected.getStringRep()).build();
new CleanerService(settings, clusterSettings, threadPool, licensee);
}
public void testGetRetentionWithSettingWithUpdatesAllowed() {
TimeValue expected = TimeValue.timeValueHours(25);
Settings settings = Settings.builder().put(MarvelSettings.HISTORY_DURATION.getKey(), expected.getStringRep()).build();
Settings settings = Settings.builder().put(MonitoringSettings.HISTORY_DURATION.getKey(), expected.getStringRep()).build();
when(licensee.allowUpdateRetention()).thenReturn(true);
@ -72,7 +72,7 @@ public class CleanerServiceTests extends ESTestCase {
public void testGetRetentionDefaultValueWithNoSettings() {
when(licensee.allowUpdateRetention()).thenReturn(true);
assertEquals(MarvelSettings.HISTORY_DURATION.get(Settings.EMPTY),
assertEquals(MonitoringSettings.HISTORY_DURATION.get(Settings.EMPTY),
new CleanerService(Settings.EMPTY, clusterSettings, threadPool, licensee).getRetention());
verify(licensee).allowUpdateRetention();
@ -80,11 +80,11 @@ public class CleanerServiceTests extends ESTestCase {
public void testGetRetentionDefaultValueWithSettingsButUpdatesNotAllowed() {
TimeValue notExpected = TimeValue.timeValueHours(25);
Settings settings = Settings.builder().put(MarvelSettings.HISTORY_DURATION.getKey(), notExpected.getStringRep()).build();
Settings settings = Settings.builder().put(MonitoringSettings.HISTORY_DURATION.getKey(), notExpected.getStringRep()).build();
when(licensee.allowUpdateRetention()).thenReturn(false);
assertEquals(MarvelSettings.HISTORY_DURATION.get(Settings.EMPTY),
assertEquals(MonitoringSettings.HISTORY_DURATION.get(Settings.EMPTY),
new CleanerService(settings, clusterSettings, threadPool, licensee).getRetention());
verify(licensee).allowUpdateRetention();
@ -150,7 +150,7 @@ public class CleanerServiceTests extends ESTestCase {
CountDownLatch latch = new CountDownLatch(nbExecutions);
logger.debug("--> creates a cleaner service that cleans every second");
MarvelLicensee licensee = mock(MarvelLicensee.class);
MonitoringLicensee licensee = mock(MonitoringLicensee.class);
when(licensee.cleaningEnabled()).thenReturn(true);
CleanerService service = new CleanerService(Settings.EMPTY, clusterSettings, licensee, threadPool,
new TestExecutionScheduler(1_000));

View File

@ -19,6 +19,7 @@ import org.elasticsearch.license.plugin.core.LicenseState;
import org.elasticsearch.license.plugin.core.Licensee;
import org.elasticsearch.license.plugin.core.LicenseeRegistry;
import org.elasticsearch.license.plugin.core.LicensesManagerService;
import org.elasticsearch.marvel.MonitoringLicensee;
import org.elasticsearch.marvel.test.MarvelIntegTestCase;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
@ -62,10 +63,10 @@ public class LicenseIntegrationTests extends MarvelIntegTestCase {
assertThat(getLicensee().collectionEnabled(), is(true));
}
private MarvelLicensee getLicensee() {
MarvelLicensee marvelLicensee = internalCluster().getInstance(MarvelLicensee.class);
assertNotNull(marvelLicensee);
return marvelLicensee;
private MonitoringLicensee getLicensee() {
MonitoringLicensee licensee = internalCluster().getInstance(MonitoringLicensee.class);
assertNotNull(licensee);
return licensee;
}
public static void disableLicensing() {

View File

@ -11,6 +11,7 @@ import org.elasticsearch.license.plugin.core.AbstractLicenseeTestCase;
import org.elasticsearch.license.plugin.core.LicenseState;
import org.elasticsearch.license.plugin.core.Licensee.Status;
import org.elasticsearch.license.plugin.core.LicenseeRegistry;
import org.elasticsearch.marvel.MonitoringLicensee;
import java.util.function.Predicate;
@ -21,13 +22,13 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
/**
* Tests {@link MarvelLicensee}.
* Tests {@link MonitoringLicensee}.
* <p>
* If you change the behavior of these tests, then it means that licensing changes for Monitoring!
*/
public class MarvelLicenseeTests extends AbstractLicenseeTestCase {
private final LicenseeRegistry registry = mock(LicenseeRegistry.class);
private final MarvelLicensee licensee = new MarvelLicensee(Settings.EMPTY, registry);
private final MonitoringLicensee licensee = new MonitoringLicensee(Settings.EMPTY, registry);
public void testAcknowledgementMessagesToAnyFromFreeIsNoOp() {
assertEmptyAck(OperationMode.BASIC, randomMode(), licensee);
@ -48,27 +49,27 @@ public class MarvelLicenseeTests extends AbstractLicenseeTestCase {
}
public void testCollectionEnabledIsTrueForActiveState() {
assertEnabled(randomEnabledOrGracePeriodState(), MarvelLicensee::collectionEnabled, true);
assertEnabled(randomEnabledOrGracePeriodState(), MonitoringLicensee::collectionEnabled, true);
}
public void testCollectionEnabledIsFalseForInactiveState() {
assertEnabled(LicenseState.DISABLED, MarvelLicensee::collectionEnabled, false);
assertEnabled(LicenseState.DISABLED, MonitoringLicensee::collectionEnabled, false);
}
public void testCleaningEnabledIsTrueForActiveState() {
assertEnabled(randomEnabledOrGracePeriodState(), MarvelLicensee::cleaningEnabled, true);
assertEnabled(randomEnabledOrGracePeriodState(), MonitoringLicensee::cleaningEnabled, true);
}
public void testCleaningEnabledIsFalseForInactiveState() {
assertEnabled(LicenseState.DISABLED, MarvelLicensee::cleaningEnabled, false);
assertEnabled(LicenseState.DISABLED, MonitoringLicensee::cleaningEnabled, false);
}
public void testAllowUpdateRetentionIsTrueForNotBasic() {
assertEnabled(randomModeExcept(OperationMode.BASIC), MarvelLicensee::allowUpdateRetention, true);
assertEnabled(randomModeExcept(OperationMode.BASIC), MonitoringLicensee::allowUpdateRetention, true);
}
public void testAllowUpdateRetentionIsFalseForBasic() {
assertEnabled(OperationMode.BASIC, MarvelLicensee::allowUpdateRetention, false);
assertEnabled(OperationMode.BASIC, MonitoringLicensee::allowUpdateRetention, false);
}
/**
@ -78,7 +79,7 @@ public class MarvelLicenseeTests extends AbstractLicenseeTestCase {
* @param predicate The method to invoke (expected to be an instance method).
* @param expected The expected outcome given the {@code state} and {@code predicate}.
*/
private void assertEnabled(LicenseState state, Predicate<MarvelLicensee> predicate, boolean expected) {
private void assertEnabled(LicenseState state, Predicate<MonitoringLicensee> predicate, boolean expected) {
Status status = mock(Status.class);
when(status.getLicenseState()).thenReturn(state);
@ -97,7 +98,7 @@ public class MarvelLicenseeTests extends AbstractLicenseeTestCase {
* @param predicate The method to invoke (expected to be an instance method).
* @param expected The expected outcome given the {@code mode} and {@code predicate}.
*/
private void assertEnabled(OperationMode mode, Predicate<MarvelLicensee> predicate, boolean expected) {
private void assertEnabled(OperationMode mode, Predicate<MonitoringLicensee> predicate, boolean expected) {
Status status = mock(Status.class);
when(status.getMode()).thenReturn(mode);

View File

@ -10,7 +10,7 @@ import org.elasticsearch.action.ActionRequestBuilder;
import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoringSettings;
import org.elasticsearch.marvel.test.MarvelIntegTestCase;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.shield.InternalClient;
@ -27,7 +27,7 @@ public class MarvelInternalClientTests extends MarvelIntegTestCase {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(NetworkModule.HTTP_ENABLED.getKey(), false)
.put(MarvelSettings.INTERVAL.getKey(), "-1")
.put(MonitoringSettings.INTERVAL.getKey(), "-1")
.build();
}

Some files were not shown because too many files have changed in this diff Show More