Commit Graph

592 Commits

Author SHA1 Message Date
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
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 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
Martijn van Groningen 1db5d1e37d Test: fix build failure where randomly a restricted header was used.
Original commit: elastic/x-pack-elasticsearch@c3892181ab
2015-05-18 12:41:00 +02:00
uboness b11f457fb7 Updated the watch_history template
- Disabled the search request body/template fields as they're too volatile to have mappings (applied for both for `search` input and transform)
- Disabled watch level transform result payload

Original commit: elastic/x-pack-elasticsearch@f69b237234
2015-05-16 02:13:17 +02:00
Martijn van Groningen a52a833264 test: change test logging
Original commit: elastic/x-pack-elasticsearch@2fe4619b4f
2015-05-15 12:50:36 +02:00
uboness 912bd1299b Introduced version name to the info API
Holds the name of the version as it is defined in the `pom.xml` (different than the version number that is automatically generated by `WatcherVersion`)

Original commit: elastic/x-pack-elasticsearch@b6cf221f63
2015-05-15 04:54:33 +02:00
uboness ba5f25f73c Updated `WatcherVersion` with min es compatibility to 1.5
Original commit: elastic/x-pack-elasticsearch@a48048aae4
2015-05-15 03:07:36 +02:00
Brian Murphy 7c1497ae3b [TEST] Ensure the license is enabled when starting watcher
This change adds a check to make sure that the license is enabled when starting watcher in the tests.
This avoids a race-condition where a test might run before the license manager had a chance to start.

Original commit: elastic/x-pack-elasticsearch@0b9d0da5d4
2015-05-14 18:22:09 -04:00
Brian Murphy 54926ec336 Fix escaping of mustache strings.
I think the escaping done in XMustacheFactory (and by extension JsonEscapingMustacheFactory in core) is broken.
You cannot just escape any control character by sticking a '\' in front of it. For example a new line character it '\n' but this will be rendered as a line break. Simply prepending a '\' to this just results in a '\' and then a new line !
Added support for different escaping strategies based on the XContentType of a template for XMustacheEngine.
Currently only JSON escaping is supported using jackson.JsonStringEncoder.
Templates will be prepended with __<contentType>__:: when the content type is set. If this is set to JSON we will json escape the content.

Fixes: elastic/elasticsearch#404

Original commit: elastic/x-pack-elasticsearch@1400cba659
2015-05-14 14:35:16 -04:00
jaymode 09621f1267 allow the system truststore to be used if one is not specified
A truststore should not be required as the default system truststore can be used
to validate certificates that have been signed by most commercial CAs.

Additionally, the HttpClient is now a lifecycle component to prevent out of memory
exceptions when starting up with a bad configuration; when an exception is thrown
in the constructor, Guice will continue to try to create the object until the system runs
out of memory.

Closes elastic/elasticsearch#476

Original commit: elastic/x-pack-elasticsearch@2333e47ac1
2015-05-14 09:45:43 -04:00
Brian Murphy 5796a771c0 Chain transform was incorrectly assuming that all transforms had to be objects.
The chain transform :
```
  "transform" : {
    "chain" : [
      {
        "search" : {
          "search_type" : "count",
          "indices" : [ "logstash-*" ],
          "body" : {
            "query" : {
              "match" : { "priority" : "error"}
            }
          }
        }
      },
      {
         "script" :  "return [ error_count : ctx.payload.hits.total ]"

      }
    ]
  },
```
Was failing because the chain transform (wrongly) refused to parse the script string as a transform.
This change will allow the transforms to determine what should parse or not.

Fixes: elastic/elasticsearch#475

Updates after review

Original commit: elastic/x-pack-elasticsearch@78c1a2498d
2015-05-13 22:23:08 -04:00
uboness 926e39d21e Disabled mapping for transform results
Transform results may product different payloads per watch/execution. It means that if the resulted transformed payload is mapped and indexed, there's a high chance for mapping conflicts and thus failures.

For this reason, this commit disables the mapping of all `transform` results (on both the watch and the action levels).

This commit also changes the field name of the transform result from `transform_result` to just `transform` (aligned with other result field names - `input`, `condition` and `actions`)

 Fixes elastic/elasticsearch#472

