Skip to content

Commit

Permalink
[Archive Migrations] security_solution-timelines
Browse files Browse the repository at this point in the history
Add new kbn archive with an index pattern
taken from the es archive.

Change the test to use both es and kbn archives.
Since all these objects are loaded into a space,
just delete the space afterwards instead of
unloading with es archiver.

Helps with: elastic#102552
  • Loading branch information
wayneseymour committed Oct 14, 2022
1 parent bf4f62e commit 2b6e527
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 30 deletions.
35 changes: 29 additions & 6 deletions scripts/archive_migration_functions.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
standard_list="url,index-pattern,query,graph-workspace,tag,visualization,canvas-element,canvas-workpad,dashboard,search,lens,map,cases,uptime-dynamic-settings,osquery-saved-query,osquery-pack,infrastructure-ui-source,metrics-explorer-view,inventory-view,infrastructure-monitoring-log-view,apm-indices"
#!/bin/bash

# ??? Should we migrate
# x-pack/test/functional/es_archives/security_solution/timelines/7.15.0_space
# ### Yes, it needs migration
# ### Saved Object type(s) that we care about:
# index-pattern
# ### Test file(s) that use it:
# x-pack/test/api_integration/apis/security_solution/timeline_migrations.ts
# ### Config(s) that govern the test file(s):
# x-pack/test/api_integration/config.ts
# The other types it contains:
# config
# index-pattern
# siem-ui-timeline
# siem-ui-timeline-note
# siem-ui-timeline-pinned-event
# space

orig_archive="x-pack/test/functional/es_archives/banners/multispace"
new_archive="x-pack/test/functional/fixtures/kbn_archiver/banners/multi_space"
standard_list="url,index-pattern,query,graph-workspace,tag,visualization,canvas-element,canvas-workpad,dashboard,search,lens,map,cases,uptime-dynamic-settings,osquery-saved-query,osquery-pack,infrastructure-ui-source,metrics-explorer-view,inventory-view,infrastructure-monitoring-log-view,apm-indices"

# newArchives=("x-pack/test/functional/fixtures/kbn_archiver/dashboard/session_in_space")
orig_archive="x-pack/test/functional/es_archives/security_solution/timelines/7.15.0_space"
new_archive="x-pack/test/functional/fixtures/kbn_archiver/security_solution/timelines/7.15.0_space"

# testFiles=("x-pack/test/functional/apps/discover/preserve_url.ts")
testFiles=("x-pack/test/api_integration/apis/security_solution/timeline_migrations.ts")

test_config="x-pack/test/banners_functional/config.ts"
test_config="x-pack/test/api_integration/config.ts"

