Skip to content

Commit

Permalink
Merge branch 'main' into graphA11yTests
Browse files Browse the repository at this point in the history
  • Loading branch information
bhavyarm authored Jun 20, 2022
2 parents 90a5b6c + e668693 commit 92de90d
Show file tree
Hide file tree
Showing 20 changed files with 360 additions and 147 deletions.
2 changes: 1 addition & 1 deletion docs/api/alerting.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ For deprecated APIs, refer to <<alerts-api>>.

include::alerting/create_rule.asciidoc[leveloffset=+1]
include::alerting/delete_rule.asciidoc[leveloffset=+1]
include::alerting/update_rule.asciidoc[]
include::alerting/update_rule.asciidoc[leveloffset=+1]
include::alerting/get_rules.asciidoc[]
include::alerting/find_rules.asciidoc[]
include::alerting/list_rule_types.asciidoc[]
Expand Down
1 change: 0 additions & 1 deletion docs/api/alerting/create_rule.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ The API returns the following:
},
"rule_type_id": ".index-threshold",
"scheduled_task_id": "425b0800-6bca-11eb-9e0d-85d233e3ee35",
"snooze_schedule":[],
"created_by": "elastic",
"updated_by": "elastic",
"created_at": "2022-06-08T17:20:31.632Z",
Expand Down
156 changes: 101 additions & 55 deletions docs/api/alerting/update_rule.asciidoc
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
[[update-rule-api]]
=== Update rule API
== Update rule API
++++
<titleabbrev>Update rule</titleabbrev>
++++

Update the attributes for an existing rule.

[[update-rule-api-request]]
==== Request
=== {api-request-title}

`PUT <kibana host>:<port>/api/alerting/rule/<id>`

`PUT <kibana host>:<port>/s/<space_id>/api/alerting/rule/<id>`

==== {api-description-title}
=== {api-prereq-title}

You must have `all` privileges for the *Management* > *Stack Rules* feature or
for the *{ml-app}*, *{observability}*, or *Security* features, depending on the
`consumer` and `rule_type_id` of the rule you're updating. If the rule has
`actions`, you must also have `read` privileges for the *Management* >
*Actions and Connectors* feature. For more details, refer to
<<kibana-feature-privileges>>.

=== {api-description-title}

[WARNING]
====
Expand All @@ -23,91 +32,117 @@ Update the attributes for an existing rule.
Thereafter, when the rule performs queries, it uses those security privileges.
If you have different privileges than the user that created or most recently
updated the rule, you might change its behavior.
* Though some properties are optional, when you update the rule the existing
property values are overwritten with default values. Therefore, it is
recommended to explicitly set all property values.
====

[[update-rule-api-path-params]]
==== Path parameters
=== {api-path-parms-title}

`id`::
(Required, string) The ID of the rule that you want to update.
(Required, string) The ID of the rule that you want to update.

`space_id`::
(Optional, string) An identifier for the space. If `space_id` is not provided in the URL, the default space is used.
(Optional, string) An identifier for the space. If `space_id` is not provided in
the URL, the default space is used.

[role="child_attributes"]
[[update-rule-api-request-body]]
==== Request body

`name`::
(Required, string) A name to reference and search.

`tags`::
(Optional, string array) A list of keywords to reference and search.
=== {api-request-body-title}

`schedule`::
(Required, object) When to run this rule. Use one of the available schedule formats.
`actions`::
(Optional, object array) An array of action objects. The default value is an
empty array (`[]`).
+
._Schedule Formats_.
.Properties of the action objects:
[%collapsible%open]
=====
A schedule uses a key: value format. {kib} currently supports the _Interval format_ , which specifies the interval in seconds, minutes, hours, or days at which to execute the rule.
`group`:::
(Required, string) Grouping actions is recommended for escalations for different
types of alerts. If you don't need this, set the value to `default`.
Example: `{ interval: "10s" }`, `{ interval: "5m" }`, `{ interval: "1h" }`, `{ interval: "1d" }`.
`id`:::
(Required, string) The identifier of the action.
`params`:::
(Required, object) The map to the `params` that the
<<action-types,connector type>> will receive. The `params` are handled as
Mustache templates and passed a default set of context.
=====

