Commit Graph

42 Commits

Author SHA1 Message Date
Martijn van Groningen bcb7428868 Renamed `email.email` to `email.message` in the email action result.
Closes elastic/elasticsearch#592

Original commit: elastic/x-pack-elasticsearch@043a4084e6
2015-06-18 11:20:55 +02:00
Martijn van Groningen e29df8dd60 Added inline watch support to _execute API
This change allows the specification of a watch inline to the `_execute` API.
This watch id will not be persisted to the index and if record_execution is set to true it will result in an error.
The internal id `_anonymous_` will be used for the watch id and will be the watch id in the watch record.

Original commit: elastic/x-pack-elasticsearch@00e32c3838
2015-06-16 16:10:07 +02:00
uboness a9448ab2a4 Moved condition errors to their result
Until now if a condition failed to execute (for whatever reason), an exception would be thrown and the watch would just abort. The problem with that approach is while the error message would have been logged in the watch record message, the result of the condition would have been lost.

This commit moves the condition execution error to the condition result (just like we have it today with actions and inputs).

- A `status` field was added to the condition result (can either be `success` or `failure`)
- A `reason` field is added to the condition result in case its status is `failure`
- If the condition result status is `failure`, the watch execution is aborted

Updated the rest APIs to verify the status & type of both the `input` and `condition` results on execution.

Original commit: elastic/x-pack-elasticsearch@dddca03ff5
2015-06-13 04:22:31 +02:00
Brian Murphy 8bf45f0340 [TEST] Watch action acking and throttling tests
This change adds tests to ack a subset of a watch's actions, use a different throttle period per action in a watch, also adds tests to make sure that both the watch level and global level throttle_period are applied correctly.
Also updates the REST tests to make sure that throttle periods can be set at a watch and action level and are returned from the GET API.

Original commit: elastic/x-pack-elasticsearch@4b006c7830
2015-06-06 02:35:42 +02:00
uboness d899c4b522 Execute API to support default trigger
Until today it was required to provide a trigger event as part of the execute API. There are two issues with it:

1. It's not user friendly (you'd expect that the execute API would just work with just pointing to the watch)
2. The API could expose inconsistencies where on one hand it points to a watch (with a well defined trigger) on the other it enabled the user to provide completely different trigger (of a different type)

This change enable supporting default triggers by enabling the trigger engine to create a simulated trigger event. This enables the execute API to look up the trigger type of the pointed watch, and ask the trigger service to simulate an event for it. It is still possible to override the trigger event data by providing it via the `trigger_data` parameter in the API.

This simplifies the execute API and prepares it for future trigger types as well.

- This commit add missing integration tests for the execute API
- Also, removed unused `setIgnoreThrottling` from the execute request/builder.

Original commit: elastic/x-pack-elasticsearch@b494ae62e6
2015-06-05 12:41:28 +02:00
uboness 613ce8762c De-normalize watch record format
Now that the watch record is write once and never read/parsed. We can de-normalize its format (the  structure of the `watch_record` document) such it'd be optimal for searching and aggregating.

- `execution_result` renamed to `result` (for minimal verbosity)

- the structure of `trigger_event` changed to:
 ```
 {
 	"trigger_event" : {
 		"type" : "<trigger_type>",
 		"triggered_time" : "<datetime>",
 		"<trigger_type>" : { // type specific data (optional) }
 	}
 }
 ```

- the structure of `input` results changed to:
 ```
 {
 	"result" : {
 		"input" : {
 			"type" : "<input_type>",
 			"payload" : { // the payload },
 			"<input_type>" : { // custom result fields per type (optional) }
 		},
 		...
 	}
 }
 ```

- the structure of `condition` results changed to:
 ```
 {
 	"result" : {
 	    ...
 		"condition" : {
 			"type" : "<condition_type>",
 			"met" : true | false,
 			"<condition_type>" : { // custom result fields per type (optional) }
 		},
 		...
 	}
 }
 ```

