Skip to content

Commit bbae345

Browse files
lcawlszabosteve
andauthored
Add Watcher API examples (#3489) (#3495)
Co-authored-by: István Zoltán Szabó <[email protected]> (cherry picked from commit 2da56ac)
1 parent 3b589f1 commit bbae345

35 files changed

+794
-100
lines changed

output/openapi/elasticsearch-openapi.json

Lines changed: 48 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

output/schema/schema.json

Lines changed: 129 additions & 57 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

output/schema/validation-errors.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -789,12 +789,6 @@
789789
],
790790
"response": []
791791
},
792-
"watcher.stop": {
793-
"request": [
794-
"Request: missing json spec query parameter 'master_timeout'"
795-
],
796-
"response": []
797-
},
798792
"watcher.update_settings": {
799793
"request": [
800794
"Missing request & response"

output/typescript/types.ts

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

specification/_doc_ids/table.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ run-as-privilege,https://www.elastic.co/guide/en/elasticsearch/reference/{branch
493493
runtime-search-request,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/runtime-search-request.html
494494
script-processor,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/script-processor.html
495495
scroll-search-results,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/paginate-search-results.html#scroll-search-results
496+
search-after,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/paginate-search-results.html#search-after
496497
search-aggregations,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/search-aggregations.html
497498
search-aggregations-bucket-adjacency-matrix-aggregation,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/search-aggregations-bucket-adjacency-matrix-aggregation.html
498499
search-aggregations-bucket-autodatehistogram-aggregation,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/search-aggregations-bucket-autodatehistogram-aggregation.html

specification/ccr/put_auto_follow_pattern/examples/response/PutAutoFollowPatternResponseExample1.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ description: A successful response for creating an auto-follow pattern.
33
# type: response
44
# response_code: 200
55
value:
6-
acknowledged": true
6+
acknowledged: true

specification/watcher/_types/Execution.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ export class ExecutionResultInput {
9292
}
9393

9494
export class ExecutionThreadPool {
95+
/**
96+
* The largest size of the execution thread pool, which indicates the largest number of concurrent running watches.
97+
*/
9598
max_size: long
99+
/**
100+
* The number of watches that were triggered and are currently queued.
101+
*/
96102
queue_size: long
97103
}

specification/watcher/ack_watch/WatcherAckWatchRequest.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,24 @@ import { Name, Names } from '@_types/common'
2828
*
2929
* IMPORTANT: If the specified watch is currently being executed, this API will return an error
3030
* The reason for this behavior is to prevent overwriting the watch status from a watch execution.
31+
*
32+
* Acknowledging an action throttles further executions of that action until its `ack.state` is reset to `awaits_successful_execution`.
33+
* This happens when the condition of the watch is not met (the condition evaluates to false).
3134
* @rest_spec_name watcher.ack_watch
3235
* @availability stack stability=stable
3336
* @cluster_privileges manage_watcher
37+
* @doc_id watcher-api-ack-watch
3438
*/
3539
export interface Request extends RequestBase {
3640
path_parts: {
41+
/**
42+
* The watch identifier.
43+
*/
3744
watch_id: Name
45+
/**
46+
* A comma-separated list of the action identifiers to acknowledge.
47+
* If you omit this parameter, all of the actions of the watch are acknowledged.
48+
*/
3849
action_id?: Names
3950
}
4051
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# summary:
2+
description: A successful response from `POST _watcher/watch/my_watch/_ack`.
3+
# type: response
4+
# response_code: 200
5+
value: |-
6+
{
7+
"status": {
8+
"state": {
9+
"active": true,
10+
"timestamp": "2015-05-26T18:04:27.723Z"
11+
},
12+
"last_checked": "2015-05-26T18:04:27.753Z",
13+
"last_met_condition": "2015-05-26T18:04:27.763Z",
14+
"actions": {
15+
"test_index": {
16+
"ack" : {
17+
"timestamp": "2015-05-26T18:04:27.713Z",
18+
"state": "acked"
19+
},
20+
"last_execution" : {
21+
"timestamp": "2015-05-25T18:04:27.733Z",
22+
"successful": true
23+
},
24+
"last_successful_execution" : {
25+
"timestamp": "2015-05-25T18:04:27.773Z",
26+
"successful": true
27+
}
28+
}
29+
},
30+
"execution_state": "executed",
31+
"version": 2
32+
}
33+
}

specification/watcher/activate_watch/WatcherActivateWatchRequest.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@ import { Name } from '@_types/common'
2626
* @rest_spec_name watcher.activate_watch
2727
* @availability stack stability=stable
2828
* @cluster_privileges manage_watcher
29+
* @doc_id watcher-api-activate-watch
2930
* @ext_doc_id watcher-works
3031
*/
3132
export interface Request extends RequestBase {
3233
path_parts: {
34+
/**
35+
* The watch identifier.
36+
*/
3337
watch_id: Name
3438
}
3539
}

specification/watcher/deactivate_watch/DeactivateWatchRequest.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@ import { Name } from '@_types/common'
2626
* @rest_spec_name watcher.deactivate_watch
2727
* @availability stack stability=stable
2828
* @cluster_privileges manage_watcher
29+
* @doc_id watcher-api-deactivate-watch
2930
* @ext_doc_id watcher-works
3031
*/
3132
export interface Request extends RequestBase {
3233
path_parts: {
34+
/**
35+
* The watch identifier.
36+
*/
3337
watch_id: Name
3438
}
3539
}

specification/watcher/delete_watch/DeleteWatchRequest.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@ import { Name } from '@_types/common'
3232
* @rest_spec_name watcher.delete_watch
3333
* @availability stack stability=stable
3434
* @cluster_privileges manage_watcher
35+
* @doc_id watcher-api-delete-watch
3536
*/
3637
export interface Request extends RequestBase {
3738
path_parts: {
39+
/**
40+
* The watch identifier.
41+
*/
3842
id: Name
3943
}
4044
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# summary:
2+
description: A successful response from `DELETE _watcher/watch/my_watch`.
3+
# type: response
4+
# response_code: 200
5+
value: |-
6+
{
7+
"found": true,
8+
"_id": "my_watch",
9+
"_version": 2
10+
}

specification/watcher/execute_watch/WatcherExecuteWatchRequest.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,20 @@ import { Id } from '@_types/common'
3535
*
3636
* You can use the run watch API to run watches that are not yet registered by specifying the watch definition inline.
3737
* This serves as great tool for testing and debugging your watches prior to adding them to Watcher.
38+
*
39+
* When Elasticsearch security features are enabled on your cluster, watches are run with the privileges of the user that stored the watches.
40+
* If your user is allowed to read index `a`, but not index `b`, then the exact same set of rules will apply during execution of a watch.
41+
*
42+
* When using the run watch API, the authorization data of the user that called the API will be used as a base, instead of the information who stored the watch.
3843
* @rest_spec_name watcher.execute_watch
3944
* @availability stack stability=stable
4045
* @cluster_privileges manage_watcher
46+
* @doc_id watcher-api-execute-watch
4147
*/
4248
export interface Request extends RequestBase {
4349
path_parts: {
4450
/**
45-
* Identifier for the watch.
51+
* The watch identifier.
4652
*/
4753
id?: Id
4854
}
@@ -68,17 +74,20 @@ export interface Request extends RequestBase {
6874
*/
6975
ignore_condition?: boolean
7076
/**
71-
* When set to `true`, the watch record representing the watch execution result is persisted to the `.watcher-history` index for the current time. In addition, the status of the watch is updated, possibly throttling subsequent executions. This can also be specified as an HTTP parameter.
77+
* When set to `true`, the watch record representing the watch execution result is persisted to the `.watcher-history` index for the current time.
78+
* In addition, the status of the watch is updated, possibly throttling subsequent runs.
79+
* This can also be specified as an HTTP parameter.
7280
* @server_default false
7381
*/
7482
record_execution?: boolean
7583
simulated_actions?: SimulatedActions
7684
/**
77-
* This structure is parsed as the data of the trigger event that will be used during the watch execution
85+
* This structure is parsed as the data of the trigger event that will be used during the watch execution.
7886
*/
7987
trigger_data?: ScheduleTriggerEvent
8088
/**
81-
* When present, this watch is used instead of the one specified in the request. This watch is not persisted to the index and record_execution cannot be set.
89+
* When present, this watch is used instead of the one specified in the request.
90+
* This watch is not persisted to the index and `record_execution` cannot be set.
8291
* @server_default null
8392
*/
8493
watch?: Watch

specification/watcher/execute_watch/WatcherExecuteWatchResponse.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,14 @@ import { Id } from '@_types/common'
2121
import { WatchRecord } from './types'
2222

2323
export class Response {
24-
body: { _id: Id; watch_record: WatchRecord }
24+
body: {
25+
/**
26+
* The watch record identifier as it would be stored in the `.watcher-history` index.
27+
*/
28+
_id: Id
29+
/**
30+
* The watch record document as it would be stored in the `.watcher-history` index.
31+
*/
32+
watch_record: WatchRecord
33+
}
2534
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
summary: Run a watch
2+
# method_request: POST _watcher/watch/my_watch/_execute
3+
description: >
4+
Run `POST _watcher/watch/my_watch/_execute` to run a watch.
5+
The input defined in the watch is ignored and the `alternative_input` is used as the payload.
6+
The condition as defined by the watch is ignored and is assumed to evaluate to true.
7+
The `force_simulate` action forces the simulation of `my-action`.
8+
Forcing the simulation means that throttling is ignored and the watch is simulated by Watcher instead of being run normally.
9+
# type: request
10+
value: |-
11+
{
12+
"trigger_data" : {
13+
"triggered_time" : "now",
14+
"scheduled_time" : "now"
15+
},
16+
"alternative_input" : {
17+
"foo" : "bar"
18+
},
19+
"ignore_condition" : true,
20+
"action_modes" : {
21+
"my-action" : "force_simulate"
22+
},
23+
"record_execution" : true
24+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
summary: Run a watch with multiple action modes
2+
# method_request: POST _watcher/watch/my_watch/_execute
3+
description: >
4+
Run `POST _watcher/watch/my_watch/_execute` and set a different mode for each action.
5+
# type: request
6+
value: |-
7+
{
8+
"action_modes" : {
9+
"action1" : "force_simulate",
10+
"action2" : "skip"
11+
}
12+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
summary: Run a watch inline
2+
# method_request: POST _watcher/watch/_execute
3+
description: >
4+
Run `POST _watcher/watch/_execute` to run a watch inline.
5+
All other settings for this API still apply when inlining a watch.
6+
In this example, while the inline watch defines a compare condition, during the execution this condition will be ignored.
7+
# type: request
8+
value: |-
9+
{
10+
"watch" : {
11+
"trigger" : { "schedule" : { "interval" : "10s" } },
12+
"input" : {
13+
"search" : {
14+
"request" : {
15+
"indices" : [ "logs" ],
16+
"body" : {
17+
"query" : {
18+
"match" : { "message": "error" }
19+
}
20+
}
21+
}
22+
}
23+
},
24+
"condition" : {
25+
"compare" : { "ctx.payload.hits.total" : { "gt" : 0 }}
26+
},
27+
"actions" : {
28+
"log_error" : {
29+
"logging" : {
30+
"text" : "Found {{ctx.payload.hits.total}} errors in the logs"
31+
}
32+
}
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)