`throttle`::
(Optional, string) How often this rule should fire the same actions. This will prevent the rule from sending out the same notification over and over. For example, if a rule with a `schedule` of 1 minute stays in a triggered state for 90 minutes, setting a `throttle` of `10m` or `1h` will prevent it from sending 90 notifications during this period.
`name`::
(Required, string) A name to reference and search.

`notify_when`::
(Required, string) The condition for throttling the notification: `onActionGroupChange`, `onActiveAlert`, or `onThrottleInterval`.
(Required, string) The condition for throttling the notification:
`onActionGroupChange`, `onActiveAlert`, or `onThrottleInterval`.

`params`::
(Required, object) The parameters to pass to the rule type executor `params` value. This will also validate against the rule type params validator, if defined.
(Required, object) The parameters to pass to the rule type executor `params`
value. This will also validate against the rule type params validator, if defined.

`actions`::
(Optional, object array) An array of the following action objects.
`schedule`::
(Required, object) When to run this rule. Use one of the available schedule formats.
+
.Properties of the action objects:
.Schedule formats
[%collapsible%open]
=====
`group`:::
(Required, string) Grouping actions is recommended for escalations for different types of alerts. If you don't need this, set the value to `default`.
`id`:::
(Required, string) The ID of the action that saved object executes.
A schedule uses a `key: value` format. {kib} currently supports the
_interval format_, which specifies the interval in seconds, minutes, hours, or
days at which to run the rule. For example: `{ "interval": "10s" }`,
`{ "interval": "5m" }`, `{ "interval": "1h" }`, or `{ "interval": "1d" }`.
`params`:::
(Required, object) The map to the `params` that the <<action-types,connector type>> will receive. `params` are handled as Mustache templates and passed a default set of context.
=====

`tags`::
(Optional, string array) A list of keywords to reference and search. The default
value is an empty array (`[]`).

`throttle`::
(Optional, string) How often this rule should fire the same actions. This will
prevent the rule from sending out the same notification over and over. For
example, if a rule with a `schedule` of 1 minute stays in a triggered state for
90 minutes, setting a `throttle` of `10m` or `1h` will prevent it from sending
90 notifications during this period. The default value is `null`.

[[update-rule-api-response-codes]]
==== Response code
=== {api-response-codes-title}

`200`::
Indicates a successful call.
Indicates a successful call.

[[update-rule-api-example]]
==== Example
=== {api-examples-title}

Update a rule with ID `ac4e6b90-6be7-11eb-ba0d-9b1c1f912d74` with a different name:
Update an index threshold rule with ID `ac4e6b90-6be7-11eb-ba0d-9b1c1f912d74`:

