Commit Graph

657 Commits

Author SHA1 Message Date
Martijn van Groningen 87e3a6a41d test: after each test, ensure that watcher only runs on one node (elected master)
Original commit: elastic/x-pack-elasticsearch@c5d0d4e1d3
2015-04-28 13:41:24 +02:00
Martijn van Groningen 59218733ea test: fix forbidden api failure
Original commit: elastic/x-pack-elasticsearch@ec8c6e1d51
2015-04-28 12:37:41 +02:00
Martijn van Groningen fcb81ab76a test: added more tests for the transform feature.
Original commit: elastic/x-pack-elasticsearch@dd46dc1c42
2015-04-28 12:22:06 +02:00
Brian Murphy 877e59c80f [TEST] Add support for HEAD and DELETE to `WebhookActionTests`
Add HEAD and DELETE to the list of http methods we test in the webhook action tests.

Original commit: elastic/x-pack-elasticsearch@7a6b29bac6
2015-04-27 18:14:17 -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
Martijn van Groningen 7f6c3814b7 test: unset 'shieldEnabled' and 'scheduleEngine' after test class is completed.
Original commit: elastic/x-pack-elasticsearch@3e9332df94
2015-04-25 17:42:48 +02:00
Martijn van Groningen 5d494a7b2d test: ensure that 'shieldEnabled' field is only set once.
The HttpInputIntegrationTest sometimes unsetted the 'shieldEnabled' field for subsequent test methods, this caused http 401 errors, because the nodes were started with Shield enabled.

Original commit: elastic/x-pack-elasticsearch@b39ca9647d
2015-04-25 15:37:41 +02:00
Martijn van Groningen 4530232060 increased logging
Original commit: elastic/x-pack-elasticsearch@704c8d6132
2015-04-24 23:07:38 +02:00
Martijn van Groningen b0a16e36fd test: quicker interval
Original commit: elastic/x-pack-elasticsearch@795827db7f
2015-04-24 14:54:13 +02:00
Brian Murphy 9a044735dd [TEST] Minimize chance of thread pre-emption when testing fair locks.
Original commit: elastic/x-pack-elasticsearch@4d52f70e7f
2015-04-24 08:47:44 -04:00
Martijn van Groningen 93fee667ab test: added no master node test for a cluster with dedicated master nodes and dedicated data nodes.
Automates: https://github.com/elastic/elasticsearch-watcher-qa/issues/83

Original commit: elastic/x-pack-elasticsearch@73fac17961
2015-04-24 14:26:30 +02:00
Martijn van Groningen e1c163dba4 test: added test for http input querying api other than _search
Original commit: elastic/x-pack-elasticsearch@ebb1d802c9
2015-04-24 12:45:35 +02:00
Martijn van Groningen 3e882fce7d test: run randomily with shield again
Original commit: elastic/x-pack-elasticsearch@d55e61af71
2015-04-24 12:14:03 +02:00
Brian Murphy f39da21905 If we fail to bind to port 2500 when starting an EmailServer try the next port up.
This change employs the same kind of logic that `HttpClientTest` uses to find an open port for it's server. This should prevent the rare build failures we have seen.

Original commit: elastic/x-pack-elasticsearch@f3b68adad5
2015-04-23 21:10:04 -04:00
Brian Murphy d319fdef1b Add timeout when stopping WatchLockService
If there were many watches concurrently executing that take some time to execute it can a long time to shutdown a node. This change introduces a Timeout when stopping the WatchLockService.
Make watcher lock service timeout configurable. The configuration setting is `watcher.stop.timeout` the default is 30s.

Fixes elastic/elasticsearch#216

Original commit: elastic/x-pack-elasticsearch@06bf029a54
2015-04-23 17:45:11 -04:00
Brian Murphy a68d9018f2 Disable minimizeJar in pom.xml
The javax package finds some needed classfiles by reflection. Minimizing the shaded jar meant that these were not available.

Fixes elastic/elasticsearch#254

