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

Move watcher history to data stream #64252

Merged
merged 54 commits into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
d7f05a1
Hidden data streams
probakowski Oct 21, 2020
b182d36
whitespace reverted
probakowski Oct 21, 2020
100dba5
stricter ds name
probakowski Oct 21, 2020
0d778f5
Revert "stricter ds name"
probakowski Oct 21, 2020
98e45c5
String.format removed
probakowski Oct 21, 2020
cf74871
fix test
probakowski Oct 21, 2020
a856a8f
fix GetDataStream action
probakowski Oct 21, 2020
4a0e20d
fix test
probakowski Oct 22, 2020
19af04d
fix test
probakowski Oct 22, 2020
5b94039
rest test
probakowski Oct 22, 2020
4441533
rest test
probakowski Oct 22, 2020
404d341
spotless
probakowski Oct 22, 2020
0059e16
tests
probakowski Oct 22, 2020
2c540be
Merge remote-tracking branch 'origin/master' into hidden-data-streams
probakowski Oct 22, 2020
54dddc4
Delete a.json
probakowski Oct 22, 2020
63c0702
added expand_wildcards for GetDataStream and DeleteDataStream
probakowski Oct 26, 2020
dd9afaf
unused imports
probakowski Oct 26, 2020
6152f02
Merge remote-tracking branch 'origin/master' into hidden-data-streams
probakowski Oct 26, 2020
4e71b53
add hidden setting to data stream template
probakowski Oct 26, 2020
f00df2d
fix expand_wildcards
probakowski Oct 26, 2020
b92f159
Merge remote-tracking branch 'origin/master' into hidden-data-streams
probakowski Oct 26, 2020
194b492
spotless
probakowski Oct 26, 2020
66c8d58
fix compilation
probakowski Oct 26, 2020
d0ee5e7
unused import
probakowski Oct 26, 2020
72add92
yaml test
probakowski Oct 26, 2020
cfe3b64
fix test
probakowski Oct 26, 2020
2475244
fix cleanup
probakowski Oct 27, 2020
136011d
Move watcher history to data stream
probakowski Oct 27, 2020
df8eba6
unused import
probakowski Oct 27, 2020
c9de864
fixed wipeDataStream
probakowski Oct 28, 2020
e9ee0f3
fix doc test
probakowski Oct 28, 2020
3654fe6
fix doc test
probakowski Oct 28, 2020
ffa0163
fix test
probakowski Oct 28, 2020
2078e95
checkstyle
probakowski Oct 28, 2020
c89f592
fix cleanup
probakowski Oct 28, 2020
c97a41d
Merge remote-tracking branch 'origin/master' into watcher-history-dat…
probakowski Oct 28, 2020
070cbf3
Merge remote-tracking branch 'origin/master' into hidden-data-streams
probakowski Oct 28, 2020
a6b533b
flush history during pause
probakowski Oct 29, 2020
da08544
fix test
probakowski Oct 29, 2020
ff845eb
review
probakowski Oct 30, 2020
b9fc82d
Merge branch 'master' into hidden-data-streams
probakowski Oct 30, 2020
8ffd444
compilation fix
probakowski Oct 30, 2020
d3d5a6a
fix javadoc
probakowski Oct 30, 2020
9a9700a
fix javadoc
probakowski Oct 30, 2020
b9c8694
Merge branch 'hidden-data-streams' into watcher-history-data-stream2
probakowski Oct 30, 2020
59830f1
Merge remote-tracking branch 'origin/master' into watcher-history-dat…
probakowski Oct 30, 2020
f8e7d1f
fix cleanup
probakowski Nov 5, 2020
8a440a5
fix opType
probakowski Nov 6, 2020
9dc5f17
Merge branch 'master' into watcher-history-data-stream2
elasticmachine Nov 6, 2020
35084e8
cleanup
probakowski Nov 6, 2020
6d0899a
Merge branch 'master' into watcher-history-data-stream2
probakowski Nov 12, 2020
83ad3fe
Remove unneeded check
probakowski Nov 12, 2020
664ff64
test fix
probakowski Nov 12, 2020
2c5c91c
unused imports
probakowski Nov 12, 2020
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
4 changes: 3 additions & 1 deletion x-pack/docs/en/rest-api/watcher/execute-watch.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<titleabbrev>Execute watch</titleabbrev>
++++

Forces the execution of a stored watch.
Forces the execution of a stored watch.