- the structure of `transform` results changed to:
 ```
 {
 	"result" : {
 	    ...
 		"transform" : {
 			"type" : "<transform_type>",
 			"payload" : { // the transformed payload }
 			"<transform_type>" : { // custom result fields per type (optional) }
 		},
 		...
 	}
 }
 ```

- the structure of `actions` results changed to:
 ```
 {
 	"result" : {
 	    ...
 		"actions" : [
 			{
 				"id" : "<action_id>"
 				"type" : "<action_type>",
 				"status" : "success" | "failure" | "simulated" | "throttled",
 				"reason" : "holds the reasoning if status is either success or throttled",
 				"transform" : { // action level transform result (if applicable)}
 				"<action_type>" : { // custom result fields per type (optional) }
 			},
 			...
 		]
 	}
 }
 ```

Original commit: elastic/x-pack-elasticsearch@98466d4b83
2015-06-02 03:57:21 +02:00
uboness 45d0fdf3de Changed Execute Watch API response format
- the response now returns the id of the stored watch record
- update/fixed the docs

Closes elastic/elasticsearch#538

Original commit: elastic/x-pack-elasticsearch@5df7d166f4
2015-05-27 21:18:16 +02:00
uboness fb893e774a Add the ability to ack specific actions
- now it's possible to ack specific actions via the `Ack Watch API`
- Added tests for acking specific actions
- Changed the watch status structure such that the action ack state can be referred to by `status.actions.<action_id>.ack` (instead of `status.actions.<action_id>.ack_status`... removed the extra redundant "_status")
- As part of this work, also added validation for watch/action ids, such that we disallow having whitespaces in them.
- Updated the docs around acking & throttling of watch actions

Closes elastic/elasticsearch#531
Closes elastic/elasticsearch#537

Original commit: elastic/x-pack-elasticsearch@813e601bf5
2015-05-27 19:29:46 +02:00
uboness e0a70722e0 Move acking/throttling to the action level
Until now, acking and throttling functionality was applied at the watch level. This has major drawbacks in different aspects:

- When multiple actions are defined on a watch, acking a watch effectively acks all the actions. This is conceptually wrong. Say you have two actions: `email` and `index`. It's very likely you'd like to ack the email action (to avoid receiving too many emails) but at the same time continue indexing the data in the `index` action. Right now it's not possible.

- Different actions types may require different throttling. An `email` action probably needs a longer throttle period compared to an `index` action. Also for different `webhook` actions, the throttling is ultimately determined by the 3rd party system that is called.

This commit changes how we do throttling & acking. Moving this functionality to the action level. Now, when acking, each action in the watch will be acked separately. During executiong, each action will determine whether it needs to be throttled or not. The throttler is not associated with the action, not with the watch.

