Skip to content

Use alias name from rollover request to query indices stats #40774

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 10 commits into from
Apr 16, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -120,7 +120,7 @@ protected void masterOperation(final RolloverRequest rolloverRequest, final Clus
final String rolloverIndexName = indexNameExpressionResolver.resolveDateMathExpression(unresolvedName);
MetaDataCreateIndexService.validateIndexName(rolloverIndexName, state); // will fail if the index already exists
checkNoDuplicatedAliasInIndexTemplate(metaData, rolloverIndexName, rolloverRequest.getAlias());
client.admin().indices().prepareStats(sourceIndexName).clear().setDocs(true).execute(
client.admin().indices().prepareStats(rolloverRequest.getAlias()).clear().setDocs(true).execute(
new ActionListener<IndicesStatsResponse>() {
@Override
public void onResponse(IndicesStatsResponse statsResponse) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
---

setup:
- skip:
features: headers

- do:
cluster.health:
wait_for_status: yellow

- do:
security.put_role:
name: "alias_write_manage_role"
body: >
{
"indices": [
{ "names": ["write_manage_alias"], "privileges": ["write", "manage"] }
]
}

- do:
security.put_user:
username: "test_user"
body: >
{
"password" : "x-pack-test-password",
"roles" : [ "alias_write_manage_role" ],
"full_name" : "user with privileges to write, manage via alias"
}

- do:
indices.create:
index: logs-000001
body:
settings:
index:
number_of_shards: 1
number_of_replicas: 0

- do:
indices.put_alias:
index: logs-000001
name: write_manage_alias

---
teardown:
- do:
security.delete_user:
username: "test_user"
ignore: 404

- do:
security.delete_role:
name: "alias_write_role"
ignore: 404

- do:
indices.delete_alias:
index: "logs-000001"
name: [ "write_manage_alias" ]
ignore: 404

- do:
indices.delete:
index: [ "logs-000001" ]
ignore: 404

---
"Test rollover, index via write alias of index":

# index using alias
- do:
headers: { Authorization: "Basic dGVzdF91c2VyOngtcGFjay10ZXN0LXBhc3N3b3Jk" } # test_user
create:
id: 1
index: write_manage_alias
body: >
{
"name" : "doc1"
}

- do:
headers: { Authorization: "Basic dGVzdF91c2VyOngtcGFjay10ZXN0LXBhc3N3b3Jk" } # test_user
create:
id: 2
index: write_manage_alias
body: >
{
"name" : "doc2"
}

- do:
indices.refresh: {}

# rollover using alias
- do:
headers: { Authorization: "Basic dGVzdF91c2VyOngtcGFjay10ZXN0LXBhc3N3b3Jk" } # test_user
indices.rollover:
alias: "write_manage_alias"
wait_for_active_shards: 1
body:
conditions:
max_docs: 1

- match: { old_index: logs-000001 }
- match: { new_index: logs-000002 }
- match: { rolled_over: true }
- match: { dry_run: false }
- match: { conditions: { "[max_docs: 1]": true } }

# ensure new index is created
- do:
indices.exists:
index: logs-000002

- is_true: ''

# index using alias
- do:
headers: { Authorization: "Basic dGVzdF91c2VyOngtcGFjay10ZXN0LXBhc3N3b3Jk" } # test_user
create:
id: 3
index: write_manage_alias
body: >
{
"name" : "doc3"
}

- do:
indices.refresh: {}

# check alias points to the new index and the doc was indexed
- do:
search:
rest_total_hits_as_int: true
index: write_manage_alias

- match: { hits.total: 1 }
- match: { hits.hits.0._index: "logs-000002"}