[[watcher-api-execute-watch-request]]
==== {api-request-title}
Expand Down Expand Up @@ -189,6 +189,7 @@ This is an example of the output:
{
"_id": "my_watch_0-2015-06-02T23:17:55.124Z", <1>
"watch_record": { <2>
"@timestamp": "2015-06-02T23:17:55.124Z",
"watch_id": "my_watch",
"node": "my_node",
"messages": [],
Expand Down Expand Up @@ -276,6 +277,7 @@ This is an example of the output:
--------------------------------------------------
// TESTRESPONSE[s/my_watch_0-2015-06-02T23:17:55.124Z/$body._id/]
// TESTRESPONSE[s/"triggered_time": "2015-06-02T23:17:55.124Z"/"triggered_time": "$body.watch_record.trigger_event.triggered_time"/]
// TESTRESPONSE[s/"@timestamp": "2015-06-02T23:17:55.124Z"/"@timestamp": "$body.watch_record.trigger_event.triggered_time"/]
// TESTRESPONSE[s/"scheduled_time": "2015-06-02T23:17:55.124Z"/"scheduled_time": "$body.watch_record.trigger_event.manual.schedule.scheduled_time"/]
// TESTRESPONSE[s/"execution_time": "2015-06-02T23:17:55.124Z"/"execution_time": "$body.watch_record.result.execution_time"/]
// TESTRESPONSE[s/"timestamp": "2015-06-02T23:17:55.111Z"/"timestamp": "$body.watch_record.status.state.timestamp"/]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,10 @@
*/
package org.elasticsearch.xpack.core.watcher.history;

import org.elasticsearch.common.time.DateFormatter;
import org.elasticsearch.xpack.core.watcher.support.WatcherIndexTemplateRegistryField;

import java.time.ZonedDateTime;

public final class HistoryStoreField {

public static final String INDEX_PREFIX = ".watcher-history-";
public static final String INDEX_PREFIX_WITH_TEMPLATE = INDEX_PREFIX + WatcherIndexTemplateRegistryField.INDEX_TEMPLATE_VERSION + "-";
private static final DateFormatter indexTimeFormat = DateFormatter.forPattern("yyyy.MM.dd");

/**
* Calculates the correct history index name for a given time
*/
public static String getHistoryIndexNameForTime(ZonedDateTime time) {
return INDEX_PREFIX_WITH_TEMPLATE + indexTimeFormat.format(time);
}
public static final String DATA_STREAM = INDEX_PREFIX + WatcherIndexTemplateRegistryField.INDEX_TEMPLATE_VERSION;
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ public final XContentBuilder toXContent(XContentBuilder builder, Params params)
builder.field(WATCH_ID.getPreferredName(), id.watchId());
builder.field(NODE.getPreferredName(), nodeId);
builder.field(STATE.getPreferredName(), state.id());
builder.field("@timestamp", triggerEvent.triggeredTime());

if (user != null) {
builder.field(USER.getPreferredName(), user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ public final class WatcherIndexTemplateRegistryField {
// version 11: watch history indices are hidden
// version 12: templates changed to composable templates
// version 13: add `allow_auto_create` setting
// version 14: move watch history to data stream
// Note: if you change this, also inform the kibana team around the watcher-ui
public static final int INDEX_TEMPLATE_VERSION = 13;
public static final int INDEX_TEMPLATE_VERSION = 14;
public static final String HISTORY_TEMPLATE_NAME = ".watch-history-" + INDEX_TEMPLATE_VERSION;
public static final String HISTORY_TEMPLATE_NAME_NO_ILM = ".watch-history-no-ilm-" + INDEX_TEMPLATE_VERSION;
public static final String TRIGGERED_TEMPLATE_NAME = ".triggered_watches";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"index_patterns": [ ".watcher-history-${xpack.watcher.template.version}*" ],
"priority": 2147483646,
"data_stream": {
"hidden":true
},
"template": {
"settings": {
"index.number_of_shards": 1,
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugin/core/src/main/resources/watch-history.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"index_patterns": [ ".watcher-history-${xpack.watcher.template.version}*" ],
"priority": 2147483647,
"data_stream": {
"hidden":true
},
"template": {
"settings": {
"index.number_of_shards": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@
import org.elasticsearch.xpack.core.watcher.transport.actions.stats.WatcherStatsAction;
import org.elasticsearch.xpack.core.watcher.watch.Watch;

import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -1569,9 +1567,7 @@ public void testWatcherAdminRole() {

assertThat(role.indices().allowedIndicesMatcher(IndexAction.NAME).test(mockIndexAbstraction("foo")), is(false));

ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
String historyIndex = HistoryStoreField.getHistoryIndexNameForTime(now);
for (String index : new String[]{ Watch.INDEX, historyIndex, TriggeredWatchStoreField.INDEX_NAME }) {
for (String index : new String[]{ Watch.INDEX, HistoryStoreField.DATA_STREAM, TriggeredWatchStoreField.INDEX_NAME }) {
assertOnlyReadAllowed(role, index);
}

Expand Down Expand Up @@ -1604,9 +1600,7 @@ public void testWatcherUserRole() {
assertThat(role.indices().allowedIndicesMatcher(IndexAction.NAME).test(mockIndexAbstraction(TriggeredWatchStoreField.INDEX_NAME)),
is(false));

ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
String historyIndex = HistoryStoreField.getHistoryIndexNameForTime(now);
for (String index : new String[]{ Watch.INDEX, historyIndex }) {
for (String index : new String[]{ Watch.INDEX, HistoryStoreField.DATA_STREAM }) {
assertOnlyReadAllowed(role, index);
}

Expand Down
1 change: 1 addition & 0 deletions x-pack/plugin/watcher/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies {

testImplementation project(path: xpackModule('core'), configuration: 'testArtifacts')
testImplementation project(xpackModule('ilm'))
testImplementation project(xpackModule('data-streams'))

// watcher deps
api 'com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:20191001.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ private void assertHistoryEntryThrottled(String id) {
}

private Map<String, Object> assertLatestHistoryEntry(String id) {
refresh(HistoryStoreField.INDEX_PREFIX_WITH_TEMPLATE + "*");
refresh(HistoryStoreField.DATA_STREAM + "*");

SearchResponse searchResponse = client().prepareSearch(HistoryStoreField.INDEX_PREFIX_WITH_TEMPLATE + "*")
SearchResponse searchResponse = client().prepareSearch(HistoryStoreField.DATA_STREAM + "*")
.setSize(1)
.setSource(new SearchSourceBuilder().query(QueryBuilders.boolQuery()
.must(termQuery("watch_id", id))))
Expand All @@ -111,7 +111,7 @@ private Map<String, Object> assertLatestHistoryEntry(String id) {
}

private void assertTotalHistoryEntries(String id, long expectedCount) {
SearchResponse searchResponse = client().prepareSearch(HistoryStoreField.INDEX_PREFIX_WITH_TEMPLATE + "*")
SearchResponse searchResponse = client().prepareSearch(HistoryStoreField.DATA_STREAM + "*")
.setSize(0)
.setSource(new SearchSourceBuilder().query(QueryBuilders.boolQuery().must(termQuery("watch_id", id))))
.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public void testThatEmailAttachmentsAreSent() throws Exception {
timeWarp().trigger("_test_id");
refresh();

SearchResponse searchResponse = client().prepareSearch(HistoryStoreField.INDEX_PREFIX_WITH_TEMPLATE + "*")
SearchResponse searchResponse = client().prepareSearch(HistoryStoreField.DATA_STREAM + "*")
.setQuery(QueryBuilders.termQuery("watch_id", "_test_id"))
.execute().actionGet();
assertHitCount(searchResponse, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void testEmailFields() throws Exception {
// the action should fail as no email server is available
assertWatchWithMinimumActionsCount("_id", ExecutionState.EXECUTED, 1);

SearchResponse response = client().prepareSearch(HistoryStoreField.INDEX_PREFIX_WITH_TEMPLATE + "*").setSource(searchSource()
SearchResponse response = client().prepareSearch(HistoryStoreField.DATA_STREAM + "*").setSource(searchSource()
.aggregation(terms("from").field("result.actions.email.message.from"))
.aggregation(terms("to").field("result.actions.email.message.to"))
.aggregation(terms("cc").field("result.actions.email.message.cc"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void testHttpFields() throws Exception {
// the action should fail as no email server is available
assertWatchWithMinimumActionsCount("_id", ExecutionState.EXECUTED, 1);

SearchResponse response = client().prepareSearch(HistoryStoreField.INDEX_PREFIX_WITH_TEMPLATE + "*").setSource(searchSource()
SearchResponse response = client().prepareSearch(HistoryStoreField.DATA_STREAM + "*").setSource(searchSource()
.aggregation(terms("input_result_path").field("result.input.http.request.path"))
.aggregation(terms("input_result_host").field("result.input.http.request.host"))
.aggregation(terms("webhook_path").field("result.actions.webhook.request.path")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void testIndexActionFields() throws Exception {
flush();
refresh();

SearchResponse response = client().prepareSearch(HistoryStoreField.INDEX_PREFIX_WITH_TEMPLATE + "*").setSource(searchSource()
SearchResponse response = client().prepareSearch(HistoryStoreField.DATA_STREAM + "*").setSource(searchSource()
.aggregation(terms("index_action_indices").field("result.actions.index.response.index")))
.get();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ WatcherSearchTemplateRequest.DEFAULT_INDICES_OPTIONS, new BytesArray("{}")
// the action should fail as no email server is available
assertWatchWithMinimumActionsCount("_id", ExecutionState.EXECUTED, 1);

SearchResponse response = client().prepareSearch(HistoryStoreField.INDEX_PREFIX_WITH_TEMPLATE + "*").setSource(searchSource()
SearchResponse response = client().prepareSearch(HistoryStoreField.DATA_STREAM + "*").setSource(searchSource()
.aggregation(terms("input_search_type").field("result.input.search.request.search_type"))
.aggregation(terms("input_indices").field("result.input.search.request.indices"))
.aggregation(terms("input_body").field("result.input.search.request.body")))
Expand Down
Loading