Commit Graph

637 Commits

Author SHA1 Message Date
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
Martijn van Groningen 4c6d2e7b39 Build: removed -XX:MaxPermSize option from pom.xml
Support for this option has been removed in Java 8 and the build works without it with Java 7 too.

Original commit: elastic/x-pack-elasticsearch@b1ba8893f2
2015-04-07 13:41:51 +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
uboness 47b0fb4ea1 [docs] added docs for input, schedule and condition
Also:

- removed `throttle` file (throttling is not covered in `alert-anatomy` page)
- fixed ctx model parameters in templates/scripts to use the `ctx` prefix.
- added a dediated section in alert-anatomy about execution context as template/script model
- wrote first page of `transform` section

Original commit: elastic/x-pack-elasticsearch@471ca7f0d9
2015-03-19 12:07:20 -07: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