Original commit: elastic/x-pack-elasticsearch@7cdc3bc55b
2015-04-23 17:37:39 -04:00
Martijn van Groningen 80a766d18e test: removed unused field
Original commit: elastic/x-pack-elasticsearch@039328fccd
2015-04-23 22:11:20 +02:00
Martijn van Groningen 946df191e9 removed unused field
Original commit: elastic/x-pack-elasticsearch@1c4e94b5b2
2015-04-23 22:00:46 +02:00
Martijn van Groningen 4e8ed283e7 Renamed `WatchService` to `WatcherService` and moved it to the `org.elasticsearch.watcher` package.
Original commit: elastic/x-pack-elasticsearch@5f602ed832
2015-04-23 21:49:29 +02:00
Martijn van Groningen ec8c9046b3 Refactored life cycle starting.
* The validation happens separately from the actual starting and loading. Also the validation happens on the cluster update thread, so that we don't miss any cluster state update.
* The starting/loading part happens on a forked thread, but if it fails then it always retry after a small timeout.
* Simplified the starting code, so that we don't need the callback interface.

Closes elastic/elasticsearch#212

Original commit: elastic/x-pack-elasticsearch@b5cd48e5bb
2015-04-23 21:49:28 +02:00
Brian Murphy 41e42f0945 The DateTimes watcher uses for scheduled and trigger times should always be UTC
Before this change DateTimes were being constructed without providing a time zone,
this was causing some non-utc time leakage. In particular watch record ids were being created with non utc dates and
watch records were going to the wrong .watch_history index.
Add Clock.now(DateTimeZone) to allow callers to get UTC now.
Also construct the DateTimes with UTC timezones when we construct from millis.
Add all constuctors of DateTime that do not specify a time zone to the forbidden APIs.
This change makes constructing a `DateTime` object without providing a `DateTimeZone` forbidden.
This is much safer and makes time zone errors much more unlikely to occur.
Statically import DateTimeZone.UTC everywhere it was being used
Now all calls that use DateTimeZone.UTC just refrence UTC.

Fixes elastic/elasticsearch#150

Original commit: elastic/x-pack-elasticsearch@7f23ce605e
2015-04-23 15:17:23 -04:00
Brian Murphy 29c76b9c8a [LOG] Catch all and log all `WatcherException`s with watch id when parsing watches at start.
This will help debugging broken watches.

Fixes elastic/elasticsearch#251

Original commit: elastic/x-pack-elasticsearch@87e3e9a0dc
2015-04-23 15:13:19 -04:00
Martijn van Groningen 096e00caed index templates: use correct property to extract version from index template from cluster state
Original commit: elastic/x-pack-elasticsearch@ab86054c7f
2015-04-23 20:58:21 +02:00
uboness 345f610bdf Cleanup and Refactored Templates
Mainly how templates read/write themselves from/to xcontent. Instead of using `text`, use `template`

Original commit: elastic/x-pack-elasticsearch@0d6f317539
2015-04-23 15:15:46 +02:00
uboness ae1d4021c0 Cleanup and Refactoring
- Changed watch `name` to watch `id
- `TriggerEngine.Job#name` -> `TriggerEngine.Job#id`
- Removed `Trigger.SourceBuilder` in favor of `Trigger.Builder`
- Fixed compile warnings in `EmailTemplate`

Original commit: elastic/x-pack-elasticsearch@b7fb23712c
2015-04-23 13:06:53 +02:00
uboness 70209698fb Changed version to 1.0.0-Beta1-SNAPSHOT
Original commit: elastic/x-pack-elasticsearch@6bd62904cc
2015-04-23 10:35:33 +02:00
uboness 690af790b2 Cleanup and Refactoring of the transforms
* Split the transform into two constructs: `Transform` and `ExecutableTransform`. The former holds all the transform configuration, the latter can execute the transform based on that configuration (an executable transform holds a transform)
 - This makes the code clearer to understand and maintain.
 - This also enabled to pull some common implementation code into the `ExecutableTransform` and by that reduce the implementation details of each executable to the minimum required.

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

* With the introduction of `Transform`, we no longer need the `SourceBuilder` for transforms. Instead, we have `Transform.Builder` that help you build a transform. This is much more intuitive from the client perspective.

Original commit: elastic/x-pack-elasticsearch@f6ee0d0c75
2015-04-23 10:23:08 +02:00
Martijn van Groningen 34c9d6af62 Removed the watcher executor thread pool as it is redundant now with the async indexing.
Original commit: elastic/x-pack-elasticsearch@6afaf0308b
2015-04-23 08:34:23 +02:00
Martijn van Groningen 7851ad6993 Removed quartz, timer and hashwheel schedule engines. Renames simple engine to ticket engine.
Original commit: elastic/x-pack-elasticsearch@f59be963ef
2015-04-22 23:36:53 +02:00
Martijn van Groningen a68db406e2 * Doubled the watcher executor thread pool size.
* Tune the index templates for higher index throughput.
* Trigger events should be processed and indexed in an async manner.
* Moved the job name into the TriggerEvent
* Added support for fire multiple events at the same time. If multiple events are fired at the same time then use async bulk to persist the watch record.
* Cut simple ticker and timer ticker over to fire multiple events at the same time
* Don't fire more than 1000 events at the time. (this also may result in large bulk requests)

