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

[RAM] Allow users to see event logs from all spaces they have access to #140449

Merged
merged 28 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b60fdce
Add all_namespaces prop to global logs api
Zacqary Sep 9, 2022
43780c6
Merge remote-tracking branch 'upstream/main' into 137995-log-space-sw…
Zacqary Oct 13, 2022
ff24cc0
Display space column and disable link on inactive spaces
Zacqary Oct 14, 2022
c64baca
Add ability to link across spaces
Zacqary Oct 17, 2022
d979592
Fix allNamespace query on default space
Zacqary Oct 17, 2022
30fcaf5
Fix KPI and link space switch to permissions
Zacqary Oct 17, 2022
c1b68c7
Open alternate space rules in new tab
Zacqary Oct 17, 2022
99dd960
Fix Jest 11
Zacqary Oct 17, 2022
e0f83b1
Fix Jest 1
Zacqary Oct 17, 2022
b336fe4
Fix Jest 4 and 10
Zacqary Oct 18, 2022
a0619bc
Fix i18n
Zacqary Oct 18, 2022
13bcd27
Merge remote-tracking branch 'upstream/main' into 137995-log-space-sw…
Zacqary Oct 18, 2022
57b38da
Move space column visibility out of data grid
Zacqary Oct 20, 2022
0f18fbf
Merge remote-tracking branch 'upstream/main' into 137995-log-space-sw…
Zacqary Oct 20, 2022
8c009ef
Merge remote-tracking branch 'upstream/main' into 137995-log-space-sw…
Zacqary Oct 25, 2022
5a185a8
Add test for link routing
Zacqary Oct 26, 2022
81d1e6f
Merge remote-tracking branch 'upstream/main' into 137995-log-space-sw…
Zacqary Oct 27, 2022
90d1bc8
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Oct 27, 2022
eeff02c
Add auth and space access to action error log
Zacqary Oct 28, 2022
0bb3bc7
Merge remote-tracking branch 'upstream/main' into 137995-log-space-sw…
Zacqary Oct 28, 2022
e37b3eb
Merge branch '137995-log-space-switch' of https://github.com/Zacqary/…
Zacqary Oct 28, 2022
c964fd8
Add test for getActionErrorLogWithAuth, fix types, consts
Zacqary Oct 28, 2022
e192495
Fix undefined spaceids error
Zacqary Oct 28, 2022
ce620aa
Fix base path support
Zacqary Oct 28, 2022
de8d641
Fix types and jest
Zacqary Oct 31, 2022
e21b64a
Merge remote-tracking branch 'upstream/main' into 137995-log-space-sw…
Zacqary Oct 31, 2022
64e9442
Fix types and jest
Zacqary Oct 31, 2022
cc99097
Remove consolelog
Zacqary Oct 31, 2022
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
1 change: 1 addition & 0 deletions x-pack/plugins/alerting/common/execution_log_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export interface IExecutionLog {
schedule_delay_ms: number;
timed_out: boolean;
rule_id: string;
space_ids: string[];
rule_name: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ describe('getExecutionLogAggregation', () => {
'error.message',
'kibana.version',
'rule.id',
'kibana.space_ids',
'rule.name',
'kibana.alerting.outcome',
],
Expand Down Expand Up @@ -486,6 +487,7 @@ describe('getExecutionLogAggregation', () => {
'error.message',
'kibana.version',
'rule.id',
'kibana.space_ids',
'rule.name',
'kibana.alerting.outcome',
],
Expand Down Expand Up @@ -692,6 +694,7 @@ describe('getExecutionLogAggregation', () => {
'error.message',
'kibana.version',
'rule.id',
'kibana.space_ids',
'rule.name',
'kibana.alerting.outcome',
],
Expand Down Expand Up @@ -954,6 +957,7 @@ describe('formatExecutionLogResult', () => {
schedule_delay_ms: 3074,
rule_id: 'a348a740-9e2c-11ec-bd64-774ed95c43ef',
rule_name: 'rule_name',
space_ids: [],
},
{
id: '41b2755e-765a-4044-9745-b03875d5e79a',
Expand All @@ -976,6 +980,7 @@ describe('formatExecutionLogResult', () => {
schedule_delay_ms: 3126,
rule_id: 'a348a740-9e2c-11ec-bd64-774ed95c43ef',
rule_name: 'rule_name',
space_ids: [],
},
],
});
Expand Down Expand Up @@ -1203,6 +1208,7 @@ describe('formatExecutionLogResult', () => {
schedule_delay_ms: 3074,
rule_id: 'a348a740-9e2c-11ec-bd64-774ed95c43ef',
rule_name: 'rule_name',
space_ids: [],
},
{
id: '41b2755e-765a-4044-9745-b03875d5e79a',
Expand All @@ -1225,6 +1231,7 @@ describe('formatExecutionLogResult', () => {
schedule_delay_ms: 3126,
rule_id: 'a348a740-9e2c-11ec-bd64-774ed95c43ef',
rule_name: 'rule_name',
space_ids: [],
},
],
});
Expand Down Expand Up @@ -1444,6 +1451,7 @@ describe('formatExecutionLogResult', () => {
schedule_delay_ms: 3074,
rule_id: 'a348a740-9e2c-11ec-bd64-774ed95c43ef',
rule_name: 'rule_name',
space_ids: [],
},
{
id: '41b2755e-765a-4044-9745-b03875d5e79a',
Expand All @@ -1466,6 +1474,7 @@ describe('formatExecutionLogResult', () => {
schedule_delay_ms: 3126,
rule_id: 'a348a740-9e2c-11ec-bd64-774ed95c43ef',
rule_name: 'rule_name',
space_ids: [],
},
],
});
Expand Down Expand Up @@ -1690,6 +1699,7 @@ describe('formatExecutionLogResult', () => {
schedule_delay_ms: 3126,
rule_id: 'a348a740-9e2c-11ec-bd64-774ed95c43ef',
rule_name: 'rule_name',
space_ids: [],
},
{
id: '61bb867b-661a-471f-bf92-23471afa10b3',
Expand All @@ -1712,6 +1722,7 @@ describe('formatExecutionLogResult', () => {
schedule_delay_ms: 3133,
rule_id: 'a348a740-9e2c-11ec-bd64-774ed95c43ef',
rule_name: 'rule_name',
space_ids: [],
},
],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const DEFAULT_MAX_BUCKETS_LIMIT = 1000; // do not retrieve more than this number
const DEFAULT_MAX_KPI_BUCKETS_LIMIT = 10000;

const RULE_ID_FIELD = 'rule.id';
const SPACE_ID_FIELD = 'kibana.space_ids';
const RULE_NAME_FIELD = 'rule.name';
const PROVIDER_FIELD = 'event.provider';
const START_FIELD = 'event.start';
Expand Down Expand Up @@ -410,6 +411,7 @@ export function getExecutionLogAggregation({
ERROR_MESSAGE_FIELD,
VERSION_FIELD,
RULE_ID_FIELD,
SPACE_ID_FIELD,
RULE_NAME_FIELD,
ALERTING_OUTCOME_FIELD,
],
Expand Down Expand Up @@ -494,8 +496,9 @@ function formatExecutionLogAggBucket(bucket: IExecutionUuidAggBucket): IExecutio
status === 'failure' ? `${outcomeMessage} - ${outcomeErrorMessage}` : outcomeMessage;
const version = outcomeAndMessage.kibana?.version ?? '';

const ruleId = outcomeAndMessage.rule?.id ?? '';
const ruleName = outcomeAndMessage.rule?.name ?? '';
const ruleId = outcomeAndMessage ? outcomeAndMessage?.rule?.id ?? '' : '';
const spaceIds = outcomeAndMessage ? outcomeAndMessage?.kibana?.space_ids ?? [] : [];
const ruleName = outcomeAndMessage ? outcomeAndMessage.rule?.name ?? '' : '';
return {
id: bucket?.key ?? '',
timestamp: bucket?.ruleExecution?.executeStartTime.value_as_string ?? '',
Expand All @@ -515,6 +518,7 @@ function formatExecutionLogAggBucket(bucket: IExecutionUuidAggBucket): IExecutio
schedule_delay_ms: scheduleDelayUs / Millis2Nanos,
timed_out: timedOut,
rule_id: ruleId,
space_ids: spaceIds,
rule_name: ruleName,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,25 @@
import { IRouter } from '@kbn/core/server';
import { schema } from '@kbn/config-schema';
import { AlertingRequestHandlerContext, INTERNAL_BASE_ALERTING_API_PATH } from '../types';
import { RewriteRequestCase, verifyAccessAndContext } from './lib';
import { RewriteRequestCase, verifyAccessAndContext, rewriteNamespaces } from './lib';
import { GetGlobalExecutionKPIParams } from '../rules_client';
import { ILicenseState } from '../lib';

const querySchema = schema.object({
date_start: schema.string(),
date_end: schema.maybe(schema.string()),
filter: schema.maybe(schema.string()),
namespaces: schema.maybe(schema.arrayOf(schema.string())),
});

const rewriteReq: RewriteRequestCase<GetGlobalExecutionKPIParams> = ({
date_start: dateStart,
date_end: dateEnd,
namespaces,
...rest
}) => ({
...rest,
namespaces: rewriteNamespaces(namespaces),
dateStart,
dateEnd,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ describe('getRuleExecutionLogRoute', () => {
schedule_delay_ms: 3126,
rule_id: 'a348a740-9e2c-11ec-bd64-774ed95c43ef',
rule_name: 'rule-name',
space_ids: ['namespace'],
},
{
id: '41b2755e-765a-4044-9745-b03875d5e79a',
Expand All @@ -69,6 +70,7 @@ describe('getRuleExecutionLogRoute', () => {
schedule_delay_ms: 3008,
rule_id: 'a348a740-9e2c-11ec-bd64-774ed95c43ef',
rule_name: 'rule-name',
space_ids: ['namespace'],
},
],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { IRouter } from '@kbn/core/server';
import { schema } from '@kbn/config-schema';
import { ILicenseState } from '../lib';
import { GetGlobalExecutionLogParams } from '../rules_client';
import { RewriteRequestCase, verifyAccessAndContext } from './lib';
import { RewriteRequestCase, verifyAccessAndContext, rewriteNamespaces } from './lib';
import { AlertingRequestHandlerContext, INTERNAL_BASE_ALERTING_API_PATH } from '../types';

const sortOrderSchema = schema.oneOf([schema.literal('asc'), schema.literal('desc')]);
Expand Down Expand Up @@ -38,15 +38,18 @@ const querySchema = schema.object({
per_page: schema.number({ defaultValue: 10, min: 1 }),
page: schema.number({ defaultValue: 1, min: 1 }),
sort: sortFieldsSchema,
namespaces: schema.maybe(schema.arrayOf(schema.string())),
});

const rewriteReq: RewriteRequestCase<GetGlobalExecutionLogParams> = ({
date_start: dateStart,
date_end: dateEnd,
per_page: perPage,
namespaces,
...rest
}) => ({
...rest,
namespaces: rewriteNamespaces(namespaces),
dateStart,
dateEnd,
perPage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe('getRuleExecutionLogRoute', () => {
schedule_delay_ms: 3126,
rule_id: 'a348a740-9e2c-11ec-bd64-774ed95c43ef',
rule_name: 'rule_name',
space_ids: ['namespace'],
},
{
id: '41b2755e-765a-4044-9745-b03875d5e79a',
Expand All @@ -70,6 +71,7 @@ describe('getRuleExecutionLogRoute', () => {
schedule_delay_ms: 3008,
rule_id: 'a348a740-9e2c-11ec-bd64-774ed95c43ef',
rule_name: 'rule_name',
space_ids: ['namespace'],
},
],
};
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/alerting/server/routes/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export type {
export { verifyAccessAndContext } from './verify_access_and_context';
export { countUsageOfPredefinedIds } from './count_usage_of_predefined_ids';
export { rewriteRule } from './rewrite_rule';
export { rewriteNamespaces } from './rewrite_namespaces';
11 changes: 11 additions & 0 deletions x-pack/plugins/alerting/server/routes/lib/rewrite_namespaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export const rewriteNamespaces = (namespaces?: Array<string | undefined>) =>
namespaces
? namespaces.map((id: string | undefined) => (id === 'default' ? undefined : id))
: undefined;
10 changes: 8 additions & 2 deletions x-pack/plugins/alerting/server/rules_client/rules_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ export interface GetGlobalExecutionKPIParams {
dateStart: string;
dateEnd?: string;
filter?: string;
namespaces?: Array<string | undefined>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to make this type a bit stricter? (I.e. just Array<string>). I see that getNameSpace could return undefined, could we filter those entries out or do they have some significance being undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Default namespace is referred to as undefined internally. As far as I can tell, this changed recently; it used to just be the string default.

}

export interface GetGlobalExecutionLogParams {
Expand All @@ -407,6 +408,7 @@ export interface GetGlobalExecutionLogParams {
page: number;
perPage: number;
sort: estypes.Sort;
namespaces?: Array<string | undefined>;
}

export interface GetActionErrorLogByIdParams {
Expand Down Expand Up @@ -930,6 +932,7 @@ export class RulesClient {
page,
perPage,
sort,
namespaces,
}: GetGlobalExecutionLogParams): Promise<IExecutionLogResult> {
this.logger.debug(`getGlobalExecutionLogWithAuth(): getting global execution log`);

Expand Down Expand Up @@ -980,7 +983,8 @@ export class RulesClient {
perPage,
sort,
}),
}
},
namespaces
);

return formatExecutionLogResult(aggResult);
Expand Down Expand Up @@ -1066,6 +1070,7 @@ export class RulesClient {
dateStart,
dateEnd,
filter,
namespaces,
}: GetGlobalExecutionKPIParams) {
this.logger.debug(`getGlobalExecutionLogWithAuth(): getting global execution log`);

Expand Down Expand Up @@ -1111,7 +1116,8 @@ export class RulesClient {
start: parsedDateStart.toISOString(),
end: parsedDateEnd.toISOString(),
aggs: getExecutionKPIAggregation(filter),
}
},
namespaces
);

return formatExecutionKPIResult(aggResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ describe('getExecutionLogForRule()', () => {
schedule_delay_ms: 3126,
rule_id: 'a348a740-9e2c-11ec-bd64-774ed95c43ef',
rule_name: 'rule-name',
space_ids: [],
},
{
id: '41b2755e-765a-4044-9745-b03875d5e79a',
Expand All @@ -407,6 +408,7 @@ describe('getExecutionLogForRule()', () => {
schedule_delay_ms: 3345,
rule_id: 'a348a740-9e2c-11ec-bd64-774ed95c43ef',
rule_name: 'rule-name',
space_ids: [],
},
],
});
Expand Down Expand Up @@ -719,6 +721,7 @@ describe('getGlobalExecutionLogWithAuth()', () => {
schedule_delay_ms: 3126,
rule_id: 'a348a740-9e2c-11ec-bd64-774ed95c43ef',
rule_name: 'rule-name',
space_ids: [],
},
{
id: '41b2755e-765a-4044-9745-b03875d5e79a',
Expand All @@ -741,6 +744,7 @@ describe('getGlobalExecutionLogWithAuth()', () => {
schedule_delay_ms: 3345,
rule_id: 'a348a740-9e2c-11ec-bd64-774ed95c43ef',
rule_name: 'rule-name',
space_ids: [],
},
],
});
Expand Down
Loading