Commit Graph

592 Commits

Author SHA1 Message Date
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 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
Brian Murphy 3e7b668406 Add started boolean and locks to `HistoryStore`
There were a few corner cases where a `HistoryStore.put` operation was underway while we were shutting down since we were not holding any lock during this time.
This change adds a ReadWriteLock and uses the ReadLock for updates and put operations and the WriteLock for shutdown.
Also add a lock around the manual execution of a watch since it could change the status.

Fixes elastic/elasticsearch#204

Original commit: elastic/x-pack-elasticsearch@60ef78eff5
2015-04-16 15:29:10 -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 6e0cabac62 [LOGGING] Log an error message when we fail to parse a `Watch` or `WatchRecord`
If we failed to parse a `Watch` or `WatchRecord` at startup we currently get stuck as this behaviour is undefined.
This commit just adds some logging so we can tell that this is what happened.

Original commit: elastic/x-pack-elasticsearch@aa6d95c172
2015-04-16 14:38:33 -04:00
Martijn van Groningen 6309d2b5d3 changed the order in which the interval services are stopped when watcher stops.
Original commit: elastic/x-pack-elasticsearch@8092a76aa4
2015-04-15 09:05:06 +02:00
uboness 13573d6c6d Cleanup and Refactoring of the actions
* Split the action into two constructs: `Action` and `ExecutableAction`. The former holds all the action configuration, the latter can execute the action based on that configuration (an executable action holds an action)
 - This the code clearer to understand and maintain.
 - This also enabled to pull some common implementation code into the `ExecutableAction` and by that reduce the implementation details of each executable to the minimum required.

* Also, extracted teh `Action.Parser` to its own top level class, and renamed it to - `ActionFactory`. The main thing that the parser does is: 1) delegate to the parsing to the `Action` class, 2) construct & wire up the `ExecutableAction`.

* Cleaned up and aligned the log messages across all actions. Introduced
 - introduced parameterized exceptions (now the exception messages are constructed exactly like that log messages - using `{}` params)
 - Introduced the notion of `Wid` - Watch (execution) ID`. Now the `WatchExecutionContext` and the `WatchRecord` hold this construct as their ID (instead of an opaque string). The Wid has a well defined structure where it's prefixed with the watch id. This is very helpful to provide context to parsing the different constructs (actions in our case) as when parsing error occurs we can point directly to the place were we found the error (ie. watch id, record id and action id).

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

Original commit: elastic/x-pack-elasticsearch@df22da4e1f
2015-04-14 17:16:47 -07: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 9b1d8fd3e6 Fix NPE in EmailTemplate
EmailTemplate was passing replyTo to all calls to templatesToAddressList

Original commit: elastic/x-pack-elasticsearch@5ecc05e3f7
2015-04-13 12:30:57 -04:00
Brian Murphy 05dbbbdc48 Fix silent failure to parse valid script condition.
`
{
  "script" : "<script>"
}
`
Should be a valid script condition. This was silently failing to parse creating invalid watches in the system that could not be executed or interacted with except via DELETE.
Added a test for this as well.

Fixes elastic/elasticsearch#191

Original commit: elastic/x-pack-elasticsearch@25ed27bf2e
2015-04-13 11:59:41 -04:00
uboness 76ac647610 Cleanup of templates
- Introduced `TemplateEngine` and its only implementation `MustacheTemplateEngine`
- Change `Template` to only hold the template config.. the rendering is now done by the engine
- Introduced `EmailTemplate` that can render itself to an `Email` (given an engine and model)
- Renamed `TemplatedHttpRequest` to `HttpRequestTemplate` and it has a `render` method that given a model and an engine it creates an `HttpRequest` construct.
 - also fixed a bug where when the http request is build, the configured scheme wasn't set.
- cleaned up `HttpRequest` - made it immutable and now we use a builder to build it.
 - also fixed a bug in `HttpRequest` where the xcontent didn't render the scheme
- Got rid of all old template implementations... also, parsing a template is now simply `Template.parse(...)` (no need for a special `TemplateParser`.
- While at it, change the action builder to only deal with actions and not know anything about the action id. The id is now passed to the watch builder directly when adding an action

Original commit: elastic/x-pack-elasticsearch@1a7acc5868
2015-04-12 21:50:41 +02:00
Brian Murphy 5a8287e3db [TEST] Change from IntervalSchedule to CronSchedule.
Original commit: elastic/x-pack-elasticsearch@039a64477a
2015-04-10 20:08:11 -04:00
Brian Murphy 053abfa8fb Force timewarp mode on ManualExecutionTests
Original commit: elastic/x-pack-elasticsearch@cc3d33a53b
2015-04-10 19:47:13 -04:00
Brian Murphy e94f62b298 Make sure watcher is started before running the test.
Original commit: elastic/x-pack-elasticsearch@c1d081fd10
2015-04-10 19:23:32 -04:00
Brian Murphy b70bdb2b89 Fix error message when email fails to send.
Closes elastic/elasticsearch#195

Original commit: elastic/x-pack-elasticsearch@7256a32505
2015-04-10 19:05:18 -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
Bill Hwang 8242e25cde Fixed minor spelling errors in exception messages
Original commit: elastic/x-pack-elasticsearch@7b9294e320
2015-04-10 11:58:33 -07:00
uboness 303616b415 [temp-fix] disabled timewarp mode for WatchCrudTests
something seems to be broken... either in the integration test infra or somewhere else.. .investigation required

Original commit: elastic/x-pack-elasticsearch@c27bc41ef4
2015-04-10 15:17:24 +02:00
uboness 92c8565af1 Fixed NPE when GETing a watch that doesn't exist
- Added watch CRUD tests + cleanup
- Changed and aligned terminology across the board. No more "watch name".. from now on we'll refer to it as "watch id" (aligned with the public APIs). Also the templates now refer to `"{{ctx.watch_id}}"` (instead of `"{{ctx.watch_name}}"`)
- cleaned up the Response constructs (removed dependency on index/delete/get responses)

Fixes elastic/elasticsearch#202

Original commit: elastic/x-pack-elasticsearch@3296a69128
2015-04-10 10:54:19 +02:00
uboness cfc8b81cea [tool] Added a `croneval` command line tool
Super useful when dealing with the `cron` schedule. It enables to:

1. validate a cron expression. If the cron expression is incorrect it will try to output a descriptive/guiding error message
2. show future times in which the cron expression will be triggered (based on the current time)

When deployed, once can access this tool from ES_HOME by `bin/watcher/croneval`

Also updated the docs

Original commit: elastic/x-pack-elasticsearch@2666c32a69
2015-04-09 10:00:27 +02:00
Brian Murphy b2586bc7c1 ShieldException -> WatcherException
ParseException should extend WatcherException not ShieldException.

Original commit: elastic/x-pack-elasticsearch@340f5b6125
2015-04-08 17:59:53 -04:00
Martijn van Groningen 7981075f05 small cleanup
Original commit: elastic/x-pack-elasticsearch@90c60d2cbe
2015-04-08 08:45:36 +02:00
Brian Murphy 2127373bb2 Fix LicenseIntegrationTest rebase fail
Original commit: elastic/x-pack-elasticsearch@e4e1d56cd8
2015-04-07 20:07:21 -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
uboness 4b4c08af16 Fixed NoMasterNodeTests with disabled license failure
Original commit: elastic/x-pack-elasticsearch@ffd4fbea2c
2015-04-08 01:37:21 +02:00
uboness 4fcbbea14f Added license integration
- When the license is disabled, all actions of all watches are throttled, and all watcher APIs are blocked.
- before license expiry we're logging warning messages to the standard log file.
- Added a check on startup verifying the installed license plugin confirms to the min compatibility requirement of watcher
- Added a check on startup verifying the installed shield plugin (if one is installed) confirms to the min compatibility requirement of watcher
- Fixed a bug in simple input deserialization where it expected a `payload` field that should be there.
- Fixed a bug in `WatcherServiceResponse` where the acknowledged state wasn't de/serialized

Closes elastic/elasticsearch#30

Original commit: elastic/x-pack-elasticsearch@35dcaf4feb
2015-04-08 00:17:16 +02:00
Martijn van Groningen 0f43a5933f Test: fix timing issues in testConditionSearchWithSource() and testConditionSearchWithIndexedTemplate() tests.
Original commit: elastic/x-pack-elasticsearch@79e5859dcf
2015-04-07 20:04:28 +02:00
uboness 8d71337be5 Added a "logging" action
Mainly useful for testing & debugging, but might be even useful as an actual action in production.

(for now, we won't document it)

Original commit: elastic/x-pack-elasticsearch@726049cece
2015-04-07 03:29:14 +02:00
uboness f9004eed31 changed the actions format and added the notion of an action id
- actions are not identified by a unique id. The actions in a "watch" definition are now keyed (instead of an array)
- the `ActionWrapper` is now a construct that holds: and action, the id of the action and optionally a transform
- the `webhook` action is now structured based on the templated http request it holds (no need for extra `request` element there`
- the `webhook` reponse holds the http response (not the `status` and `body` directly)
- the action builders now accept an `id` when created
- introduced `WatchSourceBuilders` for quickly access various source builders
- introduced `Template.SourceBuilder` to help building a template
- changed templated http request builder to accept template source builders (instead of templates directly)
- changed `HttpResponse` to accept the body as a `ByteReference` in the ctor (this construct used to be in an inconsistent state holding an input stream that could have already been read)

