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

Add Watcher API examples #3489

Merged
merged 10 commits into from
Jan 9, 2025
61 changes: 37 additions & 24 deletions output/openapi/elasticsearch-openapi.json

Large diffs are not rendered by default.

172 changes: 115 additions & 57 deletions output/schema/schema.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion output/typescript/types.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions specification/_doc_ids/table.csv
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ run-as-privilege,https://www.elastic.co/guide/en/elasticsearch/reference/{branch
runtime-search-request,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/runtime-search-request.html
script-processor,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/script-processor.html
scroll-search-results,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/paginate-search-results.html#scroll-search-results
search-after,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/paginate-search-results.html#search-after
search-aggregations,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/search-aggregations.html
search-aggregations-bucket-adjacency-matrix-aggregation,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/search-aggregations-bucket-adjacency-matrix-aggregation.html
search-aggregations-bucket-autodatehistogram-aggregation,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/search-aggregations-bucket-autodatehistogram-aggregation.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ description: A successful response for creating an auto-follow pattern.
# type: response
# response_code: 200
value:
acknowledged": true
acknowledged: true
6 changes: 6 additions & 0 deletions specification/watcher/_types/Execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ export class ExecutionResultInput {
}

export class ExecutionThreadPool {
/**
* The largest size of the execution thread pool, which indicates the largest number of concurrent running watches.
*/
max_size: long
/**
* The number of watches that were triggered and are currently queued.
*/
queue_size: long
}
11 changes: 11 additions & 0 deletions specification/watcher/ack_watch/WatcherAckWatchRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,24 @@ import { Name, Names } from '@_types/common'
*
* IMPORTANT: If the specified watch is currently being executed, this API will return an error
* The reason for this behavior is to prevent overwriting the watch status from a watch execution.
*
* Acknowledging an action throttles further executions of that action until its `ack.state` is reset to `awaits_successful_execution`.
* This happens when the condition of the watch is not met (the condition evaluates to false).
* @rest_spec_name watcher.ack_watch
* @availability stack stability=stable
* @cluster_privileges manage_watcher
* @doc_id watcher-api-ack-watch
*/
export interface Request extends RequestBase {
path_parts: {
/**
* The watch identifier.
*/
watch_id: Name
/**
* A comma-separated list of the action identifiers to acknowledge.
* If you omit this parameter, all of the actions of the watch are acknowledged.
*/
action_id?: Names
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# summary:
description: A successful response from `POST _watcher/watch/my_watch/_ack`.
# type: response
# response_code:
lcawl marked this conversation as resolved.
Show resolved Hide resolved
value: |-
{
"status": {
"state": {
"active": true,
"timestamp": "2015-05-26T18:04:27.723Z"
},
"last_checked": "2015-05-26T18:04:27.753Z",
"last_met_condition": "2015-05-26T18:04:27.763Z",
"actions": {
"test_index": {
"ack" : {
"timestamp": "2015-05-26T18:04:27.713Z",
"state": "acked"
},
"last_execution" : {
"timestamp": "2015-05-25T18:04:27.733Z",
"successful": true
},
"last_successful_execution" : {
"timestamp": "2015-05-25T18:04:27.773Z",
"successful": true
}
}
},
"execution_state": "executed",
"version": 2
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ import { Name } from '@_types/common'
* @rest_spec_name watcher.activate_watch
* @availability stack stability=stable
* @cluster_privileges manage_watcher
* @doc_id watcher-api-activate-watch
* @ext_doc_id watcher-works
*/
export interface Request extends RequestBase {
path_parts: {
/**
* The watch identifier
lcawl marked this conversation as resolved.
Show resolved Hide resolved
*/
watch_id: Name
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ import { Name } from '@_types/common'
* @rest_spec_name watcher.deactivate_watch
* @availability stack stability=stable
* @cluster_privileges manage_watcher
* @doc_id watcher-api-deactivate-watch
* @ext_doc_id watcher-works
*/
export interface Request extends RequestBase {
path_parts: {
/**
* The watch identifier.
*/
watch_id: Name
}
}
4 changes: 4 additions & 0 deletions specification/watcher/delete_watch/DeleteWatchRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ import { Name } from '@_types/common'
* @rest_spec_name watcher.delete_watch
* @availability stack stability=stable
* @cluster_privileges manage_watcher
* @doc_id watcher-api-delete-watch
*/
export interface Request extends RequestBase {
path_parts: {
/**
* The watch identifier.
*/
id: Name
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# summary:
description: A successful response from `DELETE _watcher/watch/my_watch`.
# type: response
# response_code:
lcawl marked this conversation as resolved.
Show resolved Hide resolved
value: |-
{
"found": true,
"_id": "my_watch",
"_version": 2
}
17 changes: 13 additions & 4 deletions specification/watcher/execute_watch/WatcherExecuteWatchRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,20 @@ import { Id } from '@_types/common'
*
* You can use the run watch API to run watches that are not yet registered by specifying the watch definition inline.
* This serves as great tool for testing and debugging your watches prior to adding them to Watcher.
*
* When Elasticsearch security features are enabled on your cluster, watches are run with the privileges of the user that stored the watches.
* 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.
*
* 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.
* @rest_spec_name watcher.execute_watch
* @availability stack stability=stable
* @cluster_privileges manage_watcher
* @doc_id watcher-api-execute-watch
*/
export interface Request extends RequestBase {
path_parts: {
/**
* Identifier for the watch.
* The watch identifier.
*/
id?: Id
}
Expand All @@ -68,17 +74,20 @@ export interface Request extends RequestBase {
*/
ignore_condition?: boolean
/**
* 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.
* 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 runs.
* This can also be specified as an HTTP parameter.
* @server_default false
*/
record_execution?: boolean
simulated_actions?: SimulatedActions
/**
* This structure is parsed as the data of the trigger event that will be used during the watch execution
* This structure is parsed as the data of the trigger event that will be used during the watch execution.
*/
trigger_data?: ScheduleTriggerEvent
/**
* 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.
* 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.
* @server_default null
*/
watch?: Watch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,14 @@ import { Id } from '@_types/common'
import { WatchRecord } from './types'

export class Response {
body: { _id: Id; watch_record: WatchRecord }
body: {
/**
* The watch record identifier as it would be stored in the `.watcher-history` index.
*/
_id: Id
/**
* The watch record document as it would be stored in the `.watcher-history` index.
*/
watch_record: WatchRecord
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
summary: Run a watch
# method_request: POST _watcher/watch/my_watch/_execute
description: >
Run `POST _watcher/watch/my_watch/_execute` to run a watch.
The input defined in the watch is ignored and the `alternative_input` is used as the payload.
The condition as defined by the watch is ignored and is assumed to evaluate to true.
The `force_simulate` action forces the simulation of `my-action`.
Forcing the simulation means that throttling is ignored and the watch is simulated by Watcher instead of being run normally.
# type: request
value: |-
{
"trigger_data" : {
"triggered_time" : "now",
"scheduled_time" : "now"
},
"alternative_input" : {
"foo" : "bar"
},
"ignore_condition" : true,
"action_modes" : {
"my-action" : "force_simulate"
},
"record_execution" : true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
summary: Run a watch with multiple action modes
# method_request: POST _watcher/watch/my_watch/_execute
description: >
Run `POST _watcher/watch/my_watch/_execute` and set a different mode for each action.
# type: request
value: |-
{
"action_modes" : {
"action1" : "force_simulate",
"action2" : "skip"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
summary: Run a watch inline
# method_request: POST _watcher/watch/_execute
description: >
Run `POST _watcher/watch/_execute` to run a watch inline.
All other settings for this API still apply when inlining a watch.
In this example, while the inline watch defines a compare condition, during the execution this condition will be ignored.
# type: request
value: |-
{
"watch" : {
"trigger" : { "schedule" : { "interval" : "10s" } },
"input" : {
"search" : {
"request" : {
"indices" : [ "logs" ],
"body" : {
"query" : {
"match" : { "message": "error" }
}
}
}
}
},
"condition" : {
"compare" : { "ctx.payload.hits.total" : { "gt" : 0 }}
},
"actions" : {
"log_error" : {
"logging" : {
"text" : "Found {{ctx.payload.hits.total}} errors in the logs"
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# summary:
description: >
A successful response from `POST _watcher/watch/my_watch/_execute`.
# type: response
# response_code:
lcawl marked this conversation as resolved.
Show resolved Hide resolved
value: |-
{
"_id": "my_watch_0-2015-06-02T23:17:55.124Z",
"watch_record": {
"@timestamp": "2015-06-02T23:17:55.124Z",
"watch_id": "my_watch",
"node": "my_node",
"messages": [],
"trigger_event": {
"type": "manual",
"triggered_time": "2015-06-02T23:17:55.124Z",
"manual": {
"schedule": {
"scheduled_time": "2015-06-02T23:17:55.124Z"
}
}
},
"state": "executed",
"status": {
"version": 1,
"execution_state": "executed",
"state": {
"active": true,
"timestamp": "2015-06-02T23:17:55.111Z"
},
"last_checked": "2015-06-02T23:17:55.124Z",
"last_met_condition": "2015-06-02T23:17:55.124Z",
"actions": {
"test_index": {
"ack": {
"timestamp": "2015-06-02T23:17:55.124Z",
"state": "ackable"
},
"last_execution": {
"timestamp": "2015-06-02T23:17:55.124Z",
"successful": true
},
"last_successful_execution": {
"timestamp": "2015-06-02T23:17:55.124Z",
"successful": true
}
}
}
},
"input": {
"simple": {
"payload": {
"send": "yes"
}
}
},
"condition": {
"always": {}
},
"result": {
"execution_time": "2015-06-02T23:17:55.124Z",
"execution_duration": 12608,
"input": {
"type": "simple",
"payload": {
"foo": "bar"
},
"status": "success"
},
"condition": {
"type": "always",
"met": true,
"status": "success"
},
"actions": [
{
"id": "test_index",
"index": {
"response": {
"index": "test",
"version": 1,
"created": true,
"result": "created",
"id": "AVSHKzPa9zx62AzUzFXY"
}
},
"status": "success",
"type": "index"
}
]
},
"user": "test_admin"
}
}
4 changes: 4 additions & 0 deletions specification/watcher/get_watch/GetWatchRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ import { Name } from '@_types/common'
* @rest_spec_name watcher.get_watch
* @availability stack since=5.6.0 stability=stable
* @cluster_privileges monitor_watcher
* @doc_id watcher-api-get-watch
*/
export interface Request extends RequestBase {
path_parts: {
/**
* The watch identifier.
*/
id: Name
}
}
Loading
Loading