Commit Graph

729 Commits

Author SHA1 Message Date
uboness babe40137f [cleanup] Reorganized the integration tests
Distributed them to the proper packages, such that they'll be easy to find

Original commit: elastic/x-pack-elasticsearch@e6e6c15870
2015-06-09 14:19:47 +02:00
Martijn van Groningen 478d5ecc48 Stop the TriggeredWatchStore and HistoryStore if there are no current executions.
There may be current executions still going on during stopping.
We should try to wait for the current executions to have completed.
Otherwise we can run into a situation where we didn't delete the watch from the .triggered_watches index,
but did insert into the history index. Upon start this can lead to DocumentAlreadyExistsException,
because we already stored the history record during shutdown...

Introduced `CurrentExecutions` to handle this synchronization.

(we always first store the watch record and then remove the triggered watch)

Original commit: elastic/x-pack-elasticsearch@89c4a8d8ad
2015-06-08 20:38:37 +02:00
uboness e684194c23 Fix 1. compatibility
Original commit: elastic/x-pack-elasticsearch@e409f99754
2015-06-08 12:55:14 +02:00
uboness c491e4db16 Added support for multi doc indexing to index action
This commit adds support for indexing multiple documents with the `index` action. This is done by introducing a special `_doc` field. During action execution, the `_doc` field will be looked up in the payload. If found, the value of the field will be considered as the document that needs to be indexed. If the value is an array of objects, each object in that array will be treated as a separate document and all the documents in the array will be bulk indexed.

This commit also changes the result of the action to hold `XContentSource` rather than a payload (to avoid Map creation explosions). Th `XContentSource` was also extended to support lists.

Original commit: elastic/x-pack-elasticsearch@86f454b029
2015-06-07 17:17:38 +02:00
uboness ccdaf2f116 compare condition result
The `compare` condition result will now hold all resolved values, keyed by their associated parameter place holder strings.

Original commit: elastic/x-pack-elasticsearch@f930c77d54
2015-06-06 23:12:09 +02:00
uboness a9658cca77 Enable both timewarp on & off for ActionThrottleTests
Original commit: elastic/x-pack-elasticsearch@caa2da607f
2015-06-06 13:04:50 +02:00
uboness 096bd5b039 Fix throttling test failure
Original commit: elastic/x-pack-elasticsearch@f3799bddeb
2015-06-06 04:03:51 +02:00
uboness 034425185a Fixed failing test
Original commit: elastic/x-pack-elasticsearch@1291299318
2015-06-06 03:33:46 +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
Brian Murphy 2cff8c4c32 [TEST] Increase logging for long running delete test.
This test is failing on jenkins but does not reproduce.

Original commit: elastic/x-pack-elasticsearch@2f873261c0
2015-06-03 08:43:27 -04:00
Brian Murphy 14ffe290f7 Add support for http input endpoints that do not return JSON formatted bodys.
This change allows the httpinput to receive non json formatted data from a http endpoint
(such as the elasticsearch _cat apis). If non json is read it will be stored in the `payload._value` in the same
way that the `ScriptTransform` handles non map/json data returned by transforming scripts.
Added response_content_type to http input so that the expected content type in the response can be configured. This accepts `yaml`, `json` and `text` but will be overridden by the http headers.

Original commit: elastic/x-pack-elasticsearch@753d37f14e
2015-06-02 13:51:18 -04: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
Martijn van Groningen 47247dc46a Stats api: fix serialization issue
Renamed pending watches left overs to queued watches

Original commit: elastic/x-pack-elasticsearch@c2bcdf547c
2015-05-31 13:14:32 +02:00
Martijn van Groningen 0890001470 stats: Add queued watches metric
The queued watches metric gives insight into the watches that are queued for execution.
Per watch that is queued, executing information is shared, like the `watch_id`,
when the watch was triggered and when execution started.

Original commit: elastic/x-pack-elasticsearch@deb5ddfde2
2015-05-31 11:13:13 +02:00
Martijn van Groningen 4335669635 Refactoring: Introduced TriggeredWatch concept.
Before WatchRecord was used to keep track of an execution of a Watch and used to store actual end results to it before sealing it. (for example build dashboard on the history indices)

The keeping track of an execution has been moved from WatchRecord to TriggeredWatch. If a watch triggers a TriggeredWatch is stored. The TriggeredWatch has its own index and only the watch_id (is part of id), trigger event and state is stored. If the execution of a Watch has finished (regardless if it was successfully) a WatchRecord is stored in a history index and the TriggeredWatch is deleted.

When a watch is getting executedtThe triggered watch is used the create the watch context.

