Skip to content
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

Create a mode: time_series option for indices #75638

Closed
wants to merge 46 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
895cb7e
Create a `time_series_mode` option for indices
nik9000 Jun 22, 2021
f811ce4
Better support for feature flag
nik9000 Jul 23, 2021
45c205f
Merge branch 'master' into tsid_gen
nik9000 Jul 26, 2021
0fb8060
build build build
nik9000 Jul 26, 2021
b359bef
Merge branch 'master' into tsid_gen
nik9000 Jul 27, 2021
fbb1838
Support time series index without dimensions
nik9000 Jul 27, 2021
a10c4b6
Split
nik9000 Jul 27, 2021
d3c6c9b
Ouch
nik9000 Jul 29, 2021
dfe46f2
Merge branch 'master' into tsid_gen
nik9000 Jul 29, 2021
95b05bf
Tests
nik9000 Jul 30, 2021
1b21962
Merge branch 'master' into tsid_gen
nik9000 Jul 30, 2021
159812d
Merge branch 'master' into tsid_gen
nik9000 Aug 2, 2021
cbca506
mode=time_series
nik9000 Aug 2, 2021
41bbf09
Better names
nik9000 Aug 2, 2021
500ec30
fixup
nik9000 Aug 2, 2021
930c715
Merge branch 'master' into tsid_gen
nik9000 Aug 3, 2021
9075da4
Cleanup
nik9000 Aug 3, 2021
424ff61
data stream test
nik9000 Aug 3, 2021
b5f7fbb
snapshot/restore
nik9000 Aug 3, 2021
2aebff9
Merge branch 'master' into tsid_gen
nik9000 Aug 3, 2021
c6c454e
Alias tests
nik9000 Aug 3, 2021
a590dfe
Merge branch 'master' into tsid_gen
nik9000 Aug 4, 2021
eaebf2f
Merge branch 'master' into tsid_gen
nik9000 Aug 5, 2021
8f6e2bc
Remove todo
nik9000 Aug 5, 2021
7538327
Moar test
nik9000 Aug 5, 2021
bea8d20
Merge branch 'master' into tsid_gen
nik9000 Aug 9, 2021
c11b53c
WIP
nik9000 Aug 9, 2021
b6f76ac
Merge branch 'master' into tsid_gen
nik9000 Aug 9, 2021
e7811e3
WIP
nik9000 Aug 9, 2021
b0e734f
WIP
nik9000 Aug 9, 2021
2bdd50d
WIP
nik9000 Aug 10, 2021
94984b5
Merge branch 'master' into tsid_gen
nik9000 Aug 10, 2021
3c303ae
equals/hashCode
nik9000 Aug 10, 2021
77a873d
Fail nicely
nik9000 Aug 10, 2021
8ec4db6
Fix settings
nik9000 Aug 10, 2021
3162b2b
Better
nik9000 Aug 10, 2021
7433952
Update tests
nik9000 Aug 11, 2021
04bf6d6
javadocs
nik9000 Aug 11, 2021
fc11cc5
Revert noops
nik9000 Aug 11, 2021
3b5aa95
cleanup
nik9000 Aug 11, 2021
4b48ada
Merge branch 'master' into tsid_gen
nik9000 Aug 11, 2021
f34890e
More docs
nik9000 Aug 11, 2021
9a61279
Merge branch 'master' into tsid_gen
nik9000 Aug 11, 2021
7d3b2fe
Merge branch 'master' into tsid_gen
nik9000 Aug 12, 2021
134f91c
Merge branch 'master' into tsid_gen
nik9000 Aug 12, 2021
d21d889
Merge branch 'master' into tsid_gen
nik9000 Aug 13, 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
2 changes: 1 addition & 1 deletion plugins/repository-hdfs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ dependencies {

restResources {
restApi {
include '_common', 'cluster', 'nodes', 'indices', 'index', 'snapshot'
include '_common', 'bulk', 'cluster', 'index', 'indices', 'nodes', 'search', 'snapshot'
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
---
"Create a snapshot and then restore it":
- skip:
version: " - 7.99.99"
reason: introduced in 8.0.0 to be backported to 7.15.0
features: ["allowed_warnings"]

# Create repository
- do:
snapshot.create_repository:
repository: test_restore_repository
body:
type: hdfs
settings:
uri: "hdfs://localhost:9999"
path: "test/restore"

# Create index
- do:
indices.create:
index: test_index
body:
settings:
index:
mode: time_series
number_of_replicas: 0
number_of_shards: 2
mappings:
properties:
"@timestamp":
type: date
metricset:
type: keyword
dimension: true
k8s:
properties:
pod:
properties:
uid:
type: keyword
dimension: true
name:
type: keyword
ip:
type: ip
network:
properties:
tx:
type: long
rx:
type: long
- do:
bulk:
refresh: true
index: test_index
body:
- '{"index": {}}'
- '{"@timestamp": "2021-04-28T18:50:04.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-28T18:50:24.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-28T18:50:44.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:51:04.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:50:03.142Z", "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-28T18:50:23.142Z", "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-28T18:50:53.142Z", "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:51:03.142Z", "metricset": "pod", "k8s": {"pod": {"name": "dog", "uid":"df3145b3-0563-4d3b-a0f7-897eb2876ea9", "ip": "10.10.55.3", "network": {"tx": 1434595272, "rx": 530605511}}}}'
- '{"index": {}}'
- '{"@timestamp": "2021-04-28T18:50:03.142Z", "metricset": "pod", "k8s": {"pod": {"name": "cow", "uid":"1c4fc7b8-93b7-4ba8-b609-2a48af2f8e39", "ip": "10.10.55.4", "network": {"tx": 1434521831, "rx": 530575198}}}}'
- '{"index": {}}'
- '{"@timestamp": "2021-04-28T18:50:23.142Z", "metricset": "pod", "k8s": {"pod": {"name": "cow", "uid":"1c4fc7b8-93b7-4ba8-b609-2a48af2f8e39", "ip": "10.10.55.4", "network": {"tx": 1434577921, "rx": 530600088}}}}'
- '{"index": {}}'
- '{"@timestamp": "2021-04-28T18:50:53.142Z", "metricset": "pod", "k8s": {"pod": {"name": "cow", "uid":"1c4fc7b8-93b7-4ba8-b609-2a48af2f8e39", "ip": "10.10.55.4", "network": {"tx": 1434587694, "rx": 530604797}}}}'
- '{"index": {}}'
- '{"@timestamp": "2021-04-28T18:51:03.142Z", "metricset": "pod", "k8s": {"pod": {"name": "cow", "uid":"1c4fc7b8-93b7-4ba8-b609-2a48af2f8e39", "ip": "10.10.55.4", "network": {"tx": 1434595272, "rx": 530605511}}}}'


# Wait for green
- do:
cluster.health:
wait_for_status: green

# Take snapshot
- do:
snapshot.create:
repository: test_restore_repository
snapshot: test_restore_tsdb
wait_for_completion: true

- match: { snapshot.snapshot: test_restore_tsdb }
- match: { snapshot.state : SUCCESS }
- match: { snapshot.shards.successful: 2 }
- match: { snapshot.shards.failed : 0 }
- is_true: snapshot.version
- gt: { snapshot.version_id: 0}

# Close index
- do:
indices.close:
index : test_index
allowed_warnings:
- "the default value for the ?wait_for_active_shards parameter will change from '0' to 'index-setting' in version 8; specify '?wait_for_active_shards=index-setting' to adopt the future default behaviour, or '?wait_for_active_shards=0' to preserve today's behaviour"

# Restore index
- do:
snapshot.restore:
repository: test_restore_repository
snapshot: test_restore_tsdb
wait_for_completion: true

# Check recovery stats
- do:
indices.recovery:
index: test_index

- match: { test_index.shards.0.type: SNAPSHOT }
- match: { test_index.shards.0.stage: DONE }
- match: { test_index.shards.0.index.files.recovered: 1}
- gt: { test_index.shards.0.index.size.recovered_in_bytes: 0}

# Remove our snapshot
- do:
snapshot.delete:
repository: test_restore_repository
snapshot: test_restore_tsdb

# Remove our repository
- do:
snapshot.delete_repository:
repository: test_restore_repository

- do:
search:
index: test_index
body:
fields:
- field: _tsid
query:
query_string:
query: '+@timestamp:"2021-04-28T18:51:04.467Z" +k8s.pod.name:cat'

- match: {hits.total.value: 1}
- match: {hits.hits.0.fields._tsid: [{k8s.pod.uid: 947e4ced-1786-4e53-9e0c-5c447e959507, metricset: pod}]}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.elasticsearch.core.Booleans;
import org.elasticsearch.core.CheckedFunction;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.mapper.DateFieldMapper;
import org.elasticsearch.rest.action.admin.indices.RestPutIndexTemplateAction;
import org.elasticsearch.test.NotEqualMessageBuilder;
import org.elasticsearch.test.XContentTestUtils;
Expand All @@ -45,6 +46,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -151,7 +153,7 @@ public void testSearch() throws Exception {
assertStoredBinaryFields(count);
}

public void testNewReplicasWork() throws Exception {
public void testNewReplicas() throws Exception {
if (isRunningAgainstOldCluster()) {
XContentBuilder mappingsAndSettings = jsonBuilder();
mappingsAndSettings.startObject();
Expand Down Expand Up @@ -189,7 +191,7 @@ public void testNewReplicasWork() throws Exception {
logger.debug("--> creating [{}] replicas for index [{}]", numReplicas, index);
Request setNumberOfReplicas = new Request("PUT", "/" + index + "/_settings");
setNumberOfReplicas.setJsonEntity("{ \"index\": { \"number_of_replicas\" : " + numReplicas + " }}");
Response response = client().performRequest(setNumberOfReplicas);
client().performRequest(setNumberOfReplicas);

ensureGreenLongWait(index);

Expand All @@ -210,6 +212,91 @@ public void testNewReplicasWork() throws Exception {
}
}

public void testSearchTimeSeriesMode() throws Exception {
assumeTrue("time series mode introduced in 8.0.0 to be backported to 7.15.0", getOldClusterVersion().onOrAfter(Version.V_8_0_0));
int numDocs;
if (isRunningAgainstOldCluster()) {
numDocs = createTimeSeriesModeIndex(1);
} else {
numDocs = countOfIndexedRandomDocuments();
}
assertCountAll(numDocs);
}

public void testNewReplicasTimeSeriesMode() throws Exception {
assumeTrue("time series mode introduced in 8.0.0 to be backported to 7.15.0", getOldClusterVersion().onOrAfter(Version.V_8_0_0));
if (isRunningAgainstOldCluster()) {
createTimeSeriesModeIndex(0);
} else {
final int numReplicas = 1;
final long startTime = System.currentTimeMillis();
logger.debug("--> creating [{}] replicas for index [{}]", numReplicas, index);
Request setNumberOfReplicas = new Request("PUT", "/" + index + "/_settings");
setNumberOfReplicas.setJsonEntity("{ \"index\": { \"number_of_replicas\" : " + numReplicas + " }}");
client().performRequest(setNumberOfReplicas);

ensureGreenLongWait(index);

logger.debug("--> index [{}] is green, took [{}] ms", index, (System.currentTimeMillis() - startTime));
Map<String, Object> recoverRsp = entityAsMap(client().performRequest(new Request("GET", "/" + index + "/_recovery")));
logger.debug("--> recovery status:\n{}", recoverRsp);

Set<Integer> counts = new HashSet<>();
for (String node : dataNodes(index, client())) {
Request search = new Request("GET", "/" + index + "/_search");
search.addParameter("preference", "_only_nodes:" + node);
Map<String, Object> responseBody = entityAsMap(client().performRequest(search));
assertNoFailures(responseBody);
int hits = extractTotalHits(responseBody);
counts.add(hits);
}
assertEquals("All nodes should have a consistent number of documents", 1, counts.size());
}
}

private int createTimeSeriesModeIndex(int replicas) throws IOException {
XContentBuilder mappingsAndSettings = jsonBuilder();
mappingsAndSettings.startObject();
{
mappingsAndSettings.startObject("settings");
mappingsAndSettings.field("number_of_shards", 1);
mappingsAndSettings.field("number_of_replicas", replicas);
mappingsAndSettings.field("mode", "time_series");
mappingsAndSettings.endObject();
}
{
mappingsAndSettings.startObject("mappings");
mappingsAndSettings.startObject("properties");
{
mappingsAndSettings.startObject("@timestamp").field("type", "date").endObject();
mappingsAndSettings.startObject("dim").field("type", "keyword").field("dimension", true).endObject();
}
mappingsAndSettings.endObject();
mappingsAndSettings.endObject();
}
mappingsAndSettings.endObject();

Request createIndex = new Request("PUT", "/" + index);
createIndex.setJsonEntity(Strings.toString(mappingsAndSettings));
client().performRequest(createIndex);

int numDocs = randomIntBetween(2000, 3000);
long basetime = DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER.parseMillis("2021-01-01T00:00:00Z");
indexRandomDocuments(
numDocs,
true,
true,
i -> JsonXContent.contentBuilder()
.startObject()
.field("@timestamp", basetime + TimeUnit.MINUTES.toMillis(i))
.field("dim", "value")
.endObject()
);
logger.info("Refreshing [{}]", index);
client().performRequest(new Request("POST", "/" + index + "/_refresh"));
return numDocs;
}

public void testClusterState() throws Exception {
if (isRunningAgainstOldCluster()) {
XContentBuilder mappingsAndSettings = jsonBuilder();
Expand Down Expand Up @@ -459,14 +546,18 @@ public void testRollover() throws IOException {
assertEquals(expectedCount, extractTotalHits(count));
}

void assertCountAll(int count) throws IOException {
Map<String, Object> response = entityAsMap(client().performRequest(new Request("GET", "/" + index + "/_search")));
assertNoFailures(response);
int numDocs = extractTotalHits(response);
logger.info("Found {} in old index", numDocs);
assertEquals(count, numDocs);
}

void assertBasicSearchWorks(int count) throws IOException {
logger.info("--> testing basic search");
{
Map<String, Object> response = entityAsMap(client().performRequest(new Request("GET", "/" + index + "/_search")));
assertNoFailures(response);
int numDocs = extractTotalHits(response);
logger.info("Found {} in old index", numDocs);
assertEquals(count, numDocs);
assertCountAll(count);
}

logger.info("--> testing basic search with sort");
Expand Down Expand Up @@ -1136,8 +1227,6 @@ private void checkSnapshot(final String snapshotName, final int count, final Ver
}
}

// TODO tests for upgrades after shrink. We've had trouble with shrink in the past.

private void indexRandomDocuments(
final int count,
final boolean flushAllowed,
Expand Down Expand Up @@ -1629,5 +1718,4 @@ public static void assertNumHits(String index, int numHits, int totalShards) thr
assertThat(XContentMapValues.extractValue("_shards.successful", resp), equalTo(totalShards));
assertThat(extractTotalHits(resp), equalTo(numHits));
}

}
3 changes: 3 additions & 0 deletions qa/mixed-cluster/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ for (Version bwcVersion : BuildParams.bwcVersions.wireCompatible) {

setting 'path.repo', "${buildDir}/cluster/shared/repo/${baseName}"
setting 'xpack.security.enabled', 'false'
if (BuildParams.isSnapshotBuild() == false) {
systemProperty 'es.time_series_mode_feature_flag_registered', 'true'
}
}
}

Expand Down
Loading