[Monitoring] Remove BWC Layer for Marvel (2.3 - 2.4) in 6.0 (elastic/x-pack-elasticsearch#1990)

This removes all BWC code that assisted in reading Marvel indices in 6.0.

Original commit: elastic/x-pack-elasticsearch@253fbf9a73
This commit is contained in:
Chris Earle 2017-07-24 10:23:06 -04:00 committed by GitHub
parent 9078c0b244
commit b302ff32e8
10 changed files with 38 additions and 389 deletions

View File

@ -1,137 +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.xpack.monitoring.exporter.http;
import org.apache.http.HttpEntity;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.ContentType;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.ResponseException;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.Supplier;
/**
* Creates aliases for monitoring indexes created by Marvel 2.3+.
*/
public class BackwardsCompatibilityAliasesResource extends HttpResource {
private static final Logger logger = Loggers.getLogger(BackwardsCompatibilityAliasesResource.class);
private final TimeValue masterTimeout;
/**
* Create a new {@link TemplateHttpResource}.
*
* @param resourceOwnerName The user-recognizable name.
* @param masterTimeout Master timeout to use with any request.
*/
public BackwardsCompatibilityAliasesResource(final String resourceOwnerName, @Nullable final TimeValue masterTimeout) {
super(resourceOwnerName);
this.masterTimeout = masterTimeout;
}
@Override
protected boolean doCheckAndPublish(RestClient client) {
boolean needNewAliases = false;
XContentBuilder request;
try {
Response response = client.performRequest("GET", "/.marvel-es-1-*", Collections.singletonMap("filter_path", "*.aliases"));
Map<String, Object> indices = XContentHelper.convertToMap(JsonXContent.jsonXContent, response.getEntity().getContent(), false);
request = JsonXContent.contentBuilder();
request.startObject().startArray("actions");
for (Map.Entry<String, Object> e : indices.entrySet()) {
String index = e.getKey();
// we add a suffix so that it will not collide with today's monitoring index following an upgrade
String alias = ".monitoring-es-2-" + index.substring(".marvel-es-1-".length()) + "-alias";
if (false == aliasesForIndex(e.getValue()).contains(alias)) {
needNewAliases = true;
addAlias(request, index, alias);
}
}
request.endArray().endObject();
} catch (ResponseException e) {
int statusCode = e.getResponse().getStatusLine().getStatusCode();
if (statusCode == RestStatus.NOT_FOUND.getStatus()) {
logger.debug("no 2.x monitoring indexes found so no need to create backwards compatibility aliases");
return true;
}
logger.error((Supplier<?>) () ->
new ParameterizedMessage("failed to check for 2.x monitoring indexes with [{}]", statusCode),
e);
return false;
} catch (IOException | RuntimeException e) {
logger.error("failed to check for 2.x monitoring indexes", e);
return false;
}
if (false == needNewAliases) {
// Hurray! Nothing to do!
return true;
}
/* Looks like we have to create some new aliases. Note that this is a race with all other exporters on other nodes of Elasticsearch
* targeting this cluster. That is fine because this request is idemopotent, meaning that if it has no work to do it'll just return
* 200 OK { "acknowledged": true }. */
try {
BytesRef bytes = request.bytes().toBytesRef();
HttpEntity body = new ByteArrayEntity(bytes.bytes, bytes.offset, bytes.length, ContentType.APPLICATION_JSON);
Response response = client.performRequest("POST", "/_aliases", parameters(), body);
Map<String, Object> aliasesResponse = XContentHelper.convertToMap(JsonXContent.jsonXContent, response.getEntity().getContent(),
false);
Boolean acked = (Boolean) aliasesResponse.get("acknowledged");
if (acked == null) {
logger.error("Unexpected response format from _aliases action {}", aliasesResponse);
return false;
}
return acked;
} catch (IOException | RuntimeException e) {
logger.error("failed to create aliases for 2.x monitoring indexes", e);
return false;
}
}
private Set<?> aliasesForIndex(Object indexInfo) {
Map<?, ?> info = (Map<?, ?>) indexInfo;
Map<?, ?> aliases = (Map<?, ?>) info.get("aliases");
return aliases.keySet();
}
/**
* Parameters to use for all requests.
*/
Map<String, String> parameters() {
Map<String, String> parameters = new HashMap<>();
if (masterTimeout != null) {
parameters.put("master_timeout", masterTimeout.getStringRep());
}
return parameters;
}
private void addAlias(XContentBuilder request, String index, String alias) throws IOException {
request.startObject().startObject("add");
{
request.field("index", index);
request.field("alias", alias);
}
request.endObject().endObject();
}
}

View File

@ -39,8 +39,6 @@ import org.elasticsearch.xpack.monitoring.resolver.MonitoringIndexNameResolver;
import org.elasticsearch.xpack.monitoring.resolver.ResolversRegistry;
import org.elasticsearch.xpack.ssl.SSLService;
import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds;
import javax.net.ssl.SSLContext;
import java.io.IOException;
import java.util.ArrayList;
@ -132,10 +130,6 @@ public class HttpExporter extends Exporter {
* ES level timeout used when checking and writing pipelines (used to speed up tests)
*/
public static final String PIPELINE_CHECK_TIMEOUT_SETTING = "index.pipeline.master_timeout";
/**
* ES level timeout used when checking and writing aliases (used to speed up tests)
*/
public static final String ALIAS_TIMEOUT_SETTING = "index.alias.master_timeout";
/**
* Minimum supported version of the remote monitoring cluster.
@ -329,10 +323,6 @@ public class HttpExporter extends Exporter {
// load the pipeline (this will get added to as the monitoring API version increases)
configurePipelineResources(config, resourceOwnerName, resources);
// alias .marvel-es-1-* indices
resources.add(new BackwardsCompatibilityAliasesResource(resourceOwnerName,
config.settings().getAsTime(ALIAS_TIMEOUT_SETTING, timeValueSeconds(30))));
// load the watches for cluster alerts if Watcher is available
configureClusterAlertsResources(config, resourceOwnerName, resources);

View File

@ -10,10 +10,6 @@ import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.apache.logging.log4j.util.Supplier;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesAction;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest;
@ -253,11 +249,6 @@ public class LocalExporter extends Exporter implements ClusterStateListener, Cle
}
}
if (null != prepareAddAliasesTo2xIndices(clusterState)) {
logger.debug("old monitoring indexes exist without aliases, waiting for them to get new aliases");
return false;
}
logger.trace("monitoring index templates and pipelines are installed, service can start");
// everything is setup
@ -326,38 +317,6 @@ public class LocalExporter extends Exporter implements ClusterStateListener, Cle
}
}
IndicesAliasesRequest addAliasesTo2xIndices = prepareAddAliasesTo2xIndices(clusterState);
if (addAliasesTo2xIndices == null) {
logger.trace("there are no 2.x monitoring indices or they have all the aliases they need");
} else {
final List<String> monitoringIndices2x = addAliasesTo2xIndices.getAliasActions().stream()
.flatMap((a) -> Arrays.stream(a.indices()))
.collect(Collectors.toList());
logger.debug("there are 2.x monitoring indices {} and they are missing some aliases to make them compatible with 5.x",
monitoringIndices2x);
asyncActions.add(() -> client.execute(IndicesAliasesAction.INSTANCE, addAliasesTo2xIndices,
new ActionListener<IndicesAliasesResponse>() {
@Override
public void onResponse(IndicesAliasesResponse response) {
responseReceived(pendingResponses, true, null);
if (response.isAcknowledged()) {
logger.info("Added modern aliases to 2.x monitoring indices {}", monitoringIndices2x);
} else {
logger.info("Unable to add modern aliases to 2.x monitoring indices {}, response not acknowledged.",
monitoringIndices2x);
}
}
@Override
public void onFailure(Exception e) {
responseReceived(pendingResponses, false, null);
logger.error((Supplier<?>)
() -> new ParameterizedMessage("Unable to add modern aliases to 2.x monitoring indices {}",
monitoringIndices2x), e);
}
}));
}
// avoid constantly trying to setup Watcher, which requires a lot of overhead and avoid attempting to setup during a cluster state
// change
if (state.get() == State.RUNNING && clusterStateChange == false && canUseWatcher()) {
@ -614,23 +573,6 @@ public class LocalExporter extends Exporter implements ClusterStateListener, Cle
});
}
private IndicesAliasesRequest prepareAddAliasesTo2xIndices(ClusterState clusterState) {
IndicesAliasesRequest request = null;
for (IndexMetaData index : clusterState.metaData()) {
String name = index.getIndex().getName();
if (name.startsWith(".marvel-es-1-")) {
// we add a suffix so that it will not collide with today's monitoring index following an upgrade
String alias = ".monitoring-es-2-" + name.substring(".marvel-es-1-".length()) + "-alias";
if (index.getAliases().containsKey(alias)) continue;
if (request == null) {
request = new IndicesAliasesRequest();
}
request.addAliasAction(AliasActions.add().index(name).alias(alias));
}
}
return request;
}
enum State {
INITIALIZED,
RUNNING,

View File

@ -44,7 +44,7 @@ public class ReservedRolesStore {
RoleDescriptor.IndicesPrivileges.builder().indices(".kibana*").privileges("manage", "read", "index", "delete")
.build() }, null, MetadataUtils.DEFAULT_RESERVED_METADATA))
.put("monitoring_user", new RoleDescriptor("monitoring_user", null, new RoleDescriptor.IndicesPrivileges[] {
RoleDescriptor.IndicesPrivileges.builder().indices(".marvel-es-*", ".monitoring-*").privileges("read").build() },
RoleDescriptor.IndicesPrivileges.builder().indices(".monitoring-*").privileges("read").build() },
null, MetadataUtils.DEFAULT_RESERVED_METADATA))
.put("remote_monitoring_agent", new RoleDescriptor("remote_monitoring_agent",
new String[] {
@ -54,7 +54,7 @@ public class ReservedRolesStore {
"cluster:admin/xpack/watcher/watch/delete",
},
new RoleDescriptor.IndicesPrivileges[] {
RoleDescriptor.IndicesPrivileges.builder().indices(".marvel-es-*", ".monitoring-*").privileges("all").build() },
RoleDescriptor.IndicesPrivileges.builder().indices(".monitoring-*").privileges("all").build() },
null, MetadataUtils.DEFAULT_RESERVED_METADATA))
.put("ingest_admin", new RoleDescriptor("ingest_admin", new String[] { "manage_index_templates", "manage_pipeline" },
null, null, MetadataUtils.DEFAULT_RESERVED_METADATA))

View File

@ -178,7 +178,7 @@ public class OldMonitoringIndicesBackwardsCompatibilityTests extends AbstractOld
logger.info("--> Waiting for indices deletion");
CountDown retries = new CountDown(10);
assertBusy(() -> {
String[] indices = new String[]{".marvel-*", ".monitoring-*"};
String[] indices = new String[]{".monitoring-*"};
IndicesExistsResponse existsResponse = client().admin().indices().prepareExists(indices).get();
if (existsResponse.isExists()) {
assertAcked(client().admin().indices().prepareDelete(indices));

View File

@ -26,7 +26,6 @@ import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.env.Environment;
import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.test.ESIntegTestCase;
@ -67,14 +66,12 @@ import static org.elasticsearch.xpack.monitoring.exporter.http.ClusterAlertHttpR
import static org.elasticsearch.xpack.monitoring.exporter.http.PublishableHttpResource.FILTER_PATH_RESOURCE_VERSION;
import static org.elasticsearch.xpack.monitoring.exporter.http.WatcherExistsHttpResource.WATCHER_CHECK_PARAMETERS;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.startsWith;
@ESIntegTestCase.ClusterScope(scope = Scope.TEST,
numDataNodes = 1, numClientNodes = 0, transportClientRatio = 0.0, supportsDedicatedMasters = false)
@ -86,8 +83,6 @@ public class HttpExporterIT extends MonitoringIntegTestCase {
private final boolean remoteClusterAllowsWatcher = randomBoolean();
private final boolean currentLicenseAllowsWatcher = true;
private final boolean watcherAlreadyExists = randomBoolean();
private final boolean bwcIndexesExist = randomBoolean();
private final boolean bwcAliasesExist = randomBoolean();
private final Environment environment = new Environment(Settings.builder().put("path.home", createTempDir()).build());
private MockWebServer webServer;
@ -131,8 +126,7 @@ public class HttpExporterIT extends MonitoringIntegTestCase {
enqueueGetClusterVersionResponse(Version.CURRENT);
enqueueSetupResponses(webServer,
templatesExistsAlready, includeOldTemplates, pipelineExistsAlready,
remoteClusterAllowsWatcher, currentLicenseAllowsWatcher, watcherAlreadyExists,
bwcIndexesExist, bwcAliasesExist);
remoteClusterAllowsWatcher, currentLicenseAllowsWatcher, watcherAlreadyExists);
enqueueResponse(200, "{\"errors\": false, \"msg\": \"successful bulk request\"}");
final int nbDocs = randomIntBetween(1, 25);
@ -140,8 +134,7 @@ public class HttpExporterIT extends MonitoringIntegTestCase {
assertMonitorResources(webServer,
templatesExistsAlready, includeOldTemplates, pipelineExistsAlready,
remoteClusterAllowsWatcher, currentLicenseAllowsWatcher, watcherAlreadyExists,
bwcIndexesExist, bwcAliasesExist);
remoteClusterAllowsWatcher, currentLicenseAllowsWatcher, watcherAlreadyExists);
assertBulk(webServer, nbDocs);
}
@ -167,8 +160,7 @@ public class HttpExporterIT extends MonitoringIntegTestCase {
enqueueGetClusterVersionResponse(Version.CURRENT);
enqueueSetupResponses(webServer,
templatesExistsAlready, includeOldTemplates, pipelineExistsAlready,
remoteClusterAllowsWatcher, currentLicenseAllowsWatcher, watcherAlreadyExists,
bwcIndexesExist, bwcAliasesExist);
remoteClusterAllowsWatcher, currentLicenseAllowsWatcher, watcherAlreadyExists);
enqueueResponse(200, "{\"errors\": false, \"msg\": \"successful bulk request\"}");
final int nbDocs = randomIntBetween(1, 25);
@ -177,7 +169,6 @@ public class HttpExporterIT extends MonitoringIntegTestCase {
assertMonitorResources(webServer,
templatesExistsAlready, includeOldTemplates, pipelineExistsAlready,
remoteClusterAllowsWatcher, currentLicenseAllowsWatcher, watcherAlreadyExists,
bwcIndexesExist, bwcAliasesExist,
headers, null);
assertBulk(webServer, nbDocs, headers, null);
}
@ -228,8 +219,7 @@ public class HttpExporterIT extends MonitoringIntegTestCase {
enqueueGetClusterVersionResponse(Version.CURRENT);
enqueueSetupResponses(webServer,
templatesExistsAlready, includeOldTemplates, pipelineExistsAlready,
remoteClusterAllowsWatcher, currentLicenseAllowsWatcher, watcherAlreadyExists,
bwcIndexesExist, bwcAliasesExist);
remoteClusterAllowsWatcher, currentLicenseAllowsWatcher, watcherAlreadyExists);
enqueueResponse(200, "{\"errors\": false}");
final int nbDocs = randomIntBetween(1, 25);
@ -238,7 +228,6 @@ public class HttpExporterIT extends MonitoringIntegTestCase {
assertMonitorResources(webServer,
templatesExistsAlready, includeOldTemplates, pipelineExistsAlready,
remoteClusterAllowsWatcher, currentLicenseAllowsWatcher, watcherAlreadyExists,
bwcIndexesExist, bwcAliasesExist,
headers, basePath);
assertBulk(webServer, nbDocs, headers, basePath);
}
@ -253,16 +242,14 @@ public class HttpExporterIT extends MonitoringIntegTestCase {
enqueueGetClusterVersionResponse(Version.CURRENT);
enqueueSetupResponses(webServer,
templatesExistsAlready, includeOldTemplates, pipelineExistsAlready,
remoteClusterAllowsWatcher, currentLicenseAllowsWatcher, watcherAlreadyExists,
bwcIndexesExist, bwcAliasesExist);
remoteClusterAllowsWatcher, currentLicenseAllowsWatcher, watcherAlreadyExists);
enqueueResponse(200, "{\"errors\": false}");
export(settings, Collections.singletonList(newRandomMonitoringDoc()));
assertMonitorResources(webServer,
templatesExistsAlready, includeOldTemplates, pipelineExistsAlready,
remoteClusterAllowsWatcher, currentLicenseAllowsWatcher, watcherAlreadyExists,
bwcIndexesExist, bwcAliasesExist);
remoteClusterAllowsWatcher, currentLicenseAllowsWatcher, watcherAlreadyExists);
assertBulk(webServer);
try (MockWebServer secondWebServer = createMockWebServer()) {
@ -287,7 +274,6 @@ public class HttpExporterIT extends MonitoringIntegTestCase {
}
// opposite of if it existed before
enqueuePipelineResponses(secondWebServer, !pipelineExistsAlready);
enqueueBackwardsCompatibilityAliasResponse(secondWebServer, bwcIndexesExist, true);
enqueueWatcherResponses(secondWebServer, remoteClusterAllowsWatcher, currentLicenseAllowsWatcher, watcherAlreadyExists);
enqueueResponse(secondWebServer, 200, "{\"errors\": false}");
@ -311,7 +297,6 @@ public class HttpExporterIT extends MonitoringIntegTestCase {
}
}
assertMonitorPipelines(secondWebServer, !pipelineExistsAlready, null, null);
assertMonitorBackwardsCompatibilityAliases(secondWebServer, false, null, null);
assertMonitorWatches(secondWebServer, remoteClusterAllowsWatcher, currentLicenseAllowsWatcher, watcherAlreadyExists,
null, null);
assertBulk(secondWebServer);
@ -353,8 +338,7 @@ public class HttpExporterIT extends MonitoringIntegTestCase {
enqueueGetClusterVersionResponse(Version.CURRENT);
enqueueSetupResponses(webServer,
templatesExistsAlready, includeOldTemplates, pipelineExistsAlready,
remoteClusterAllowsWatcher, currentLicenseAllowsWatcher, watcherAlreadyExists,
bwcIndexesExist, bwcAliasesExist);
remoteClusterAllowsWatcher, currentLicenseAllowsWatcher, watcherAlreadyExists);
enqueueResponse(200, "{\"errors\": false, \"msg\": \"successful bulk request\"}");
MonitoringDoc doc = newRandomMonitoringDoc();
@ -362,8 +346,7 @@ public class HttpExporterIT extends MonitoringIntegTestCase {
assertMonitorResources(webServer,
templatesExistsAlready, includeOldTemplates, pipelineExistsAlready,
remoteClusterAllowsWatcher, currentLicenseAllowsWatcher, watcherAlreadyExists,
bwcIndexesExist, bwcAliasesExist);
remoteClusterAllowsWatcher, currentLicenseAllowsWatcher, watcherAlreadyExists);
MockRequest recordedRequest = assertBulk(webServer);
@SuppressWarnings("unchecked")
@ -384,8 +367,7 @@ public class HttpExporterIT extends MonitoringIntegTestCase {
enqueueGetClusterVersionResponse(Version.CURRENT);
enqueueSetupResponses(webServer, true, includeOldTemplates, true,
true, true, true,
false, false);
true, true, true);
enqueueResponse(200, "{\"errors\": false, \"msg\": \"successful bulk request\"}");
doc = newRandomMonitoringDoc();
@ -395,8 +377,7 @@ public class HttpExporterIT extends MonitoringIntegTestCase {
+ DateTimeFormat.forPattern(newTimeFormat).withZoneUTC().print(doc.getTimestamp());
assertMonitorResources(webServer, true, includeOldTemplates, true,
true, true, true,
false, false);
true, true, true);
recordedRequest = assertBulk(webServer);
bytes = recordedRequest.getBody().getBytes(StandardCharsets.UTF_8);
@ -427,11 +408,10 @@ public class HttpExporterIT extends MonitoringIntegTestCase {
final boolean templateAlreadyExists, final boolean includeOldTemplates,
final boolean pipelineAlreadyExists,
final boolean remoteClusterAllowsWatcher, final boolean currentLicenseAllowsWatcher,
final boolean watcherAlreadyExists,
final boolean bwcIndexesExist, final boolean bwcAliasesExist) throws Exception {
final boolean watcherAlreadyExists) throws Exception {
assertMonitorResources(webServer, templateAlreadyExists, includeOldTemplates, pipelineAlreadyExists,
remoteClusterAllowsWatcher, currentLicenseAllowsWatcher, watcherAlreadyExists,
bwcIndexesExist, bwcAliasesExist, null, null);
null, null);
}
private void assertMonitorResources(final MockWebServer webServer,
@ -439,13 +419,11 @@ public class HttpExporterIT extends MonitoringIntegTestCase {
final boolean pipelineAlreadyExists,
final boolean remoteClusterAllowsWatcher, final boolean currentLicenseAllowsWatcher,
final boolean watcherAlreadyExists,
boolean bwcIndexesExist, boolean bwcAliasesExist,
@Nullable final Map<String, String[]> customHeaders,
@Nullable final String basePath) throws Exception {
assertMonitorVersion(webServer, customHeaders, basePath);
assertMonitorTemplates(webServer, templateAlreadyExists, includeOldTemplates, customHeaders, basePath);
assertMonitorPipelines(webServer, pipelineAlreadyExists, customHeaders, basePath);
assertMonitorBackwardsCompatibilityAliases(webServer, bwcIndexesExist && false == bwcAliasesExist, customHeaders, basePath);
assertMonitorWatches(webServer, remoteClusterAllowsWatcher, currentLicenseAllowsWatcher, watcherAlreadyExists,
customHeaders, basePath);
}
@ -541,28 +519,6 @@ public class HttpExporterIT extends MonitoringIntegTestCase {
}
}
private void assertMonitorBackwardsCompatibilityAliases(final MockWebServer webServer, final boolean expectPost,
@Nullable final Map<String, String[]> customHeaders, @Nullable final String basePath) throws Exception {
final String pathPrefix = basePathToAssertablePrefix(basePath);
MockRequest request = webServer.takeRequest();
assertThat(request.getMethod(), equalTo("GET"));
assertThat(request.getUri().getPath(), startsWith(pathPrefix + "/.marvel-es-1-*"));
assertThat(request.getUri().getQuery(), containsString("filter_path=*.aliases"));
assertHeaders(request, customHeaders);
if (expectPost) {
request = webServer.takeRequest();
assertThat(request.getMethod(), equalTo("POST"));
assertThat(request.getUri().getPath(), startsWith(pathPrefix + "/_aliases"));
assertThat(request.getUri().getQuery(), containsString("master_timeout=30s"));
assertThat(request.getBody(), containsString("add"));
assertHeaders(request, customHeaders);
}
}
private MockRequest assertBulk(final MockWebServer webServer) throws Exception {
return assertBulk(webServer, -1);
}
@ -708,11 +664,9 @@ public class HttpExporterIT extends MonitoringIntegTestCase {
final boolean templatesAlreadyExists, final boolean includeOldTemplates,
final boolean pipelineAlreadyExists,
final boolean remoteClusterAllowsWatcher, final boolean currentLicenseAllowsWatcher,
final boolean watcherAlreadyExists,
final boolean bwcIndexesExist, final boolean bwcAliasesExist) throws IOException {
final boolean watcherAlreadyExists) throws IOException {
enqueueTemplateResponses(webServer, templatesAlreadyExists, includeOldTemplates);
enqueuePipelineResponses(webServer, pipelineAlreadyExists);
enqueueBackwardsCompatibilityAliasResponse(webServer, bwcIndexesExist, bwcAliasesExist);
enqueueWatcherResponses(webServer, remoteClusterAllowsWatcher, currentLicenseAllowsWatcher, watcherAlreadyExists);
}
@ -868,26 +822,6 @@ public class HttpExporterIT extends MonitoringIntegTestCase {
}
}
private void enqueueBackwardsCompatibilityAliasResponse(MockWebServer webServer, boolean bwcIndexesExist, boolean bwcAliasesExist)
throws IOException {
if (false == bwcIndexesExist && randomBoolean()) {
enqueueResponse(webServer, 404, "index does not exist");
return;
}
XContentBuilder response = JsonXContent.contentBuilder().prettyPrint().startObject();
if (bwcIndexesExist) {
int timestampIndexes = between(1, 100);
for (int i = 0; i < timestampIndexes; i++) {
writeIndex(response, ".marvel-es-1-" + i, bwcAliasesExist ? ".monitoring-es-2-" + i + "-alias" : "ignored");
}
}
response.endObject();
enqueueResponse(webServer, 200, response.string());
if (bwcIndexesExist && false == bwcAliasesExist) {
enqueueResponse(webServer, 200, "{\"acknowledged\": true}");
}
}
private void writeIndex(XContentBuilder response, String index, String alias) throws IOException {
response.startObject(index);
{

View File

@ -343,7 +343,6 @@ public class HttpExporterResourceTests extends AbstractPublishableHttpResourceTe
whenSuccessfulPutTemplates(unsuccessfulGetTemplates);
whenGetPipelines(successfulGetPipelines, unsuccessfulGetPipelines);
whenSuccessfulPutPipelines(unsuccessfulGetPipelines);
whenSuccessfulBackwardsCompatibilityAliases();
// there's only one check
when(client.performRequest(eq("GET"), eq("/_xpack"), anyMapOf(String.class, String.class))).thenThrow(exception);
@ -358,7 +357,6 @@ public class HttpExporterResourceTests extends AbstractPublishableHttpResourceTe
verifyPutTemplates(unsuccessfulGetTemplates);
verifyGetPipelines(EXPECTED_PIPELINES);
verifyPutPipelines(unsuccessfulGetPipelines);
verifyBackwardsCompatibilityAliases();
verifyWatcherCheck();
verifyNoMoreInteractions(client);
}
@ -378,7 +376,6 @@ public class HttpExporterResourceTests extends AbstractPublishableHttpResourceTe
whenSuccessfulPutTemplates(unsuccessfulGetTemplates);
whenGetPipelines(successfulGetPipelines, unsuccessfulGetPipelines);
whenSuccessfulPutPipelines(unsuccessfulGetPipelines);
whenSuccessfulBackwardsCompatibilityAliases();
whenWatcherCanBeUsed(validLicense);
// failure in the middle of various watches being checked/published; suggests a node dropped
@ -435,7 +432,6 @@ public class HttpExporterResourceTests extends AbstractPublishableHttpResourceTe
verifyPutTemplates(unsuccessfulGetTemplates);
verifyGetPipelines(EXPECTED_PIPELINES);
verifyPutPipelines(unsuccessfulGetPipelines);
verifyBackwardsCompatibilityAliases();
verifyWatcherCheck();
if (validLicense) {
verifyGetWatches(expectedGets);
@ -461,7 +457,6 @@ public class HttpExporterResourceTests extends AbstractPublishableHttpResourceTe
whenSuccessfulPutTemplates(unsuccessfulGetTemplates);
whenGetPipelines(successfulGetPipelines, unsuccessfulGetPipelines);
whenSuccessfulPutPipelines(unsuccessfulGetPipelines);
whenSuccessfulBackwardsCompatibilityAliases();
// license needs to be valid, otherwise we'll do DELETEs, which are tested earlier
whenWatcherCanBeUsed(true);
@ -511,7 +506,6 @@ public class HttpExporterResourceTests extends AbstractPublishableHttpResourceTe
verifyPutTemplates(unsuccessfulGetTemplates);
verifyGetPipelines(EXPECTED_PIPELINES);
verifyPutPipelines(unsuccessfulGetPipelines);
verifyBackwardsCompatibilityAliases();
verifyWatcherCheck();
verifyGetWatches(expectedGets);
verifyPutWatches(expectedPuts);
@ -542,7 +536,6 @@ public class HttpExporterResourceTests extends AbstractPublishableHttpResourceTe
} else {
whenWatcherCannotBeUsed();
}
whenSuccessfulBackwardsCompatibilityAliases();
assertTrue(resources.isDirty());
@ -564,7 +557,6 @@ public class HttpExporterResourceTests extends AbstractPublishableHttpResourceTe
verifyDeleteWatches(EXPECTED_WATCHES);
}
}
verifyBackwardsCompatibilityAliases();
verifyNoMoreInteractions(client);
}
@ -590,7 +582,6 @@ public class HttpExporterResourceTests extends AbstractPublishableHttpResourceTe
whenSuccessfulPutTemplates(unsuccessfulGetTemplates);
whenGetPipelines(successfulGetPipelines, unsuccessfulGetPipelines);
whenSuccessfulPutPipelines(1);
whenSuccessfulBackwardsCompatibilityAliases();
assertTrue(resources.isDirty());
@ -603,7 +594,6 @@ public class HttpExporterResourceTests extends AbstractPublishableHttpResourceTe
verifyPutTemplates(unsuccessfulGetTemplates);
verifyGetPipelines(EXPECTED_PIPELINES);
verifyPutPipelines(unsuccessfulGetPipelines);
verifyBackwardsCompatibilityAliases();
verifyNoMoreInteractions(client);
}
@ -877,23 +867,6 @@ public class HttpExporterResourceTests extends AbstractPublishableHttpResourceTe
.thenReturn(successfulDeletes.get(0), successfulDeletes.subList(1, successful).toArray(new Response[successful - 1]));
}
}
private void whenSuccessfulBackwardsCompatibilityAliases() throws IOException {
// Just return no indexes so we won't have to mock adding aliases
final Response response = mock(Response.class);
final StatusLine statusLine = mock(StatusLine.class);
when(response.getStatusLine()).thenReturn(statusLine);
when(statusLine.getStatusCode()).thenReturn(RestStatus.OK.getStatus());
when(response.getEntity()).thenReturn(new StringEntity("{}", ContentType.APPLICATION_JSON));
when(client.performRequest(eq("GET"),
startsWith("/.marvel-es-1-*"),
anyMapOf(String.class, String.class)))
.thenReturn(response);
}
private void verifyVersionCheck() throws IOException {
verify(client).performRequest(eq("GET"), eq("/"), anyMapOf(String.class, String.class));
}
@ -943,10 +916,6 @@ public class HttpExporterResourceTests extends AbstractPublishableHttpResourceTe
any(HttpEntity.class)); // raw template
}
private void verifyBackwardsCompatibilityAliases() throws IOException {
verify(client).performRequest(eq("GET"), startsWith("/.marvel-es-1-*"), anyMapOf(String.class, String.class));
}
private ClusterService mockClusterService(final ClusterState state) {
final ClusterService clusterService = mock(ClusterService.class);

View File

@ -292,7 +292,6 @@ public class HttpExporterTests extends ESTestCase {
final boolean createOldTemplates = randomBoolean();
final TimeValue templateTimeout = randomFrom(TimeValue.timeValueSeconds(30), null);
final TimeValue pipelineTimeout = randomFrom(TimeValue.timeValueSeconds(30), null);
final TimeValue aliasTimeout = randomFrom(TimeValue.timeValueSeconds(30), null);
final Settings.Builder builder = Settings.builder()
.put("xpack.monitoring.exporters._http.type", "http");
@ -318,10 +317,6 @@ public class HttpExporterTests extends ESTestCase {
builder.put("xpack.monitoring.exporters._http.index.pipeline.master_timeout", pipelineTimeout.getStringRep());
}
if (aliasTimeout != null) {
builder.put("xpack.monitoring.exporters._http.index.aliases.master_timeout", aliasTimeout.getStringRep());
}
final Config config = createConfig(builder.build());
final MultiHttpResource multiResource = HttpExporter.createResources(config, new ResolversRegistry(config.settings()));
@ -349,25 +344,19 @@ public class HttpExporterTests extends ESTestCase {
.map(ClusterAlertHttpResource.class::cast)
.collect(Collectors.toList());
}
final List<BackwardsCompatibilityAliasesResource> bwc =
resources.stream().filter(resource -> resource instanceof BackwardsCompatibilityAliasesResource)
.map(BackwardsCompatibilityAliasesResource.class::cast)
.collect(Collectors.toList());
// expected number of resources
assertThat(multiResource.getResources().size(),
equalTo(version + templates.size() + pipelines.size() + watcherCheck.size() + bwc.size()));
equalTo(version + templates.size() + pipelines.size() + watcherCheck.size()));
assertThat(version, equalTo(1));
assertThat(templates, hasSize(createOldTemplates ? 5 + OLD_TEMPLATE_IDS.length : 5));
assertThat(pipelines, hasSize(useIngest ? PIPELINE_IDS.length : 0));
assertThat(watcherCheck, hasSize(clusterAlertManagement ? 1 : 0));
assertThat(watches, hasSize(clusterAlertManagement ? ClusterAlertsUtil.WATCH_IDS.length : 0));
assertThat(bwc, hasSize(1));
// timeouts
assertMasterTimeoutSet(templates, templateTimeout);
assertMasterTimeoutSet(pipelines, pipelineTimeout);
assertMasterTimeoutSet(bwc, aliasTimeout);
// logging owner names
final List<String> uniqueOwners =
@ -478,9 +467,6 @@ public class HttpExporterTests extends ESTestCase {
for (final HttpResource resource : resources) {
if (resource instanceof PublishableHttpResource) {
assertEquals(timeout.getStringRep(), ((PublishableHttpResource) resource).getParameters().get("master_timeout"));
} else if (resource instanceof BackwardsCompatibilityAliasesResource) {
assertEquals(timeout.getStringRep(),
((BackwardsCompatibilityAliasesResource) resource).parameters().get("master_timeout"));
}
}
}

View File

@ -7,12 +7,10 @@ package org.elasticsearch.xpack.monitoring.exporter.local;
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse;
import org.elasticsearch.action.admin.indices.get.GetIndexResponse;
import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse;
import org.elasticsearch.action.index.IndexRequestBuilder;
import org.elasticsearch.action.ingest.GetPipelineResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.cluster.metadata.AliasMetaData;
import org.elasticsearch.cluster.metadata.IndexTemplateMetaData;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference;
@ -60,7 +58,6 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcke
import static org.elasticsearch.xpack.monitoring.MonitoredSystem.BEATS;
import static org.elasticsearch.xpack.monitoring.MonitoredSystem.KIBANA;
import static org.elasticsearch.xpack.monitoring.MonitoredSystem.LOGSTASH;
import static org.elasticsearch.xpack.monitoring.exporter.MonitoringTemplateUtils.OLD_TEMPLATE_VERSION;
import static org.elasticsearch.xpack.monitoring.exporter.MonitoringTemplateUtils.PIPELINE_IDS;
import static org.elasticsearch.xpack.monitoring.exporter.MonitoringTemplateUtils.TEMPLATE_VERSION;
import static org.hamcrest.Matchers.greaterThan;
@ -92,15 +89,6 @@ public class LocalExporterIntegTests extends LocalExporterIntegTestCase {
indexRandom(true, indexRequestBuilders);
}
if (randomBoolean()) {
// create some marvel indices to check if aliases are correctly created
final int oldies = randomIntBetween(1, 5);
for (int i = 0; i < oldies; i++) {
assertAcked(client().admin().indices().prepareCreate(".marvel-es-1-2014.12." + i)
.setSettings("number_of_shards", 1, "number_of_replicas", 0).get());
}
}
Settings.Builder exporterSettings = Settings.builder()
.put("xpack.monitoring.exporters._local.enabled", true);
@ -134,7 +122,6 @@ public class LocalExporterIntegTests extends LocalExporterIntegTestCase {
checkMonitoringTemplates();
checkMonitoringPipelines();
checkMonitoringAliases();
checkMonitoringDocs();
}
@ -194,7 +181,6 @@ public class LocalExporterIntegTests extends LocalExporterIntegTestCase {
checkMonitoringTemplates();
checkMonitoringPipelines();
checkMonitoringAliases();
checkMonitoringWatches();
checkMonitoringDocs();
} finally {
@ -269,23 +255,6 @@ public class LocalExporterIntegTests extends LocalExporterIntegTestCase {
assertTrue("monitoring ingest pipeline not found", response.isFound());
}
/**
* Checks that the local exporter correctly added aliases to indices created with previous
* Marvel versions.
*/
private void checkMonitoringAliases() {
GetIndexResponse response =
client().admin().indices().prepareGetIndex().setIndices(".marvel-es-1-*").get();
for (String index : response.getIndices()) {
List<AliasMetaData> aliases = response.getAliases().get(index);
assertEquals("marvel index should have at least 1 alias: " + index, 1, aliases.size());
String indexDate = index.substring(".marvel-es-1-".length());
String expectedAlias = ".monitoring-es-" + OLD_TEMPLATE_VERSION + "-" + indexDate + "-alias";
assertEquals(expectedAlias, aliases.get(0).getAlias());
}
}
/**
* Checks that the local exporter correctly creates Watches.
*/

View File

@ -214,8 +214,7 @@ public class ReservedRolesStoreTests extends ESTestCase {
assertThat(monitoringUserRole.indices().allowedIndicesMatcher("indices:foo").test(randomAlphaOfLengthBetween(8, 24)),
is(false));
Arrays.asList(".monitoring-" + randomAlphaOfLength(randomIntBetween(0, 13)),
".marvel-es-" + randomAlphaOfLength(randomIntBetween(0, 13))).forEach((index) -> {
final String index = ".monitoring-" + randomAlphaOfLength(randomIntBetween(0, 13));
assertThat(monitoringUserRole.indices().allowedIndicesMatcher("indices:foo").test(index), is(false));
assertThat(monitoringUserRole.indices().allowedIndicesMatcher("indices:bar").test(index), is(false));
assertThat(monitoringUserRole.indices().allowedIndicesMatcher(DeleteIndexAction.NAME).test(index), is(false));
@ -225,7 +224,6 @@ public class ReservedRolesStoreTests extends ESTestCase {
assertThat(monitoringUserRole.indices().allowedIndicesMatcher(UpdateSettingsAction.NAME).test(index), is(false));
assertThat(monitoringUserRole.indices().allowedIndicesMatcher(SearchAction.NAME).test(index), is(true));
assertThat(monitoringUserRole.indices().allowedIndicesMatcher(GetAction.NAME).test(index), is(true));
});
}
public void testRemoteMonitoringAgentRole() {
@ -259,8 +257,7 @@ public class ReservedRolesStoreTests extends ESTestCase {
assertThat(remoteMonitoringAgentRole.indices().allowedIndicesMatcher("indices:foo")
.test(randomAlphaOfLengthBetween(8, 24)), is(false));
Arrays.asList(".monitoring-" + randomAlphaOfLength(randomIntBetween(0, 13)),
".marvel-es-" + randomAlphaOfLength(randomIntBetween(0, 13))).forEach((index) -> {
final String index = ".monitoring-" + randomAlphaOfLength(randomIntBetween(0, 13));
assertThat(remoteMonitoringAgentRole.indices().allowedIndicesMatcher("indices:foo").test(index), is(true));
assertThat(remoteMonitoringAgentRole.indices().allowedIndicesMatcher("indices:bar").test(index), is(true));
assertThat(remoteMonitoringAgentRole.indices().allowedIndicesMatcher(DeleteIndexAction.NAME).test(index), is(true));
@ -271,7 +268,6 @@ public class ReservedRolesStoreTests extends ESTestCase {
assertThat(remoteMonitoringAgentRole.indices().allowedIndicesMatcher(SearchAction.NAME).test(index), is(true));
assertThat(remoteMonitoringAgentRole.indices().allowedIndicesMatcher(GetAction.NAME).test(index), is(true));
assertThat(remoteMonitoringAgentRole.indices().allowedIndicesMatcher(GetIndexAction.NAME).test(index), is(true));
});
}
public void testReportingUserRole() {