Skip to content

[Rollup] Better error message when trying to set non-rollup index #32965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,18 @@ static void updateMapping(RollupJob job, ActionListener<AcknowledgedResponse> li
MappingMetaData mappings = getMappingResponse.getMappings().get(indexName).get(RollupField.TYPE_NAME);
Object m = mappings.getSourceAsMap().get("_meta");
if (m == null) {
String msg = "Expected to find _meta key in mapping of rollup index [" + indexName + "] but not found.";
String msg = "Rollup data cannot be added to existing indices that contain non-rollup data (expected " +
"to find _meta key in mapping of rollup index [" + indexName + "] but not found).";
logger.error(msg);
listener.onFailure(new RuntimeException(msg));
return;
}

Map<String, Object> metadata = (Map<String, Object>) m;
if (metadata.get(RollupField.ROLLUP_META) == null) {
String msg = "Expected to find rollup meta key [" + RollupField.ROLLUP_META + "] in mapping of rollup index [" + indexName
+ "] but not found.";
String msg = "Rollup data cannot be added to existing indices that contain non-rollup data (expected " +
"to find rollup meta key [" + RollupField.ROLLUP_META + "] in mapping of rollup index ["
+ indexName + "] but not found).";
logger.error(msg);
listener.onFailure(new RuntimeException(msg));
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ public void testNoMetadataInMapping() {
ActionListener<AcknowledgedResponse> testListener = ActionListener.wrap(response -> {
fail("Listener success should not have been triggered.");
}, e -> {
assertThat(e.getMessage(), equalTo("Expected to find _meta key in mapping of rollup index ["
+ job.getConfig().getRollupIndex() + "] but not found."));
assertThat(e.getMessage(), equalTo("Rollup data cannot be added to existing indices that contain " +
"non-rollup data (expected to find _meta key in mapping of rollup index ["
+ job.getConfig().getRollupIndex() + "] but not found)."));
});

Logger logger = mock(Logger.class);
Expand All @@ -206,6 +207,44 @@ public void testNoMetadataInMapping() {
verify(client).execute(eq(GetMappingsAction.INSTANCE), any(GetMappingsRequest.class), any());
}

@SuppressWarnings("unchecked")
public void testMetadataButNotRollup() {
RollupJob job = new RollupJob(ConfigTestHelpers.randomRollupJobConfig(random()), Collections.emptyMap());

ActionListener<AcknowledgedResponse> testListener = ActionListener.wrap(response -> {
fail("Listener success should not have been triggered.");
}, e -> {
assertThat(e.getMessage(), equalTo("Rollup data cannot be added to existing indices that contain " +
"non-rollup data (expected to find rollup meta key [_rollup] in mapping of rollup index ["
+ job.getConfig().getRollupIndex() + "] but not found)."));
});

Logger logger = mock(Logger.class);
Client client = mock(Client.class);

ArgumentCaptor<ActionListener> requestCaptor = ArgumentCaptor.forClass(ActionListener.class);
doAnswer(invocation -> {
GetMappingsResponse response = mock(GetMappingsResponse.class);
Map<String, Object> m = new HashMap<>(2);
m.put("random",
Collections.singletonMap(job.getConfig().getId(), job.getConfig()));
MappingMetaData meta = new MappingMetaData(RollupField.TYPE_NAME,
Collections.singletonMap("_meta", m));
ImmutableOpenMap.Builder<String, MappingMetaData> builder = ImmutableOpenMap.builder(1);
builder.put(RollupField.TYPE_NAME, meta);

ImmutableOpenMap.Builder<String, ImmutableOpenMap<String, MappingMetaData>> builder2 = ImmutableOpenMap.builder(1);
builder2.put(job.getConfig().getRollupIndex(), builder.build());

when(response.getMappings()).thenReturn(builder2.build());
requestCaptor.getValue().onResponse(response);
return null;
}).when(client).execute(eq(GetMappingsAction.INSTANCE), any(GetMappingsRequest.class), requestCaptor.capture());

TransportPutRollupJobAction.updateMapping(job, testListener, mock(PersistentTasksService.class), client, logger);
verify(client).execute(eq(GetMappingsAction.INSTANCE), any(GetMappingsRequest.class), any());
}

@SuppressWarnings("unchecked")
public void testNoMappingVersion() {
RollupJob job = new RollupJob(ConfigTestHelpers.randomRollupJobConfig(random()), Collections.emptyMap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,38 @@ setup:
]
}

---
"Test put_job in non-rollup index":
- do:
indices.create:
index: non-rollup
- do:
catch: /foo/
headers:
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
xpack.rollup.put_job:
id: foo
body: >
{
"index_pattern": "foo",
"rollup_index": "non-rollup",
"cron": "*/30 * * * * ?",
"page_size" :10,
"groups" : {
"date_histogram": {
"field": "the_field",
"interval": "1h"
}
},
"metrics": [
{
"field": "value_field",
"metrics": ["min", "max", "sum"]
}
]
}


---
"Try to include headers":

Expand Down