The throttle period was enhanced. There is a default throttle period that is configured for watcher as a whole (using the `watcher.execution.default_throttle_period` setting. Next to that, each `watch` can define its own `throttle_period` that can serve as the default throttle period for the actions in the watch. Lastly, each action can have its own throttle period set.

Since the throttler is now an action "thing", the `throttle` package was renamed to `throttler` and moved under the `actions` package. Also, `WatchThrottler` was renamed to `ActionThrottler`.

With this change, the `Watch Execute API` changed as well. Now, when executing a watch, you can define an execution mode per action. The execution mode offers 4 types of execution:
- `execute`: executes the watch normally (actually executing the action and it may be throttled)
- `force_execute`: skips/ignores throttling and executes the watch
- `simulate`: simulates the watch execution yet it may be throttled
- `force_simulate`: skips/ignores throttling and simulates the watch execution

As part of this change, the structure of the watch status changed along with the xconent representing the `watch_record`. A new `ActionStatus` was introduced (as part of the `WatchStatus`) and is always set for every action in the watch. This status holds:
 - the current state of the action (`ackable`, `awaits_successful_execution`, `acked`)
 - the last execution state (success/failure + reason)
 - the last successful execution state
 - the last throttle state (timestamp + reason)

Original commit: elastic/x-pack-elasticsearch@32c2985ed8
2015-05-22 20:57:51 +02:00
Brian Murphy 81d19d3468 [REST-TEST] Remove check for snapshot.
This change removes the check for snapshot in the info test.

Original commit: elastic/x-pack-elasticsearch@5eb0618b56
2015-05-20 09:58:05 -04:00
uboness 7d12d314ad moving version to 2.0.0-SNAPSHOT
Original commit: elastic/x-pack-elasticsearch@58e7b38de5
2015-05-20 15:29:52 +02:00
uboness 0a3c85803c moving version to 1.0.0-Beta1
Original commit: elastic/x-pack-elasticsearch@d88dd97379
2015-05-20 14:23:05 +02:00
uboness 46dfa059fd Changed `watch_record` xcontent structure
- Renamed `watch_execution` to `execution_result`
- Renamed `actions_results` to `actions`
- Renamed `input_result` to `input`
- Renamed `condition_result` to `condition`
- Updated the `watch_history.json` template to reflect the changes, also added concrete mappings for action types (such that field that should not be analized will be mapped as `not_analyzed`
- Fixed a bug in `WatchUtils.createSearchRequestFromPrototype` where the document types were ignored.

Also, changed the `actions` (fka `actions_results`) from an object to an array. the action id is not part of the action objects (indicated by the `id` field). For example:

```
{
  "actions" : [
    {
      "id" : "my_email",
      "email" : {
        ...
      }
    }
  ]
}
```

The reason for this change is to make the path to the action fields predictable deterministic. With the object structure, where the actions were keyed by their `id`, the path to the action fields depended on the action id, which is unpredictable and continuously changing from one action to another. This made it impossible to properly analyze the action data using aggregations (as aggs require full path into the aggregated fields).

With this change, the mappings of `watch_record` changed as well where the `actions` are not defined as nested type, yet it is still configured to include all the fields in the root object. We do this so in the future, when appropriate support will be added to kibana, it'll be able to apply nested aggregations on the actions, enabling correct/safe multi-dimensional aggregations. In the mean time however, while kibana doesn't support nested aggregations, we still need to have all the fields indexed on the root, so at least a single dimensional aggregations can be safely applied.

Also, change the `input` and `condition` objects in the `watch_record` such that their mappings are disabled. The main reason for this is the fact that a lot of the inputs use elements that can be configured in many ways, but the mappings are too strict to accept it. For example, a template can be configured as a `string` or as an `object`.

Original commit: elastic/x-pack-elasticsearch@83464a0c71
2015-05-10 19:17:09 +02:00
Brian Murphy 4c939a7c3d Hijack the DELETE .watches index delete endpoint.
This change disables the DELETE .watches index endpoint.

Fixes: elastic/elasticsearch#439

Original commit: elastic/x-pack-elasticsearch@2e66cd55fa
2015-05-08 10:39:06 -04:00
Brian Murphy 8bc238e10a [REST-TEST] Use catch: missing instead of ignore: 404
Some of the non java clients don't return the body on an ignore: 404 so we must use catch missing instead.

Original commit: elastic/x-pack-elasticsearch@a10582691c
2015-05-08 10:11:43 -04:00
uboness a06303a894 Change Script & Template configuration
Scripts and Templates are very much alike. There are only two main differences between them when it comes to watcher:

1. The template doesn't have a language type - it's always mustache.
2. Templates are often used to render xcontent (json/yaml). So there's build in support for  content type in it

Traditionally, in es core, the configuration of the scripts and templates was always a bit of a mess. There was no consistency between the two and when it comes to the templates configuration, they're even not future proof (future additions to the search requests body can break the templates).

After a long discussion, we've decided that we need to change the way users configure templates & scripts in es core... and align the two. These changes will only come in es 2.0. That said, it's important that watcher will be aligned with es core in how templates and scripts are configured and therefore we need to change it for that purpose.

Watcher will come with support for the scripts & templates configuration format of es 2.0. We want to future proof the configuration from day one.

here are the configuration:

Inline:

```
{
  "inline" : "script here",
  "lang" : "lang here",
  "params" : { parameters here }
}
```

File:

```
{
  "file" : "file name here",
  "lang" : "language here",
  "params" : { parameters here }
}
```

Indexed:

```
{
  "id" : "template id here",
  "lang" : "language here",
  "params" : { parameters here }
}
```

For templates it's the same configuration except there is no `lang` field. Also, for templates, there's native support for xcontent:

```
{
  "inline" : { "key" : "{{param1}}" },
  "params" : { "param1" : "value1" }
  }
}
```

Original commit: elastic/x-pack-elasticsearch@4a31114f35
2015-05-08 09:27:18 +02:00
Brian Murphy 6f2429afb4 [REST-TEST] Add master_timeout to the rest API specs
This change adds the parameter `master_timeout` to the rest requests that can write to a watch PUT, ACK and DELETE.
Also add support in the rest tests to verify that this is accepted.

Fixes: elastic/elasticsearch#416

Original commit: elastic/x-pack-elasticsearch@4cc1c50f2c
2015-05-07 19:19:49 -04:00
Brian Murphy f5c50c44de Fix NPE in Rest Layer when GET missing watch.
The REST GET API was trying to render a	null watch on GET which	was causing an NPE. Don't render the watch if it's not found and add a test for this case.

Fixes: elastic/elasticsearch#202

Original commit: elastic/x-pack-elasticsearch@0c8afa63ba
2015-05-07 17:12:57 -04:00
Clinton Gormley 00efe8593e REST tests: Add a real bulk body to the hijack tests
The Java REST runner expects a real body for the bulk API, rather than
an empty array

Original commit: elastic/x-pack-elasticsearch@86dc149ff7
2015-05-07 16:36:55 +02:00
Clinton Gormley d76df0d590 Merge pull request elastic/elasticsearch#411 from clintongormley/wait_for_green
REST tests: Wait for yellow, not green

Original commit: elastic/x-pack-elasticsearch@296b312e17
2015-05-07 16:07:08 +02:00
Clinton Gormley 2aab635792 Merge pull request elastic/elasticsearch#409 from clintongormley/bulk_format
REST tests: Bulk API expects an array not a hash

Original commit: elastic/x-pack-elasticsearch@82e39629fa
2015-05-07 16:06:32 +02:00
Brian Murphy 9bf00d80ba [TEST] Make hijack test description more descriptive.
This change renames the hijack test name from "Test Hijack api" to "Test Hijack and Block Direct Access to Internal Indices".

Original commit: elastic/x-pack-elasticsearch@118ac18132
2015-05-07 10:05:08 -04:00
Clinton Gormley 41b974b784 REST tests: Wait for yellow, not green
When testing on a single node, waiting for green times out

Original commit: elastic/x-pack-elasticsearch@ca91bbbbe6
2015-05-07 15:43:09 +02:00
Clinton Gormley 85ac38c622 REST tests: Bulk API expects an array not a hash
Original commit: elastic/x-pack-elasticsearch@20ee1d38e7
2015-05-07 15:42:37 +02:00
Clinton Gormley 35d2d86beb REST tests: Fix bad YAML
Original commit: elastic/x-pack-elasticsearch@362aac9c96
2015-05-07 15:41:33 +02:00
Brian Murphy 7d98358012 Change the `ManualTriggerEvent` to wrap a `TriggerEvent`
This change changes the manual trigger event to be a wrapper for another `TriggerEvent`.
TriggerEvent is required field for the execute API either via setTriggerEvent on the request or requestBuilder in the java API or `trigger_event` in the REST API

Original commit: elastic/x-pack-elasticsearch@790bdb96a5
2015-05-06 16:59:26 -04:00
uboness 8730b066c1 Refactored `WatcherService.State`
- Moved it to its own top level enum `WatcherState`
- Also changed the key holding the current state in the `stats` API to `watcher_state`

Original commit: elastic/x-pack-elasticsearch@2e5ca90f57
2015-05-06 12:29:59 +02:00
Brian Murphy 75bdf7de0d [TEST] Change execute test watches to have cron schedules that trigger in 2099.
Original commit: elastic/x-pack-elasticsearch@dde1dbae86
2015-05-05 12:37:44 -04:00
Brian Murphy b5f5862146 Clean up Watch parsing to disallow arrays.
This change cleans up the watch parsing which had allowed arrays in actions as a hold over from when actions was an array.

Fixes elastic/elasticsearch#367

Original commit: elastic/x-pack-elasticsearch@3f4fb82124
2015-05-05 10:44:28 -04:00
Brian Murphy 2ff8e2fb4e [TEST] Fix ack watch test to not trigger while test is running.
Original commit: elastic/x-pack-elasticsearch@d0261b355d
2015-05-04 16:19:41 -04:00
Brian Murphy 0a545cb358 Change actual default of ignore_condition to false
Change default of ignore_codition to match docs as `false`.
Add test to verify defaults.

Fixes elastic/elasticsearch#348

Original commit: elastic/x-pack-elasticsearch@d740286a26
2015-05-03 19:33:04 -04:00
Brian Murphy 0d6fb1081a Hijack document APIs for .watches index
This change hijacks the document APIs for the .watches index and prevents direct access to these APIs via REST.
This hijacking is controlled by the "watcher.index.rest.direct_access" setting, this setting defaults to false which restricts access to the index. To allow direct access to the .watches index from the REST API set this setting to `true`
Copied json files from core es to test this feature and added comments to the json files indicating why they have been copied from es core.

Fixes elastic/elasticsearch#336

Original commit: elastic/x-pack-elasticsearch@22335750bd
2015-05-02 10:55:24 -04:00
Brian Murphy 94bea8f83a Change the watch specific actions to reflect that they operate on watches.
This change changes the watch specific actions put/get/delete/execute/ack to be watcher.<action>_watch.

Original commit: elastic/x-pack-elasticsearch@86a91cb141
2015-04-28 19:08:28 -04:00
Brian Murphy 4482d8d2ba Change watcher REST API call namespace to be watcher.
This change changes the API spec such that all of the watcher APIs are in the `watcher` namespace.

Original commit: elastic/x-pack-elasticsearch@f409ab4569
2015-04-28 18:50:07 -04:00
Brian Murphy 01c80e63b0 [TEST] Add automated tests that were missing.
SearchInput using inline, indexed and on disk templates.
ScriptedCondition where the script accesses the ctx.
ScriptedCondition where the script throws an exception.
ScriptedCondition where the script doesn't return a boolean.
Webhook tests using templated body, path and parameters.
Some REST test fixes.

Original commit: elastic/x-pack-elasticsearch@d02b6d1d7b
2015-04-27 17:56:55 -04:00
uboness ebda02438e Cleanup and Refactoring of the inputs
* Split the action into two constructs: `Input` and `ExecutableInput`. The former holds all the input configuration, the latter can execute the input based on that configuration (an executable input holds an input)
 - This the code clearer to understand and maintain.
 - This also enabled to pull some common implementation code into the `ExecutableInput` and by that reduce the implementation details of each executable to the minimum required.

* Also, extracted the `Input.Parser` to its own top level class, and renamed it to - `InputFactory`. The main thing that the factory does is: 1) delegate to the parsing to the `Input` class, 2) construct & wire up the `ExecutableInput`.