Original commit: elastic/x-pack-elasticsearch@2c6d4f5182
2015-05-13 20:18:45 +02:00
Martijn van Groningen aba3f8f34c Revert TP SAME change for the service api
Original commit: elastic/x-pack-elasticsearch@f7e52fda96
2015-05-13 14:03:10 +02:00
Martijn van Groningen af1d4ad79c Use ThreadPool.Names.SAME executor in stats and service apis.
Original commit: elastic/x-pack-elasticsearch@03c52668e0
2015-05-13 10:44:15 +02:00
Brian Murphy f14fe49dfa Use a different separator in `Wid`
`#` is a reserved character in the URL spec and must be escaped to be used. This change uses `-` instead.

Fixes: elastic/elasticsearch#467

Original commit: elastic/x-pack-elasticsearch@a75eb89cb8
2015-05-12 17:26:28 -04:00
uboness a59e157ca3 Added default `actions`
Until now you always needed to define the `actions` in a watch. Even if you didn't want any actions, you had to define and empty objects there.

Now, the `actions` is an optional field. When missing, we default to "no actions"

Original commit: elastic/x-pack-elasticsearch@3d1a961232
2015-05-12 20:38:30 +02:00
Brian Murphy 86262d5ca5 [TEST] Fix the MonthlyScheduleTests
Move deduping to `validMonthTimes`
This change dedups the `MonthTimes` in `validMonthTimes` to support this two new methods on `MonthTimes` are added `contains(int,DayTime)` which detects if a given day and DayTime combination is contained in the MonthTime and `intersects(MonthTimes)` which detects if a `MonthTimes` has any day/DayTime combinations contained in this `MonthTimes`.

Original commit: elastic/x-pack-elasticsearch@f68039bc39
2015-05-12 14:10:35 -04:00
Martijn van Groningen 9367cd23f2 test: increasing test logging from trace to debug
Original commit: elastic/x-pack-elasticsearch@8709256210
2015-05-12 14:49:30 +02:00
Martijn van Groningen 887e97cb81 Merge pull request elastic/elasticsearch#452 from martijnvg/fix_es1x_compatibility
Fix Watcher binary compatibility between ES 1.5 and 1.6

Original commit: elastic/x-pack-elasticsearch@c7a5fc9379
2015-05-11 21:57:17 +02:00
Martijn van Groningen ddfb05dc05 test: properly set node types.
Original commit: elastic/x-pack-elasticsearch@46096c087b
2015-05-11 17:39:28 +02:00
Martijn van Groningen 66c032f6df Fix Watcher binary compatibility between ES 1.5 and 1.6
Original commit: elastic/x-pack-elasticsearch@a367d016aa
2015-05-11 15:32:31 +02:00
uboness 6320f39023 Cleanup for xcontent results + docs
Code:

- renamed 'executed_request` back to `request` in the search input/transform result (makes more sense in the context of the overall response structure
- renamed `sent_request` back to `request` in the http input result (makes more sense in the context of the overall response structure)
- renamed `http_status` to `status` in the http input result (makes more sense in the context of the overall response structure)

Docs:

- fixed indentations
- fixed wrong example in put-watch docs (`actions` was shown as an array)
- changed action ids to be lowercased & underscored

Original commit: elastic/x-pack-elasticsearch@6ded0936d5
2015-05-11 10:54:41 +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
Shay Banon 7ff92c8f96 Merge pull request elastic/elasticsearch#445 from kimchy/remove_content_unsafe
Remove rest content unsafe usage

Original commit: elastic/x-pack-elasticsearch@c290326f3f
2015-05-09 16:26:11 +02:00
Shay Banon 02ad78743e Remove rest content unsafe usage
Original commit: elastic/x-pack-elasticsearch@4725a3de22
2015-05-09 16:21:45 +02:00
Brian Murphy 9a5455f573 [TESTS] Fix Inline template tests
This change adds a method to WatcherTestUtils to compare two json structures since order is not guaranteed in template parameters.
The Inline template tests in SearchInputTests and SearchTransformTests now use this instead of string comparision.

Original commit: elastic/x-pack-elasticsearch@c433545128
2015-05-09 10:18:45 -04:00
Martijn van Groningen 8fad9937f7 Changed search template format for search input and search transform to the new Watcher template format.
Also the WatcherUtils now always use the search template support from core and never uses ScriptService:
* A template is re-parsed and extended with the watch context variables.
* A normal request body is converted into a search template and watch context variables are used as template params.

