Skip to content

Commit 2da56ac

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

34 files changed

+759
-95
lines changed

output/openapi/elasticsearch-openapi.json

Lines changed: 37 additions & 24 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: 115 additions & 57 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

output/typescript/types.ts

Lines changed: 2 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
@@ -504,6 +504,7 @@ run-as-privilege,https://www.elastic.co/guide/en/elasticsearch/reference/{branch
504504
runtime-search-request,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/runtime-search-request.html
505505
script-processor,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/script-processor.html
506506
scroll-search-results,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/paginate-search-results.html#scroll-search-results
507+
search-after,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/paginate-search-results.html#search-after
507508
search-aggregations,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/search-aggregations.html
508509
search-aggregations-bucket-adjacency-matrix-aggregation,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/search-aggregations-bucket-adjacency-matrix-aggregation.html
509510
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+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# summary:
2+
description: >
3+
A successful response from `POST _watcher/watch/my_watch/_execute`.
4+
# type: response
5+
# response_code: 200
6+
value: |-
7+
{
8+
"_id": "my_watch_0-2015-06-02T23:17:55.124Z",
9+
"watch_record": {
10+
"@timestamp": "2015-06-02T23:17:55.124Z",
11+
"watch_id": "my_watch",
12+
"node": "my_node",
13+
"messages": [],
14+
"trigger_event": {
15+
"type": "manual",
16+
"triggered_time": "2015-06-02T23:17:55.124Z",
17+
"manual": {
18+
"schedule": {
19+
"scheduled_time": "2015-06-02T23:17:55.124Z"
20+
}
21+
}
22+
},
23+
"state": "executed",
24+
"status": {
25+
"version": 1,
26+
"execution_state": "executed",
27+
"state": {
28+
"active": true,
29+
"timestamp": "2015-06-02T23:17:55.111Z"
30+
},
31+
"last_checked": "2015-06-02T23:17:55.124Z",
32+
"last_met_condition": "2015-06-02T23:17:55.124Z",
33+
"actions": {
34+
"test_index": {
35+
"ack": {
36+
"timestamp": "2015-06-02T23:17:55.124Z",
37+
"state": "ackable"
38+
},
39+
"last_execution": {
40+
"timestamp": "2015-06-02T23:17:55.124Z",
41+
"successful": true
42+
},
43+
"last_successful_execution": {
44+
"timestamp": "2015-06-02T23:17:55.124Z",
45+
"successful": true
46+
}
47+
}
48+
}
49+
},
50+
"input": {
51+
"simple": {
52+
"payload": {
53+
"send": "yes"
54+
}
55+
}
56+
},
57+
"condition": {
58+
"always": {}
59+
},
60+
"result": {
61+
"execution_time": "2015-06-02T23:17:55.124Z",
62+
"execution_duration": 12608,
63+
"input": {
64+
"type": "simple",
65+
"payload": {
66+
"foo": "bar"
67+
},
68+
"status": "success"
69+
},
70+
"condition": {
71+
"type": "always",
72+
"met": true,
73+
"status": "success"
74+
},
75+
"actions": [
76+
{
77+
"id": "test_index",
78+
"index": {
79+
"response": {
80+
"index": "test",
81+
"version": 1,
82+
"created": true,
83+
"result": "created",
84+
"id": "AVSHKzPa9zx62AzUzFXY"
85+
}
86+
},
87+
"status": "success",
88+
"type": "index"
89+
}
90+
]
91+
},
92+
"user": "test_admin"
93+
}
94+
}

specification/watcher/get_watch/GetWatchRequest.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ import { Name } from '@_types/common'
2525
* @rest_spec_name watcher.get_watch
2626
* @availability stack since=5.6.0 stability=stable
2727
* @cluster_privileges monitor_watcher
28+
* @doc_id watcher-api-get-watch
2829
*/
2930
export interface Request extends RequestBase {
3031
path_parts: {
32+
/**
33+
* The watch identifier.
34+
*/
3135
id: Name
3236
}
3337
}

0 commit comments

Comments
 (0)