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

[dot-kibana-split] Address some PR remarks #155116

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
1,943 changes: 0 additions & 1,943 deletions cases.patch

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import {
import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal';
import type { DeprecationRegistryProvider } from '@kbn/core-deprecations-server';
import type { NodeInfo } from '@kbn/core-node-server';
import { MAIN_SAVED_OBJECT_INDEX, SavedObjectsIndexPatterns } from '@kbn/core-saved-objects-server';
import { MAIN_SAVED_OBJECT_INDEX, ALL_SAVED_OBJECT_INDICES } from '@kbn/core-saved-objects-server';
import { registerRoutes } from './routes';
import { calculateStatus$ } from './status';
import { registerCoreObjectTypes } from './object_types';
Expand Down Expand Up @@ -198,7 +198,7 @@ export class SavedObjectsService
},
getTypeRegistry: () => this.typeRegistry,
getDefaultIndex: () => MAIN_SAVED_OBJECT_INDEX,
getAllIndices: () => [...SavedObjectsIndexPatterns],
getAllIndices: () => [...ALL_SAVED_OBJECT_INDICES],
};
}

Expand Down Expand Up @@ -355,7 +355,7 @@ export class SavedObjectsService
});
return [...indices];
},
getAllIndices: () => [...SavedObjectsIndexPatterns],
getAllIndices: () => [...ALL_SAVED_OBJECT_INDICES],
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export {
ALERTING_CASES_SAVED_OBJECT_INDEX,
SECURITY_SOLUTION_SAVED_OBJECT_INDEX,
ANALYTICS_SAVED_OBJECT_INDEX,
SavedObjectsIndexPatterns,
ALL_SAVED_OBJECT_INDICES,
} from './src/saved_objects_index_pattern';
export type {
SavedObjectsType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const INGEST_SAVED_OBJECT_INDEX = `${MAIN_SAVED_OBJECT_INDEX}_ingest`;
export const ALERTING_CASES_SAVED_OBJECT_INDEX = `${MAIN_SAVED_OBJECT_INDEX}_alerting_cases`;
export const SECURITY_SOLUTION_SAVED_OBJECT_INDEX = `${MAIN_SAVED_OBJECT_INDEX}_security_solution`;
export const ANALYTICS_SAVED_OBJECT_INDEX = `${MAIN_SAVED_OBJECT_INDEX}_analytics`;
export const SavedObjectsIndexPatterns = [
export const ALL_SAVED_OBJECT_INDICES = [
MAIN_SAVED_OBJECT_INDEX,
TASK_MANAGER_SAVED_OBJECT_INDEX,
ALERTING_CASES_SAVED_OBJECT_INDEX,
Expand Down
10 changes: 5 additions & 5 deletions packages/kbn-es-archiver/src/actions/empty_kibana_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import type { Client } from '@elastic/elasticsearch';
import { ToolingLog } from '@kbn/tooling-log';
import { KbnClient } from '@kbn/test';

import { SavedObjectsIndexPatterns } from '@kbn/core-saved-objects-server';
import { migrateKibanaIndex, createStats, cleanKibanaIndices } from '../lib';
import { ALL_SAVED_OBJECT_INDICES } from '@kbn/core-saved-objects-server';
import { migrateSavedObjectIndices, createStats, cleanSavedObjectIndices } from '../lib';

export async function emptyKibanaIndexAction({
client,
Expand All @@ -24,8 +24,8 @@ export async function emptyKibanaIndexAction({
}) {
const stats = createStats('emptyKibanaIndex', log);

await cleanKibanaIndices({ client, stats, log });
await migrateKibanaIndex(kbnClient);
SavedObjectsIndexPatterns.forEach((indexPattern) => stats.createdIndex(indexPattern));
await cleanSavedObjectIndices({ client, stats, log });
await migrateSavedObjectIndices(kbnClient);
ALL_SAVED_OBJECT_INDICES.forEach((indexPattern) => stats.createdIndex(indexPattern));
return stats.toJSON();
}
4 changes: 2 additions & 2 deletions packages/kbn-es-archiver/src/actions/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
createParseArchiveStreams,
createCreateIndexStream,
createIndexDocRecordsStream,
migrateKibanaIndex,
migrateSavedObjectIndices,
Progress,
createDefaultSpace,
} from '../lib';
Expand Down Expand Up @@ -107,7 +107,7 @@ export async function loadAction({

// If we affected saved objects indices, we need to ensure they are migrated...
if (Object.keys(result).some((k) => k.startsWith(MAIN_SAVED_OBJECT_INDEX))) {
await migrateKibanaIndex(kbnClient);
await migrateSavedObjectIndices(kbnClient);
log.debug('[%s] Migrated Kibana index after loading Kibana data', name);

if (kibanaPluginIds.includes('spaces')) {
Expand Down
6 changes: 3 additions & 3 deletions packages/kbn-es-archiver/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export {
createCreateIndexStream,
createDeleteIndexStream,
createGenerateIndexRecordsStream,
deleteKibanaIndices,
migrateKibanaIndex,
cleanKibanaIndices,
deleteSavedObjectIndices,
migrateSavedObjectIndices,
cleanSavedObjectIndices,
createDefaultSpace,
} from './indices';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
* Side Public License, v 1.
*/

import type { deleteKibanaIndices } from './kibana_index';
import type { deleteSavedObjectIndices } from './kibana_index';

export const mockDeleteKibanaIndices = jest.fn() as jest.MockedFunction<typeof deleteKibanaIndices>;
export const mockdeleteSavedObjectIndices = jest.fn() as jest.MockedFunction<
typeof deleteSavedObjectIndices
>;

jest.mock('./kibana_index', () => ({
deleteKibanaIndices: mockDeleteKibanaIndices,
deleteSavedObjectIndices: mockdeleteSavedObjectIndices,
}));
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { mockDeleteKibanaIndices } from './create_index_stream.test.mock';
import { mockdeleteSavedObjectIndices } from './create_index_stream.test.mock';

import sinon from 'sinon';
import Chance from 'chance';
Expand All @@ -28,7 +28,7 @@ const chance = new Chance();
const log = createStubLogger();

beforeEach(() => {
mockDeleteKibanaIndices.mockClear();
mockdeleteSavedObjectIndices.mockClear();
});

describe('esArchiver: createCreateIndexStream()', () => {
Expand Down Expand Up @@ -187,7 +187,7 @@ describe('esArchiver: createCreateIndexStream()', () => {
});
});

describe('deleteKibanaIndices', () => {
describe('deleteSavedObjectIndices', () => {
function doTest(...indices: string[]) {
return createPromiseFromStreams([
createListStream(indices.map((index) => createStubIndexRecord(index))),
Expand All @@ -199,15 +199,15 @@ describe('esArchiver: createCreateIndexStream()', () => {
it('does not delete Kibana indices for indexes that do not start with .kibana', async () => {
await doTest('.foo');

expect(mockDeleteKibanaIndices).not.toHaveBeenCalled();
expect(mockdeleteSavedObjectIndices).not.toHaveBeenCalled();
});

it('deletes Kibana indices at most once for indices that start with .kibana', async () => {
// If we are loading the main Kibana index, we should delete all Kibana indices for backwards compatibility reasons.
await doTest('.kibana_7.16.0_001', '.kibana_task_manager_7.16.0_001');

expect(mockDeleteKibanaIndices).toHaveBeenCalledTimes(1);
expect(mockDeleteKibanaIndices).toHaveBeenCalledWith(
expect(mockdeleteSavedObjectIndices).toHaveBeenCalledTimes(1);
expect(mockdeleteSavedObjectIndices).toHaveBeenCalledWith(
expect.not.objectContaining({ onlyTaskManager: true })
);
});
Expand All @@ -216,8 +216,8 @@ describe('esArchiver: createCreateIndexStream()', () => {
// If we are loading the Kibana task manager index, we should only delete that index, not any other Kibana indices.
await doTest('.kibana_task_manager_7.16.0_001', '.kibana_task_manager_7.16.0_002');

expect(mockDeleteKibanaIndices).toHaveBeenCalledTimes(1);
expect(mockDeleteKibanaIndices).toHaveBeenCalledWith(
expect(mockdeleteSavedObjectIndices).toHaveBeenCalledTimes(1);
expect(mockdeleteSavedObjectIndices).toHaveBeenCalledWith(
expect.objectContaining({ onlyTaskManager: true })
);
});
Expand All @@ -227,12 +227,12 @@ describe('esArchiver: createCreateIndexStream()', () => {
// So, we first delete only the Kibana task manager indices, then we wind up deleting all Kibana indices.
await doTest('.kibana_task_manager_7.16.0_001', '.kibana_7.16.0_001');

expect(mockDeleteKibanaIndices).toHaveBeenCalledTimes(2);
expect(mockDeleteKibanaIndices).toHaveBeenNthCalledWith(
expect(mockdeleteSavedObjectIndices).toHaveBeenCalledTimes(2);
expect(mockdeleteSavedObjectIndices).toHaveBeenNthCalledWith(
1,
expect.objectContaining({ onlyTaskManager: true })
);
expect(mockDeleteKibanaIndices).toHaveBeenNthCalledWith(
expect(mockdeleteSavedObjectIndices).toHaveBeenNthCalledWith(
2,
expect.not.objectContaining({ onlyTaskManager: true })
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
TASK_MANAGER_SAVED_OBJECT_INDEX,
} from '@kbn/core-saved-objects-server';
import { Stats } from '../stats';
import { deleteKibanaIndices } from './kibana_index';
import { deleteSavedObjectIndices } from './kibana_index';
import { deleteIndex } from './delete_index';
import { deleteDataStream } from './delete_data_stream';
import { ES_CLIENT_HEADERS } from '../../client_headers';
Expand Down Expand Up @@ -110,10 +110,10 @@ export function createCreateIndexStream({
async function attemptToCreate(attemptNumber = 1) {
try {
if (isKibana && !kibanaIndexAlreadyDeleted) {
await deleteKibanaIndices({ client, stats, log }); // delete all .kibana* indices
await deleteSavedObjectIndices({ client, stats, log }); // delete all .kibana* indices
kibanaIndexAlreadyDeleted = kibanaTaskManagerIndexAlreadyDeleted = true;
} else if (isKibanaTaskManager && !kibanaTaskManagerIndexAlreadyDeleted) {
await deleteKibanaIndices({ client, stats, onlyTaskManager: true, log }); // delete only .kibana_task_manager* indices
await deleteSavedObjectIndices({ client, stats, onlyTaskManager: true, log }); // delete only .kibana_task_manager* indices
kibanaTaskManagerIndexAlreadyDeleted = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ToolingLog } from '@kbn/tooling-log';
import { MAIN_SAVED_OBJECT_INDEX } from '@kbn/core-saved-objects-server';
import { Stats } from '../stats';
import { deleteIndex } from './delete_index';
import { cleanKibanaIndices } from './kibana_index';
import { cleanSavedObjectIndices } from './kibana_index';
import { deleteDataStream } from './delete_data_stream';

export function createDeleteIndexStream(client: Client, stats: Stats, log: ToolingLog) {
Expand All @@ -30,7 +30,7 @@ export function createDeleteIndexStream(client: Client, stats: Stats, log: Tooli
const { index } = record.value;

if (index.startsWith(MAIN_SAVED_OBJECT_INDEX)) {
await cleanKibanaIndices({ client, stats, log });
await cleanSavedObjectIndices({ client, stats, log });
} else {
await deleteIndex({ client, stats, log, index });
}
Expand Down
6 changes: 3 additions & 3 deletions packages/kbn-es-archiver/src/lib/indices/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export { createCreateIndexStream } from './create_index_stream';
export { createDeleteIndexStream } from './delete_index_stream';
export { createGenerateIndexRecordsStream } from './generate_index_records_stream';
export {
migrateKibanaIndex,
deleteKibanaIndices,
cleanKibanaIndices,
migrateSavedObjectIndices,
deleteSavedObjectIndices,
cleanSavedObjectIndices,
createDefaultSpace,
} from './kibana_index';
16 changes: 8 additions & 8 deletions packages/kbn-es-archiver/src/lib/indices/kibana_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ToolingLog } from '@kbn/tooling-log';
import { KbnClient } from '@kbn/test';
import {
MAIN_SAVED_OBJECT_INDEX,
SavedObjectsIndexPatterns,
ALL_SAVED_OBJECT_INDICES,
TASK_MANAGER_SAVED_OBJECT_INDEX,
} from '@kbn/core-saved-objects-server';
import { Stats } from '../stats';
Expand All @@ -23,7 +23,7 @@ import { ES_CLIENT_HEADERS } from '../../client_headers';
/**
* Deletes all saved object indices, or if onlyTaskManager==true, it deletes task_manager indices
*/
export async function deleteKibanaIndices({
export async function deleteSavedObjectIndices({
client,
stats,
onlyTaskManager = false,
Expand Down Expand Up @@ -66,7 +66,7 @@ export async function deleteKibanaIndices({
* builds up an object that implements just enough of the kbnMigrations interface
* as is required by migrations.
*/
export async function migrateKibanaIndex(kbnClient: KbnClient) {
export async function migrateSavedObjectIndices(kbnClient: KbnClient) {
await kbnClient.savedObjects.migrate();
}

Expand All @@ -83,8 +83,8 @@ export async function migrateKibanaIndex(kbnClient: KbnClient) {
* @returns boolean 'true' if the index is a Kibana saved object index.
*/

const LEGACY_INDICES_REGEXP = new RegExp(`^(${SavedObjectsIndexPatterns.join('|')})(:?_\\d*)?$`);
const INDICES_REGEXP = new RegExp(`^(${SavedObjectsIndexPatterns.join('|')})_(pre)?\\d+.\\d+.\\d+`);
const LEGACY_INDICES_REGEXP = new RegExp(`^(${ALL_SAVED_OBJECT_INDICES.join('|')})(:?_\\d*)?$`);
const INDICES_REGEXP = new RegExp(`^(${ALL_SAVED_OBJECT_INDICES.join('|')})_(pre)?\\d+.\\d+.\\d+`);

function isSavedObjectIndex(index?: string): index is string {
return Boolean(index && (LEGACY_INDICES_REGEXP.test(index) || INDICES_REGEXP.test(index)));
Expand All @@ -107,7 +107,7 @@ async function fetchSavedObjectIndices(client: Client) {

const delay = (delayInMs: number) => new Promise((resolve) => setTimeout(resolve, delayInMs));

export async function cleanKibanaIndices({
export async function cleanSavedObjectIndices({
client,
stats,
log,
Expand All @@ -119,7 +119,7 @@ export async function cleanKibanaIndices({
while (true) {
const resp = await client.deleteByQuery(
{
index: SavedObjectsIndexPatterns,
index: ALL_SAVED_OBJECT_INDICES,
body: {
query: {
bool: {
Expand Down Expand Up @@ -156,7 +156,7 @@ export async function cleanKibanaIndices({
`.kibana rather than deleting the whole index`
);

SavedObjectsIndexPatterns.forEach((indexPattern) => stats.deletedIndex(indexPattern));
ALL_SAVED_OBJECT_INDICES.forEach((indexPattern) => stats.deletedIndex(indexPattern));
}

export async function createDefaultSpace({ index, client }: { index: string; client: Client }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
createRootWithCorePlugins,
type TestElasticsearchUtils,
} from '@kbn/core-test-helpers-kbn-server';
import { SavedObjectsIndexPatterns } from '@kbn/core-saved-objects-server';
import { ALL_SAVED_OBJECT_INDICES } from '@kbn/core-saved-objects-server';

const logFilePath = path.join(__dirname, '7.7.2_xpack_100k.log');

Expand Down Expand Up @@ -116,7 +116,7 @@ describe('migration from 7.7.2-xpack with 100k objects', () => {

it('copies all the document of the previous index to the new one', async () => {
const migratedIndexResponse = await esClient.count({
index: SavedObjectsIndexPatterns,
index: ALL_SAVED_OBJECT_INDICES,
});
const oldIndexResponse = await esClient.count({
index: '.kibana_1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Hapi from '@hapi/hapi';
import h2o2 from '@hapi/h2o2';
import { URL } from 'url';
import { SavedObject, SavedObjectsIndexPatterns } from '@kbn/core-saved-objects-server';
import { SavedObject, ALL_SAVED_OBJECT_INDICES } from '@kbn/core-saved-objects-server';
import type { ISavedObjectsRepository } from '@kbn/core-saved-objects-api-server';
import type { InternalCoreSetup, InternalCoreStart } from '@kbn/core-lifecycle-server-internal';
import { Root } from '@kbn/core-root-server-internal';
Expand Down Expand Up @@ -101,7 +101,7 @@ describe('404s from proxies', () => {
// register specific routes to modify the response and a catch-all to relay the request/response as-is

allCombinationsPermutations(
SavedObjectsIndexPatterns.map((indexPattern) => `${indexPattern}_${pkg.version}`)
ALL_SAVED_OBJECT_INDICES.map((indexPattern) => `${indexPattern}_${pkg.version}`)
)
.map((indices) => indices.join(','))
.forEach((kbnIndexPath) => {
Expand Down
4 changes: 2 additions & 2 deletions x-pack/test/api_integration/apis/security/index_fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { SavedObjectsIndexPatterns } from '@kbn/core-saved-objects-server';
import { ALL_SAVED_OBJECT_INDICES } from '@kbn/core-saved-objects-server';
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';

Expand All @@ -25,7 +25,7 @@ export default function ({ getService }: FtrProviderContext) {
describe('GET /internal/security/fields/{query}', () => {
it('should return a list of available index mapping fields', async () => {
await supertest
.get(`/internal/security/fields/${SavedObjectsIndexPatterns.join(',')}`)
.get(`/internal/security/fields/${ALL_SAVED_OBJECT_INDICES.join(',')}`)
.set('kbn-xsrf', 'xxx')
.send()
.expect(200)
Expand Down
4 changes: 2 additions & 2 deletions x-pack/test/api_integration/apis/security_solution/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type { TransportResult } from '@elastic/elasticsearch';
import type { Client } from '@elastic/elasticsearch';
import { JsonObject } from '@kbn/utility-types';
import { SavedObjectsIndexPatterns } from '@kbn/core-saved-objects-server';
import { ALL_SAVED_OBJECT_INDICES } from '@kbn/core-saved-objects-server';

export async function getSavedObjectFromES<T>(
es: Client,
Expand All @@ -18,7 +18,7 @@ export async function getSavedObjectFromES<T>(
): Promise<TransportResult<estypes.SearchResponse<T>, unknown>> {
return await es.search<T>(
{
index: SavedObjectsIndexPatterns,
index: ALL_SAVED_OBJECT_INDICES,
body: {
query: {
bool: {
Expand Down
4 changes: 2 additions & 2 deletions x-pack/test/common/lib/test_data_loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { LegacyUrlAlias } from '@kbn/core-saved-objects-base-server-internal';
import { SavedObjectsIndexPatterns } from '@kbn/core-saved-objects-server';
import { ALL_SAVED_OBJECT_INDICES } from '@kbn/core-saved-objects-server';
import Fs from 'fs/promises';
import { FtrProviderContext } from '../ftr_provider_context';

Expand Down Expand Up @@ -177,7 +177,7 @@ export function getTestDataLoader({ getService }: Pick<FtrProviderContext, 'getS

deleteAllSavedObjectsFromKibanaIndex: async () => {
await es.deleteByQuery({
index: SavedObjectsIndexPatterns,
index: ALL_SAVED_OBJECT_INDICES,
wait_for_completion: true,
body: {
// @ts-expect-error
Expand Down
Loading