Original commit: elastic/x-pack-elasticsearch@296350b6a8
2015-04-07 00:18:02 +02:00
uboness 46e27cf517 Small fixes
- Introduced `SearchRequestParseException`
- fixed typo

Original commit: elastic/x-pack-elasticsearch@618208036e
2015-04-06 19:18:14 +02:00
uboness be5fefc6dd Enhanced search request de/serialization
- now enables defining `types` (for document types)
- enables defining `types` and `indices` as comma-delimited strings (not just string arrays)
- aligned the parsing in `WatcherUtils` with the way we're parsing xcontent across the board (e.g. using `ParseField`)
- Added additional unit test to test deserialization

Original commit: elastic/x-pack-elasticsearch@5491b85f75
2015-04-06 14:57:11 +02:00
uboness a1cda57863 Enable the script transform return any value
This commit enables the script transform return any value. If the value is of type `Map` we'll just use it as the payload itself. Otherwise (any other value type) we'll take that value and put it in a map under the `"_value"` key, and that map will be the new payload.

This will simplify writing scripts (as it doesn't require the script to build a map)

Original commit: elastic/x-pack-elasticsearch@73fab7dc2b
2015-04-06 14:53:26 +02:00
Martijn van Groningen e9d2a38d3a Test: Now that automatic refresh interval has been increased to 5m we need to invoke api refreshes from tests.
Original commit: elastic/x-pack-elasticsearch@71a12c3365
2015-04-03 10:41:26 +02:00
Martijn van Groningen d522156e40 Now that automatic refresh interval has been increased to 5m we need to invoke api refreshes from tests.
Original commit: elastic/x-pack-elasticsearch@5106e6e21b
2015-04-03 10:26:38 +02:00
Martijn van Groningen 500b86577e Changed refresh interval for .watch .watch_history* indices from 1 second to 5 minutes.
Closes elastic/elasticsearch#151

Original commit: elastic/x-pack-elasticsearch@5147d635c2
2015-04-03 09:52:04 +02:00
Brian Murphy f12ead6a4c Change SearchTypes to be `QUERY_THEN_FETCH`
This closes elastic/elasticsearch#165

Original commit: elastic/x-pack-elasticsearch@b7642cf33d
2015-04-02 19:15:09 -04:00
Brian Murphy b85c0ca1a7 Fix null pointer in writing email action.
This commit fixes two issues.
1. The actual emails that were being sent after getting the defaults applied were not being returned as part of EmailSent
2. There was a possible NPE when writing an `Email` if from or to was null.

Closes elastic/elasticsearch#147

Original commit: elastic/x-pack-elasticsearch@0468280090
2015-04-02 18:09:33 -04:00
Brian Murphy 27f6239fe9 Add HttpRequest support to webhook action.
Also add docs for HttpRequest support in webhook action

Closes elastic/elasticsearch#156

Original commit: elastic/x-pack-elasticsearch@3e1e3dbe95
2015-04-02 15:08:56 -04:00
Martijn van Groningen feb745763b Added a `scheme` option to the `http` input that supports the values http or https.
Closes elastic/elasticsearch#174

Original commit: elastic/x-pack-elasticsearch@9ad7665b66
2015-04-02 16:56:34 +02:00
Martijn van Groningen a778f1978d improved benchmark
Original commit: elastic/x-pack-elasticsearch@70b2a8a042
2015-04-02 14:43:15 +02:00
Martijn van Groningen 17bc9442e1 test: run without shield integration
Original commit: elastic/x-pack-elasticsearch@dea9889523
2015-04-01 23:37:11 +02:00
Brian Murphy 5e57389c11 Add webhook and index actions tests.
This commit adds tests for the webhook and index actions.
Also adds docs for the webhook and index actions and fixes url escaping of webhook action urls.

Original commit: elastic/x-pack-elasticsearch@b70435b198
2015-04-01 16:18:37 -04:00
Martijn van Groningen 9bb38fa4e1 Test: make sure index `test` exists
Original commit: elastic/x-pack-elasticsearch@4c4b7af85d
2015-04-01 21:37:08 +02:00
Martijn van Groningen 46f75d8fa1 Test: add AWI#enableShield() to decide if shield should run and let AWI#shieldEnabled() return whether shield is running in the test cluster
Original commit: elastic/x-pack-elasticsearch@698900d002
2015-04-01 20:47:39 +02:00
Martijn van Groningen 54380478e5 Test: also run shield with http input integration test
Original commit: elastic/x-pack-elasticsearch@6c2dbc75e1
2015-04-01 19:25:23 +02:00
Martijn van Groningen 3a37ebca41 Test: make sure a refresh has ran.
Original commit: elastic/x-pack-elasticsearch@db9a8c417c
2015-04-01 17:45:36 +02:00
Martijn van Groningen efb6ae8e1f Added `extract` option to filter keys out of the `search` and `http` input.
Via the `extract` option an array of keys can be defined that will be extracted from the input response in a streaming manner and used as payload instead of the entire input response.

http example:

```json
{
  "input" : {
    "http" : {
      "request" : {
         "host" : "host.domain",
         "port" : 9200,
         "path" : "/idx/_search"
      },
      "extract" : ["hits.hits.total", "aggregations.my_agg"]
    }
  }
  ...
}
```

search example:

```json
{
  "input" : {
    "search" : {
      "request" : {
         "indices" : [ "idx" ],
          "body" : {
             "query" : { "match_all" : {} }
          }
       },
       "extract" : ["hits.hits.total", "aggregations.my_agg"]
    }
  }
  ...
}
```

Closes elastic/elasticsearch#167

Original commit: elastic/x-pack-elasticsearch@437c35698b
2015-04-01 13:12:12 +02: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
Martijn van Groningen baf0901b3a test: adjusted find available port loop
Original commit: elastic/x-pack-elasticsearch@ae44c570c0
2015-03-30 20:50:14 +02:00
Brian Murphy 06efbf1481 Actually the test and don't call start twice on the same server.
Original commit: elastic/x-pack-elasticsearch@3b994ef9e7
2015-03-30 14:40:05 -04:00
Brian Murphy 72d2f5174e Fix HttpClientTest
If port 9200 isn't available inc the port and try again until we reach 9300.

Original commit: elastic/x-pack-elasticsearch@90ca05544f
2015-03-30 14:22:26 -04:00
Martijn van Groningen e00bb69982 Added http input.
The http input allows to let any http interface be the input for a watch.
The http input can be configured with the following options:
* `method` - Optional http method. (default to GET)
* `host` - The host of the http service.
* `port` - The port of the http service.
* `path` - The url path.
* `params` - Optional url query string options.
* `header` - Optional http header.
* `auth` - Optional authentication http heads.
* `body` - Optional body

The response of the http request is expected to be valid json.

Closes elastic/elasticsearch#157

Original commit: elastic/x-pack-elasticsearch@0b1f122615
2015-03-30 18:32:06 +02:00
uboness a632d57803 Introducing the `Trigger` notion
Today every `watch` is associated with a `schedule`. When the watch is added to the system, its schedule is registered with the `scheduler` that is responsible to trigger the watch based on the schedule. This is effectively time based triggering of a `watch`.

Thinking about it further, triggering a watch is a higher abstraction than the schedule. Many things can potentially trigger a watch - a schedule (or time based triggering) is just one example of such trigger.

A `Trigger` was added to provide this abstraction. A `watch` is associated with a `trigger` not with a `schedule` directly. One type of `trigger` that can be set on a watch is a `schedule`.

This abstraction will enable us much flexibility in the future as we'll be able to add other types of triggers that are not necessarily based on time. 3 examples:

- we're planning to have a API that executes triggers on demand (rather than waiting for them to be triggered "naturally"). We could have a `"passive"` trigger with the intention to have a watch that can only be executed on demand. Today (with schedule only) you can achieve this by setting a `cron` schedule that is set to trigger very far in the future - but it's a hack.

- In the future we plan to have changes API in elasticsearch. An interesting trigger that we might want to add is `"changes"` - an ESP (event-stream processing) trigger that listens to all (data) events in the changes API, processes them and using some sort of state machine decides to trigger a watch based on some condition.

- With Shield we have audit trails. currently the only audit trail that is supported is log based (access logs). Another audit trail we'll add soon will be index based (indexing the audit info to elasticsearch). In the future, we might want to have `watcher` extend shield and add a `"watcher"` audit trail. this will effectively be a `"audit"` trigger that will trigger watches based on events arriving in the audit trail (think about notifying at real-time about a potential DDoS attack)

To support this change, we needed to change existing and introduce new constructs:

- A `Trigger` defines the logic of when a watch should be triggered
- A `TriggerEngine` is responsible for executing the logic defined by the `Trigger`
- A `TriggerEvent` is created whenever the engine triggers the trigger. The event holds relevant information (may be different for every trigger depending on its type and nature).
- A `TriggerService` manages trigger engines.

We currently have a single engine implementation - a `"scheduler"` trigger

- `ScheduleTrigger` defines a clock/calendar based schedule on which a watch should be triggered
- `QuartzScheduleEngine` a trigger engine that runs quartz scheduler which triggers the registered schedules.
- `ScheduleTriggerEvent` holds the `triggered_time` (the time the trigger was actually triggered) and the `scheduled_time` (the time the trigger was scheduled to trigger)

- Updated the docs

Closes elastic/elasticsearch#158

Original commit: elastic/x-pack-elasticsearch@5be20917cc
2015-03-30 14:44:35 +02:00
uboness c1fe5378aa An attempt to fix in correct mime-type handling of JavaMail
Apparently sometimes Java doesn't pick up the correct mailcap file and therefore doesn't handle mime types correctly. This commit
statically sets the mailcap.

Relates to elastic/elasticsearch#126

Original commit: elastic/x-pack-elasticsearch@a958e07267
2015-03-29 22:41:20 +02:00
uboness fca9b6a1e6 Integration with Shield
- Change action names to be aligned with Shield. All actions are categorized as `cluster management`.. the read actions (get & stats) are also also categorized as `cluster monitoring`.

- Added `ShieldIntegration` and `WatcherShieldModule` to handle all the integration points.

- We have a new internal shield user `__watcher_user` that will be the actor behind all the watcher interal action executions (managing the `.watches` and `.watch_history` indices

- This integration revealed a bug where the watcher plugin would not wire correctly with transport clients. This is now fixed with the introduction of a dedicated `TransportClientWatcherModule`

- Added docs

Closes elastic/elasticsearch#43

Original commit: elastic/x-pack-elasticsearch@26e9b0da06
2015-03-27 20:19:19 +01:00
Martijn van Groningen 6277a32b91 Set minimum binary compatibility to ES 1.5
Closes elastic/elasticsearch#160

Original commit: elastic/x-pack-elasticsearch@10da3efb1a
2015-03-26 18:20:39 +01:00
Martijn van Groningen 9994326f11 Renamed AlertsBenchmark to WatcherBenchmark
Original commit: elastic/x-pack-elasticsearch@3c8000e7bf
2015-03-26 11:19:47 +01:00
uboness 41832b6f5b Change project name to elasticsearch-watcher
- `alerts` package is now `watcher` package
- we no longer use the term `Alert`, but instead we use `Watch`
- documentation still needs to be updated

Original commit: elastic/x-pack-elasticsearch@1225edf7e3
2015-03-24 13:46:01 +01:00
Martijn van Groningen a6bdbf0b0b Added simple benchmark to test fired alert throughput
Original commit: elastic/x-pack-elasticsearch@186b6305ff
2015-03-19 13:09:05 -07:00
Brian Murphy 100b5b922c Fix SearchInput tests.
SearchInput tests were failing locally for me in DEBUG because they weren't setting a valid alert on the ExecutionContext which was causing
the debug log messages in the SearchInput.execute method to NPE. I've added a dummy Alert to the context to fix things.
`

Original commit: elastic/x-pack-elasticsearch@2d744fdb7b
2015-03-19 15:56:19 -04:00
Martijn van Groningen 5dfe02ec64 Core: Make sure that the queue size is set on the alert thread pools
Also removed hack leftover.

Original commit: elastic/x-pack-elasticsearch@44fd070f5d
2015-03-18 16:40:22 -07:00
Martijn van Groningen 2377d1525b Tests: added tests for AlertStore, AlertService and AlertLockService
Changed ClientProxy to be return responses instead of ActionFutures and removed builders. This helps with mocking.

Original commit: elastic/x-pack-elasticsearch@bfc36d9405
2015-03-18 10:08:28 -07:00
Martijn van Groningen e6445a9d2e Iternal: Removed Payload.ActionResponse in favour of an extra constructor to Payload.XContent
Tests: Write more tests for AlertUtils

Closes elastic/elasticsearch#132

Original commit: elastic/x-pack-elasticsearch@b0e675b89c
2015-03-06 10:36:54 +01:00
uboness 50f4a1c0e3 Introducing TimeWarp mode for tests
The idea behind a time warp mode is that while it's enabled the time related constructs in the alerts module are replaced with a mock test friendly version.. so we'll be able to control time and therefore avoid sleeping the threads.

 In time warp mode:

-  The `SchedulerMock` is used to manually fire jobs
-  The `ClockMock` is used to set and fast forward time
-  The alerts are executed on the same thread as the scheduler mock... so we don't have to deal with async nature at all. This is accomplished by the added `AlertsExecutor` abstraction.

By default, the time warp mode is enabled and tests run in it. If a test must not use the time warp mode, it is possible to add `@TimeWarped(false)` annotation to the test and it will then run with the standard scheduler & clock. It is also possible to disable this mode all together by running the tests with `-Dtests.timewarp=false`.

All the updated tests now work in both modes (whether the time warp mode is dis/enabled). This is important as on the server we would like to run the tests outside of this mode as well, but locally we'd like to run them with time warped enabled (so they'll be faster)

Also, cleaned up the tests.. we now only do `assertThat(...)` calls (no `assertTrue` or `assertEquals`... for consistency sake)

Original commit: elastic/x-pack-elasticsearch@11e09f6dea
2015-03-06 08:33:21 +01:00
Martijn van Groningen ffdf23b411 Tests: Added tests for HistoryStore
Closes elastic/elasticsearch#129

Original commit: elastic/x-pack-elasticsearch@16043bcec2
2015-03-05 20:49:22 +01:00
uboness 6eb27e2519 Introduced Clock as an abstraction over the system clock
Use in:

- Determining the execution time of an alert
- The period throttler to determine the time passed since last execution

Original commit: elastic/x-pack-elasticsearch@9197b86b68
2015-03-04 23:26:56 +01:00
Martijn van Groningen f28dee2e44 Tests: Made sure that resources are properly cleaned up after test classes extending from AbstractAlertsSingleNodeTests have been completed
Original commit: elastic/x-pack-elasticsearch@4621b76fe1
2015-03-04 12:11:21 +01:00
uboness 5903ea7493 Fixed NPE when email action has no subject or text body
Fixes elastic/elasticsearch#137

Original commit: elastic/x-pack-elasticsearch@7f575657f3
2015-03-04 11:03:13 +01:00
uboness f5c48576bc Cleaned up the use of execution context mocking in the tests
Added helper methods in `AlertsTestUtils` to mock `ExecutionContext` and create a simple payload

Original commit: elastic/x-pack-elasticsearch@eac6b63e62
2015-03-04 10:37:38 +01:00
uboness 4874fa2f1b change the SES email port to 587
Original commit: elastic/x-pack-elasticsearch@d69d02236b
2015-03-04 10:03:07 +01:00
uboness 01145b8025 Aligned Transform.Result with all other result constructs
- the transform parser and registry can now parse transform results
- every transform result may have its own format
- the chain transform result outputs the "transformation trail" of all the chained transforms (great tool for debugging)
- removed `Transform.NOOP` - was redundant, when no transform is defined the alert's transform is `null`
- removed `payload` from the `AlertExecution`. Instead, the execution holds the input result, transform result and potentially the transform results of the actions
- changed the xcontent representing a transofrm result to `{ "transform_type" : { "payload" : {...}, ... } }`
- with this change, the `Action` interface is cleaned up (`execute` only accepts the execution context)

Original commit: elastic/x-pack-elasticsearch@6ecf7f2c92
2015-03-04 09:52:31 +01:00
Martijn van Groningen 167f6814ab Fix tests
Original commit: elastic/x-pack-elasticsearch@ad7b4ae1ef
2015-03-04 09:42:57 +01:00
Martijn van Groningen 0382310cae Moved testAlertsWithDifferentSearchType and testWithAggregations to more unit like tests.
Original commit: elastic/x-pack-elasticsearch@115e361c42
2015-03-04 09:15:35 +01:00
uboness f6c17bd802 Added a transform construct to actions
An alert may have multiple actions associated with it, but each action may need to have different view of the data. For example, the email may need a certain model for its templates while the index or webhook actions may need a completely different data structure.

Until now, there's only an option to defina a single `transform` on the alert level that would have applied to all actions. This commit adds
 the ability to associate a transform with each action. We still keep the tranform on the alert level (in case all actions need the same transformation, in which case we'd like to avoid repetition).

Original commit: elastic/x-pack-elasticsearch@5493a2179b
2015-03-04 03:20:17 +01:00
uboness d25bf008b3 Added Amazon SES to ManualPublicSmtpServersTests
Original commit: elastic/x-pack-elasticsearch@d7f8180d1a
2015-03-03 23:41:56 +01:00
uboness dfc8249d4b added support for template params in search requests
Original commit: elastic/x-pack-elasticsearch@06e7dab935
2015-03-03 12:01:45 +02:00
uboness f9765fd393 standardized script/template model variables
Now `Variables.createCtxModel` is responsible for creating the model for scripts & templates across the board. Accessing the payload, alert name, fired time and scheduled fire time is done via the `ctx.` prefix.

Original commit: elastic/x-pack-elasticsearch@443ac17579
2015-03-03 10:27:47 +02:00
uboness 43f11cbb3d [fix] added the script params to the condition script execution
Now the script's params in the `script` condition are merged with the payload data into a single variable context to the script execution. The payload data is now accessed using the `payload.` prefix.

Original commit: elastic/x-pack-elasticsearch@e313a6301c
2015-03-02 22:01:02 +02:00
Martijn van Groningen 2aa91e84ed Now fix test for real
Original commit: elastic/x-pack-elasticsearch@57e5a401e7
2015-03-02 14:40:05 +01:00
Martijn van Groningen 14b1f6c3d2 Test: fixed test issue
Original commit: elastic/x-pack-elasticsearch@7fbce014d9
2015-03-02 14:31:37 +01:00
Martijn van Groningen 96d80597c4 Test: fixed test timing issue
Original commit: elastic/x-pack-elasticsearch@ccdac702f4
2015-03-02 14:17:37 +01:00
Martijn van Groningen 803fa4c4df Added tests for HistoryService#execute(...)
Original commit: elastic/x-pack-elasticsearch@b5c5fcf7f3
2015-03-02 11:18:18 +01:00
Martijn van Groningen a2b71a94b7 Increased logging to see why history index isn't deleted
Original commit: elastic/x-pack-elasticsearch@eb0f4e9e46
2015-03-02 10:56:15 +01:00
Martijn van Groningen 9e8405e619 applied feedback
Original commit: elastic/x-pack-elasticsearch@115429ae67
2015-02-27 11:00:10 +01:00
Martijn van Groningen 127aee514c Added unit test
Renamed AlertBootstrap to AlertsLifeCycleService

Original commit: elastic/x-pack-elasticsearch@5dedefe196
2015-02-27 10:14:53 +01:00
Martijn van Groningen bebfbf9664 Move the bootstrap logic out of AlertService which will make it easier to test.
Original commit: elastic/x-pack-elasticsearch@bf5c47dd5f
2015-02-27 10:14:52 +01:00
uboness aae6ff834f [client] reorganized tests and added alert source builder
The `AlertSourceBuilder` along with a set of source builder for all the different constructs that make an alert (condition, input, transform and action), provides a structured approach for building an alert from the client side (instead of forcing the clients to use xcontent directory)

- fixed some of the tests to already use these builders (I reckon there are still quite a few that need to be converted.. but we'll do that over time).
- moved all integration tests under `test/integration` package.
- changed the `AlertsTests` to **not** be an integration test... it randomizes the alert structure and makes sure that it can serialize & deserialize itself to/from xcontent.
- fixed small bugs found by the tests

Original commit: elastic/x-pack-elasticsearch@94b76b6fc7
2015-02-27 08:01:10 +02:00
Martijn van Groningen b76b0e7129 Test: change assertion to make sense
Original commit: elastic/x-pack-elasticsearch@8f01dcff03
2015-02-26 19:26:07 +01:00
Martijn van Groningen 4363acb09b Internal: Only clear the alert execution threadpool's queue when alerts plugin stops.
Before we shutdown the alert execution threadpool, which caused us to use a hacky workaround to get the thread pool started again when alerts is going to run again.
Clearing the threadpool's queue is sufficient for stopping fired alerts from being ran. Only fired alerts already being executed by TP will won't be stopped.

Also removed the volatile previousFiredAlerts field, because execution the fired alert doesn't need the AlertService anymore the purpose of this field doesn't exist any more.

Original commit: elastic/x-pack-elasticsearch@6a622b5579
2015-02-26 14:30:37 +01:00
Martijn van Groningen 469acfa551 Test: Fix SearchTransformTests suite error
Original commit: elastic/x-pack-elasticsearch@03568dce09
2015-02-26 12:43:25 +01:00
uboness 0f7dc295b3 [script] utilize Script in ScriptTemplate & ScriptCondition
- also changed the `AbstractAlertsSingleNodeTests` to not reset after each test

Original commit: elastic/x-pack-elasticsearch@14377498e8
2015-02-26 13:35:51 +02:00
Martijn van Groningen de681481d1 Tests: wait for alerting to be stopped and added a TODO about using a start/stop lock
Original commit: elastic/x-pack-elasticsearch@7404bb56b0
2015-02-26 11:56:27 +01:00
Martijn van Groningen 42716a5adb Test: pass down parameters
Original commit: elastic/x-pack-elasticsearch@2210246872
2015-02-26 11:05:52 +01:00
Martijn van Groningen 4934267789 test: increase timeout
Original commit: elastic/x-pack-elasticsearch@abf2297f87
2015-02-26 08:36:49 +01:00
Martijn van Groningen c016516d7e test: evaluate if this prevents the data loss that causes no alerts being loaded.
Original commit: elastic/x-pack-elasticsearch@611f3df816
2015-02-25 23:31:11 +01:00
Martijn van Groningen 1aad9fd390 typo
Original commit: elastic/x-pack-elasticsearch@3ae5403f39
2015-02-25 22:33:44 +01:00
Martijn van Groningen 57d4fd0d50 test: increased logging
Original commit: elastic/x-pack-elasticsearch@b1cfced485
2015-02-25 22:27:05 +01:00
Martijn van Groningen ab43bde67f adjust log level
Original commit: elastic/x-pack-elasticsearch@ddbe44ed25
2015-02-25 22:27:05 +01:00
uboness df491d036f [transform] added a new chain transform
Enables chaining multiple transforms

Original commit: elastic/x-pack-elasticsearch@312b7330df
2015-02-25 17:33:23 +02:00
uboness 46f6572756 [transform] added a new script transform
Enables manipulating existing payload and building a new payload based on a script

Original commit: elastic/x-pack-elasticsearch@912dafe709
2015-02-25 17:22:24 +02:00
uboness 7ab8271692 [test] introduced AlertsSingleNodeTests
- changed SearchTransformTests to extend it

Original commit: elastic/x-pack-elasticsearch@19d1d32d1a
2015-02-25 15:36:35 +02:00
uboness 3aa988472c [transform] fixed and added unit tests for SearchTransform
- Also, the search template/script are not populated not just by the fired/scheduled time, but also by the payload

Original commit: elastic/x-pack-elasticsearch@7ca8331a1c
2015-02-25 14:52:19 +02:00
Brian Murphy 46cefe261a Now input is separate from condition and condition just contains the decision logic.
```
    "input": {
        "search": {
            "request": {
                "body": {
                    "query": {
                        "match_all": {}
                    }
                }
            }
        }
    },
    "condition": {
        "script": {
            "script": "return true"
        }
    },
```
The result of this in the `alert_execution` looks like :
```
        "input_result": {
            "search": {
                "payload": {
                    "hits": {
                        "total": 1,
                        "hits": [
                            {
                                "_type": "my-type",
                                "_source": {
                                    "field": "value"
                                },
                                "_id": "AUujS61M4FTW2U3Ztz5U",
                                "_index": "my-index",
                                "_score": 0.30685282
                            }
                        ],
                        "max_score": 0.30685282
                    },
                    "_shards": {
                        "total": 5,
                        "failed": 0,
                        "successful": 5
                    },
                    "timed_out": false,
                    "took": 1823
                },
                "request": {
                    "body": {
                        "query": {
                            "match_all": {}
                        }
                   }
                }
            }
      }
      "condition_result": {
        "script": {
            "met": true
        }
      }
```
There are two Inputs currently the `SearchInput` as shown above and a `SimpleInput` that just contains a payload that will be returned in the result.
There are three conditions, the `ScriptCondition` as shown above and an `AlwaysTrueCondition` and AlwaysFalseCondition` condition.

Original commit: elastic/x-pack-elasticsearch@0d8ac24c5a
2015-02-24 12:05:30 -05:00
uboness fa02c150b4 [throttler] added unit tests for all throttlers
Original commit: elastic/x-pack-elasticsearch@3014d2b723
2015-02-24 14:45:02 +02:00
uboness 6fdd6d49e2 [throttler] changed the Throttler interface
Removed the passed in `Condition.Result` from the `apply` method

Original commit: elastic/x-pack-elasticsearch@23101b028d
2015-02-24 14:45:02 +02:00
uboness b292051a13 [email] fixed bugs and added unit tests
Original commit: elastic/x-pack-elasticsearch@3b5406d4c8
2015-02-24 12:27:13 +02:00
Martijn van Groningen d916f99800 The lock used during executing a fired alert should also encapsulate the updating of the fired alert.
During stopping alerts we wait until all ongoing operations are completed, such as adding, deleting alerts and executing fired alerts.
For fired alerts we should also let the update of fired alert happen under a lock. We could miss an ongoing operation if we would shutdown.

This can be a reason why BasicAlertingTest.testDeleteAlert failed: https://build.elasticsearch.com/job/es_alerting/187/testReport/junit/org.elasticsearch.alerts/BasicAlertingTest/testDeleteAlert/

Original commit: elastic/x-pack-elasticsearch@732b213cf2
2015-02-23 23:24:28 +01:00
Martijn van Groningen a3825aa242 Cleanup: removed unused method.
Original commit: elastic/x-pack-elasticsearch@5dd9126d71
2015-02-23 15:29:36 +01:00
uboness 6a5c86e46c Added a SchedulerMock to be used for unit tests
Original commit: elastic/x-pack-elasticsearch@d4dfb37431
2015-02-23 15:44:15 +02:00
uboness 89b7d085e1 [scheduler] cleaned up and extended scheduler support
- Added additional user friendly schedules
 - `hourly` - a simple to configure schedule that will fire every hour on one or more specific minutes in the hour
 - `daily` - a simple to configure schedule that will fire every day on one or more specific times in the day
 - `weekly` - a simple to configure schedule that will fire every week on one or more specific days + times in the week
 - `monthly` - a simple to configure schedule that will fire every month on one or more specific days + times in the month
 - `yearly` - a simple to configure schedule that will fire every year on one or more specific months + days + times in the year
 - `interval` - a simple interval based schedule that will fire every fixed configurable interval (supported units are: seconds, minutes, hours, days and weeks)

- Added unit tests to all the schedules and the schedule registry
- Introduced `Scheduler` as an interface and `InternalScheduler` for the quartz implementation. This will help unit testing other dependent services
- `Scheduler` is now independent of `Alert`. It works with `Job` constructs (`Alert` now implements a `Job`).
- Introduced `SchedulerMock` as a simple `Scheduler` implementation that can be used for unit tests - enables manual triggering of jobs.

- introduced `@Slow` test annotation support in the `pom.xml`

Original commit: elastic/x-pack-elasticsearch@94a8f5ddea
2015-02-23 15:44:14 +02:00
Martijn van Groningen 59f0883721 Cleanup: Removed config service infrastructure
Original commit: elastic/x-pack-elasticsearch@3f99c357c8
2015-02-23 14:36:17 +01:00
uboness 2136210711 [template] formalized the template definition
- Introduced `Template` & `Template.Parser` interfaces
- There main template implementation is the `ScriptTemplate` and its parser is bound to `Template.Parser`
- There are also xContent templates - YAML & JSON that just render the model as xContent. (used as a fallback in webhook action)
- updated all actions to use the new template infrastructure

Also

- introduced mockito for unit testing
- removed `WebhookTest` as it was effectively testing the template functionality... we'll add a proper test for teh webhook action in a later commit

Original commit: elastic/x-pack-elasticsearch@34a90e8c2f
2015-02-23 12:30:31 +01:00
Martijn van Groningen c0c5b3cf6b Test: just create json based alerts
Original commit: elastic/x-pack-elasticsearch@6aa88ac5a1
2015-02-18 20:50:44 +01:00
Martijn van Groningen b4a465496a Test: increased logging
Original commit: elastic/x-pack-elasticsearch@8f95a60683
2015-02-18 20:11:51 +01:00
Martijn van Groningen 69bbea6985 Changed the initialization retry logic of the AlertService to be event based instead of blocking (actively polling for a new cluster state).
This avoids that a single thread will be busy during the time that not all primary shards of the alerts and alert history indices are started.

Also the execution of alert history items that were loaded during initialization will be executed once the AlertService goes into started state, before this was executed once the AlertActionService has started, which could load to failures, because there was a small window of time where the alert manager wasn't started. Executing alert history items with the state search_needed requires the alert manager to be started and that isn't yet the case when the AlertActionService has started.

Closes elastic/elasticsearch#75
Closes elastic/elasticsearch#76

Original commit: elastic/x-pack-elasticsearch@a799bc34e3
2015-02-17 19:35:18 +01:00
uboness 54923420d9 [cleanup] - added forbidden apis mvn plugin
- fixed the use of the found forbidden APIs
- changed `FiredAlert.State` values to lower case (for consistency sake)

Original commit: elastic/x-pack-elasticsearch@9b3f8383d9
2015-02-17 16:31:18 +01:00
uboness 37d9fd062e Replacing "trigger" with "condition"
- renamed "trigger" notion to "condition"

- the main parts that make an alert are:
 - **schedule** - determines when/how often should the alert be checked
 - **condition** - determines whether the alert should execute
 - **actions** - define what the alert should do

- the lifecycle terminology of a fired alert changed as well, to the following
 - **fired** - the schedule fired an event indicating the alert should be **checked**
 - **checked** - the condition associated with the alert was checked - either it was met (indicating the the alert should be executed) or it wasn't (indicating the alert should not be executed)
 - **throttled** - although the condition was met, the system decided **not** to execute the alert after all based on the throttling logic
 - **executed** - the condition of the alert was met, and the system decided it should not throttle it, thefore the actions of the alert were executed.

- `FiredAlert.State` changed to reflect the new lifecycle (as described above)

Original commit: elastic/x-pack-elasticsearch@d67d13d982
2015-02-17 14:51:38 +01:00
uboness 61761286e0 Refactoring
- moved alert execution logic to the history service (the history service now listener to schedule events)
- introduced `AlertLockService` - used by both alerts service and history service to lock alerts across services
- the history service is now responsible for executing the previous "not yet executed" fired alerts.
- renamed `AlertContext` to `ExecutionContext`
- renamed `AlertRun` to `AlertExecution`
- improved actions result parsing logic (`success` field is mandatory)
- renamed the alert history type to `fired_alert` (used to be `alerthistory`)
- renamed fired alert `error_msg` to just `message`.

Original commit: elastic/x-pack-elasticsearch@09f26ce3cf
2015-02-17 12:14:00 +01:00
Brian Murphy 8b83d74994 Fix DateTime issues
We were using DateTime without a timezone to pick the history index to write the alert runs to.
This caused tests to fail because we use UTC internally (as we should)

Original commit: elastic/x-pack-elasticsearch@6d6f57fb9e
2015-02-13 17:07:46 -08:00
Brian Murphy ba15a197ea Make all tests pass
This change fixes the compilation errors in
`EmailTemplateTest` `WebhookTest` `AlertActionsTest` `AbstractAlertingTests` and `ActionHistoryIndexNameTest`.
Fix alert parsing.
Don't attempt to emit a null body template.
Add inject to parser construction.
Fix Alert serialization.
Fix json template to work with the NWO.
Fix ToXContent of Actions.
Add equals methods to Actions and Schedule to facilitate testing.
Changes after rebase to take new EmailAction into account.
Fix `AlertSerializationTest`
Many serialization fixes.
Fix alerthistory template
This change brings the alert history index template uptodate with the code.
Fix createAlertSource
This change brings createAlertSource uptodate with the NWO
Fix Webhook test
Change default template in webhook action to use the simple constructor.
Shutdown the thread pool in the `EmailActionTest`
Don't try to throttle if this alert has never run before.
Add serialization to AlertRun and fix serialization for FiredAlert
This change also makes all trigger and action results serializable and de-serializable.
Parsers now implement parseResult() and the registries for actions and triggers also have matching calls.
Add alert_run to alert history JSON.
Fix logging in index action.
Fix Ack serialization.
Change payload of index action ... IndexResponse isn't serializing properly.
Fix success of index action.
Fix TimeThrottler to use lastExecutedTime instead of lastRunTime.
Fix ThrottleTest
We don't need to assert busy here. The sleeps should be enough. If they aren't something is wrong.
Horrible hack to get around thread pool issues.
Fix Bootstrap test
Also always request version when loading alert history
Fix bootstrap test and set the correct cron into the future.

Original commit: elastic/x-pack-elasticsearch@d3a6c8c3aa
2015-02-13 15:15:36 -08:00
Martijn van Groningen 6392007c72 - Made the threadpools fixed and the size based on the number of processors in a node.
- Removed the the queue reading in the HistoryService.
- Let the HistoryService use the alerts threadpool directly for executing fired alerts, which will use the internal queueing of ThreadPool is all threads are busy.
- Moved the alert thread pool startup to the start of the history service.
- Enforce versioning check if fired alerts are updated.

Closes elastic/elasticsearch#101

Original commit: elastic/x-pack-elasticsearch@39b0de7112
2015-02-13 18:17:40 +01:00
uboness 70b5d36098 Enhanced email action
- Introducing the notion of email account (i.e. smtp account). It is now possible to configure multiple email accounts (in node settings) via which the emails will be sent. The email alert action can be configured with an account name, to indicate which account should be used, if no account is configured, the email will be sent with the _default account_. The default account can also be configured using the `default_account` node setting.
- `InternalEmailService` maintains the email sessions and responsible for sending emails.
- the account settings are dynamic (configurable at runtime)
- `Email` class was introduces to abstract away the email structure (`javax.mail`'s `Message` is not the most intuitive construct to deal with. `Email` enables setting both `text` and `html` content and also support normal and inlined attachments.
- "profiles" were added to support different email message formats. Unfortunately the different email systems don't fully comply to the standards and each has their own way of structuring the mime message (especially when it comes to attachments). The `Profile` enum abstracts this by letting the user define what email system structure it wants to support. we define 4 profiles - `GMAIL`, `MAC`, `OUTLOOK` and `STANDARD`. `STANDARD` is the official way of structuring the mime message according to the different RFC standard (it also serves as the default profile).
- The `EmailAction` only task is to create an `Email` based on the action settings and the payload, and send it via the `EmailService`.

Original commit: elastic/x-pack-elasticsearch@2b893c8127
2015-02-10 18:19:11 -08:00
uboness ec42ec8fdc introduced AlertContext
Represents the context of an alert run. It's passed as an argument to all the different constructs that execute during an alert run - trigger, throttler, transform and action. This will provide each execution phase access to to all the results of the previous phase. It also holds the current payload in the execution.

Action results representing failures now hold the `reason` for the failure. This will provide insight on failed action execution as these messages will end up in the fired alert history.

Original commit: elastic/x-pack-elasticsearch@6846a49247
2015-02-09 20:41:42 +01:00
uboness 157c7b6fd6 Introduced the `payload` and `transform` constructs
A payload represents a the payload the is originally created by the trigger and passed all the way down to the executing actions. The action may use this payload during their execution, for example, the email action may use this payload as the model behind the email templats.

A transform represents a transformation of a payload. In its core, it accepts a payload applies a transformation to it and outputs the outcome of the transformation as a payload. This simple design makes transforms chainable, meaning, a list of transformations can be applied in a well defined order to a payload.

The transform is applied on the payload initially generated by the trigger. The output of the transformation will be provided to the actions as a payload when they're executed.

Currently we only have two transform types - `noop` and `search`. The former is a transform construct that doesn't actually do any transformation, but instead outputs the same payload it's applied on. The latter (`search`) perform a search on elasticsearch and uses the output of the search (the search response) as the payload it outputs.

Original commit: elastic/x-pack-elasticsearch@6d40337635
2015-02-07 01:25:47 +01:00
uboness 241444437f Refactored `Alert` and `Alert.Status`
- all alerts are now ackable (there's no way to define an "unackable" alert)
 - `Alert.Status` now holds an `ack` that represents the ack status
 - `Alert.Status` now holds a `lastThrottle` that represents the state of the last throttle (will be `null` if not throttled yet)
 - changed the `Alert.Status.Ack.State` to hold more intuitive values - `awaits_execution`, `ackable` and `acked`
 - `Alert.Status` is now streamble
 - introduced additional info method on `Alert.Status` (e.g. `executed()`, `triggered()`, `ran()`)

Original commit: elastic/x-pack-elasticsearch@3eda1c211a
2015-02-06 18:33:11 +01:00
Brian Murphy 0470fdf6af Add EmailSettingsService to hold global email settings.
This change adds a service to hold the dynamically updateable email settings.
Added logging and made inner settings holding class static.

Original commit: elastic/x-pack-elasticsearch@e1690fa292
2015-02-06 11:08:28 -05:00
Brian Murphy da1f446b49 Add HttpClient to encapsulate HttpRequest from `WebhookAction`
Create a `HttpClient` in alerts.support to handle http requests.
`HttpClient` is an injectable AbstractComponent.

Original commit: elastic/x-pack-elasticsearch@8e70962ddf
2015-02-06 11:02:24 -05:00
Martijn van Groningen f261d8aeaf Componentized the history service and alert record parser.
Renamed AlertRecord to FiredAlert
Refactored the persistence part of FiredAlert out of HistoryService to HistoryStore.
Moved AlertActionState to FiredAlert.State

Original commit: elastic/x-pack-elasticsearch@595c733cfc
2015-02-06 08:23:27 +01:00
Brian Murphy 31a3907bed Use `ParseField` when parsing actions
Use parse fields when parsing and building XContent in Actions.

Original commit: elastic/x-pack-elasticsearch@db48702b76
2015-02-05 16:57:30 -05:00
Brian Murphy 3147927e20 Refactor actions to match trigger refactoring.
This change refactors the old AlertActions code into Actions to mirror the triggers code.
This work also includes the configuration changes and webhook changes from master.
TemplateUtils has been renamed to StringTemplateUtils. References to the old AlertActions code have been removed and updated
to reference the new code.
Action.Result now implements ToXContent
This allows the FiredAlerts to track the history of the actions.

Original commit: elastic/x-pack-elasticsearch@a3d5d3bd4d
2015-02-05 16:42:45 -05:00
uboness 01375a320d updated the alert service and store
Original commit: elastic/x-pack-elasticsearch@61c75d8258
2015-02-05 12:37:08 +01:00
uboness af7cf03a1c removed compound throttler in favour of an alert throttler
We don't really need a generic compound throttler. Instead we now have an `AlertThrottler` that can be configured with optional `AckThrottler` and `PeriodThrottler`.

The logic of what throttler is applied first has therefore moved from the `Alert` to the `AlertThrottler` (back to its natural place)

Original commit: elastic/x-pack-elasticsearch@b81e467c97
2015-02-05 12:08:50 +01:00
uboness 7d9d0aae05 Refactoring of the codebase
Original commit: elastic/x-pack-elasticsearch@08872f71ea
2015-02-05 10:00:48 +01:00
uboness 79ee2ed62e [cleanup] Refactoring of the code base
- Renamed `AlertingModule` to `AlertsModule`
- Started modularizing the code base.. each module has its own guice module and `AlertsModule` spawn all the sub-modules
- Renamed `*Helper` classes to `*Utils` for consistency sake and moved all utilities to `support` package
- Moved `AlertsPlugin` to the base package (no need for `plugin` package... it just creates noise)
- Moved `State` to be inner enum within `AlertsService` (that's where it belongs)
- Moved all the rest actions to `rest.action` package

Original commit: elastic/x-pack-elasticsearch@4ce9bf8dcd
2015-02-03 14:55:28 +01:00
uboness 4b38006f64 Changed the alerts client to wrap es client
Instead of having another client interface, the alerts client should be a wrapper around the standard es client. This will make sure that whatever logic that is applied on these std clients will also be applied to any requests/actions that are executed in the alerts client.

Using the es client introduces a cyclic dependency for all those services that use the es client and that are also injected into the transport actions. For this reason, instead of using the es client and script service directory, we're using proxies. The proxies are initialized lazily be a new `InitializationService`.

Also introduced the `AlertsClientModule` and `AlertsTransportModule`

Closes elastic/elasticsearch#56

Original commit: elastic/x-pack-elasticsearch@58990a7c85
2015-02-03 11:54:08 +01:00
Brian Murphy 8c6aad11ed Add username to SMTP settings.
This partially addresses elastic/elasticsearch#69 until I can make the changes suggested in the code review.

Original commit: elastic/x-pack-elasticsearch@0f1433d9b4
2015-01-30 11:31:15 -05:00
Martijn van Groningen 27b6aa50f7 Add version and build information to the stats api
Also set the current maven version to -SNAPSHOT

Original commit: elastic/x-pack-elasticsearch@964c740373
2015-01-30 17:08:19 +01:00
Martijn van Groningen f5605db41b Share all libraries and noop-ed quartz logging
Original commit: elastic/x-pack-elasticsearch@88228b7f46
2015-01-30 17:02:28 +01:00
Martijn van Groningen d68cad9b72 Renamed AlertActionEntry to AlertHistory.
Original commit: elastic/x-pack-elasticsearch@cc48a27a3c
2015-01-29 21:08:34 +01:00
Martijn van Groningen 57e65fccf1 Rename *Manager to *Service
Original commit: elastic/x-pack-elasticsearch@f37d301660
2015-01-29 20:53:51 +01:00
Martijn van Groningen 61af10f7c0 Added jdoc explanation why the execution of fired alerts is split it into two operations.
Original commit: elastic/x-pack-elasticsearch@03c8645e9d
2015-01-29 17:00:28 +01:00
Martijn van Groningen 11864df421 Fix thread pool name
Original commit: elastic/x-pack-elasticsearch@0ed6327768
2015-01-29 16:20:11 +01:00
Martijn van Groningen 2892154ace Merge pull request elastic/elasticsearch#64 from joehillen/fix-email-port
Fix email port setting

Original commit: elastic/x-pack-elasticsearch@ee669b55d8
2015-01-16 21:24:43 +01:00
Brian Murphy c81a37a2ee Fix the email template test to be a lightweight unit test case and not start any unneeded services.
Original commit: elastic/x-pack-elasticsearch@93fc61d61a
2015-01-15 16:54:48 -05:00
Joe Hillenbrand 5c904dfafa Fix email port setting
The setting was mistyped as 'smpt' when it should have been 'smtp', but
it is better to change it to 'email' to be consistent with the other settings.

Original commit: elastic/x-pack-elasticsearch@0e610d89b5
2015-01-15 12:55:30 -08:00
Brian Murphy a458e2df1d Register the ack handler again.
Original commit: elastic/x-pack-elasticsearch@b229c52f78
2015-01-15 10:31:59 -05:00
Brian Murphy cdd222aad5 Add email templating.
This commit adds support for email templating to alerting.

Original commit: elastic/x-pack-elasticsearch@6280801ce5
2015-01-15 09:34:17 -05:00
Brian Murphy f90d600a22 Add webhook action
This action can be added to an alert as :
      "webhook" : {
        "url" : "http://localhost:8080/alert/{{alert_name}}",
        "method" : "GET"
      }

Original commit: elastic/x-pack-elasticsearch@34e04229ab
2015-01-15 09:31:23 -05:00
Martijn van Groningen 30506ef41d Only primary shards are now required to be available during alerting initialization.
Original commit: elastic/x-pack-elasticsearch@4ef5fd87dc
2015-01-15 10:43:07 +01:00
Martijn van Groningen fc5cbd5d08 Fixed typo
Original commit: elastic/x-pack-elasticsearch@a549bd9e18
2015-01-15 10:15:49 +01:00
Martijn van Groningen 9f014a9bf9 slightly improved logging.
Original commit: elastic/x-pack-elasticsearch@7a131bc4d8
2014-12-23 16:41:16 +01:00
Martijn van Groningen df7fc714e7 Ensure that the refresh has ran on all shards.
Original commit: elastic/x-pack-elasticsearch@6214514956
2014-12-23 16:30:04 +01:00
Martijn van Groningen a7e85df649 Move the get alert api over to be a master node api and that it fetches the alert from the in memory alert store instead via core get api from an index.
Original commit: elastic/x-pack-elasticsearch@6bf471bf74
2014-12-05 19:59:58 +01:00
Martijn van Groningen 05848603d8 Added missing rest handler
Original commit: elastic/x-pack-elasticsearch@749dfc61f5
2014-12-05 19:24:11 +01:00
Martijn van Groningen b039f8bbdb Changed to use indexBlockedException instead of indicesBlockedException
Original commit: elastic/x-pack-elasticsearch@33f581ddd2
2014-12-05 19:13:31 +01:00
Martijn van Groningen bbaa122d7e Removed unused field.
Original commit: elastic/x-pack-elasticsearch@b6b0d926ba
2014-12-05 19:11:24 +01:00
Martijn van Groningen 45e5c13369 Disallow dynamic mapping
Added config mapping

Original commit: elastic/x-pack-elasticsearch@f3de2c17bd
2014-12-05 17:03:26 +01:00
Brian Murphy c97e083a59 Move the saving of configs to the manager.
Original commit: elastic/x-pack-elasticsearch@aa8372d34e
2014-12-05 15:55:19 +00:00
Martijn van Groningen ac45a4fe99 Changes the configuration manager to rely more on alert store for the .alerts index / templated to be loaded. This simplified to loading logic in the configuration manager.
Original commit: elastic/x-pack-elasticsearch@ccd7a23243
2014-12-05 16:42:58 +01:00
Brian Murphy 780c89ec23 Move settings checking to the creation of SMTP alert actions.
Original commit: elastic/x-pack-elasticsearch@30da14cb9e
2014-12-05 15:09:07 +00:00
Martijn van Groningen 203cf5c024 Remove redundant config manager start checking
Original commit: elastic/x-pack-elasticsearch@5369765398
2014-12-05 16:02:28 +01:00
Martijn van Groningen 984d7d615a removed log statements
Original commit: elastic/x-pack-elasticsearch@c4b7b16cd4
2014-12-05 15:36:18 +01:00
Martijn van Groningen aeacbe44ca Removed redundant if statement
Original commit: elastic/x-pack-elasticsearch@2de43dc7d5
2014-12-05 15:34:44 +01:00
Martijn van Groningen 1258a4c327 Renamed ConfigManager#isReady() to ConfigManager#start()
Add ConfigManager#stop()
Simplified config loading
smpt alert action settings are now also updated

Original commit: elastic/x-pack-elasticsearch@acb180f88c
2014-12-05 15:14:24 +01:00
Brian Murphy 920f7ea2a9 More changes for configuration manager and email action renaming.
Original commit: elastic/x-pack-elasticsearch@1c5087e79a
2014-12-05 12:07:31 +00:00
Brian Murphy d8b751f6ed Change to support name change of email alert action.
Original commit: elastic/x-pack-elasticsearch@d8bba3194b
2014-12-05 12:07:31 +00:00
Brian Murphy d4f8bf0d2c Fix test to pass in a dummy cluster state when readying the ConfigManager.
Original commit: elastic/x-pack-elasticsearch@e085844f9f
2014-12-05 12:07:31 +00:00
Brian Murphy 1f49c9199d Changes after review.
Original commit: elastic/x-pack-elasticsearch@a5fac88f19
2014-12-05 12:07:31 +00:00
Brian Murphy d70164de4d Rename EmailAlertAction
Original commit: elastic/x-pack-elasticsearch@35e819cdf2
2014-12-05 12:06:42 +00:00
Brian Murphy 6791841f42 Changes after review.
Original commit: elastic/x-pack-elasticsearch@0a9055b918
2014-12-05 12:05:57 +00:00
Brian Murphy 31173507a5 Add actions and listeners for Configuration.
Add transport actions for configuration.
Add Listener so that components can listen for config changes.

Original commit: elastic/x-pack-elasticsearch@bab02770d9
2014-12-05 12:05:57 +00:00
Brian Murphy d3ec7f40ba Add tests for configuration manager.
Original commit: elastic/x-pack-elasticsearch@9c284fc4c6
2014-12-05 12:05:57 +00:00
Brian Murphy 8fa42a581f Configuration : Add ability to configure alerting by creating .alerts/config/<name> documents in the index.
This commit adds the ConfigurationManager which the components use to load configuration from the index.
The configuration manager exposes an isReady method which components should not start until it is returns true.

Original commit: elastic/x-pack-elasticsearch@96a2f9f44f
2014-12-05 12:05:57 +00:00
Martijn van Groningen a4f0077a2a Fix tests differently
Original commit: elastic/x-pack-elasticsearch@00ec42c29b
2014-12-04 16:55:32 +01:00
Brian Murphy cc9fac0f93 TEST: Fix AbstractAlertingTests
Original commit: elastic/x-pack-elasticsearch@1611f84a41
2014-12-04 15:40:18 +00:00
Brian Murphy 3f4d469d4a FIX: Fixes after merge fail.
Original commit: elastic/x-pack-elasticsearch@6bab2d2640
2014-12-04 15:10:18 +00:00
Brian Murphy f175b298b4 Add payload search test
Original commit: elastic/x-pack-elasticsearch@9fba7e97d1
2014-12-04 14:55:08 +00:00
Brian Murphy b68d7e5554 Changes for payload merge.
Original commit: elastic/x-pack-elasticsearch@7989471378
2014-12-04 14:54:20 +00:00
Martijn van Groningen e09fface02 adjust formatting
Original commit: elastic/x-pack-elasticsearch@aeabde439e
2014-12-04 13:53:09 +01:00
Martijn van Groningen d3dcecbd77 Changed visibility of setters and made naming of setters and getters consistent
Original commit: elastic/x-pack-elasticsearch@c9cc736012
2014-12-01 18:52:02 +01:00
Martijn van Groningen 8e8d360fd2 Test: ensure a no action entry has been fired
Original commit: elastic/x-pack-elasticsearch@0e6d915669
2014-11-28 16:32:09 +01:00
Martijn van Groningen 8910a1f284 Let the xcontent type of alert history documents be based on the xcontent type of alert documents.
Closes elastic/elasticsearch#54

Original commit: elastic/x-pack-elasticsearch@e03bf5d3bf
2014-11-28 15:54:32 +01:00
Martijn van Groningen c094430584 Moved the stopping log info message
Original commit: elastic/x-pack-elasticsearch@0391704846
2014-11-28 15:36:34 +01:00
Martijn van Groningen b883641b01 Also check if the refresh was successful on all the shards it was supposed to execute.
Original commit: elastic/x-pack-elasticsearch@ab867346e4
2014-11-28 12:49:51 +01:00
Martijn van Groningen 737e9567b9 Alert action manager: Start the queue reader thread with self maintained thread instead of using thread pool.
This gives us more control over interrupting and joining this thread during stopping, so we have a good moment in time to clear the queue.

Original commit: elastic/x-pack-elasticsearch@ed3f85fa75
2014-11-27 17:22:22 +01:00
Martijn van Groningen 0ec1f66c60 Test: Run refresh before the search on metadata occurs.
Original commit: elastic/x-pack-elasticsearch@2097f01458
2014-11-27 17:20:32 +01:00
Martijn van Groningen ac715134b3 Increased logging
Original commit: elastic/x-pack-elasticsearch@39093540fd
2014-11-27 15:46:41 +01:00
Brian Murphy fbec93d941 This adds metadata to alerts that are copied to the action entries for this alert.
Original commit: elastic/x-pack-elasticsearch@0abfc22421
2014-11-27 14:00:28 +00:00
Martijn van Groningen b54aea7c14 Test: We can't be sure how often an alert has been fired, so these asserts should by in the atleast mindset.
Original commit: elastic/x-pack-elasticsearch@d4195eb3c0
2014-11-27 14:27:56 +01:00
Martijn van Groningen c29e3c9611 But we still need to clear if loading fails
Original commit: elastic/x-pack-elasticsearch@69bf786e81
2014-11-27 14:07:20 +01:00
Martijn van Groningen 385ea45b7c If loading or alerts or alert entries fail the alert manager should retry and if the search response are partial alert manager should retry as well.
Original commit: elastic/x-pack-elasticsearch@ea6a5a6372
2014-11-27 13:57:09 +01:00
Martijn van Groningen 6da23d412a When stopping alert manager wait for ongoing operations to complete.
Original commit: elastic/x-pack-elasticsearch@646e534628
2014-11-27 13:36:09 +01:00
Martijn van Groningen 27f83bb621 Clear the queue once the reader thread sees that it needs to stop.
Original commit: elastic/x-pack-elasticsearch@b70a224ff1
2014-11-27 12:14:30 +01:00
Martijn van Groningen 1cd5ae6a31 Added assertion
Original commit: elastic/x-pack-elasticsearch@3aae405242
2014-11-27 11:40:56 +01:00
Martijn van Groningen 29dd1bb888 Removed error log for null values
Original commit: elastic/x-pack-elasticsearch@4477fc1c2a
2014-11-27 10:17:51 +01:00
Martijn van Groningen 775f1cb878 Increased logging
Original commit: elastic/x-pack-elasticsearch@375279fca5
2014-11-27 09:53:10 +01:00
Martijn van Groningen 45ee1d2d9b Test: Added test that uses an agg in a trigger.
Original commit: elastic/x-pack-elasticsearch@ad87b18aa5
2014-11-26 23:31:40 +01:00
Martijn van Groningen 3965cb194c Make sure that the alerts templates get applied and disabled test template since it conflicts with the alerts templates.
Original commit: elastic/x-pack-elasticsearch@ddd178da78
2014-11-26 23:23:15 +01:00
Martijn van Groningen e4d10c58a9 Core: load alert store before the action manager, b/c action depends on alert store
Original commit: elastic/x-pack-elasticsearch@6aa3cb33b0
2014-11-26 22:51:34 +01:00
Martijn van Groningen 56a121109d Simplified getAlertHistoryIndexNameForTime()
Original commit: elastic/x-pack-elasticsearch@08ce6daf75
2014-11-26 22:38:40 +01:00
Martijn van Groningen 4048bfe55c Removed explicit delete index calls, because it redundant and the test framework wipes the clusters between tests.
Original commit: elastic/x-pack-elasticsearch@eebeef3bee
2014-11-26 22:18:19 +01:00
Martijn van Groningen 6b4f68fcb3 Test: made the simple no master node test more useful
Original commit: elastic/x-pack-elasticsearch@4ffc11d702
2014-11-26 22:00:26 +01:00
Martijn van Groningen 168bed9d32 Restored some code and fix the assert trigger methods
Original commit: elastic/x-pack-elasticsearch@7ca18b77b9
2014-11-26 21:56:13 +01:00
Brian Murphy 871274adbd Add back in the exists checks for the alert history indices.
Original commit: elastic/x-pack-elasticsearch@a170742e56
2014-11-26 18:17:31 +00:00
Brian Murphy 87e056d762 Fix missing index issue by explicitly creating the index if implicit creation fails
This really shouldn't be happening.

Original commit: elastic/x-pack-elasticsearch@7d334ec76f
2014-11-26 18:10:52 +00:00
Brian Murphy 193865925c Properly catch errors on startup and return false from start if we get errors looking for the alert history indices.
Original commit: elastic/x-pack-elasticsearch@9db4691783
2014-11-26 17:27:22 +00:00
Brian Murphy 779e7e83c0 TEST Fix Bootstrap test that got munged by merge.
Original commit: elastic/x-pack-elasticsearch@b0f40fd764
2014-11-26 16:28:11 +00:00
Brian Murphy f8e26c2f75 Remove dependency on the alert history indices being started in the actions.
Original commit: elastic/x-pack-elasticsearch@a3f0e0fe46
2014-11-26 15:58:52 +00:00
Brian Murphy 713327cee5 TEST : Add bootstrap test to boot strap different history indices.
Original commit: elastic/x-pack-elasticsearch@72c36f6d4d
2014-11-26 15:58:52 +00:00
Brian Murphy aaef7de62d TEST: This test got forgotten when I squash the commits.
Original commit: elastic/x-pack-elasticsearch@5109b4bea6
2014-11-26 15:58:52 +00:00
Brian Murphy 914a5035fd Remove merge conflict in comment.
Original commit: elastic/x-pack-elasticsearch@aa4bb3dab6
2014-11-26 15:58:52 +00:00
Brian Murphy f6027e9a6b Alert History : Make alert history index time based.
This commit makes the alert history index a time based index.
The alert history now is a timebased index prefixed with .alert_history_
with the time fomat YYYY-MM-dd.

This commit makes the alert history index a time based index.

Original commit: elastic/x-pack-elasticsearch@df6d6dee29
2014-11-26 15:58:52 +00:00
Martijn van Groningen 8512dfcb36 Removed enable from Alert.
Original commit: elastic/x-pack-elasticsearch@d65a883f70
2014-11-26 15:30:11 +01:00
Martijn van Groningen b0b3721f84 Added forgotten cluster block check
Original commit: elastic/x-pack-elasticsearch@022be40b54
2014-11-26 14:59:27 +01:00
Martijn van Groningen a34504b45e Test: stabilize the alert stopping during test cluster close and between tests.
Original commit: elastic/x-pack-elasticsearch@f2e7818d86
2014-11-26 12:21:05 +01:00
Martijn van Groningen b7dfde7de7 Changed the way alerting gets shut down when the test cluster gets closed.
Original commit: elastic/x-pack-elasticsearch@74c148c025
2014-11-26 00:26:43 +01:00
Martijn van Groningen 470fb053fd Load quartz job in batch style when starting the scheduler.
Original commit: elastic/x-pack-elasticsearch@9bcf84092a
2014-11-25 21:18:02 +01:00
Martijn van Groningen c9e181e597 Test: Replaced the internal clearing of the alert manager between tests with public stop alert service, delete alerts and alerts history index and start alert service calls.
Original commit: elastic/x-pack-elasticsearch@57c0120eb4
2014-11-25 15:12:00 +01:00
Martijn van Groningen 4b147b8f85 Fixes updating an existing alert works as expected.
Original commit: elastic/x-pack-elasticsearch@236407367a
2014-11-25 13:21:37 +01:00
Martijn van Groningen 00bfd694af Tests: restart action manager before clearing store between tests
Original commit: elastic/x-pack-elasticsearch@15f057c820
2014-11-25 00:17:43 +01:00
Martijn van Groningen 4eca3c86a0 Tests: restart the action manager between tests.
Original commit: elastic/x-pack-elasticsearch@73bc51717b
2014-11-24 21:33:30 +01:00
Martijn van Groningen 98bb60e4ba improve assert
Original commit: elastic/x-pack-elasticsearch@cfedeb5da8
2014-11-24 21:27:14 +01:00
Martijn van Groningen 7eb1ec8ba0 Test: Also clear the alert actions te be processed between tests.
Original commit: elastic/x-pack-elasticsearch@f6da5717aa
2014-11-24 21:14:18 +01:00
Martijn van Groningen 53ef534567 No need to clear the scheduler when it is going to be shut down.
Original commit: elastic/x-pack-elasticsearch@5e8e4134ee
2014-11-24 21:06:47 +01:00
Martijn van Groningen 3c896c3d44 Test: Fix mistake, this test requires cluster scope test
Original commit: elastic/x-pack-elasticsearch@e84b055c19
2014-11-24 18:38:03 +01:00
Martijn van Groningen 1a4e118d0d Improving the starting and stop logic of the alert manager.
- Remove synchronized
- Add STOPPING state
- Expose alert state in stats api
- Let the test framework disable alerting before closing the test cluster

Original commit: elastic/x-pack-elasticsearch@5794f5fd8f
2014-11-24 17:35:10 +01:00
Martijn van Groningen 4e543ded65 Test: Move ClusterScope annotation to base alerting test class.
Original commit: elastic/x-pack-elasticsearch@96bb107c03
2014-11-24 16:21:45 +01:00
Martijn van Groningen 619afe51af Test: use refresh and assertBusy
Original commit: elastic/x-pack-elasticsearch@44e0dab7ef
2014-11-24 10:15:14 +01:00
Martijn van Groningen e0eecc5550 Test: ensure alerting is started before adding alerts
Original commit: elastic/x-pack-elasticsearch@f034d20016
2014-11-23 21:02:21 +01:00
Martijn van Groningen 44b9d8229f Set the manually stopped flag we a node gets shutdown.
Original commit: elastic/x-pack-elasticsearch@f3841481b0
2014-11-23 20:55:40 +01:00
Martijn van Groningen 4e239a8be6 Test: check no master block on all nodes
Original commit: elastic/x-pack-elasticsearch@611ce01d69
2014-11-23 20:32:50 +01:00
Martijn van Groningen beb4fada5f Core: Changed the loading logic in AlertManager to happen all in a single forked thread only. Also retry attempts stay on the the same thread and is only done if there is a new cluster state version.
Test: Added first version of test that fails the elected master multiple times.

Original commit: elastic/x-pack-elasticsearch@2f7b840f5a
2014-11-21 18:15:09 +01:00
Brian Murphy c471abdab5 Merge branch 'master' of https://github.com/elasticsearch/elasticsearch-alerts
Original commit: elastic/x-pack-elasticsearch@7aee9aef96
2014-11-21 15:52:08 +00:00
Martijn van Groningen e6336010be Changed info log into debug log
Original commit: elastic/x-pack-elasticsearch@b142696ca5
2014-11-21 14:30:51 +01:00
Brian Murphy 97bbd747ea DOCS : Add REST API doc for akcing alerts.
Original commit: elastic/x-pack-elasticsearch@633444773d
2014-11-21 12:52:31 +00:00