list_stragglers() {

Expand Down Expand Up @@ -366,6 +383,12 @@ save_kbn() {
# node scripts/kbn_archiver.js --config x-pack/test/spaces_api_integration/security_and_spaces/config_basic.ts save x-pack/test/functional/fixtures/kbn_archiver/saved_objects/default_space --type search,index-pattern,visualization,dashboard,lens,map,graph-workspace,query,tag,url,canvas-workpad
}

load_my_kbn() {
set -x
node scripts/kbn_archiver.js --config "$test_config" load my-es-archive.json
set +x
}

load_kbn() {
local space=${1:-default}
local archive=${2:-${new_archive}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import {
pinnedEventSavedObjectType,
timelineSavedObjectType,
} from '@kbn/security-solution-plugin/server/lib/timeline/saved_object_mappings';
import { TimelineWithoutExternalRefs } from '@kbn/security-solution-plugin/common/types/timeline';
import { NoteWithoutExternalRefs } from '@kbn/security-solution-plugin/common/types/timeline/note';
import {TimelineWithoutExternalRefs} from '@kbn/security-solution-plugin/common/types/timeline';
import {NoteWithoutExternalRefs} from '@kbn/security-solution-plugin/common/types/timeline/note';

import { PinnedEventWithoutExternalRefs } from '@kbn/security-solution-plugin/common/types/timeline/pinned_event';
import { FtrProviderContext } from '../../ftr_provider_context';
import { getSavedObjectFromES } from './utils';
import {PinnedEventWithoutExternalRefs} from '@kbn/security-solution-plugin/common/types/timeline/pinned_event';
import {FtrProviderContext} from '../../ftr_provider_context';
import {getSavedObjectFromES} from './utils';

interface TimelineWithoutSavedQueryId {
[timelineSavedObjectType]: TimelineWithoutExternalRefs;
Expand All @@ -30,12 +30,14 @@ interface PinnedEventWithoutTimelineId {
[pinnedEventSavedObjectType]: PinnedEventWithoutExternalRefs;
}

export default function ({ getService }: FtrProviderContext) {
export default function ({getService}: FtrProviderContext) {
const supertest = getService('supertest');

describe('Timeline migrations', () => {
describe.only('Timeline migrations', () => {
const esArchiver = getService('esArchiver');
const es = getService('es');
const kibanaServer = getService('kibanaServer');
const spacesService = getService('spaces');

describe('8.0 id migration', () => {
const resolveWithSpaceApi = '/s/awesome-space/api/timeline/resolve';
Expand All @@ -44,19 +46,18 @@ export default function ({ getService }: FtrProviderContext) {
await esArchiver.load(
'x-pack/test/functional/es_archives/security_solution/timelines/7.15.0_space'
);
});

after(async () => {
await esArchiver.unload(
'x-pack/test/functional/es_archives/security_solution/timelines/7.15.0_space'
await kibanaServer.importExport.load(
'x-pack/test/functional/fixtures/kbn_archiver/security_solution/timelines/7.15.0_space', {space: 'awesome-space'}
);
});

after(async () => await spacesService.delete('awesome-space'));

describe('resolve', () => {
it('should return an aliasMatch outcome', async () => {
const resp = await supertest
.get(resolveWithSpaceApi)
.query({ id: '1e2e9850-25f8-11ec-a981-b77847c6ef30' });
.query({id: '1e2e9850-25f8-11ec-a981-b77847c6ef30'});

expect(resp.body.data.outcome).to.be('aliasMatch');
expect(resp.body.data.alias_target_id).to.not.be(undefined);
Expand All @@ -67,15 +68,15 @@ export default function ({ getService }: FtrProviderContext) {
it('should return the notes with the correct eventId', async () => {
const resp = await supertest
.get(resolveWithSpaceApi)
.query({ id: '1e2e9850-25f8-11ec-a981-b77847c6ef30' });
.query({id: '1e2e9850-25f8-11ec-a981-b77847c6ef30'});

expect(resp.body.data.timeline.notes[0].eventId).to.be('StU_UXwBAowmaxx6YdiS');
});

it('should return notes with the timelineId matching the resolved timeline id', async () => {
const resp = await supertest
.get(resolveWithSpaceApi)
.query({ id: '1e2e9850-25f8-11ec-a981-b77847c6ef30' });
.query({id: '1e2e9850-25f8-11ec-a981-b77847c6ef30'});

expect(resp.body.data.timeline.notes[0].timelineId).to.be(
resp.body.data.timeline.savedObjectId
Expand All @@ -90,7 +91,7 @@ export default function ({ getService }: FtrProviderContext) {
it('should pinned events with eventId', async () => {
const resp = await supertest
.get(resolveWithSpaceApi)
.query({ id: '1e2e9850-25f8-11ec-a981-b77847c6ef30' });
.query({id: '1e2e9850-25f8-11ec-a981-b77847c6ef30'});

expect(resp.body.data.timeline.pinnedEventsSaveObject[0].eventId).to.be(
'StU_UXwBAowmaxx6YdiS'
Expand All @@ -100,7 +101,7 @@ export default function ({ getService }: FtrProviderContext) {
it('should return pinned events with the timelineId matching request id', async () => {
const resp = await supertest
.get(resolveWithSpaceApi)
.query({ id: '1e2e9850-25f8-11ec-a981-b77847c6ef30' });
.query({id: '1e2e9850-25f8-11ec-a981-b77847c6ef30'});

expect(resp.body.data.timeline.pinnedEventsSaveObject[0].timelineId).to.be(
resp.body.data.timeline.savedObjectId
Expand Down Expand Up @@ -149,15 +150,15 @@ export default function ({ getService }: FtrProviderContext) {
it('preserves the eventId in the saved object after migration', async () => {
const resp = await supertest
.get('/api/timeline')
.query({ id: '6484cc90-126e-11ec-83d2-db1096c73738' });
.query({id: '6484cc90-126e-11ec-83d2-db1096c73738'});

expect(resp.body.data.getOneTimeline.notes[0].eventId).to.be('Edo00XsBEVtyvU-8LGNe');
});

it('returns the timelineId in the response', async () => {
const resp = await supertest
.get('/api/timeline')
.query({ id: '6484cc90-126e-11ec-83d2-db1096c73738' });
.query({id: '6484cc90-126e-11ec-83d2-db1096c73738'});

expect(resp.body.data.getOneTimeline.notes[0].timelineId).to.be(
'6484cc90-126e-11ec-83d2-db1096c73738'
Expand All @@ -174,7 +175,7 @@ export default function ({ getService }: FtrProviderContext) {
es,
timelineSavedObjectType,
{
ids: { values: ['siem-ui-timeline:8dc70950-1012-11ec-9ad3-2d7c6600c0f7'] },
ids: {values: ['siem-ui-timeline:8dc70950-1012-11ec-9ad3-2d7c6600c0f7']},
}
);

Expand All @@ -186,15 +187,15 @@ export default function ({ getService }: FtrProviderContext) {
it('preserves the title in the saved object after migration', async () => {
const resp = await supertest
.get('/api/timeline')
.query({ id: '8dc70950-1012-11ec-9ad3-2d7c6600c0f7' });
.query({id: '8dc70950-1012-11ec-9ad3-2d7c6600c0f7'});

expect(resp.body.data.getOneTimeline.title).to.be('Awesome Timeline');
});

it('returns the savedQueryId in the response', async () => {
const resp = await supertest
.get('/api/timeline')
.query({ id: '8dc70950-1012-11ec-9ad3-2d7c6600c0f7' });
.query({id: '8dc70950-1012-11ec-9ad3-2d7c6600c0f7'});

expect(resp.body.data.getOneTimeline.savedQueryId).to.be("It's me");
});
Expand Down Expand Up @@ -226,7 +227,7 @@ export default function ({ getService }: FtrProviderContext) {
it('preserves the eventId in the saved object after migration', async () => {
const resp = await supertest
.get('/api/timeline')
.query({ id: '6484cc90-126e-11ec-83d2-db1096c73738' });
.query({id: '6484cc90-126e-11ec-83d2-db1096c73738'});

expect(resp.body.data.getOneTimeline.pinnedEventsSaveObject[0].eventId).to.be(
'DNo00XsBEVtyvU-8LGNe'
Expand All @@ -239,7 +240,7 @@ export default function ({ getService }: FtrProviderContext) {
it('returns the timelineId in the response', async () => {
const resp = await supertest
.get('/api/timeline')
.query({ id: '6484cc90-126e-11ec-83d2-db1096c73738' });
.query({id: '6484cc90-126e-11ec-83d2-db1096c73738'});

expect(resp.body.data.getOneTimeline.pinnedEventsSaveObject[0].timelineId).to.be(
'6484cc90-126e-11ec-83d2-db1096c73738'
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"attributes": {
"fieldAttrs": "{}",
"fields": "[]",
"runtimeFieldMap": "{}",
"timeFieldName": "",
"title": ".kibana_7.15.0",
"typeMeta": "{}"
},
"coreMigrationVersion": "8.6.0",
"id": "cf0a7895-d367-5eff-9d71-8d6b58b0b5d9",
"migrationVersion": {
"index-pattern": "8.0.0"
},
"originId": "4f57d680-25f3-11ec-a981-b77847c6ef30",
"references": [],
"type": "index-pattern",
"updated_at": "2021-10-05T15:45:48.019Z",
"version": "WzIyLDJd"
}

0 comments on commit 2b6e527

Please sign in to comment.