* With the introduction of `Input`, we no longer need the `SourceBuilder` for inputs. Instead, we have an `Input.Builder` that help you build an input. This is much more intuitive from the client perspective.

* Changed the `request` xcontent field in the http input result to `sent_request` for clarity
* Changed the `request` xcontent field in the search input result to `executed_request` for clarity

Original commit: elastic/x-pack-elasticsearch@63b93f9c7b
2015-04-21 23:12:43 +02:00
Brian Murphy 0a7cf71152 Persist the Watch.Status if needed after execution
This change persists the Watch.Status if needed by marking the Status as `dirty` if the status mutates during watch execution.
If the status is dirty it will be persisted at the end of execution while the execution lock is held.
Change record_in_history to record_execution which also controls weither the status will be updated.

Fixes elastic/elasticsearch#222

Original commit: elastic/x-pack-elasticsearch@25869cabf0
2015-04-16 16:57:14 -04:00
Brian Murphy 7f0e4fab41 Fix REST execute API call with empty body.
Execute with an empty body will now just use the defaults.
Add REST test for empty body.
Fixes elastic/elasticsearch#217

Original commit: elastic/x-pack-elasticsearch@072cd47250
2015-04-16 15:27:08 -04:00
Brian Murphy 8c87cb0728 Add test for invalid license.
This change adds a new test class that runs the REST tests with the license disabled.
It checks the error message to make sure that all api access is blocked from all the apis we normally test.

