Skip to content

Route documents to the correct shards in tsdb #77731

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 43 commits into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
76f50c3
Route documents to the correct shards in tsdb
nik9000 Sep 13, 2021
a6cbecf
Merge branch 'master' into index_routing_from_source
nik9000 Sep 15, 2021
8949f79
Merge branch 'master' into index_routing_from_source
nik9000 Sep 15, 2021
8480c0b
Merge branch 'master' into index_routing_from_source
nik9000 Sep 15, 2021
9828ea0
Moar skip
nik9000 Sep 15, 2021
653c7f0
tsdb survives full cluster restart
nik9000 Sep 15, 2021
d762a03
Remove auto generated id rejection
nik9000 Sep 16, 2021
85faa61
Simplify
nik9000 Sep 16, 2021
1b398e5
Forbid routing_required
nik9000 Sep 16, 2021
8c00e18
Merge branch 'master' into index_routing_from_source
nik9000 Sep 16, 2021
5f65cf2
Merge branch 'master' into index_routing_from_source
nik9000 Sep 23, 2021
317cbe6
Small
nik9000 Sep 23, 2021
80548de
Fork fork knife
nik9000 Sep 23, 2021
517b2cf
Let failures flow
nik9000 Sep 23, 2021
b0c6de4
Merge branch 'master' into index_routing_from_source
nik9000 Sep 27, 2021
09cb170
Fix full cluster
nik9000 Sep 27, 2021
51bcc4d
Merge branch 'master' into index_routing_from_source
nik9000 Oct 1, 2021
a3c592a
Always fork
nik9000 Oct 1, 2021
b3eae86
Retry?
nik9000 Oct 1, 2021
7147bb7
Remove pressure test arm
nik9000 Oct 4, 2021
4acf433
Merge branch 'master' into index_routing_from_source
nik9000 Oct 4, 2021
e86650f
Add missing settings
nik9000 Oct 4, 2021
f021e72
WIP
nik9000 Oct 4, 2021
92f10a0
Merge branch 'master' into index_routing_from_source
nik9000 Oct 6, 2021
0761120
Remove leftover
nik9000 Oct 6, 2021
d501811
More cleaning
nik9000 Oct 6, 2021
07b2435
Fixup more tests
nik9000 Oct 7, 2021
7d81f2a
Remove old skip
nik9000 Oct 7, 2021
99bbf13
New tests for Retry
nik9000 Oct 7, 2021
671c83f
More tests
nik9000 Oct 7, 2021
0f86b77
Revert unrelated
nik9000 Oct 7, 2021
81f1878
Merge branch 'master' into index_routing_from_source
nik9000 Oct 7, 2021
d6b644d
Merge branch 'master' into index_routing_from_source
nik9000 Oct 15, 2021
b838554
One dispatch please
nik9000 Oct 15, 2021
b341a64
Stuff moved
nik9000 Oct 15, 2021
5c147d4
More moving
nik9000 Oct 15, 2021
75392e2
Explain why fork
nik9000 Oct 15, 2021
6ff5158
Back to ActionRunnable
nik9000 Oct 15, 2021
076afa5
Update comment
nik9000 Oct 15, 2021
db1f179
Utility method
nik9000 Oct 15, 2021
90afc69
Move routing_path under feature flag
nik9000 Oct 15, 2021
63fa3bd
Imports
nik9000 Oct 15, 2021
a4c00f1
Merge branch 'master' into index_routing_from_source
nik9000 Oct 15, 2021
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 @@ -91,6 +91,9 @@ private Object[] getTargets(String projectPath) {
"src/*/java/org/elasticsearch/action/admin/cluster/snapshots/**/*.java",
"src/test/java/org/elasticsearch/common/xcontent/support/AbstractFilteringTestCase.java",
"src/test/java/org/elasticsearch/common/xcontent/support/XContentMapValuesTests.java",
"src/*/java/org/elasticsearch/index/IndexMode.java",
"src/*/java/org/elasticsearch/index/IndexRouting.java",
"src/*/java/org/elasticsearch/index/TimeSeriesModeTests.java",
"src/*/java/org/elasticsearch/index/snapshots/**/*.java",
"src/*/java/org/elasticsearch/repositories/**/*.java",
"src/*/java/org/elasticsearch/search/aggregations/**/*.java",
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ setup:
settings:
index:
mode: time_series
routing_path: [metricset, k8s.pod.uid]
number_of_replicas: 0
number_of_shards: 2
mappings:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ tsdb:
settings:
index:
mode: time_series
routing_path: [metricset, k8s.pod.uid]
number_of_replicas: 0
number_of_shards: 2
mappings:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private void bulk(String index, String entity) throws IOException {
Request bulk = new Request("POST", "/_bulk");
bulk.addParameter("refresh", "true");
bulk.setJsonEntity(entity.toString());
client().performRequest(bulk);
assertThat(EntityUtils.toString(client().performRequest(bulk).getEntity()), containsString("\"errors\":false"));
}

private void createTsdbIndex() throws IOException {
Expand All @@ -318,7 +318,10 @@ private void createTsdbIndex() throws IOException {
indexSpec.startObject("dim").field("type", "keyword").field("time_series_dimension", true).endObject();
}
indexSpec.endObject().endObject();
indexSpec.startObject("settings").field("mode", "time_series").endObject();
indexSpec.startObject("settings").startObject("index");
indexSpec.field("mode", "time_series");
indexSpec.array("routing_path", new String[] {"dim"});
indexSpec.endObject().endObject();
createIndex.setJsonEntity(Strings.toString(indexSpec.endObject()));
client().performRequest(createIndex);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Test the mode:time_series properly groups by _tsid. If we could put this in
# rest-api-spec we would, but it requires painless.

setup:
- skip:
version: " - 7.99.99"
reason: introduced in 8.0.0

- do:
indices.create:
index: test
body:
settings:
index:
mode: time_series
routing_path: [metricset, k8s.pod.uid]
number_of_shards: 10
number_of_replicas: 1
mappings:
properties:
"@timestamp":
type: date
metricset:
type: keyword
time_series_dimension: true
k8s:
properties:
pod:
properties:
uid:
type: keyword
time_series_dimension: true
name:
type: keyword
ip:
type: ip
network:
properties:
tx:
type: long
rx:
type: long
- do:
bulk:
refresh: true
index: test
body:
- '{"index": {}}'
- '{"@timestamp": "2021-04-28T18:35:24.467Z", "metricset": "pod", "k8s": {"pod": {"name": "cat", "uid":"947e4ced-1786-4e53-9e0c-5c447e959507", "ip": "10.10.55.1", "network": {"tx": 2001818691, "rx": 802133794}}}}'
- '{"index": {}}'
- '{"@timestamp": "2021-04-28T19:50:04.467Z", "metricset": "pod", "k8s": {"pod": {"name": "cat", "uid":"947e4ced-1786-4e53-9e0c-5c447e959507", "ip": "10.10.55.1", "network": {"tx": 2005177954, "rx": 801479970}}}}'
- '{"index": {}}'
- '{"@timestamp": "2021-04-28T17:53:34.467Z", "metricset": "pod", "k8s": {"pod": {"name": "cat", "uid":"947e4ced-1786-4e53-9e0c-5c447e959507", "ip": "10.10.55.1", "network": {"tx": 2006223737, "rx": 802337279}}}}'
- '{"index": {}}'
- '{"@timestamp": "2021-04-28T18:03:24.467Z", "metricset": "pod", "k8s": {"pod": {"name": "cat", "uid":"947e4ced-1786-4e53-9e0c-5c447e959507", "ip": "10.10.55.2", "network": {"tx": 2012916202, "rx": 803685721}}}}'
- '{"index": {}}'
- '{"@timestamp": "2021-04-28T18:35:24.467Z", "metricset": "pod", "k8s": {"pod": {"name": "dog", "uid":"df3145b3-0563-4d3b-a0f7-897eb2876ea9", "ip": "10.10.55.3", "network": {"tx": 1434521831, "rx": 530575198}}}}'
- '{"index": {}}'
- '{"@timestamp": "2021-04-28T19:50:04.467Z", "metricset": "pod", "k8s": {"pod": {"name": "dog", "uid":"df3145b3-0563-4d3b-a0f7-897eb2876ea9", "ip": "10.10.55.3", "network": {"tx": 1434577921, "rx": 530600088}}}}'
- '{"index": {}}'
- '{"@timestamp": "2021-04-28T17:53:34.467Z", "metricset": "pod", "k8s": {"pod": {"name": "dog", "uid":"df3145b3-0563-4d3b-a0f7-897eb2876ea9", "ip": "10.10.55.3", "network": {"tx": 1434587694, "rx": 530604797}}}}'
- '{"index": {}}'
- '{"@timestamp": "2021-04-28T18:03:24.467Z", "metricset": "pod", "k8s": {"pod": {"name": "dog", "uid":"df3145b3-0563-4d3b-a0f7-897eb2876ea9", "ip": "10.10.55.3", "network": {"tx": 1434595272, "rx": 530605511}}}}'

---
"index with replicas and shards is green":
- skip:
version: " - 7.99.99"
reason: introduced in 8.0.0 to be backported to 7.16.0

- do:
cluster.health:
wait_for_status: green
- match: { status: green }

---
"each shard has unique _tsids":
- skip:
version: " - 7.99.99"
reason: introduced in 8.0.0 to be backported to 7.16.0

- do:
search:
index: test
body:
size: 0
aggs:
check:
scripted_metric:
init_script: "state.timeSeries = new HashSet()"
map_script: "state.timeSeries.add(doc['metricset'].value + ':' + doc['k8s.pod.uid'].value)"
combine_script: "return state.timeSeries"
reduce_script: |
Set timeSeries = new TreeSet();
for (s in states) {
for (ts in s) {
boolean newTs = timeSeries.add(ts);
if (false == newTs) {
throw new IllegalArgumentException(ts + " appeared in two shards");
}
}
}
return timeSeries;
- match: {hits.total.value: 8}
- match: {aggregations.check.value: ['pod:947e4ced-1786-4e53-9e0c-5c447e959507', 'pod:df3145b3-0563-4d3b-a0f7-897eb2876ea9']}

# todo clone and shrink
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ enable:
settings:
index:
mode: time_series
routing_path: [metricset, k8s.pod.uid]
number_of_replicas: 0
number_of_shards: 2
mappings:
Expand Down Expand Up @@ -117,3 +118,53 @@ no partitioning:
mode: time_series
shards: 5
routing_partition_size: 2

---
routing_path required:
- skip:
version: " - 7.99.99"
reason: introduced in 8.0.0 to be backported to 7.16.0

- do:
catch: /\[index.mode=time_series\] requires \[index.routing_path\]/
indices.create:
index: test_index
body:
settings:
index:
mode: time_series
shards: 5

---
routing_path is not allowed in standard mode:
- skip:
version: " - 7.99.99"
reason: introduced in 8.0.0 to be backported to 7.16.0

- do:
catch: /\[index.routing_path\] requires \[index.mode=time_series\]/
indices.create:
index: test_index
body:
settings:
index:
routing_path: foo

---
routing required:
- skip:
version: " - 7.99.99"
reason: introduced in 8.0.0 to be backported to 7.16.0

- do:
catch: /routing is forbidden on CRUD operations that target indices in \[index.mode=time_series\]/
indices.create:
index: test_index
body:
settings:
index:
mode: time_series
routing_path: foo
mappings:
_routing:
required: true
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ add time series mappings:
settings:
index:
mode: time_series
routing_path: [metricset, k8s.pod.uid]
number_of_replicas: 0
number_of_shards: 2
mappings:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ teardown:
settings:
index:
mode: time_series
routing_path: [metricset, k8s.pod.uid]
number_of_replicas: 0
number_of_shards: 2
mappings:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ setup:
settings:
index:
mode: time_series
routing_path: [metricset, k8s.pod.uid]
mappings:
properties:
"@timestamp":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ setup:
settings:
index:
mode: time_series
routing_path: [metricset, k8s.pod.uid]
mappings:
properties:
"@timestamp":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ add dimensions with put_mapping:
settings:
index:
mode: time_series
routing_path: [metricset, k8s.pod.uid]
mappings:
properties:
"@timestamp":
Expand Down Expand Up @@ -60,6 +61,7 @@ add dimensions to no dims with dynamic_template over index:
settings:
index:
mode: time_series
routing_path: [metricset]
mappings:
dynamic_templates:
- keywords:
Expand Down Expand Up @@ -104,6 +106,7 @@ add dimensions to no dims with dynamic_template over bulk:
settings:
index:
mode: time_series
routing_path: [metricset]
mappings:
dynamic_templates:
- keywords:
Expand Down Expand Up @@ -148,6 +151,7 @@ add dimensions to some dims with dynamic_template over index:
settings:
index:
mode: time_series
routing_path: [metricset]
mappings:
dynamic_templates:
- keywords:
Expand Down Expand Up @@ -196,6 +200,7 @@ add dimensions to some dims with dynamic_template over bulk:
settings:
index:
mode: time_series
routing_path: [metricset]
mappings:
dynamic_templates:
- keywords:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ keyword dimension:
settings:
index:
mode: time_series
routing_path: [uid]
mappings:
properties:
"@timestamp":
Expand Down Expand Up @@ -58,10 +59,14 @@ long dimension:
settings:
index:
mode: time_series
routing_path: [metricset]
mappings:
properties:
"@timestamp":
type: date
metricset:
type: keyword
time_series_dimension: true
id:
type: long
time_series_dimension: true
Expand All @@ -72,21 +77,21 @@ long dimension:
index: test
body:
- '{"index": {}}'
- '{"@timestamp": "2021-04-28T18:35:24.467Z", "id": 1, "voltage": 7.2}'
- '{"@timestamp": "2021-04-28T18:35:24.467Z", "metricset": "aa", "id": 1, "voltage": 7.2}'
- '{"index": {}}'
- '{"@timestamp": "2021-04-28T18:35:34.467Z", "id": "1", "voltage": 7.6}'
- '{"@timestamp": "2021-04-28T18:35:34.467Z", "metricset": "aa", "id": "1", "voltage": 7.6}'
- '{"index": {}}'
- '{"@timestamp": "2021-04-28T18:35:44.467Z", "id": 1.0, "voltage": 7.1}'
- '{"@timestamp": "2021-04-28T18:35:44.467Z", "metricset": "aa", "id": 1.0, "voltage": 7.1}'
- '{"index": {}}'
- '{"@timestamp": "2021-04-28T18:35:54.467Z", "id": "001", "voltage": 7.3}'
- '{"@timestamp": "2021-04-28T18:35:54.467Z", "metricset": "aa", "id": "001", "voltage": 7.3}'
- '{"index": {}}'
- '{"@timestamp": "2021-04-28T18:35:24.467Z", "id": 2, "voltage": 3.2}'
- '{"@timestamp": "2021-04-28T18:35:24.467Z", "metricset": "aa", "id": 2, "voltage": 3.2}'
- '{"index": {}}'
- '{"@timestamp": "2021-04-28T18:35:34.467Z", "id": 2, "voltage": 3.6}'
- '{"@timestamp": "2021-04-28T18:35:34.467Z", "metricset": "aa", "id": 2, "voltage": 3.6}'
- '{"index": {}}'
- '{"@timestamp": "2021-04-28T18:35:44.467Z", "id": 2, "voltage": 3.1}'
- '{"@timestamp": "2021-04-28T18:35:44.467Z", "metricset": "aa", "id": 2, "voltage": 3.1}'
- '{"index": {}}'
- '{"@timestamp": "2021-04-28T18:35:54.467Z", "id": 2, "voltage": 3.3}'
- '{"@timestamp": "2021-04-28T18:35:54.467Z", "metricset": "aa", "id": 2, "voltage": 3.3}'

# TODO aggregate on tsid

Expand All @@ -104,10 +109,14 @@ ip dimension:
settings:
index:
mode: time_series
routing_path: [metricset]
mappings:
properties:
"@timestamp":
type: date
metricset:
type: keyword
time_series_dimension: true
ip:
type: ip
time_series_dimension: true
Expand All @@ -118,20 +127,20 @@ ip dimension:
index: test
body:
- '{"index": {}}'
- '{"@timestamp": "2021-04-28T18:35:24.467Z", "ip": "10.10.1.1", "voltage": 7.2}'
- '{"@timestamp": "2021-04-28T18:35:24.467Z", "metricset": "aa", "ip": "10.10.1.1", "voltage": 7.2}'
- '{"index": {}}'
- '{"@timestamp": "2021-04-28T18:35:34.467Z", "ip": "10.10.1.1", "voltage": 7.6}'
- '{"@timestamp": "2021-04-28T18:35:34.467Z", "metricset": "aa", "ip": "10.10.1.1", "voltage": 7.6}'
- '{"index": {}}'
- '{"@timestamp": "2021-04-28T18:35:44.467Z", "ip": "10.10.1.1", "voltage": 7.1}'
- '{"@timestamp": "2021-04-28T18:35:44.467Z", "metricset": "aa", "ip": "10.10.1.1", "voltage": 7.1}'
- '{"index": {}}'
- '{"@timestamp": "2021-04-28T18:35:54.467Z", "ip": "::ffff:10.10.1.1", "voltage": 7.3}'
- '{"@timestamp": "2021-04-28T18:35:54.467Z", "metricset": "aa", "ip": "::ffff:10.10.1.1", "voltage": 7.3}'
- '{"index": {}}'
- '{"@timestamp": "2021-04-28T18:35:24.467Z", "ip": "2001:0db8:85a3:0000:0000:8a2e:0370:7334", "voltage": 3.2}'
- '{"@timestamp": "2021-04-28T18:35:24.467Z", "metricset": "aa", "ip": "2001:0db8:85a3:0000:0000:8a2e:0370:7334", "voltage": 3.2}'
- '{"index": {}}'
- '{"@timestamp": "2021-04-28T18:35:34.467Z", "ip": "2001:0db8:85a3:0:0:8a2e:0370:7334", "voltage": 3.6}'
- '{"@timestamp": "2021-04-28T18:35:34.467Z", "metricset": "aa", "ip": "2001:0db8:85a3:0:0:8a2e:0370:7334", "voltage": 3.6}'
- '{"index": {}}'
- '{"@timestamp": "2021-04-28T18:35:44.467Z", "ip": "2001:0db8:85a3::8a2e:0370:7334", "voltage": 3.1}'
- '{"@timestamp": "2021-04-28T18:35:44.467Z", "metricset": "aa", "ip": "2001:0db8:85a3::8a2e:0370:7334", "voltage": 3.1}'
- '{"index": {}}'
- '{"@timestamp": "2021-04-28T18:35:54.467Z", "ip": "2001:0db8:85a3::8a2e:0370:7334", "voltage": 3.3}'
- '{"@timestamp": "2021-04-28T18:35:54.467Z", "metricset": "aa", "ip": "2001:0db8:85a3::8a2e:0370:7334", "voltage": 3.3}'

# TODO aggregate on tsid
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ setup:
settings:
index:
mode: time_series
routing_path: [metricset, k8s.pod.uid]
number_of_shards: 3
number_of_replicas: 0
mappings:
Expand Down
Loading