Also the WatchRecord.State has been removed to its own enum class named ExecutionState. The CHECKING value has been removed, because it wasn't really used. The CHECKING state was set when the execution began, but it was never persisted and because of this state has also been removed from triggered watch.

By separating the result of a watch execution we are more flexible to in the future change the document format of WatchRecord. The history indices will be used by users to build analytics on top of watcher. Also the history indices become truely append only indices.

When update the watch status, only change the status part with the update api
Also set the version when we delete the watch on the in memory instance enforce more ensureStarted() in the components

Removed all watch record and result parsing code (actions, conditions, inputs and transforms)

Original commit: elastic/x-pack-elasticsearch@8f5ffdac13
2015-05-30 17:59:24 +02:00
uboness 6175b9efda Disallow negative time value settings
- Consolidated setting validation under `WatcherSettingsValidation`
- `WatcherSettingsException` is now only used for settings errors

We need this consolidation as Guice doesn't deal well with exceptions in constructors. So instead, `WatcherSettingsValidation` can be injected and used as a registry for settings errors and then, since it's a service, if there any registered errors, it'll throw `WatcherSettingsException` when it's started.

Fixes elastic/elasticsearch#539

Original commit: elastic/x-pack-elasticsearch@2c1895d18c
2015-05-28 23:24:18 +02:00
Martijn van Groningen f66f460313 test: removed @Seed
Original commit: elastic/x-pack-elasticsearch@aafc29f3b1
2015-05-28 12:40:33 +02:00
jaymode 9643ec2c62 add support for separate keystore and truststore in HttpClient
The HttpClient class tried to use the truststore as a keystore for watcher with Shield fallback.
This is trappy because in Shield, the default is to only have a keystore that also acts as the
truststore, so the fallback would probably fail in most cases. Additionally, support was missing
for a keystore that had a separate key password.

The new behavior allows for specifying both a keystore and a truststore. If only a keystore is
specified, it will also be used as the truststore. If neither is defined, the system truststore will
be used. All settings fallback to shield settings.

Closes elastic/elasticsearch#480

Original commit: elastic/x-pack-elasticsearch@ad02814806
2015-05-28 06:04:40 -04: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 6acc3f2616 Added support for headers in HttpClient
- HttpResponse now holds the response headers
- Added specific support for content type of the response, based on which we create the xcontent payload.

Original commit: elastic/x-pack-elasticsearch@beae27f576
2015-05-26 16:53:05 +02:00
Brian Murphy 46c111b016 Add execution_duration to watch history records.
This change add the actual length of time a watch spends executing. This is useful to find watches that take long to execute to pinpoint those watches that may be candidates for throttling.
Add the execution_duration as a number of milliseconds rather than a timevalue so it can be aggregated from the watch_history index.

Original commit: elastic/x-pack-elasticsearch@0036468f55
2015-05-26 10:34:24 -04:00
uboness 2f48d980b3 Fixing issues after master rebase
Original commit: elastic/x-pack-elasticsearch@d3dfa53483
2015-05-22 20:57:51 +02:00
uboness 33bc0761e7 fixed bad rebase merge
Original commit: elastic/x-pack-elasticsearch@a6793fedf8
2015-05-22 20:57:51 +02:00
uboness 575208c338 Centralized xcontent parsing of time values
- Renamed `WatcherDateUtils` to `WatcherDateTimeUtils`

Original commit: elastic/x-pack-elasticsearch@6b5557058a
2015-05-22 20:57:51 +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
uboness ea91c1e617 third attempt to fix the failing tests windows
Original commit: elastic/x-pack-elasticsearch@30bb93ce4a
2015-05-22 11:39:09 +02:00
uboness 8e13a03069 fixing failing test on windows... now for realz
Original commit: elastic/x-pack-elasticsearch@159144f18c
2015-05-22 00:41:32 +02:00
uboness 47e50008a0 fixing failing test on windows
Original commit: elastic/x-pack-elasticsearch@5af44b88d2
2015-05-21 22:00:41 +02:00
Martijn van Groningen 1bdd84bcb2 test: Add a simple runner that allows to run Watcher from the IDE and work out of the box with Sense.
Original commit: elastic/x-pack-elasticsearch@8c4100258e
2015-05-21 14:44:13 +02:00
Martijn van Groningen bbcfecbe90 test: added 'cluster:monitor/nodes/info' role for the test user
Original commit: elastic/x-pack-elasticsearch@78144d3313
2015-05-21 13:35:19 +02:00
Martijn van Groningen 39f83974ef test: added missing roles for the test user
Original commit: elastic/x-pack-elasticsearch@36f6d36817
2015-05-21 12:41:30 +02:00
Martijn van Groningen 2861f8ce21 test: Add more Shield related tests for testing the Watcher roles.
Original commit: elastic/x-pack-elasticsearch@482d8fe65c
2015-05-21 12:05:44 +02:00
Martijn van Groningen 284a60e16d stats: fix npe during serialization
Original commit: elastic/x-pack-elasticsearch@3233836d0b
2015-05-21 11:38:24 +02:00
Martijn van Groningen 60c7e92ced stats: fix serialization error
Original commit: elastic/x-pack-elasticsearch@5210ca9ee7
2015-05-21 11:29:32 +02:00
Martijn van Groningen 283445b9d8 stats: fix npe in rest layer
Original commit: elastic/x-pack-elasticsearch@43b3fcf3e7
2015-05-21 11:12:52 +02:00
Martijn van Groningen c3dd74df7f Expose the current executing watches as part of the Watcher stats API.
The following additional information will be shown per watch that is executing:  `watch_id`, `watch_execution_id`, `triggered_time`, `execution_time`, `execution_phase` (whether it is execution an input, condition or an action) and `stack_trace` (useful for us when a customer reports an issue :) ).