Fixes elastic/elasticsearch#193

Original commit: elastic/x-pack-elasticsearch@a70de9b7a7
2015-04-14 13:57:55 -04:00
Brian Murphy 3e9c109079 This commit contains a major refactoring to some of the core constructs in watcher.
- What used to be the `HistoryService` is not named `ExecutionService`. In fact, it always was an execution context and was simply named wrong and place in the wrog place in the code.

- A new `execution` package was created, to contain all execution related contsructs which includes the new `ExecutionService`, `WatchExecutionContext`, `WatchExecutor`, `InternalWatchExecutor`.

- The `WatchExecutionContext` role in the execution process was extended to also enable it to "control" the execution. "control" in the sence that it can now provide default results to some of the contructs (for example, it can provide a default input and by that skip the execution of the input). Also, it enables simulating actions (more bellow).

- There are two implementations now of the `WatchExecutionContext`. A `TriggeredExecutionContext` which is used when the trigger service triggers the execution of a watch. And `ManualExecutionContext` enabling to manually execute a watch. The latter, can be configured such that different phases in the normal executions of the watch can be skipped. This is great for simulating a watch execution, that is, executing a watch without actually fully executing the actions (e.g. create the emails that the email action would have normally send, but without actually sending it). Both of these new context implementations also sit in the new `execution` package.

