Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort by name when fetching alerts and connectors #60506

Merged
merged 4 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion x-pack/legacy/plugins/actions/server/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
"action": {
"properties": {
"name": {
"type": "text"
"type": "text",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These mapping changes won't require any kind of migration, since they're additive, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct, when .kibana migrates from ex: _1 to _2, the data will be analyzed differently but no migration necessary.

"fields": {
"keyword": {
"type": "keyword"
}
}
},
"actionTypeId": {
"type": "keyword"
Expand Down
7 changes: 6 additions & 1 deletion x-pack/legacy/plugins/alerting/server/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
"type": "boolean"
},
"name": {
"type": "text"
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"tags": {
"type": "keyword"
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/actions/server/routes/find.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ describe('findActionRoute', () => {
"perPage": 1,
"search": undefined,
"sortField": undefined,
"sortOrder": undefined,
},
},
]
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/actions/server/routes/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const querySchema = schema.object({
}),
search_fields: schema.maybe(schema.oneOf([schema.arrayOf(schema.string()), schema.string()])),
sort_field: schema.maybe(schema.string()),
sort_order: schema.maybe(schema.oneOf([schema.literal('asc'), schema.literal('desc')])),
has_reference: schema.maybe(
// use nullable as maybe is currently broken
// in config-schema
Expand Down Expand Up @@ -70,6 +71,7 @@ export const findActionRoute = (router: IRouter, licenseState: LicenseState) =>
sortField: query.sort_field,
fields: query.fields,
filter: query.filter,
sortOrder: query.sort_order,
};

if (query.search_fields) {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/alerting/server/routes/find.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ describe('findAlertRoute', () => {
"perPage": 1,
"search": undefined,
"sortField": undefined,
"sortOrder": undefined,
},
},
]
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/alerting/server/routes/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const querySchema = schema.object({
}),
search_fields: schema.maybe(schema.oneOf([schema.arrayOf(schema.string()), schema.string()])),
sort_field: schema.maybe(schema.string()),
sort_order: schema.maybe(schema.oneOf([schema.literal('asc'), schema.literal('desc')])),
has_reference: schema.maybe(
// use nullable as maybe is currently broken
// in config-schema
Expand Down Expand Up @@ -70,6 +71,7 @@ export const findAlertRoute = (router: IRouter, licenseState: LicenseState) => {
sortField: query.sort_field,
fields: query.fields,
filter: query.filter,
sortOrder: query.sort_order,
};

if (query.search_fields) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ describe('loadAllActions', () => {
Object {
"query": Object {
"per_page": 10000,
"sort_field": "name.keyword",
"sort_order": "asc",
},
},
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export async function loadAllActions({
return await http.get(`${BASE_ACTION_API_PATH}/_find`, {
query: {
per_page: MAX_ACTIONS_RETURNED,
sort_field: 'name.keyword',
sort_order: 'asc',
},
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ describe('loadAlerts', () => {
"per_page": 10,
"search": undefined,
"search_fields": undefined,
"sort_field": "name.keyword",
"sort_order": "asc",
},
},
]
Expand All @@ -188,20 +190,22 @@ describe('loadAlerts', () => {
const result = await loadAlerts({ http, searchText: 'apples', page: { index: 0, size: 10 } });
expect(result).toEqual(resolvedValue);
expect(http.get.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"/api/alert/_find",
Object {
"query": Object {
"default_search_operator": "AND",
"filter": undefined,
"page": 1,
"per_page": 10,
"search": "apples",
"search_fields": "[\\"name\\",\\"tags\\"]",
},
},
]
`);
Array [
"/api/alert/_find",
Object {
"query": Object {
"default_search_operator": "AND",
"filter": undefined,
"page": 1,
"per_page": 10,
"search": "apples",
"search_fields": "[\\"name\\",\\"tags\\"]",
"sort_field": "name.keyword",
"sort_order": "asc",
},
},
]
`);
});

test('should call find API with actionTypesFilter', async () => {
Expand All @@ -220,20 +224,22 @@ describe('loadAlerts', () => {
});
expect(result).toEqual(resolvedValue);
expect(http.get.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"/api/alert/_find",
Object {
"query": Object {
"default_search_operator": "AND",
"filter": undefined,
"page": 1,
"per_page": 10,
"search": "foo",
"search_fields": "[\\"name\\",\\"tags\\"]",
},
},
]
`);
Array [
"/api/alert/_find",
Object {
"query": Object {
"default_search_operator": "AND",
"filter": undefined,
"page": 1,
"per_page": 10,
"search": "foo",
"search_fields": "[\\"name\\",\\"tags\\"]",
"sort_field": "name.keyword",
"sort_order": "asc",
},
},
]
`);
});

test('should call find API with typesFilter', async () => {
Expand All @@ -252,20 +258,22 @@ describe('loadAlerts', () => {
});
expect(result).toEqual(resolvedValue);
expect(http.get.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"/api/alert/_find",
Object {
"query": Object {
"default_search_operator": "AND",
"filter": "alert.attributes.alertTypeId:(foo or bar)",
"page": 1,
"per_page": 10,
"search": undefined,
"search_fields": undefined,
},
},
]
`);
Array [
"/api/alert/_find",
Object {
"query": Object {
"default_search_operator": "AND",
"filter": "alert.attributes.alertTypeId:(foo or bar)",
"page": 1,
"per_page": 10,
"search": undefined,
"search_fields": undefined,
"sort_field": "name.keyword",
"sort_order": "asc",
},
},
]
`);
});

test('should call find API with actionTypesFilter and typesFilter', async () => {
Expand All @@ -285,20 +293,22 @@ describe('loadAlerts', () => {
});
expect(result).toEqual(resolvedValue);
expect(http.get.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"/api/alert/_find",
Object {
"query": Object {
"default_search_operator": "AND",
"filter": "alert.attributes.alertTypeId:(foo or bar)",
"page": 1,
"per_page": 10,
"search": "baz",
"search_fields": "[\\"name\\",\\"tags\\"]",
},
},
]
`);
Array [
"/api/alert/_find",
Object {
"query": Object {
"default_search_operator": "AND",
"filter": "alert.attributes.alertTypeId:(foo or bar)",
"page": 1,
"per_page": 10,
"search": "baz",
"search_fields": "[\\"name\\",\\"tags\\"]",
"sort_field": "name.keyword",
"sort_order": "asc",
},
},
]
`);
});

test('should call find API with searchText and tagsFilter and typesFilter', async () => {
Expand All @@ -318,20 +328,22 @@ describe('loadAlerts', () => {
});
expect(result).toEqual(resolvedValue);
expect(http.get.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"/api/alert/_find",
Object {
"query": Object {
"default_search_operator": "AND",
"filter": "alert.attributes.alertTypeId:(foo or bar)",
"page": 1,
"per_page": 10,
"search": "apples, foo, baz",
"search_fields": "[\\"name\\",\\"tags\\"]",
},
},
]
`);
Array [
"/api/alert/_find",
Object {
"query": Object {
"default_search_operator": "AND",
"filter": "alert.attributes.alertTypeId:(foo or bar)",
"page": 1,
"per_page": 10,
"search": "apples, foo, baz",
"search_fields": "[\\"name\\",\\"tags\\"]",
"sort_field": "name.keyword",
"sort_order": "asc",
},
},
]
`);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ export async function loadAlerts({
search: searchText,
filter: filters.length ? filters.join(' and ') : undefined,
default_search_operator: 'AND',
sort_field: 'name.keyword',
sort_order: 'asc',
},
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,21 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
const supertest = getService('supertest');
const find = getService('find');

async function createAlert(alertTypeId?: string, name?: string, params?: any) {
async function createAlert(overwrites: Record<string, any> = {}) {
const { body: createdAlert } = await supertest
.post(`/api/alert`)
.set('kbn-xsrf', 'foo')
.send({
enabled: true,
name: name ?? generateUniqueKey(),
name: generateUniqueKey(),
tags: ['foo', 'bar'],
alertTypeId: alertTypeId ?? 'test.noop',
alertTypeId: 'test.noop',
consumer: 'test',
schedule: { interval: '1m' },
throttle: '1m',
actions: [],
params: params ?? {},
params: {},
...overwrites,
})
.expect(200);
return createdAlert;
Expand Down Expand Up @@ -98,6 +99,22 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
]);
});

it('should display alerts in alphabetical order', async () => {
const uniqueKey = generateUniqueKey();
await createAlert({ name: 'b', tags: [uniqueKey] });
await createAlert({ name: 'c', tags: [uniqueKey] });
await createAlert({ name: 'a', tags: [uniqueKey] });

await pageObjects.common.navigateToApp('triggersActions');
await pageObjects.triggersActionsUI.searchAlerts(uniqueKey);

const searchResults = await pageObjects.triggersActionsUI.getAlertsList();
expect(searchResults).to.have.length(3);
expect(searchResults[0].name).to.eql('a');
expect(searchResults[1].name).to.eql('b');
expect(searchResults[2].name).to.eql('c');
});

it('should search for alert', async () => {
const createdAlert = await createAlert();
await pageObjects.common.navigateToApp('triggersActions');
Expand All @@ -115,16 +132,20 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
});

it('should edit an alert', async () => {
const createdAlert = await createAlert('.index-threshold', 'new alert', {
aggType: 'count',
termSize: 5,
thresholdComparator: '>',
timeWindowSize: 5,
timeWindowUnit: 'm',
groupBy: 'all',
threshold: [1000, 5000],
index: ['.kibana_1'],
timeField: 'alert',
const createdAlert = await createAlert({
alertTypeId: '.index-threshold',
name: 'new alert',
params: {
aggType: 'count',
termSize: 5,
thresholdComparator: '>',
timeWindowSize: 5,
timeWindowUnit: 'm',
groupBy: 'all',
threshold: [1000, 5000],
index: ['.kibana_1'],
timeField: 'alert',
},
});
await pageObjects.common.navigateToApp('triggersActions');
await pageObjects.triggersActionsUI.searchAlerts(createdAlert.name);
Expand Down