[source,sh]
--------------------------------------------------
$ curl -X PUT api/alerting/rule/ac4e6b90-6be7-11eb-ba0d-9b1c1f912d74
PUT api/alerting/rule/ac4e6b90-6be7-11eb-ba0d-9b1c1f912d74
{
"notify_when": "onActionGroupChange",
"params": {
"aggType": "avg",
"index":[".test-index"],
"timeField":"@timestamp",
"groupBy":"top",
"aggType":"avg",
"timeWindowSize":5,
"timeWindowUnit":"m",
"thresholdComparator":">",
"threshold":[1000],
"aggType":"avg",
"aggField":"sheet.version",
"termField":"name.keyword",
"termSize":6
},
"schedule": {
"interval": "1m"
},
"actions": [],
"tags": [],
"name": "new name",
"throttle": null,
"throttle": null
}
--------------------------------------------------
// KIBANA
Expand All @@ -118,31 +153,42 @@ The API returns the following:
--------------------------------------------------
{
"id": "ac4e6b90-6be7-11eb-ba0d-9b1c1f912d74",
"notify_when": "onActionGroupChange",
"params": {
"aggType": "avg",
},
"consumer": "alerts",
"rule_type_id": "test.rule.type",
"schedule": {
"interval": "1m"
},
"actions": [],
"tags": [],
"name": "new name",
"enabled": true,
"throttle": null,
"schedule": {
"interval": "1m"
},
"params": {
"index": [".updated-index"],
"timeField": "@timestamp",
"groupBy": "top",
"aggType": "avg",
"timeWindowSize": 5,
"timeWindowUnit": "m",
"thresholdComparator": ">",
"threshold": [1000],
"aggField": "sheet.version",
"termField": "name.keyword",
"termSize": 6
},
"api_key_owner": "elastic",
"created_by": "elastic",
"updated_by": "elastic",
"rule_type_id": ".index-threshold",
"scheduled_task_id": "4c5eda00-e74f-11ec-b72f-5b18752ff9ea",
"created_at": "2022-06-08T17:20:31.632Z",
"updated_at": "2022-06-09T23:36:36.090Z",
"notify_when": "onActionGroupChange",
"mute_all": false,
"muted_alert_ids": [],
"updated_at": "2021-02-10T05:37:19.086Z",
"created_at": "2021-02-10T05:37:19.086Z",
"scheduled_task_id": "0b092d90-6b62-11eb-9e0d-85d233e3ee35",
"execution_status": {
"last_execution_date": "2021-02-10T17:55:14.262Z",
"status": "ok"
}
"status": "ok",
"last_execution_date": "2022-06-09T23:36:17.332Z",
"last_duration": 577
},
"actions":[]
}
--------------------------------------------------
59 changes: 52 additions & 7 deletions src/plugins/discover/public/hooks/use_es_doc_search.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@
* Side Public License, v 1.
*/

import { renderHook } from '@testing-library/react-hooks';
import { renderHook, act } from '@testing-library/react-hooks';
import { buildSearchBody, useEsDocSearch } from './use_es_doc_search';
import { Observable } from 'rxjs';
import { Subject } from 'rxjs';
import { DataView } from '@kbn/data-views-plugin/public';
import { DocProps } from '../application/doc/components/doc';
import { ElasticRequestState } from '../application/doc/types';
import { SEARCH_FIELDS_FROM_SOURCE as mockSearchFieldsFromSource } from '../../common';
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import React from 'react';

const mockSearchResult = new Observable();

const mockSearchResult = new Subject();
const services = {
data: {
search: {
Expand Down Expand Up @@ -171,23 +170,69 @@ describe('Test of <Doc /> helper / hook', () => {
`);
});

test('useEsDocSearch', async () => {
test('useEsDocSearch loading', async () => {
const indexPattern = {
getComputedFields: () => [],
};
const props = {
id: '1',
index: 'index1',
indexPattern,
} as unknown as DocProps;

const hook = renderHook((p: DocProps) => useEsDocSearch(p), {
initialProps: props,
wrapper: ({ children }) => (
<KibanaContextProvider services={services}>{children}</KibanaContextProvider>
),
});

expect(hook.result.current.slice(0, 2)).toEqual([ElasticRequestState.Loading, null]);
});

test('useEsDocSearch ignore partial results', async () => {
const indexPattern = {
getComputedFields: () => [],
};

const record = { test: 1 };

const props = {
id: '1',
index: 'index1',
indexPattern,
} as unknown as DocProps;

const { result } = renderHook((p: DocProps) => useEsDocSearch(p), {
const hook = renderHook((p: DocProps) => useEsDocSearch(p), {
initialProps: props,
wrapper: ({ children }) => (
<KibanaContextProvider services={services}>{children}</KibanaContextProvider>
),
});

expect(result.current.slice(0, 2)).toEqual([ElasticRequestState.Loading, null]);
await act(async () => {
mockSearchResult.next({
isPartial: true,
isRunning: false,
rawResponse: {
hits: {
hits: [],
},
},
});
mockSearchResult.next({
isPartial: false,
isRunning: false,
rawResponse: {
hits: {
hits: [record],
},
},
});
mockSearchResult.complete();
await hook.waitForNextUpdate();
});

expect(hook.result.current.slice(0, 2)).toEqual([ElasticRequestState.Found, record]);
});
});
Loading

0 comments on commit 92de90d

Please sign in to comment.