Skip to content

Commit

Permalink
[Event Log] Adds namespace into save objects (#62974)
Browse files Browse the repository at this point in the history
Adds a namespace attribute to the saved object object within the Event Log so that each Saved Object can have its own. This change also removes the existing kibana.namespace field.

As Event Log is not yet in use, this does not include a migration.
  • Loading branch information
gmmorris authored and wayneseymour committed Apr 15, 2020
1 parent 9aa3405 commit 28ce219
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 38 deletions.
9 changes: 4 additions & 5 deletions x-pack/plugins/actions/server/lib/action_executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export class ActionExecutor {
} = this.actionExecutorContext!;

const services = getServices(request);
const namespace = spaces && spaces.getSpaceId(request);
const spaceId = spaces && spaces.getSpaceId(request);
const namespace = spaceId && spaceId !== 'default' ? { namespace: spaceId } : {};

// Ensure user can read the action before processing
const {
Expand All @@ -91,9 +92,7 @@ export class ActionExecutor {
} = await encryptedSavedObjectsPlugin.getDecryptedAsInternalUser<RawAction>(
'action',
actionId,
{
namespace: namespace === 'default' ? undefined : namespace,
}
namespace
);
const actionType = actionTypeRegistry.get(actionTypeId);

Expand All @@ -112,7 +111,7 @@ export class ActionExecutor {
const actionLabel = `${actionTypeId}:${actionId}: ${name}`;
const event: IEvent = {
event: { action: EVENT_LOG_ACTIONS.execute },
kibana: { namespace, saved_objects: [{ type: 'action', id: actionId }] },
kibana: { saved_objects: [{ type: 'action', id: actionId, ...namespace }] },
};

eventLogger.startTiming(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ test('calls actionsPlugin.execute per selected action', async () => {
"alerting": Object {
"instance_id": "2",
},
"namespace": "default",
"saved_objects": Array [
Object {
"id": "1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,17 @@ export function createExecutionHandler({
apiKey,
});

const namespace = spaceId === 'default' ? {} : { namespace: spaceId };

const event: IEvent = {
event: { action: EVENT_LOG_ACTIONS.executeAction },
kibana: {
alerting: {
instance_id: alertInstanceId,
},
namespace: spaceId,
saved_objects: [
{ type: 'alert', id: alertId },
{ type: 'action', id: action.id },
{ type: 'alert', id: alertId, ...namespace },
{ type: 'action', id: action.id, ...namespace },
],
},
};
Expand Down
15 changes: 8 additions & 7 deletions x-pack/plugins/alerting/server/task_runner/task_runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ describe('Task Runner', () => {
"action": "execute",
},
"kibana": Object {
"namespace": undefined,
"saved_objects": Array [
Object {
"id": "1",
"namespace": undefined,
"type": "alert",
},
],
Expand Down Expand Up @@ -229,10 +229,10 @@ describe('Task Runner', () => {
"action": "execute",
},
"kibana": Object {
"namespace": undefined,
"saved_objects": Array [
Object {
"id": "1",
"namespace": undefined,
"type": "alert",
},
],
Expand All @@ -249,10 +249,10 @@ describe('Task Runner', () => {
"alerting": Object {
"instance_id": "1",
},
"namespace": undefined,
"saved_objects": Array [
Object {
"id": "1",
"namespace": undefined,
"type": "alert",
},
],
Expand All @@ -269,14 +269,15 @@ describe('Task Runner', () => {
"alerting": Object {
"instance_id": "1",
},
"namespace": undefined,
"saved_objects": Array [
Object {
"id": "1",
"namespace": undefined,
"type": "alert",
},
Object {
"id": "1",
"namespace": undefined,
"type": "action",
},
],
Expand Down Expand Up @@ -344,10 +345,10 @@ describe('Task Runner', () => {
"action": "execute",
},
"kibana": Object {
"namespace": undefined,
"saved_objects": Array [
Object {
"id": "1",
"namespace": undefined,
"type": "alert",
},
],
Expand All @@ -364,10 +365,10 @@ describe('Task Runner', () => {
"alerting": Object {
"instance_id": "2",
},
"namespace": undefined,
"saved_objects": Array [
Object {
"id": "1",
"namespace": undefined,
"type": "alert",
},
],
Expand Down Expand Up @@ -560,10 +561,10 @@ describe('Task Runner', () => {
"action": "execute",
},
"kibana": Object {
"namespace": undefined,
"saved_objects": Array [
Object {
"id": "1",
"namespace": undefined,
"type": "alert",
},
],
Expand Down
5 changes: 2 additions & 3 deletions x-pack/plugins/alerting/server/task_runner/task_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class TaskRunner {
const alertLabel = `${this.alertType.id}:${alertId}: '${name}'`;
const event: IEvent = {
event: { action: EVENT_LOG_ACTIONS.execute },
kibana: { namespace, saved_objects: [{ type: 'alert', id: alertId }] },
kibana: { saved_objects: [{ type: 'alert', id: alertId, namespace }] },
};
eventLogger.startTiming(event);

Expand Down Expand Up @@ -378,11 +378,10 @@ function generateNewAndResolvedInstanceEvents(params: GenerateNewAndResolvedInst
action,
},
kibana: {
namespace: params.namespace,
alerting: {
instance_id: id,
},
saved_objects: [{ type: 'alert', id: params.alertId }],
saved_objects: [{ type: 'alert', id: params.alertId, namespace: params.namespace }],
},
message,
};
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/event_log/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ Here's the event written to the event log index:
"duration": 1000000
},
"kibana": {
"namespace": "default",
"saved_objects": [
{
"type": "action",
Expand Down
6 changes: 1 addition & 5 deletions x-pack/plugins/event_log/generated/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@
"type": "keyword",
"ignore_above": 1024
},
"namespace": {
"type": "keyword",
"ignore_above": 1024
},
"alerting": {
"properties": {
"instance_id": {
Expand All @@ -86,7 +82,7 @@
},
"saved_objects": {
"properties": {
"store": {
"namespace": {
"type": "keyword",
"ignore_above": 1024
},
Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/event_log/generated/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export const EventSchema = schema.maybe(
kibana: schema.maybe(
schema.object({
server_uuid: ecsString(),
namespace: ecsString(),
alerting: schema.maybe(
schema.object({
instance_id: ecsString(),
Expand All @@ -65,7 +64,7 @@ export const EventSchema = schema.maybe(
saved_objects: schema.maybe(
schema.arrayOf(
schema.object({
store: ecsString(),
namespace: ecsString(),
id: ecsString(),
type: ecsString(),
})
Expand Down
12 changes: 3 additions & 9 deletions x-pack/plugins/event_log/scripts/mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,12 @@ exports.EcsKibanaExtensionsMappings = {
},
},
},
// relevant kibana space
namespace: {
type: 'keyword',
ignore_above: 1024,
},
// array of saved object references, for "linking" via search
saved_objects: {
type: 'nested',
properties: {
// 'kibana' for typical saved object, 'task_manager' for TM, etc
store: {
// relevant kibana space
namespace: {
type: 'keyword',
ignore_above: 1024,
},
Expand Down Expand Up @@ -61,9 +56,8 @@ exports.EcsEventLogProperties = [
'error.message',
'user.name',
'kibana.server_uuid',
'kibana.namespace',
'kibana.alerting.instance_id',
'kibana.saved_objects.store',
'kibana.saved_objects.namespace',
'kibana.saved_objects.id',
'kibana.saved_objects.name',
'kibana.saved_objects.type',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ export function fakeEvent(overrides = {}) {
duration: 1000000,
},
kibana: {
namespace: 'default',
saved_objects: [
{
namespace: 'default',
type: 'action',
id: '968f1b82-0414-4a10-becc-56b6473e4a29',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ export default function({ getService }: FtrProviderContext) {
duration: 1000000,
},
kibana: {
namespace: 'default',
saved_objects: [
{
namespace: 'default',
type: 'event_log_test',
id,
},
Expand Down

0 comments on commit 28ce219

Please sign in to comment.