Original commit: elastic/x-pack-elasticsearch@16bacaf094
2015-05-09 13:17:25 +02:00
uboness 8ddb0a65c4 Added a setting to disable watcher
The following node setting will disable watcher (it's enabled by default).

```
watcher.enabled: false
```

Original commit: elastic/x-pack-elasticsearch@1d0541a924
2015-05-09 01:33:00 +02:00
Brian Murphy eef3a1b1e8 Add force parameter to delete to force a delete
This change adds a force paramter to delete to allow the forcing of a delete to happen ignoring locking.
This means that watch executions may fail when they go to update the watch. Watches executing from the scheduler will fail fast if the watch they are supposed to execute has been removed.
Also move the history store updates outside of the watch locks.

Fixes: elastic/elasticsearch#405

Original commit: elastic/x-pack-elasticsearch@57561b6f85
2015-05-08 19:07:10 -04:00
uboness 87d4f67b10 Changed the `body` settings of the email
moved from `text_body` and `html_body` to a more structured `body` object as follows:

```
{
  "body" : {
    "text" : "the text body",
    "html" : "the html body"
  }
}
```
`body` can also accpet a string, in which case it will default to the text body of the email:

```
{
  "body" : "the text body of the email"
}
```
the above is a syntactic sugar for the following:

```
{
  "body" : {
    "text" : "the text body of the email"
  }
}
```

Original commit: elastic/x-pack-elasticsearch@92406ac2a1
2015-05-08 19:12:06 +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
uboness 3289ee9029 Changed `attach_data` in emails to be more flexible
Bye default, when `attach_data` is set to `true` we attache the watch execution data as a `yaml` file. Now it's possible to configure the format of the file by setting the `attach_data` to an object with a `format` field (can either be set to `yaml` or `json`). Example:

```
"attach_data" : {
  "format" : "json"
}
```

Original commit: elastic/x-pack-elasticsearch@5cab59a676
2015-05-08 14:37:38 +02:00
Martijn van Groningen 97413eba38 test: also have trace logging for the other tests
Original commit: elastic/x-pack-elasticsearch@84584cd158
2015-05-08 12:19:30 +02:00
Martijn van Groningen 46838d3477 test: Don't run check index on shard close.
Original commit: elastic/x-pack-elasticsearch@38404e8994
2015-05-08 11:43:54 +02: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
uboness ddb5efeb25 Throw appropriate error when input is empty
When the watch `input` is an empty object, we need to throw an appropriate error indicating the problem (instead of the NPE that is currently thrown)

Closes elastic/elasticsearch#427

Original commit: elastic/x-pack-elasticsearch@c8b27e6653
2015-05-08 03:28:22 +02:00
Brian Murphy f78bc8dcb2 Add DateMath support to ScheduledTriggerEvent
This change changes how the ScheduledTriggerEvent is parsed to parse using DateMath instead of just as a date. This will allow the execute API to use such constructs as
```
POST _watcher/watch/test_watch/_execute
{
  "ignore_throttle" : true,
  "trigger_event" : {
    "schedule" : {
        "triggered_time": "now-5h",
        "scheduled_time": "now"
    }
  }
}
```

Fixes: elastic/elasticsearch#374

Original commit: elastic/x-pack-elasticsearch@fa286b217e
2015-05-07 19:23:33 -04:00
Brian Murphy 2e787fff2b Throw an WatcherSettingsException when parsing an invalid hourly schedule.
```
   "schedule" : {
       "hourly" :  [0]
}
```
Was throwing an NPE now it gives a WatcherSettingsException.

Fixes: elastic/elasticsearch#419

Original commit: elastic/x-pack-elasticsearch@f334712f96
2015-05-07 17:23:27 -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
Martijn van Groningen a90d5a581e fix wrong parse field
Original commit: elastic/x-pack-elasticsearch@d017fb3e63
2015-05-07 16:50:52 +02:00
Martijn van Groningen f198b1bbae Use parse field instead of a plain string
Original commit: elastic/x-pack-elasticsearch@4c58dbdbb1
2015-05-07 16:46:10 +02:00
Martijn van Groningen 16910bb7d8 removed unused method
Original commit: elastic/x-pack-elasticsearch@8b5568c4e8
2015-05-07 16:45:37 +02:00
Martijn van Groningen 34a0de4b38 test: after first elected master node has been stopped assert that watcher is started and only running once.
Original commit: elastic/x-pack-elasticsearch@e193b80215
2015-05-07 00:54:44 +02:00
Martijn van Groningen 5e7ef773b3 test: change no master block assert and if it fails print which node doesn't have a master block.
Original commit: elastic/x-pack-elasticsearch@656a1bc3df
2015-05-07 00:40:39 +02:00
Martijn van Groningen e1beb6e9b3 Fixes a bug that prevents the actual job in the schedule engine not being adjusted if the watch's interval is being updated with the same interval unit.
Closes elastic/elasticsearch#388

Original commit: elastic/x-pack-elasticsearch@ecf991f42c
2015-05-07 00:11:53 +02:00
Brian Murphy cf23d54aed Fix execute REST API call
We weren't assigning the trigger event in the execute REST API

Original commit: elastic/x-pack-elasticsearch@cc8a6d043c
2015-05-06 17:05:43 -04: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
Brian Murphy 42fc43451c Unshade the javax.mail and javax.activation jars
This change removes these jars from shading and changes the assemblies file so that they are included as is.

Original commit: elastic/x-pack-elasticsearch@695f5e2b20
2015-05-06 15:59:05 -04:00
Martijn van Groningen 3f2070cc0a index template: Added support to add additional settings to the index templates.
Also removed the version checking from the index template support, so that if the settings are changed these settings always get stored in the index template. This means we always put two index templates once watcher started.

And also shutdown watcher after the cluster service has been stopped.

This was done caused deadlock in the integration test framework when we are stopping the test cluster.
If multiple nodes are stopped, a node may briefly try to or run Watcher during the test cluster shutdown.
As part if starting we always put an index template, which will block any other start or stop calls for the WatcherService.
A node was running a put index template call as part of the start procedure while the start framework would stop the node.
The stop call would wait because it doesn't own the lock yet.
The put index template call didn't return, which caused the stop call the keep waiting.

The reason why put index template was hanging is that it failed to return anything while it the node was stopped.
Likely the put index template request got queued up waiting for a change in the cluster state, the cluster service
got stopped and the request got lost, but the watcher start procedure was still waiting.

By stopping Watcher before we stop the cluster service we avoid the scenario described above.

Original commit: elastic/x-pack-elasticsearch@db94b2279e
2015-05-06 21:22:47 +02:00
uboness 1a9db6140a fixed Java API docs
- wrote an intro where we tell how to get the watcher jar and we tall about the `WatcherClient`
- cleaned up the code snippets
- removed a reference to the `Watch.Parser`

- Also renamed `WatcherStatsResponse#getWatchServiceState` to `watcherStatsResponse.getWatcherState`

Original commit: elastic/x-pack-elasticsearch@814329cba7
2015-05-06 20:50:21 +02:00
uboness 5ecf1dbdcd Introduced `XContentSource`
An absraction aover XContent byte reference that:

- implements `ToXContent`
- can resolve values given a dot-notation path
- Used in `GetWatchResponse` and `ExecuteWatchResponse`

Also

- Moved `WatchExecutionResult` to the `execution` package

Original commit: elastic/x-pack-elasticsearch@0b41f53f38
2015-05-06 18:37:00 +02: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
Martijn van Groningen 70cc41d710 Changed internal indices naming pattern
The `.watch_history` indices names should be aligned with logstash and marvel indices patterns so changing them to `.watch_history-YY.MM.dd`

Closes elastic/elasticsearch#387

Original commit: elastic/x-pack-elasticsearch@20baa1018f
2015-05-06 11:16:14 +02:00
uboness 690641d0c9 Cleaned up the `Script` and `Template` constructs
Change them to consistently serialize themselves the same way they deserialize themselves.

If the script (or template) is read from a `string` value, it will serialize it self to xcontent as a `string` value as well. Otherwise it will serialize as an object, holding only those fields that where configured in the first place.

Original commit: elastic/x-pack-elasticsearch@52a82e0bbe
2015-05-05 23:25:14 +02: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 e6c4b53bf8 Move email html body sanitization to the EmailTemplate.render
This change moves the sanitization of the html body of emails to render time instead of at message send time.
Move the sanitization code the the EmailTemplate class.
Add <hr> tag to allowed html tags.
Add global setting `watcher.actions.email.sanitize_html` that defaults to true. If this is set to false html sanitization will be disabled
Add documentation for sanitization disable setting.
Enhance email tests to verify that sanitization is happening at construction time.

Fixes elastic/elasticsearch#356

Original commit: elastic/x-pack-elasticsearch@282a2d85c2
2015-05-04 12:44:43 -04:00
uboness 5e9f747005 Enable inlined xcontent structure in http input body
The body of the http input may hold xcontent data (json/yaml). The problem is that today, the body only accepts text and writing
 escapted json in text makes it very hard to maintain.

 This commit introduces another field settings - `xbody`. Now, use `xbody` for inlined xcontent and `body` for any text content. When `xbody` is used, we keep around the xcontent type and the http request that is then executed will include a content-type header that will match the xcontent type of input.

Original commit: elastic/x-pack-elasticsearch@7210908064
2015-05-04 13:28:32 +02:00
Martijn van Groningen e148b7e427 tests; added assertBusy(...) to get around the time issue in tests due to the async mapping update for fields introduced in tests.
Closes elastic/elasticsearch#351

Original commit: elastic/x-pack-elasticsearch@0df48aa7e8
2015-05-04 11:55:00 +02:00
uboness b63630496f Centralized all the date xcontent rendering
Original commit: elastic/x-pack-elasticsearch@08248c30cd
2015-05-04 04:53:47 +03:00
Brian Murphy d95e068a77 [TEST] Add html found during testing to cause problems for the sanitizer.
This change adds a html string that was found to cause problems for the sanitizer during testing.

Original commit: elastic/x-pack-elasticsearch@275e728674
2015-05-03 21:35:35 -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 9bbaaa7588 [TEST] Mark HistoryTemplateTimeMappingsTests.testTimeFields awaitsfix.
Original commit: elastic/x-pack-elasticsearch@a9b59e23de
2015-05-03 13:30:59 -04:00
Brian Murphy 73e64292b0 [TEST] Add refresh to make sure watch record is in the index before checking the mappings.
Original commit: elastic/x-pack-elasticsearch@bd9b266af1
2015-05-03 12:53:14 -04:00
Brian Murphy 1d052e545d [TEST] Add logging to see why test is failing.
Log the metadata we get back to see why this test is failing on jenkins.

Original commit: elastic/x-pack-elasticsearch@7e2e4a5856
2015-05-03 12:36:23 -04:00
uboness dc6235a90a Updated watch_history template to better support aggregations
- added dynamic_templates to the index template that make sure not to analyze email addresses and http `path` and `host` under the `watch_execution` object. This will enabled building aggregations over these fields. Also make sure that different time fields in thw `watch_record` are mapped as date types.
- While at it changed the `watch_execution.input_result` mapping such that it's enabled and only disabled `watch_execution.input_result.payload` as different payloads from different sources may conflict with one another in terms of mappings
- Fixed a bug in the `EmailTemplate` building of the `reply_to` field.

- Also, added missing `execution_time` to the `watch_record` (under `watch_execution` object).

Closes elastic/elasticsearch#335

Original commit: elastic/x-pack-elasticsearch@dd28c70bca
2015-05-03 17:53:06 +03:00
Brian Murphy 7d8dc38c29 Change `meta` to metadata in the code.
The meta data field was known and `metadata` in the docs but the parsing logic expected `meta`.
This change unifies everything to use `metadata`. Also clean up Watch parsing to fail in a more consistent way when unknown fields are encountered.

Fixes elastic/elasticsearch#329

Original commit: elastic/x-pack-elasticsearch@a9013127d8
2015-05-03 07:44:35 -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
Martijn van Groningen 299527c46a Serialize `input` field too.
Also added assertions to verify if all watch record not null field are expected to be there at parse time.

Original commit: elastic/x-pack-elasticsearch@42052ae02c
2015-05-02 11:31:52 +02:00
Martijn van Groningen 3b652d1772 test: fix failing tests
Original commit: elastic/x-pack-elasticsearch@3c35a828a4
2015-05-02 02:22:37 +02:00
Martijn van Groningen 31f039d1bd Make sure we skip over watches and watch records that are malformed during the Watcher starting phase.
Original commit: elastic/x-pack-elasticsearch@8bc37cdcc3
2015-05-02 01:45:21 +02:00
uboness c8a986cab7 Added a timeout to all watch write operations
The problem we have today is that since all write operations on a watch are blocked on the watch lock, if a watch is executing for a long time (for whatever reason) the action will simply block and by that hold a `management` thread for potentially a long time. This impacts elasticsearch as a whole - if for example there's an infinite loop in the condition script, then you try to delete/ack/update the watch 5 times (the default size of the management thread pool in elasticsearch is 5). You effectively block all management threads in elasticsearch and from that moment on, the only thing left to do is kill the node.

This commit introduces a timeout for the tree write watch actions - `put`, `ack` and `delete`. It is set to 10 seconds by default, but you can customize it both in java and in the rest API using the standard `master_timeout` query parameter.

Updated the relevant docs.

Fixes elastic/elasticsearch#309

Original commit: elastic/x-pack-elasticsearch@03292db37b
2015-05-01 19:02:29 +03:00
Brian Murphy b57e887095 Disallow the use of SCAN search type
This change disallows the SCAN search type in our search requests used by search input and search transform.
Add tests for this and update the current tests to both detect SCAN and not use SCAN in valid tests.

Original commit: elastic/x-pack-elasticsearch@c9d61930c8
2015-05-01 11:12:37 -04:00
Brian Murphy 56e422b9e8 Unify SearchRequest construction between SearchTransform and SearchInput.
This is a step between the old and elastic/elasticsearch#184 this change unifies the logic that generates the search requests from prototype for SearchTransforms and SearchInputs.
This change also adds the `executed_request` field to the `SearchTransform.Result` that was missing.
Add tests for SearchTransform.Result parsing and all different templating options for SearchTransform along with testing handling of search_type in SearchTransform which was being missed previously.

Fixes elastic/elasticsearch#311

Original commit: elastic/x-pack-elasticsearch@26e68576f5
2015-05-01 10:25:10 -04:00
Martijn van Groningen 118389bc06 shield: The rest layer can never use the Guice injected WatcherClient, but must always use the provided WatcherClient instance from the WatcherRestHandler base class.
Closes elastic/elasticsearch#316
Closes elastic/elasticsearch#317

Original commit: elastic/x-pack-elasticsearch@82df644895
2015-05-01 15:42:02 +02:00
Martijn van Groningen f66fc7575d test: moved all tests over to use source builders.
Original commit: elastic/x-pack-elasticsearch@e13e5b8b43
2015-05-01 11:54:56 +02:00
Brian Murphy 9df97fe845 Report the actual interval that was sent if less than 1000ms.
This change reports the actual interval that was used instead of just reporting the ms of the interval if the interval was less than 1000ms.

Fixes elastic/elasticsearch#301

Original commit: elastic/x-pack-elasticsearch@d625c952fe
2015-04-30 19:03:36 -04:00
Brian Murphy d0d646aa4c Remove default of 5m refresh on .watches and .watch_history* indices.
This default is far too high for normal use. It makes it very hard to build on top of watcher using the search APIs.

Fixes elastic/elasticsearch#279

Original commit: elastic/x-pack-elasticsearch@4e22d5c19e
2015-04-30 19:01:04 -04:00
Brian Murphy dad012fc2c Disable indexing of the WatchRecord.watch_exection.input_result
This input_result may contain different types for the same field names. This will cause mapping failures when we try to write the updated watch record.
This change disables this field and adds a test in the `ManualExecutionTests` to test this case.

Fixes elastic/elasticsearch#307

Original commit: elastic/x-pack-elasticsearch@5340761343
2015-04-30 18:05:16 -04:00
Brian Murphy 1819dc97f4 Throw exception when trying to use the default account but no accounts are configured.
This change throws an exception to let the user know that they are trying to send an email using the default account
but no accounts have been configured.

Fixes elastic/elasticsearch#303

Original commit: elastic/x-pack-elasticsearch@3e68bddf24
2015-04-30 16:45:36 -04:00