The stats api will by default include the executing watches in the response. In order to control this, a `metric` option has been added, which can be specified as query string argument or as last path element in the stats api url. By default the watcher stats API will only return the basic statistics that are already there.

The `metric` option has the following values:
* `current_watches` - Include the current executing watches in the response.
* `_all` - Include all metrics in the stats response. Not very useful now, but when we expose more metrics in this api it will be more useful.

Original commit: elastic/x-pack-elasticsearch@093bef9bb3
2015-05-21 10:51: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 68d0420dd2 Added maven deployment profiles
Original commit: elastic/x-pack-elasticsearch@37a867aa26
2015-05-20 13:36:36 +02:00
uboness 8218170711 Added `execution_result.condition.met` field
Until today we could not search on the `met` field in the condition result. The reason for that is that this field was index as part of the condition result type only, and we disable the indexing for all condition results (to avoid mapping conflicts).

 This commit pulls the `met` condition one level higher and enables its mapping. For now (beta1) we can live with the duplication of the condition result source (were the `met` is not placed in both the condition result type and on the condition result itself). Later we should remove the duplication though.

 An example of a  "compare" condition result now looks like:

 ```
 "condition": {
    "met": true,
    "compare": {
       "met": true,
       "resolved_value": 1
    }
 }
 ```

Original commit: elastic/x-pack-elasticsearch@74a3372c25
2015-05-20 09:46:42 +02:00
Martijn van Groningen 2ede3c29d8 test: removed unused method
Original commit: elastic/x-pack-elasticsearch@465bf69daa
2015-05-19 16:58:08 +02:00
uboness 9aef7bb52b Added `compare` condition
A simple `condition` that compares a path into the model in the execution context to a value. The comparison is based on the following possible operators: `eq`, `not_eq`, `lt`, `lte`, `gt`, `gte`.

The following example shows a `compare` condition that checks if the total hits in the payload is greater or equal to 5.

```
{
	"compare" : {
		"ctx.payload.hits.total" : { "gte" :  "5" }
	}
}
```

Original commit: elastic/x-pack-elasticsearch@6d4f2bbf10
2015-05-19 04:17:12 +02:00
uboness 9e5fa64e03 Fixed watch_history template for Index Action
Fixed the mappings of the index action fields such that the `index` and `type` of the index response won't be analyzed.

Original commit: elastic/x-pack-elasticsearch@5db8bf6a33
2015-05-19 03:11:56 +02:00
Martijn van Groningen 4b3e1592ca Test: apply `shield.user` property only once,
rely on http header to be send for Shield authentication
and finally omit the manage_watcher role from the test user.

Original commit: elastic/x-pack-elasticsearch@57a6366119
2015-05-18 18:47:06 +02:00
Martijn van Groningen 00c5c5c8b6 Test: Added a test that verifies that we fail with 403 when the user doesn't have the `manage_watcher` role.
Original commit: elastic/x-pack-elasticsearch@4776bbdd11
2015-05-18 17:16:00 +02:00
Martijn van Groningen 511ac9f6a9 Test: Use internalTestCluster() instead of internalCluster()
Original commit: elastic/x-pack-elasticsearch@a2b72000c8
2015-05-18 13:26:46 +02:00
Martijn van Groningen 6404b2c7e5 Test: clear unicast temporal response list before we stop the elected master node.
Original commit: elastic/x-pack-elasticsearch@0b2675f9ff
2015-05-18 13:06:42 +02:00