- With the changes described above, the actions now consult the execution context before actually performing their tasks. If the execution context indicates that the action should run in a "simulated" mode, the action will semi execute and return a `Simulated` result. Each action type defines what is "simulated mode" for it. For example, the email action creates the email and renders all its templats but doesn't actually send it, the returned `Email.Simulated` result will contain the email that would have been sent if it was running under normal conditions (non-simulated mode). The `index` action, doesn't actually indexes anything (just creating the index request that would have been executed), and the `webhook` action only creates the HTTP request but doesn't actually send it.

- A new `execute` API was introduced that utilizes all of the above and enables to manually execute registered watches. The API provides all the tools to control what actions are simulated and enables skipping the execution of the watch `input` and `condition`. By default it also skip the recording of the execution in the watch history (though this can be enabled if desired). This API is exposed both by the Java `WatcherClient` and via a dedicated REST endpoint. (documentation around this new API was added as well)

Closes elastic/elasticsearch#149

Original commit: elastic/x-pack-elasticsearch@ee8fe0490a
2015-04-10 18:02:48 -04:00
Brian Murphy 31fbbcfc9a Add support for testing all REST endpoints.
This change adds support for testing all watcher REST endpoints.
It also updates the api docs to be current with the latest code.
Change GetWatchResponse to only have the information in needs
GetWatchResponse used to contain a GetResponse this is not needed. Now it just contains the needed fields.

Closes elastic/elasticsearch#35

Original commit: elastic/x-pack-elasticsearch@905c5da318
2015-04-07 19:47:04 -04:00
Brian Murphy 3a09914b67 Add support for rest tests
This commit adds support for rest tests using the same yaml and json formatting as for core elasticsearch.
Also added is support for shield in the rest tests.

Original commit: elastic/x-pack-elasticsearch@bbeb9c0fc9
2015-03-31 17:25:48 -04:00