[Monitoring] Add 'logstash' type to old .monitoring-data-2 indices (elastic/elasticsearch#4517)

Add `logstash`, in addition to `kibana` type mappings if they are missing from the _existing_ .monitoring-data-2 indices. This allows existing indices to be upgraded in place to support the Logstash monitoring feature added in 5.2 without having to delete the .monitoring-data-2 index.

Original commit: elastic/x-pack-elasticsearch@864343a116
This commit is contained in:
Chris Earle 2017-01-04 00:43:30 -05:00 committed by GitHub
parent b799c1603b
commit 35b405d029
5 changed files with 60 additions and 63 deletions

View File

@ -24,7 +24,7 @@ public final class MonitoringTemplateUtils {
/**
* Data types that should be supported by the {@linkplain #DATA_INDEX data index} that were not by the initial release.
*/
public static final String[] NEW_DATA_TYPES = { "kibana" };
public static final String[] NEW_DATA_TYPES = { "kibana", "logstash" };
private MonitoringTemplateUtils() {
}

View File

@ -411,7 +411,7 @@ public class HttpExporterIT extends MonitoringIntegTestCase {
final String pathPrefix = basePathToAssertablePrefix(basePath);
MockRequest request;
for (String type : monitoringProductTypes()) {
for (final String type : MonitoringTemplateUtils.NEW_DATA_TYPES) {
request = webServer.takeRequest();
assertThat(request.getMethod(), equalTo("GET"));
@ -586,10 +586,6 @@ public class HttpExporterIT extends MonitoringIntegTestCase {
return docs;
}
private List<String> monitoringProductTypes() {
return Arrays.asList("kibana");
}
private String basePathToAssertablePrefix(@Nullable String basePath) {
if (basePath == null) {
return "";
@ -635,14 +631,14 @@ public class HttpExporterIT extends MonitoringIntegTestCase {
}
private void enqueueMappingTypeResponsesDoesNotExistYet(final MockWebServer webServer) throws IOException {
for (String type : monitoringProductTypes()) {
for (final String type : MonitoringTemplateUtils.NEW_DATA_TYPES) {
enqueueResponse(webServer, 200, "{}");
enqueueResponse(webServer, 200, "type [" + type + "] created");
}
}
private void enqueueMappingTypeResponsesExistsAlreadyOrWillBeCreated(final MockWebServer webServer) throws IOException {
for (final String type : monitoringProductTypes()) {
for (final String type : MonitoringTemplateUtils.NEW_DATA_TYPES) {
if (randomBoolean()) {
enqueueResponse(webServer, 200, "{\".monitoring-data-2\":{\"" + type + "\":{\"enabled\":false}}}");
} else {

View File

@ -16,6 +16,7 @@ import org.elasticsearch.client.RestClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.xpack.monitoring.exporter.Exporter;
import org.elasticsearch.xpack.monitoring.exporter.MonitoringTemplateUtils;
import org.elasticsearch.xpack.monitoring.resolver.ResolversRegistry;
import java.io.IOException;
@ -39,9 +40,9 @@ import static org.mockito.Mockito.when;
public class HttpExporterResourceTests extends AbstractPublishableHttpResourceTestCase {
/**
* kibana, logstash, beats (This PR only really covers kibana, but a follow-on will add logstash and eventually we'll support beats)
* kibana, logstash, beats
*/
private final int EXPECTED_TYPES = 1;
private final int EXPECTED_TYPES = MonitoringTemplateUtils.NEW_DATA_TYPES.length;
private final int EXPECTED_TEMPLATES = 4;
private final RestClient client = mock(RestClient.class);
@ -65,39 +66,38 @@ public class HttpExporterResourceTests extends AbstractPublishableHttpResourceTe
verifyNoMoreInteractions(client);
}
// COMMENTED OUT CODE WILL BE USED IN FOLLOW-UP PR FOR "logstash" type
public void testTypeMappingCheckBlocksAfterSuccessfulVersion() throws IOException {
final Exception exception = failureGetException();
// final boolean firstSucceeds = randomBoolean();
final boolean firstSucceeds = randomBoolean();
int expectedGets = 1;
int expectedPuts = 0;
whenValidVersionResponse();
// failure in the middle of various templates being checked/published; suggests a node dropped
// if (firstSucceeds) {
// final boolean successfulFirst = randomBoolean();
// // -2 from one success + a necessary failure after it!
// final int extraPasses = Math.max(randomIntBetween(0, EXPECTED_TYPES - 2), 0);
// final int successful = randomIntBetween(0, extraPasses);
// final int unsuccessful = extraPasses - successful;
//
// final Response first = successfulFirst ? successfulGetTypeMappingResponse() : unsuccessfulGetTypeMappingResponse();
//
// final List<Response> otherResponses = getTypeMappingResponses(successful, unsuccessful);
//
// // last check fails implies that N - 2 publishes succeeded!
// when(client.performRequest(eq("GET"), startsWith("/" + DATA_INDEX + "/_mapping/"), anyMapOf(String.class, String.class)))
// .thenReturn(first, otherResponses.toArray(new Response[otherResponses.size()]))
// .thenThrow(exception);
// whenSuccessfulPutTypeMappings(otherResponses.size() + 1);
//
// expectedGets += 1 + successful + unsuccessful;
// expectedPuts = (successfulFirst ? 0 : 1) + unsuccessful;
// } else {
if (firstSucceeds) {
final boolean successfulFirst = randomBoolean();
// -2 from one success + a necessary failure after it!
final int extraPasses = Math.max(randomIntBetween(0, EXPECTED_TYPES - 2), 0);
final int successful = randomIntBetween(0, extraPasses);
final int unsuccessful = extraPasses - successful;
final Response first = successfulFirst ? successfulGetTypeMappingResponse() : unsuccessfulGetTypeMappingResponse();
final List<Response> otherResponses = getTypeMappingResponses(successful, unsuccessful);
// last check fails implies that N - 2 publishes succeeded!
when(client.performRequest(eq("GET"), startsWith("/" + DATA_INDEX + "/_mapping/"), anyMapOf(String.class, String.class)))
.thenReturn(first, otherResponses.toArray(new Response[otherResponses.size()]))
.thenThrow(exception);
whenSuccessfulPutTypeMappings(otherResponses.size() + 1);
expectedGets += 1 + successful + unsuccessful;
expectedPuts = (successfulFirst ? 0 : 1) + unsuccessful;
} else {
when(client.performRequest(eq("GET"), startsWith("/" + DATA_INDEX + "/_mapping/"), anyMapOf(String.class, String.class)))
.thenThrow(exception);
// }
}
assertTrue(resources.isDirty());
assertFalse(resources.checkAndPublish(client));
@ -110,41 +110,40 @@ public class HttpExporterResourceTests extends AbstractPublishableHttpResourceTe
verifyNoMoreInteractions(client);
}
// COMMENTED OUT CODE WILL BE USED IN FOLLOW-UP PR FOR "logstash" type
public void testTypeMappingPublishBlocksAfterSuccessfulVersion() throws IOException {
final Exception exception = failurePutException();
// final boolean firstSucceeds = randomBoolean();
final boolean firstSucceeds = randomBoolean();
int expectedGets = 1;
int expectedPuts = 1;
whenValidVersionResponse();
// failure in the middle of various templates being checked/published; suggests a node dropped
// if (firstSucceeds) {
// final Response firstSuccess = successfulPutResponse();
// // -2 from one success + a necessary failure after it!
// final int extraPasses = randomIntBetween(0, EXPECTED_TYPES - 2);
// final int successful = randomIntBetween(0, extraPasses);
// final int unsuccessful = extraPasses - successful;
//
// final List<Response> otherResponses = successfulPutResponses(unsuccessful);
//
// // first one passes for sure, so we need an extra "unsuccessful" GET
// whenGetTypeMappingResponse(successful, unsuccessful + 2);
//
// // previous publishes must have succeeded
// when(client.performRequest(eq("PUT"),
// startsWith("/" + DATA_INDEX + "/_mapping/"),
// anyMapOf(String.class, String.class),
// any(HttpEntity.class)))
// .thenReturn(firstSuccess, otherResponses.toArray(new Response[otherResponses.size()]))
// .thenThrow(exception);
//
// // GETs required for each PUT attempt (first is guaranteed "unsuccessful")
// expectedGets += successful + unsuccessful + 1;
// // unsuccessful are PUT attempts + the guaranteed successful PUT (first)
// expectedPuts += unsuccessful + 1;
// } else {
if (firstSucceeds) {
final Response firstSuccess = successfulPutResponse();
// -2 from one success + a necessary failure after it!
final int extraPasses = randomIntBetween(0, EXPECTED_TYPES - 2);
final int successful = randomIntBetween(0, extraPasses);
final int unsuccessful = extraPasses - successful;
final List<Response> otherResponses = successfulPutResponses(unsuccessful);
// first one passes for sure, so we need an extra "unsuccessful" GET
whenGetTypeMappingResponse(successful, unsuccessful + 2);
// previous publishes must have succeeded
when(client.performRequest(eq("PUT"),
startsWith("/" + DATA_INDEX + "/_mapping/"),
anyMapOf(String.class, String.class),
any(HttpEntity.class)))
.thenReturn(firstSuccess, otherResponses.toArray(new Response[otherResponses.size()]))
.thenThrow(exception);
// GETs required for each PUT attempt (first is guaranteed "unsuccessful")
expectedGets += successful + unsuccessful + 1;
// unsuccessful are PUT attempts + the guaranteed successful PUT (first)
expectedPuts += unsuccessful + 1;
} else {
// fail the check so that it has to attempt the PUT
whenGetTypeMappingResponse(0, 1);
@ -153,7 +152,7 @@ public class HttpExporterResourceTests extends AbstractPublishableHttpResourceTe
anyMapOf(String.class, String.class),
any(HttpEntity.class)))
.thenThrow(exception);
// }
}
assertTrue(resources.isDirty());
assertFalse(resources.checkAndPublish(client));

View File

@ -17,6 +17,7 @@ import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.monitoring.exporter.Exporter;
import org.elasticsearch.xpack.monitoring.exporter.Exporter.Config;
import org.elasticsearch.xpack.monitoring.exporter.MonitoringTemplateUtils;
import org.elasticsearch.xpack.monitoring.resolver.ResolversRegistry;
import org.elasticsearch.xpack.ssl.SSLService;
@ -305,7 +306,7 @@ public class HttpExporterTests extends ESTestCase {
assertThat(multiResource.getResources().size(),
equalTo(version + typeMappings.size() + templates.size() + pipelines.size() + bwc.size()));
assertThat(version, equalTo(1));
assertThat(typeMappings, hasSize(1));
assertThat(typeMappings, hasSize(MonitoringTemplateUtils.NEW_DATA_TYPES.length));
assertThat(templates, hasSize(4));
assertThat(pipelines, hasSize(useIngest ? 1 : 0));
assertThat(bwc, hasSize(1));

View File

@ -71,7 +71,8 @@ public class NodeStatsTests extends MonitoringIntegTestCase {
continue;
}
}
// fs stats and cgroup stats are not reported on every node
// fs and cgroup stats are only reported on Linux, but it's acceptable for _node/stats to report them as null if the OS is
// misconfigured or not reporting them for some reason (e.g., older kernel)
if (filter.startsWith("node_stats.fs") || filter.startsWith("node_stats.os.cgroup")) {
continue;
}