Commit Graph

332 Commits

Author SHA1 Message Date
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