Original commit: elastic/x-pack-elasticsearch@c7f6bd3812
2015-04-22 23:35:20 +02:00
Martijn van Groningen c8a0c27934 * Log EsRejectedExecutionException better than it is now. (letting it bubble up the the thread that is actually firing triggers, which then prints uncaught exception...)
* if we have EsRejectedExecutionException log on debug level.

Original commit: elastic/x-pack-elasticsearch@e8eb8fcf36
2015-04-22 23:30:11 +02:00
Martijn van Groningen a1b3d41822 * Added overall benchmark that tests all the scheduler engines
* Changed the isolated ScheduleEngineBenchmark to tests all engines and collect statistics during a test run.
* Updated the isolated schedule benchmark to just test the trigger part of the scheduler and capture some basic matrics.

Original commit: elastic/x-pack-elasticsearch@88bbf3688d
2015-04-22 23:30:10 +02:00
uboness 3f26a1b2e0 Adds initial schedule engine implementation
- `TimerScheduleTriggerEngine` - a single threaded Java `Timer`based scheduler. "Ticks" every second and checks all the registered schedules.

- `SimpleTickerScheduleTriggerEngine` - a single threaded scheduler. "Ticks" every second and checks all the registered schedules

- `SchedulerScheduleTriggerEngine` - a single threaded engine based on Java's schedule executor service. Here, every job is added as a scheduled task to the executor and each job is managing its own execution times.

- `HashWheelScheduleTriggerEngine` - a single threaded engine based on Netty's `HashWheelTimer`. Like with the `scheduler` above, every job is added as a scheduled task to the executor and each job is managing its own execution times.

Also:

- Added an undocumented feature to configure the schedule engine in the settings using `watcher.trigger.schedule.engine` (optional values right now are `quartz`, `simple`, `timer`, `hashwheel` and `scheduler`)
- `Cron` is a fork/copy of quartz `CronExpression`.. a bit cleaned up though.
- `Schedule` now exposes `nextScheduledTimeAfter` to return the next scheduled time after the given one.
- `CronnableSchedule` is now based on `Cron` (this exposed bugs in the schedule tests where we generated invalid cron expression. Now, since `Cronnable` creates the actual cron, validation is in place to make sure only valid expressions are created)
- While at it... refactored how the thread pool settings are set. Removed it from the plugin class, now each module is responsible for the settings of its own TPs. Also, if the thread pools are already configured in node settings we don't configure our default ones. This will enable users to configure the TPs in `elasticsearch.yml`
- Also updated `CronEvalTool` to work with `DateTime` construct (instead of java's `Date`)

Original commit: elastic/x-pack-elasticsearch@40d107c66e
2015-04-22 23:30:10 +02:00
Brian Murphy 3c7b42eb7b Support for Sanitized HTML in emails.
This change adds a shaded dependency on owasp (https://code.google.com/p/owasp-java-html-sanitizer/) to add support for HTML Sanitization.
Only images that reference an attachment are supported. This Sanitization may be customized for each email profile.
Other dangerous behavior is suppressed.

See elastic/elasticsearch#163
Fixes elastic/elasticsearch#163

Original commit: elastic/x-pack-elasticsearch@bc237d1beb
2015-04-22 16:57:03 -04:00
Martijn van Groningen 771b8824a5 Merge pull request elastic/elasticsearch#240 from martijnvg/improve_index_templates
Improve index templates

Original commit: elastic/x-pack-elasticsearch@8483e8872f
2015-04-22 16:05:51 +02:00
Martijn van Groningen f2fe639a3a Improve index templates:
* Disable the `_all` field, because it isn't used.
* Tune the history index for write throughput.

Original commit: elastic/x-pack-elasticsearch@db946a42b7
2015-04-22 15:51:55 +02: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
uboness 54fddac93f Add array access support for mustache templates
The default mustache template that is supported by elasticsearch doesn't support array/list access. This poses a real limitation for watcher as with `search` input, the hits are returned as an array/list. To bypass this limitation, an extra (tedious) step is required in order to transform the hits to a data structure that is supported by mustache.

This commit adds a new mustache script engine - `xmustache` to elasticsearch that supports array/list access in the form of `array.X` where `X` is the index into the array/list. This enables accessing the search results without using a transform. The following example will fetch the `"key"` field of the 3rd hit in the search result: `ctx.payload.hits.hits.3._source.key`.

This array/list support will be added to elasticsearch, but it'll only be available in later versions. For now, the default template in watcher will therefore be `xmustache`.

Added docs for templates

Fixes elastic/elasticsearch#230

Original commit: elastic/x-pack-elasticsearch@b09cad7f8b
2015-04-21 23:08:19 +02:00
uboness 02ba76fe21 Added the watch metadata to the template/script model
The watch metadata is now accessible to the templates and scripts (under `ctx.metadata`).

Also, changed the default email attachment to include the ctx model as a whole (not just the payload). This provides more context to the watch exectuion (e.g. watch id, execution time, metadata, etc...)

Original commit: elastic/x-pack-elasticsearch@c5dde855d2
2015-04-21 21:01:42 +02:00
Brian Murphy ca38fd6a89 [TEST] Add CountDownLatches to ensure order of operation.
This change adds countdownlatches to the `FairKeyedLock` tests on `WatchLockService`.

Original commit: elastic/x-pack-elasticsearch@2bf36e10d2
2015-04-21 14:54:11 -04:00
Brian Murphy 6c54251e61 Make lock service use fair locks.
The `WatchLockService` was not using fair locks. This could result in out of order execution of queue executions of the same watch.
Fork KeydLock tests from core and make global lock fair.

Fixes elastic/elasticsearch#225

Original commit: elastic/x-pack-elasticsearch@77382e09ca
2015-04-21 13:22:38 -04:00
Martijn van Groningen 49bbb0c801 Test: change `maxNumDataNodes` from 6 (which is the default) to 3
Original commit: elastic/x-pack-elasticsearch@1e13c7964b
2015-04-21 16:27:02 +02:00
Martijn van Groningen 901d2c0984 Test: if in starting state, wait until started state has been reached
Original commit: elastic/x-pack-elasticsearch@12e8b9da69
2015-04-21 16:24:00 +02:00
uboness 175423b984 Show a proper error when email password is not specified
Fixes elastic/elasticsearch#232

Original commit: elastic/x-pack-elasticsearch@2c0ab575d0
2015-04-20 21:36:16 +02:00
uboness f54c610c29 Cleanup and Refactoring of the conditions
* Split the action into two constructs: `Condition` and `ExecutableCondition`. The former holds all the condition configuration, the latter can execute the condition based on that configuration (an executable condition holds a condition)
 - This the code clearer to understand and maintain.
 - This also enabled to pull some common implementation code into the `ExecutableCondition` and by that reduce the implementation details of each executable to the minimum required.

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

* With the introduction of `Condition`, we no longer need the `SourceBuilder` for conditions. Instead, we have `Condiiton.Builder` that help you build condition. This is much more intuitive from the client perspective.

* Renamed `always_true` condition type to `always`
* Renamed `always_false` condition type to `never`

* Updated docs (also added docs for the `never` condition)

Original commit: elastic/x-pack-elasticsearch@0f8eb494ca
2015-04-17 15:07:23 -07:00
Brian Murphy cce3291b59 Register the `ScriptTransform.Parser` and `ChainTransform.Parser`.
We weren't properly registering the chain or script transforms so that they were accessable from the Watch.parse and PUT Watch APIs.

Original commit: elastic/x-pack-elasticsearch@2a236d62f3
2015-04-17 12:42:34 -04:00
Brian Murphy 90fa55d1eb Change default throttle period to 5s.
This change makes the default throttle period 5s.
This default can be controlled from config with the parameter `watcher.throttle.period.default_period`.
Added test and updated docs.

Original commit: elastic/x-pack-elasticsearch@cf8f5de724
2015-04-17 09:54:37 -04: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 44a3f600ab Update after review.
Change log level of message at shutdown.

Original commit: elastic/x-pack-elasticsearch@c6d80aaec9
2015-04-16 15:29:10 -04:00
Brian Murphy c6b5507436 Changes after review.
Add tests for stopped history store.

Original commit: elastic/x-pack-elasticsearch@e496891ed5
2015-04-16 15:29:10 -04:00