-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Add a template parameter to override auto_create_index value #61858
Merged
pugnascotia
merged 78 commits into
elastic:master
from
pugnascotia:20640-auto-create-templates
Oct 26, 2020
Merged
Changes from all commits
Commits
Show all changes
78 commits
Select commit
Hold shift + click to select a range
ee50924
Override auto-create index behaviour via a template flag
pugnascotia f62c83b
WIP - trying to test watcher
pugnascotia 097d9f5
Merge remote-tracking branch 'upstream/master' into 20640-auto-create…
pugnascotia 3bb580c
Fixes
pugnascotia 42cfc00
Remove logging
pugnascotia 8c17371
Merge remote-tracking branch 'upstream/master' into 20640-auto-create…
pugnascotia 9a1e10a
Merge remote-tracking branch 'upstream/master' into 20640-auto-create…
pugnascotia 961cfcf
Use AutoCreateIndex in AutoCreateAction
pugnascotia 41fdcb3
Imports
pugnascotia 2228033
Merge remote-tracking branch 'upstream/master' into 20640-auto-create…
pugnascotia b00297e
Fixes
pugnascotia ad5021d
Merge remote-tracking branch 'upstream/master' into 20640-auto-create…
pugnascotia ad9e699
Fix compile error
pugnascotia c42e3ce
Tweak ComposableIndexTemplate serialisation under code changes land i…
pugnascotia 6a689b2
Fix auto create index bug
pugnascotia f81a510
Merge remote-tracking branch 'upstream/master' into 20640-auto-create…
pugnascotia 2d54d2c
Test fix
pugnascotia 85abcbc
Handle null Boolean
pugnascotia eb299a0
Merge remote-tracking branch 'upstream/master' into 20640-auto-create…
pugnascotia a3e3691
Imports
pugnascotia 9421140
Checkstyle
pugnascotia ebb42d4
Tweaks
pugnascotia a93cfb2
Merge remote-tracking branch 'upstream/master' into 20640-auto-create…
pugnascotia bfe8c8c
Post-merge fix
pugnascotia 2694fb2
Update synthentics template to add allow_auto_create
pugnascotia 5d5eeb4
Merge remote-tracking branch 'upstream/master' into 20640-auto-create…
pugnascotia 39abb38
Address review feedback
pugnascotia 4b9034a
Address review feedback
pugnascotia ce8c2ed
Merge remote-tracking branch 'upstream/master' into 20640-auto-create…
pugnascotia 2e9a4c7
Specify the same version for ser/deser
pugnascotia d5db431
Merge remote-tracking branch 'upstream/master' into 20640-auto-create…
pugnascotia 1d07709
Fix stupid typo
pugnascotia 36b9ca8
Merge remote-tracking branch 'upstream/master' into 20640-auto-create…
pugnascotia 93e2440
Address review comments
pugnascotia 4a2e64c
Increment some template versions due to the new setting
pugnascotia 82ad6e4
Add Java REST tests for auto-creating indices
pugnascotia 6022b3c
Checkstyle
pugnascotia 41b2fc6
Merge remote-tracking branch 'upstream/master' into 20640-auto-create…
pugnascotia 6127caf
Update component template docs
pugnascotia 9d6b6cf
Checkstyle
pugnascotia c0394e4
Docs tweak
pugnascotia cbfbb98
Merge remote-tracking branch 'upstream/master' into 20640-auto-create…
pugnascotia 383d6ff
Merge remote-tracking branch 'upstream/master' into 20640-auto-create…
pugnascotia 61ab28e
Make data stream subject to auto_create_index
pugnascotia 6c4c817
Add tests for auto-creating data streams
pugnascotia ed692c7
Formatting
pugnascotia e8617b6
Merge branch 'master' into 20640-auto-create-templates
elasticmachine 4f051af
Fix max/min aggs for unsigned_long (#63904)
mayya-sharipova 44d7d66
Add APM configuration index to Kibana system indices (#63756)
williamrandolph e145266
[ML] Rename evaluation metric result fields to value (#63809)
dimitris-athanasiou 9e8221a
Update gradle wrapper to Gradle 6.7 (#62386)
breskeby dd7a22f
Add snapshot shard size based test in DiskThresholdDeciderTests (#63546)
tlrx cfca1e4
DocumentMapperParser to no longer depend directly on MapperService (#…
javanna 85c0b54
Composite aggregation must check live docs when the index is sorted (…
jimczi 0204f0a
Fix build tools integTest failure after vault update (#63914)
breskeby eae0eaa
Upgrade to lucene-8.7.0-snapshot-72d8528c3a6 (#63912)
iverase d9aea1c
[ML] fix inference binary classification predication label and featur…
benwtrent 13ef3ab
Move clone snapshot API page. (#63902)
4bdc322
Remove two redundant DocumentMapper methods (#63922)
javanna c3d1981
make sure AggregationTest creates reduced aggregations. (#63931)
iverase ae05665
[ML] adding new flag exclude_generated that removes generated fields …
benwtrent 2cd82f2
[Transform] add new exclude_generated flag to GET transform (#63093)
benwtrent 8bf7976
Gradle - compatible REST test plugin - adopt bwc artifact (#63629)
jakelandis b4cc55c
Remove documentMapperParser method from MapperService (#63938)
javanna 1545c0a
Minor FieldTypeLookup tweaks (#63944)
javanna 55172b6
[Transform] add support for unsigned_long data type (#63940)
9a9b96b
Make agg test less confusing (#63952)
nik9000 7db889c
Add a test for regex usage to runtime fields (#63951)
nik9000 70f758e
[ML] Extend default evaluation metrics to all available (#63939)
dimitris-athanasiou 1376afd
geo_point runtime field implementation (#63164)
iverase dec6ea9
Mute CoreValuesSourceTypeTests.testDatePrepareRoundingWithDocs (#63970)
javanna 00b0bdf
Handle range query edge case (#63397)
473975c
Mute DatafeedJobsIT#testDatafeedTimingStats_DatafeedRecreated (#63974)
javanna f45ea30
Mute FieldSortIT#testCastDate (#63972)
javanna 0482f5c
Only subject data streams to allow_auto_create, not auto_create_index
pugnascotia 421679d
Merge remote-tracking branch 'upstream/master' into 20640-auto-create…
pugnascotia 6bd5456
Tweak docs
pugnascotia 0fd0f84
Merge branch 'master' into 20640-auto-create-templates
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
126 changes: 126 additions & 0 deletions
126
qa/smoke-test-http/src/test/java/org/elasticsearch/http/AutoCreateIndexIT.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,126 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.http; | ||
|
||
import org.elasticsearch.action.support.AutoCreateIndex; | ||
import org.elasticsearch.client.Request; | ||
import org.elasticsearch.client.Response; | ||
import org.elasticsearch.client.ResponseException; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.io.Streams; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.common.xcontent.json.JsonXContent; | ||
import org.elasticsearch.test.rest.ESRestTestCase; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
import static org.hamcrest.Matchers.containsString; | ||
|
||
public class AutoCreateIndexIT extends ESRestTestCase { | ||
|
||
/** | ||
* Check that setting {@link AutoCreateIndex#AUTO_CREATE_INDEX_SETTING} to <code>false</code> | ||
* disable the automatic creation on indices. | ||
*/ | ||
public void testCannotAutoCreateIndexWhenDisabled() throws IOException { | ||
configureAutoCreateIndex(false); | ||
|
||
// Attempt to add a document to a non-existing index. Auto-creating the index should fail owing to the setting above. | ||
final Request indexDocumentRequest = new Request("POST", "recipe_kr/_doc/123456"); | ||
indexDocumentRequest.setJsonEntity("{ \"name\": \"Kimchi\" }"); | ||
final ResponseException responseException = expectThrows(ResponseException.class, this::indexDocument); | ||
|
||
assertThat( | ||
Streams.copyToString(new InputStreamReader(responseException.getResponse().getEntity().getContent(), UTF_8)), | ||
containsString("no such index [recipe_kr] and [action.auto_create_index] is [false]") | ||
); | ||
} | ||
|
||
/** | ||
* Check that automatically creating an index is allowed, even when {@link AutoCreateIndex#AUTO_CREATE_INDEX_SETTING} | ||
* is <code>false</code>, when the index name matches a template and that template has <code>allow_auto_create</code> | ||
* set to <code>true</code>. | ||
*/ | ||
public void testCanAutoCreateIndexWhenAllowedByTemplate() throws IOException { | ||
configureAutoCreateIndex(false); | ||
|
||
createTemplateWithAllowAutoCreate(true); | ||
|
||
// Attempt to add a document to a non-existing index. Auto-creating the index should succeed because the index name | ||
// matches the template pattern | ||
assertOK(this.indexDocument()); | ||
} | ||
|
||
/** | ||
* Check that automatically creating an index is disallowed when the index name matches a template and that template has | ||
* <code>allow_auto_create</code> explicitly to <code>false</code>, even when {@link AutoCreateIndex#AUTO_CREATE_INDEX_SETTING} | ||
* is set to <code>true</code>. | ||
*/ | ||
public void testCannotAutoCreateIndexWhenDisallowedByTemplate() throws IOException { | ||
configureAutoCreateIndex(true); | ||
|
||
createTemplateWithAllowAutoCreate(false); | ||
|
||
// Attempt to add a document to a non-existing index. Auto-creating the index should succeed because the index name | ||
// matches the template pattern | ||
final ResponseException responseException = expectThrows(ResponseException.class, this::indexDocument); | ||
|
||
assertThat( | ||
Streams.copyToString(new InputStreamReader(responseException.getResponse().getEntity().getContent(), UTF_8)), | ||
containsString("no such index [composable template [recipe*] forbids index auto creation]") | ||
); | ||
} | ||
|
||
|
||
private void configureAutoCreateIndex(boolean value) throws IOException { | ||
XContentBuilder builder = JsonXContent.contentBuilder() | ||
.startObject() | ||
.startObject("transient") | ||
.field(AutoCreateIndex.AUTO_CREATE_INDEX_SETTING.getKey(), value) | ||
.endObject() | ||
.endObject(); | ||
|
||
final Request settingsRequest = new Request("PUT", "_cluster/settings"); | ||
settingsRequest.setJsonEntity(Strings.toString(builder)); | ||
final Response settingsResponse = client().performRequest(settingsRequest); | ||
assertOK(settingsResponse); | ||
} | ||
|
||
private void createTemplateWithAllowAutoCreate(Boolean allowAutoCreate) throws IOException { | ||
XContentBuilder builder = JsonXContent.contentBuilder() | ||
.startObject() | ||
.array("index_patterns", "recipe*") | ||
.field("allow_auto_create", allowAutoCreate) | ||
.endObject(); | ||
|
||
final Request createTemplateRequest = new Request("PUT", "_index_template/recipe_template"); | ||
createTemplateRequest.setJsonEntity(Strings.toString(builder)); | ||
final Response createTemplateResponse = client().performRequest(createTemplateRequest); | ||
assertOK(createTemplateResponse); | ||
} | ||
|
||
private Response indexDocument() throws IOException { | ||
final Request indexDocumentRequest = new Request("POST", "recipe_kr/_doc/123456"); | ||
indexDocumentRequest.setJsonEntity("{ \"name\": \"Kimchi\" }"); | ||
return client().performRequest(indexDocumentRequest); | ||
} | ||
} |
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.
Maybe
distribution/archives/integ-test-zip
is a better place for this test class? Given that it doesn't extendHttpSmokeTestCase
and this test class doesn't seem to require to start a node with special settings or plugins.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.
I'm honestly not sure. I tried before to find out where is the "correct" place for REST tests, but couldn't get a clear answer. I think I'll leave this test alone and start an email thread about it. I feel that it ought to be easier to say where a REST test should live.