-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
[ML-DataFrame] version data frame transform internal index #45375
Merged
Merged
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e67a1aa
version data frame transform internal index
0ee1be3
handle move on update, add some comments
1f4e500
mention templates as well
9975df7
add mappings for config::version, config::create_time, checkpoint::ti…
446251b
fix style
2726149
use the pattern for search instead of the last versioned index name
c62c602
Adjusting abstract transport get resources to handle more than one re…
benwtrent fb4b4f3
minor cleanup
benwtrent a6e28d6
Merge branch 'master' into HEAD
benwtrent d8aea65
running dbq to remove old documents for _update and new stats index
benwtrent 8a6ea02
addressing PR comments
benwtrent 49a2e07
addressing PR comments
benwtrent a91d89d
Merge branch 'master' into df-index-refactor
elasticmachine b7fa3d9
Merge branch 'master' into df-index-refactor
elasticmachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
...java/org/elasticsearch/xpack/dataframe/integration/DataFrameTransformInternalIndexIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* 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.dataframe.integration; | ||
|
||
import org.elasticsearch.action.get.GetRequest; | ||
import org.elasticsearch.action.get.GetResponse; | ||
import org.elasticsearch.action.index.IndexRequest; | ||
import org.elasticsearch.action.support.WriteRequest; | ||
import org.elasticsearch.client.RequestOptions; | ||
import org.elasticsearch.client.RestHighLevelClient; | ||
import org.elasticsearch.client.dataframe.GetDataFrameTransformRequest; | ||
import org.elasticsearch.client.dataframe.GetDataFrameTransformResponse; | ||
import org.elasticsearch.client.dataframe.UpdateDataFrameTransformRequest; | ||
import org.elasticsearch.client.dataframe.UpdateDataFrameTransformResponse; | ||
import org.elasticsearch.client.dataframe.transforms.DataFrameTransformConfigUpdate; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.common.xcontent.XContentFactory; | ||
import org.elasticsearch.search.SearchModule; | ||
import org.elasticsearch.xpack.core.dataframe.DataFrameField; | ||
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformConfig; | ||
import org.elasticsearch.client.indices.CreateIndexRequest; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.util.concurrent.ThreadContext; | ||
import org.elasticsearch.common.xcontent.XContentType; | ||
import org.elasticsearch.test.rest.ESRestTestCase; | ||
import org.elasticsearch.xpack.dataframe.persistence.DataFrameInternalIndex; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Base64; | ||
import java.util.Collections; | ||
|
||
import static org.elasticsearch.xpack.dataframe.persistence.DataFrameInternalIndex.addDataFrameTransformsConfigMappings; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
|
||
public class DataFrameTransformInternalIndexIT extends ESRestTestCase { | ||
|
||
|
||
private static final String CURRENT_INDEX = DataFrameInternalIndex.LATEST_INDEX_NAME; | ||
private static final String OLD_INDEX = DataFrameInternalIndex.INDEX_PATTERN + "1"; | ||
|
||
|
||
public void testUpdateDeletesOldTransformConfig() throws Exception { | ||
TestRestHighLevelClient client = new TestRestHighLevelClient(); | ||
// The mapping does not need to actually be the "OLD" mapping, we are testing that the old doc gets deleted, and the new one | ||
// created. | ||
try (XContentBuilder builder = XContentFactory.jsonBuilder()) { | ||
builder.startObject(); | ||
builder.startObject("properties"); | ||
builder.startObject(DataFrameField.INDEX_DOC_TYPE.getPreferredName()).field("type", "keyword").endObject(); | ||
addDataFrameTransformsConfigMappings(builder); | ||
builder.endObject(); | ||
builder.endObject(); | ||
client.indices().create(new CreateIndexRequest(OLD_INDEX).mapping(builder), RequestOptions.DEFAULT); | ||
} | ||
String transformIndex = "transform-index-deletes-old"; | ||
createSourceIndex(transformIndex); | ||
String transformId = "transform-update-deletes-old-transform-config"; | ||
String config = "{\"dest\": {\"index\":\"bar\"}," | ||
+ " \"source\": {\"index\":\"" + transformIndex + "\", \"query\": {\"match_all\":{}}}," | ||
+ " \"id\": \""+transformId+"\"," | ||
+ " \"doc_type\": \"data_frame_transform_config\"," | ||
+ " \"pivot\": {" | ||
+ " \"group_by\": {" | ||
+ " \"reviewer\": {" | ||
+ " \"terms\": {" | ||
+ " \"field\": \"user_id\"" | ||
+ " } } }," | ||
+ " \"aggregations\": {" | ||
+ " \"avg_rating\": {" | ||
+ " \"avg\": {" | ||
+ " \"field\": \"stars\"" | ||
+ " } } } }," | ||
+ "\"frequency\":\"1s\"" | ||
+ "}"; | ||
client.index(new IndexRequest(OLD_INDEX) | ||
.id(DataFrameTransformConfig.documentId(transformId)) | ||
.source(config, XContentType.JSON) | ||
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE), | ||
RequestOptions.DEFAULT); | ||
GetResponse getResponse = client.get(new GetRequest(OLD_INDEX, DataFrameTransformConfig.documentId(transformId)), | ||
RequestOptions.DEFAULT); | ||
assertThat(getResponse.isExists(), is(true)); | ||
|
||
GetDataFrameTransformResponse response = client.dataFrame() | ||
.getDataFrameTransform(new GetDataFrameTransformRequest(transformId), RequestOptions.DEFAULT); | ||
assertThat(response.getTransformConfigurations().get(0).getId(), equalTo(transformId)); | ||
|
||
UpdateDataFrameTransformResponse updated = client.dataFrame().updateDataFrameTransform( | ||
new UpdateDataFrameTransformRequest(DataFrameTransformConfigUpdate.builder().setDescription("updated").build(), transformId), | ||
RequestOptions.DEFAULT); | ||
|
||
assertThat(updated.getTransformConfiguration().getId(), equalTo(transformId)); | ||
assertThat(updated.getTransformConfiguration().getDescription(), equalTo("updated")); | ||
|
||
// Old should now be gone | ||
getResponse = client.get(new GetRequest(OLD_INDEX, DataFrameTransformConfig.documentId(transformId)), RequestOptions.DEFAULT); | ||
assertThat(getResponse.isExists(), is(false)); | ||
|
||
// New should be here | ||
getResponse = client.get(new GetRequest(CURRENT_INDEX, DataFrameTransformConfig.documentId(transformId)), | ||
RequestOptions.DEFAULT); | ||
assertThat(getResponse.isExists(), is(true)); | ||
} | ||
|
||
|
||
@Override | ||
protected Settings restClientSettings() { | ||
final String token = "Basic " + | ||
Base64.getEncoder().encodeToString(("x_pack_rest_user:x-pack-test-password").getBytes(StandardCharsets.UTF_8)); | ||
return Settings.builder() | ||
.put(ThreadContext.PREFIX + ".Authorization", token) | ||
.build(); | ||
} | ||
|
||
private void createSourceIndex(String index) throws IOException { | ||
TestRestHighLevelClient client = new TestRestHighLevelClient(); | ||
client.indices().create(new CreateIndexRequest(index), RequestOptions.DEFAULT); | ||
} | ||
|
||
private class TestRestHighLevelClient extends RestHighLevelClient { | ||
TestRestHighLevelClient() { | ||
super(client(), restClient -> {}, new SearchModule(Settings.EMPTY, Collections.emptyList()).getNamedXContents()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need to create the source index when you PUT directly to the index bypassing any validations or this for the update?