-
Notifications
You must be signed in to change notification settings - Fork 25k
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] Dataframe REST cleanups #39451
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6d8e206
check if id from body match id from the url path
5b5174b
disallow body for delete
94ba65a
allow get and stats without an id
9a8f766
fix line length
8e07b0e
id in body and url must match
a1ab5c9
add a test of the message string
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
71 changes: 71 additions & 0 deletions
71
...rc/test/java/org/elasticsearch/xpack/dataframe/integration/DataFrameGetAndGetStatsIT.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,71 @@ | ||
/* | ||
* 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.client.Request; | ||
import org.elasticsearch.common.xcontent.support.XContentMapValues; | ||
import org.junit.Before; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
public class DataFrameGetAndGetStatsIT extends DataFrameRestTestCase { | ||
|
||
private static boolean indicesCreated = false; | ||
|
||
// preserve indices in order to reuse source indices in several test cases | ||
@Override | ||
protected boolean preserveIndicesUponCompletion() { | ||
return true; | ||
} | ||
|
||
@Before | ||
public void createIndexes() throws IOException { | ||
|
||
// it's not possible to run it as @BeforeClass as clients aren't initialized then, so we need this little hack | ||
if (indicesCreated) { | ||
return; | ||
} | ||
|
||
createReviewsIndex(); | ||
indicesCreated = true; | ||
} | ||
|
||
public void testGetAndGetStats() throws Exception { | ||
createPivotReviewsTransform("pivot_1", "pivot_reviews_1", null); | ||
createPivotReviewsTransform("pivot_2", "pivot_reviews_2", null); | ||
|
||
startAndWaitForTransform("pivot_1", "pivot_reviews_1"); | ||
startAndWaitForTransform("pivot_2", "pivot_reviews_2"); | ||
|
||
// check all the different ways to retrieve all stats | ||
Map<String, Object> stats = entityAsMap(client().performRequest(new Request("GET", DATAFRAME_ENDPOINT + "_stats"))); | ||
assertEquals(2, XContentMapValues.extractValue("count", stats)); | ||
stats = entityAsMap(client().performRequest(new Request("GET", DATAFRAME_ENDPOINT + "_all/_stats"))); | ||
assertEquals(2, XContentMapValues.extractValue("count", stats)); | ||
stats = entityAsMap(client().performRequest(new Request("GET", DATAFRAME_ENDPOINT + "*/_stats"))); | ||
assertEquals(2, XContentMapValues.extractValue("count", stats)); | ||
|
||
// only pivot_1 | ||
stats = entityAsMap(client().performRequest(new Request("GET", DATAFRAME_ENDPOINT + "pivot_1/_stats"))); | ||
assertEquals(1, XContentMapValues.extractValue("count", stats)); | ||
|
||
// check all the different ways to retrieve all transforms | ||
Map<String, Object> transforms = entityAsMap(client().performRequest(new Request("GET", DATAFRAME_ENDPOINT))); | ||
assertEquals(2, XContentMapValues.extractValue("count", transforms)); | ||
transforms = entityAsMap(client().performRequest(new Request("GET", DATAFRAME_ENDPOINT + "_all"))); | ||
assertEquals(2, XContentMapValues.extractValue("count", transforms)); | ||
transforms = entityAsMap(client().performRequest(new Request("GET", DATAFRAME_ENDPOINT + "*"))); | ||
assertEquals(2, XContentMapValues.extractValue("count", transforms)); | ||
|
||
// only pivot_1 | ||
transforms = entityAsMap(client().performRequest(new Request("GET", DATAFRAME_ENDPOINT + "pivot_1"))); | ||
assertEquals(1, XContentMapValues.extractValue("count", transforms)); | ||
} | ||
|
||
|
||
} |
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
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
44 changes: 44 additions & 0 deletions
44
...rg/elasticsearch/xpack/dataframe/rest/action/RestDeleteDataFrameTransformActionTests.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,44 @@ | ||
/* | ||
* 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.rest.action; | ||
|
||
import org.elasticsearch.client.node.NodeClient; | ||
import org.elasticsearch.common.bytes.BytesArray; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.xcontent.NamedXContentRegistry; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.common.xcontent.XContentType; | ||
import org.elasticsearch.common.xcontent.json.JsonXContent; | ||
import org.elasticsearch.rest.RestController; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.test.rest.FakeRestRequest; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.mockito.Mockito.mock; | ||
|
||
public class RestDeleteDataFrameTransformActionTests extends ESTestCase { | ||
|
||
public void testBodyRejection() throws Exception { | ||
final RestDeleteDataFrameTransformAction handler = new RestDeleteDataFrameTransformAction(Settings.EMPTY, | ||
mock(RestController.class)); | ||
try (XContentBuilder builder = JsonXContent.contentBuilder()) { | ||
builder.startObject(); | ||
{ | ||
builder.field("id", "my_id"); | ||
} | ||
builder.endObject(); | ||
final FakeRestRequest request = new FakeRestRequest.Builder(NamedXContentRegistry.EMPTY) | ||
.withContent(new BytesArray(builder.toString()), XContentType.JSON) | ||
.build(); | ||
IllegalArgumentException e = expectThrows( | ||
IllegalArgumentException.class, | ||
() -> handler.prepareRequest(request, mock(NodeClient.class))); | ||
assertThat(e.getMessage(), equalTo("delete data frame transforms requests can not have a request body")); | ||
} | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -36,8 +36,7 @@ public class DataFrameTransformConfigTests extends AbstractSerializingDataFrameT | |
|
||
public static DataFrameTransformConfig randomDataFrameTransformConfigWithoutHeaders() { | ||
return new DataFrameTransformConfig(randomAlphaOfLengthBetween(1, 10), randomAlphaOfLengthBetween(1, 10), | ||
randomAlphaOfLengthBetween(1, 10), null, QueryConfigTests.randomQueryConfig(), | ||
PivotConfigTests.randomPivotConfig()); | ||
randomAlphaOfLengthBetween(1, 10), null, QueryConfigTests.randomQueryConfig(), PivotConfigTests.randomPivotConfig()); | ||
} | ||
|
||
public static DataFrameTransformConfig randomDataFrameTransformConfig() { | ||
|
@@ -46,6 +45,16 @@ public static DataFrameTransformConfig randomDataFrameTransformConfig() { | |
PivotConfigTests.randomPivotConfig()); | ||
} | ||
|
||
public static DataFrameTransformConfig randomDataFrameTransformConfigWithoutHeaders(String id) { | ||
return new DataFrameTransformConfig(id, randomAlphaOfLengthBetween(1, 10), randomAlphaOfLengthBetween(1, 10), null, | ||
QueryConfigTests.randomQueryConfig(), PivotConfigTests.randomPivotConfig()); | ||
} | ||
|
||
public static DataFrameTransformConfig randomDataFrameTransformConfig(String id) { | ||
return new DataFrameTransformConfig(id, randomAlphaOfLengthBetween(1, 10), randomAlphaOfLengthBetween(1, 10), randomHeaders(), | ||
QueryConfigTests.randomQueryConfig(), PivotConfigTests.randomPivotConfig()); | ||
} | ||
|
||
public static DataFrameTransformConfig randomInvalidDataFrameTransformConfig() { | ||
if (randomBoolean()) { | ||
return new DataFrameTransformConfig(randomAlphaOfLengthBetween(1, 10), randomAlphaOfLengthBetween(1, 10), | ||
|
@@ -74,7 +83,7 @@ protected DataFrameTransformConfig doParseInstance(XContentParser parser) throws | |
|
||
@Override | ||
protected DataFrameTransformConfig createTestInstance() { | ||
return runWithHeaders ? randomDataFrameTransformConfig() : randomDataFrameTransformConfigWithoutHeaders(); | ||
return runWithHeaders ? randomDataFrameTransformConfig(transformId) : randomDataFrameTransformConfigWithoutHeaders(transformId); | ||
} | ||
|
||
@Override | ||
|
@@ -143,6 +152,33 @@ public void testPreventHeaderInjection() throws IOException { | |
() -> createDataFrameTransformConfigFromString(pivotTransform, "test_header_injection")); | ||
} | ||
|
||
public void testSetIdInBody() throws IOException { | ||
String pivotTransform = "{" | ||
+ " \"id\" : \"body_id\"," | ||
+ " \"source\" : \"src\"," | ||
+ " \"dest\" : \"dest\"," | ||
+ " \"pivot\" : {" | ||
+ " \"group_by\": {" | ||
+ " \"id\": {" | ||
+ " \"terms\": {" | ||
+ " \"field\": \"id\"" | ||
+ "} } }," | ||
+ " \"aggs\": {" | ||
+ " \"avg\": {" | ||
+ " \"avg\": {" | ||
+ " \"field\": \"points\"" | ||
+ "} } } } }"; | ||
|
||
DataFrameTransformConfig dataFrameTransformConfig = createDataFrameTransformConfigFromString(pivotTransform, "body_id"); | ||
assertEquals("body_id", dataFrameTransformConfig.getId()); | ||
|
||
IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, | ||
() -> createDataFrameTransformConfigFromString(pivotTransform, "other_id")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could also assert that the error message is as expected here. (For example this will detect if the body ID and URL ID are the wrong way around when the error message is formed.) |
||
|
||
assertEquals("Inconsistent id; 'body_id' specified in the body differs from 'other_id' specified as a URL argument", | ||
ex.getCause().getMessage()); | ||
} | ||
|
||
private DataFrameTransformConfig createDataFrameTransformConfigFromString(String json, String id) throws IOException { | ||
final XContentParser parser = XContentType.JSON.xContent().createParser(xContentRegistry(), | ||
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json); | ||
|
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.
nit: All these tests seem like they could just be yml tests.