Skip to content

Commit

Permalink
[Build] restore kibana index (#374)
Browse files Browse the repository at this point in the history
* [Build] restore kibana index

Restoring the index from .opensearch_dashboards to .kibana and then
updated the tests. This is allowable because this is for functional
purposes and for clusters/plugins that will migrate to Dashboards.
Their index will not require re-indexing for 1.0.0 and won't require
migration after further updates.
Signed-off-by: Kawika Avilla <[email protected]>

* [Tests] updates tests for consistency

This doesn't have impact on the results of tests but to keep
consistency in the index name these updates were missed.

Signed-off-by: Kawika Avilla <[email protected]>
  • Loading branch information
kavilla authored May 26, 2021
1 parent 747ef8e commit 963b640
Show file tree
Hide file tree
Showing 119 changed files with 191 additions and 198 deletions.
4 changes: 2 additions & 2 deletions packages/osd-opensearch-archiver/src/actions/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ export async function loadAction({
});

// If we affected the OpenSearch Dashboards index, we need to ensure it's migrated...
if (Object.keys(result).some((k) => k.startsWith('.opensearch_dashboards'))) {
if (Object.keys(result).some((k) => k.startsWith('.kibana'))) {
await migrateOpenSearchDashboardsIndex({ client, osdClient });

if (opensearchDashboardsPluginIds.includes('spaces')) {
await createDefaultSpace({ client, index: '.opensearch_dashboards' });
await createDefaultSpace({ client, index: '.kibana' });
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,9 @@ export function createGenerateDocRecordsStream({
this.push({
type: 'doc',
value: {
// always rewrite the .opensearch_dashboards_* index to .opensearch_dashboards_1 so that
// always rewrite the .kibana_* index to .kibana_1 so that
// when it is loaded it can skip migration, if possible
index: hit._index.startsWith('.opensearch_dashboards')
? '.opensearch_dashboards_1'
: hit._index,
index: hit._index.startsWith('.kibana') ? '.kibana_1' : hit._index,
type: hit._type,
id: hit._id,
source: hit._source,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function createCreateIndexStream({

// Determine if the mapping belongs to a pre-7.0 instance, for BWC tests, mainly
const isPre7Mapping = !!mappings && Object.keys(mappings).length > 0 && !mappings.properties;
const isOpenSearchDashboards = index.startsWith('.opensearch_dashboards');
const isOpenSearchDashboards = index.startsWith('.kibana');

async function attemptToCreate(attemptNumber = 1) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function createDeleteIndexStream(
if (!record || record.type === 'index') {
const { index } = record.value;

if (index.startsWith('.opensearch_dashboards')) {
if (index.startsWith('.kibana')) {
await cleanOpenSearchDashboardsIndices({
client,
stats,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,9 @@ export function createGenerateIndexRecordsStream(client: Client, stats: Stats) {
this.push({
type: 'index',
value: {
// always rewrite the .opensearch_dashboards_* index to .opensearch_dashboards_1 so that
// always rewrite the .kibana_* index to .kibana_1 so that
// when it is loaded it can skip migration, if possible
index: index.startsWith('.opensearch_dashboards')
? '.opensearch_dashboards_1'
: index,
index: index.startsWith('.kibana') ? '.kibana_1' : index,
settings,
mappings,
aliases,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { Stats } from '../stats';
import { deleteIndex } from './delete_index';

/**
* Deletes all indices that start with `.opensearch_dashboards`
* Deletes all indices that start with `.kibana`
*/
export async function deleteOpenSearchDashboardsIndices({
client,
Expand Down Expand Up @@ -68,7 +68,7 @@ export async function deleteOpenSearchDashboardsIndices({
}

/**
* Given an opensearch client, and a logger, migrates the `.opensearch_dashboards` index. This
* Given an opensearch client, and a logger, migrates the `.kibana` index. This
* builds up an object that implements just enough of the osdMigrations interface
* as is required by migrations.
*/
Expand All @@ -82,7 +82,7 @@ export async function migrateOpenSearchDashboardsIndex({
// we allow dynamic mappings on the index, as some interceptors are accessing documents before
// the migration is actually performed. The migrator will put the value back to `strict` after migration.
await client.indices.putMapping({
index: '.opensearch_dashboards',
index: '.kibana',
body: {
dynamic: true,
},
Expand All @@ -93,17 +93,16 @@ export async function migrateOpenSearchDashboardsIndex({

/**
* Migrations mean that the OpenSearch Dashboards index will look something like:
* .opensearch_dashboards, .opensearch_dashboards_1, .opensearch_dashboards_323, etc. This finds all indices starting
* with .opensearch_dashboards, then filters out any that aren't actually OpenSearch Dashboards's core
* .kibana, .kibana_1, .kibana_323, etc. This finds all indices starting
* with .kibana then filters out any that aren't actually OpenSearch Dashboards's core
* index (e.g. we don't want to remove .opensearch_dashboards_task_manager or the like).
*/
async function fetchOpenSearchDashboardsIndices(client: Client) {
const opensearchDashboardsIndices = await client.cat.indices({
index: '.opensearch_dashboards*',
index: '.kibana*',
format: 'json',
});
const isOpenSearchDashboardsIndex = (index: string) =>
/^\.opensearch_dashboards(:?_\d*)?$/.test(index);
const isOpenSearchDashboardsIndex = (index: string) => /^\.kibana(:?_\d*)?$/.test(index);
return opensearchDashboardsIndices
.map((x: { index: string }) => x.index)
.filter(isOpenSearchDashboardsIndex);
Expand All @@ -130,7 +129,7 @@ export async function cleanOpenSearchDashboardsIndices({

while (true) {
const resp = await client.deleteByQuery({
index: `.opensearch_dashboards`,
index: `.kibana`,
body: {
query: {
bool: {
Expand Down Expand Up @@ -160,10 +159,10 @@ export async function cleanOpenSearchDashboardsIndices({

log.warning(
`since spaces are enabled, all objects other than the default space were deleted from ` +
`.opensearch_dashboards rather than deleting the whole index`
`.kibana rather than deleting the whole index`
);

stats.deletedIndex('.opensearch_dashboards');
stats.deletedIndex('.kibana');
}

export async function createDefaultSpace({ index, client }: { index: string; client: Client }) {
Expand Down
4 changes: 2 additions & 2 deletions scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ You can save existing data into an archive by using the `save` command:
node scripts/opensearch_archiver.js save <archive name for opensearch_dashboards data> [space separated list of index patterns to include]
```

You may want to store the .opensearch_dashboards index separate from data. Since adding a lot of data will bloat our repo size, we have many tests that reuse the same
data indices but use their own `.opensearch_dashboards` index.
You may want to store the .kibana index separate from data. Since adding a lot of data will bloat our repo size, we have many tests that reuse the same
data indices but use their own `.kibana` index.
12 changes: 6 additions & 6 deletions src/core/server/core_usage_data/core_usage_data_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('CoreUsageDataService', () => {
opensearch.client.asInternalUser.cat.indices.mockResolvedValueOnce({
body: [
{
name: '.opensearch_dashboards_task_manager_1',
name: '.kibana_task_manager_1',
'docs.count': 10,
'docs.deleted': 10,
'store.size': 1000,
Expand All @@ -96,7 +96,7 @@ describe('CoreUsageDataService', () => {
opensearch.client.asInternalUser.cat.indices.mockResolvedValueOnce({
body: [
{
name: '.opensearch_dashboards_1',
name: '.kibana_1',
'docs.count': 20,
'docs.deleted': 20,
'store.size': 2000,
Expand All @@ -106,8 +106,8 @@ describe('CoreUsageDataService', () => {
} as any);
const typeRegistry = savedObjectsServiceMock.createTypeRegistryMock();
typeRegistry.getAllTypes.mockReturnValue([
{ name: 'type 1', indexPattern: '.opensearch_dashboards' },
{ name: 'type 2', indexPattern: '.opensearch_dashboards_task_manager' },
{ name: 'type 1', indexPattern: '.kibana' },
{ name: 'type 2', indexPattern: '.kibana_task_manager' },
] as any);

const { getCoreUsageData } = service.start({
Expand Down Expand Up @@ -215,14 +215,14 @@ describe('CoreUsageDataService', () => {
"savedObjects": Object {
"indices": Array [
Object {
"alias": ".opensearch_dashboards_task_manager",
"alias": ".kibana_task_manager",
"docsCount": 10,
"docsDeleted": 10,
"primaryStoreSizeBytes": 2000,
"storeSizeBytes": 1000,
},
Object {
"alias": ".opensearch_dashboards_task_manager",
"alias": ".kibana_task_manager",
"docsCount": 20,
"docsDeleted": 20,
"primaryStoreSizeBytes": 4000,
Expand Down
6 changes: 2 additions & 4 deletions src/core/server/core_usage_data/core_usage_data_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export interface StartDeps {
* we need to map customized index names back to a "standard" index name.
*
* e.g. If a user configures `opensearchDashboards.index: .my_saved_objects` we want to the
* collected data to be grouped under `.opensearch_dashboards` not ".my_saved_objects".
* collected data to be grouped under `.kibana` not ".my_saved_objects".
*
* This is rather brittle, but the option to configure index names might go
* away completely anyway (see #60053).
Expand All @@ -73,9 +73,7 @@ const opensearchDashboardsOrTaskManagerIndex = (
index: string,
opensearchDashboardsConfigIndex: string
) => {
return index === opensearchDashboardsConfigIndex
? '.opensearch_dashboards'
: '.opensearch_dashboards_task_manager';
return index === opensearchDashboardsConfigIndex ? '.kibana' : '.kibana_task_manager';
};

export class CoreUsageDataService implements CoreService<void, CoreUsageDataStart> {
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/opensearch_dashboards_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const config = {
path: 'opensearchDashboards',
schema: schema.object({
enabled: schema.boolean({ defaultValue: true }),
index: schema.string({ defaultValue: '.opensearch_dashboards' }),
index: schema.string({ defaultValue: '.kibana' }),
autocompleteTerminateAfter: schema.duration({ defaultValue: 100000 }),
autocompleteTimeout: schema.duration({ defaultValue: 1000 }),
}),
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/plugins/plugin_context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('createPluginInitializerContext', () => {
.toPromise();
expect(configObject).toStrictEqual({
opensearchDashboards: {
index: '.opensearch_dashboards',
index: '.kibana',
autocompleteTerminateAfter: duration(100000),
autocompleteTimeout: duration(1000),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const createRegistry = (...types: Array<Partial<SavedObjectsType>>) => {

test('mappings without index pattern goes to default index', () => {
const result = createIndexMap({
opensearchDashboardsIndexName: '.opensearch_dashboards',
opensearchDashboardsIndexName: '.kibana',
registry: createRegistry({
name: 'type1',
namespaceType: 'single',
Expand All @@ -62,7 +62,7 @@ test('mappings without index pattern goes to default index', () => {
},
});
expect(result).toEqual({
'.opensearch_dashboards': {
'.kibana': {
typeMappings: {
type1: {
properties: {
Expand All @@ -78,7 +78,7 @@ test('mappings without index pattern goes to default index', () => {

test(`mappings with custom index pattern doesn't go to default index`, () => {
const result = createIndexMap({
opensearchDashboardsIndexName: '.opensearch_dashboards',
opensearchDashboardsIndexName: '.kibana',
registry: createRegistry({
name: 'type1',
namespaceType: 'single',
Expand Down Expand Up @@ -111,7 +111,7 @@ test(`mappings with custom index pattern doesn't go to default index`, () => {

test('creating a script gets added to the index pattern', () => {
const result = createIndexMap({
opensearchDashboardsIndexName: '.opensearch_dashboards',
opensearchDashboardsIndexName: '.kibana',
registry: createRegistry({
name: 'type1',
namespaceType: 'single',
Expand Down Expand Up @@ -145,7 +145,7 @@ test('creating a script gets added to the index pattern', () => {
});

test('throws when two scripts are defined for an index pattern', () => {
const defaultIndex = '.opensearch_dashboards';
const defaultIndex = '.kibana';
const registry = createRegistry(
{
name: 'type1',
Expand Down Expand Up @@ -182,6 +182,6 @@ test('throws when two scripts are defined for an index pattern', () => {
indexMap,
})
).toThrowErrorMatchingInlineSnapshot(
`"convertToAliasScript has been defined more than once for index pattern \\".opensearch_dashboards\\""`
`"convertToAliasScript has been defined more than once for index pattern \\".kibana\\""`
);
});
Loading

0 comments on commit 963b640

Please sign in to comment.