Skip to content

Commit

Permalink
[Rename] .opensearch-dashboards index to .opensearch_dashboards (#37)…
Browse files Browse the repository at this point in the history
… (#188)

* [Rename] .opensearch-dashboards index to .opensearch_dashboards (#37)

Signed-off-by: Bishoy Boktor <boktorbb@amazon.com>

* Address PR comments

Signed-off-by: Bishoy Boktor <boktorbb@amazon.com>

* Address PR comments

Signed-off-by: Bishoy Boktor <boktorbb@amazon.com>
  • Loading branch information
boktorbb authored and kavilla committed Mar 19, 2021
1 parent 9e3c146 commit a9ef387
Show file tree
Hide file tree
Showing 112 changed files with 239 additions and 239 deletions.
2 changes: 1 addition & 1 deletion config/opensearch_dashboards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

# OpenSearch Dashboards uses an index in OpenSearch to store saved searches, visualizations and
# dashboards. OpenSearch Dashboards creates a new index if the index doesn't already exist.
#opensearchDashboards.index: ".opensearch-dashboards"
#opensearchDashboards.index: ".opensearch_dashboards"

# The default application to load.
#opensearchDashboards.defaultAppId: "home"
Expand Down
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 @@ -107,11 +107,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('.opensearch_dashboards'))) {
await migrateOpenSearchDashboardsIndex({ client, osdClient });

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('opensearchArchiver: createGenerateDocRecordsStream()', () => {
await delay(200);
return {
_scroll_id: 'index1ScrollId',
hits: { total: 2, hits: [{ _id: 1, _index: '.opensearch-dashboards_foo' }] },
hits: { total: 2, hits: [{ _id: 1, _index: '.opensearch_dashboards_foo' }] },
};
},
async (name, params) => {
Expand Down Expand Up @@ -123,7 +123,7 @@ describe('opensearchArchiver: createGenerateDocRecordsStream()', () => {
{
type: 'doc',
value: {
index: '.opensearch-dashboards_1',
index: '.opensearch_dashboards_1',
type: undefined,
id: 1,
source: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ export function createGenerateDocRecordsStream({
this.push({
type: 'doc',
value: {
// always rewrite the .opensearch-dashboards_* index to .opensearch-dashboards_1 so that
// always rewrite the .opensearch_dashboards_* index to .opensearch_dashboards_1 so that
// when it is loaded it can skip migration, if possible
index: hit._index.startsWith('.opensearch-dashboards')
? '.opensearch-dashboards_1'
index: hit._index.startsWith('.opensearch_dashboards')
? '.opensearch_dashboards_1'
: hit._index,
type: hit._type,
id: hit._id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,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('.opensearch_dashboards');

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

if (index.startsWith('.opensearch-dashboards')) {
if (index.startsWith('.opensearch_dashboards')) {
await cleanOpenSearchDashboardsIndices({
client,
stats,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ 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 .opensearch_dashboards_* index to .opensearch_dashboards_1 so that
// when it is loaded it can skip migration, if possible
index: index.startsWith('.opensearch-dashboards')
? '.opensearch-dashboards_1'
index: index.startsWith('.opensearch_dashboards')
? '.opensearch_dashboards_1'
: index,
settings,
mappings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { Stats } from '../stats';
import { deleteIndex } from './delete_index';

/**
* Deletes all indices that start with `.opensearch-dashboards`
* Deletes all indices that start with `.opensearch_dashboards`
*/
export async function deleteOpenSearchDashboardsIndices({
client,
Expand Down Expand Up @@ -55,7 +55,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 `.opensearch_dashboards` index. This
* builds up an object that implements just enough of the osdMigrations interface
* as is required by migrations.
*/
Expand All @@ -69,7 +69,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: '.opensearch_dashboards',
body: {
dynamic: true,
},
Expand All @@ -80,17 +80,17 @@ 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
* index (e.g. we don't want to remove .opensearch-dashboards_task_manager or the 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
* 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: '.opensearch_dashboards*',
format: 'json',
});
const isOpenSearchDashboardsIndex = (index: string) =>
/^\.opensearch-dashboards(:?_\d*)?$/.test(index);
/^\.opensearch_dashboards(:?_\d*)?$/.test(index);
return opensearchDashboardsIndices
.map((x: { index: string }) => x.index)
.filter(isOpenSearchDashboardsIndex);
Expand All @@ -117,7 +117,7 @@ export async function cleanOpenSearchDashboardsIndices({

while (true) {
const resp = await client.deleteByQuery({
index: `.opensearch-dashboards`,
index: `.opensearch_dashboards`,
body: {
query: {
bool: {
Expand Down Expand Up @@ -147,10 +147,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`
`.opensearch_dashboards rather than deleting the whole index`
);

stats.deletedIndex('.opensearch-dashboards');
stats.deletedIndex('.opensearch_dashboards');
}

export async function createDefaultSpace({ index, client }: { index: string; client: Client }) {
Expand Down
4 changes: 2 additions & 2 deletions packages/osd-plugin-helpers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ When you're targeting versions before OpenSearch Dashboards 6.3, use the `@elast

## Configuration

`plugin-helpers` accepts a number of settings, which can be specified at runtime, or included in a `.opensearch-dashboards-plugin-helpers.json` file if you'd like to bundle those settings with your project.
`plugin-helpers` accepts a number of settings, which can be specified at runtime, or included in a `.opensearch_dashboards-plugin-helpers.json` file if you'd like to bundle those settings with your project.

It will also observe a `.opensearch-dashboards-plugin-helpers.dev.json`, much like OpenSearch Dashboards does, which we encourage you to add to your `.gitignore` file and use for local settings that you don't intend to share. These "dev" settings will override any settings in the normal json config.
It will also observe a `.opensearch_dashboards-plugin-helpers.dev.json`, much like OpenSearch Dashboards does, which we encourage you to add to your `.gitignore` file and use for local settings that you don't intend to share. These "dev" settings will override any settings in the normal json config.

All configuration setting listed below can simply can be included in the json config files. If you intend to inline the command, you will need to convert the setting to snake case (ie. `skipArchive` becomes `--skip-archive`).

Expand Down
2 changes: 1 addition & 1 deletion packages/osd-plugin-helpers/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const isArrayOfStrings = (v: any): v is string[] =>

export async function loadConfig(log: ToolingLog, plugin: Plugin): Promise<Config> {
try {
const path = Path.resolve(plugin.directory, '.opensearch-dashboards-plugin-helpers.json');
const path = Path.resolve(plugin.directory, '.opensearch_dashboards-plugin-helpers.json');
const file = await loadJsonFile(path);

if (!(typeof file === 'object' && file && !Array.isArray(file))) {
Expand Down
6 changes: 3 additions & 3 deletions scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ may also change based on those settings (for example if you are not running with
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]
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 .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.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('CoreUsageDataService', () => {
opensearch.client.asInternalUser.cat.indices.mockResolvedValueOnce({
body: [
{
name: '.opensearch-dashboards_1',
name: '.opensearch_dashboards_1',
'docs.count': 20,
'docs.deleted': 20,
'store.size': 2000,
Expand All @@ -93,7 +93,7 @@ describe('CoreUsageDataService', () => {
} as any);
const typeRegistry = savedObjectsServiceMock.createTypeRegistryMock();
typeRegistry.getAllTypes.mockReturnValue([
{ name: 'type 1', indexPattern: '.opensearch-dashboards' },
{ name: 'type 1', indexPattern: '.opensearch_dashboards' },
{ name: 'type 2', indexPattern: '.opensearch_dashboards_task_manager' },
] as any);

Expand Down Expand Up @@ -202,7 +202,7 @@ describe('CoreUsageDataService', () => {
"savedObjects": Object {
"indices": Array [
Object {
"alias": ".opensearch-dashboards",
"alias": ".opensearch_dashboards",
"docsCount": 10,
"docsDeleted": 10,
"primaryStoreSizeBytes": 2000,
Expand Down
4 changes: 2 additions & 2 deletions src/core/server/core_usage_data/core_usage_data_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,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 `.opensearch_dashboards` not ".my_saved_objects".
*
* This is rather brittle, but the option to configure index names might go
* away completely anyway (see #60053).
Expand All @@ -61,7 +61,7 @@ const opensearchDashboardsOrTaskManagerIndex = (
opensearchDashboardsConfigIndex: string
) => {
return index === opensearchDashboardsConfigIndex
? '.opensearch-dashboards'
? '.opensearch_dashboards'
: '.opensearch_dashboards_task_manager';
};

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 @@ -25,7 +25,7 @@ export const config = {
path: 'opensearchDashboards',
schema: schema.object({
enabled: schema.boolean({ defaultValue: true }),
index: schema.string({ defaultValue: '.opensearch-dashboards' }),
index: schema.string({ defaultValue: '.opensearch_dashboards' }),
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 @@ -83,7 +83,7 @@ describe('createPluginInitializerContext', () => {
.toPromise();
expect(configObject).toStrictEqual({
opensearchDashboards: {
index: '.opensearch-dashboards',
index: '.opensearch_dashboards',
autocompleteTerminateAfter: duration(100000),
autocompleteTimeout: duration(1000),
},
Expand Down
28 changes: 14 additions & 14 deletions src/core/server/saved_objects/migrations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ All of this happens prior to OpenSearch Dashboards serving any http requests.

Here is the gist of what happens if an index migration is necessary:

* If `.opensearch-dashboards` (or whatever the OpenSearch Dashboards index is named) is not an alias, it will be converted to one:
* Reindex `.opensearch-dashboards` into `.opensearch-dashboards_1`
* Delete `.opensearch-dashboards`
* Create an alias `.opensearch-dashboards` that points to `.opensearch-dashboards_1`
* Create a `.opensearch-dashboards_2` index
* Copy all documents from `.opensearch-dashboards_1` into `.opensearch-dashboards_2`, running them through any applicable migrations
* Point the `.opensearch-dashboards` alias to `.opensearch-dashboards_2`
* If `.opensearch_dashboards` (or whatever the OpenSearch Dashboards index is named) is not an alias, it will be converted to one:
* Reindex `.opensearch_dashboards` into `.opensearch_dashboards_1`
* Delete `.opensearch_dashboards`
* Create an alias `.opensearch_dashboards` that points to `.opensearch_dashboards_1`
* Create a `.opensearch_dashboards_2` index
* Copy all documents from `.opensearch_dashboards_1` into `.opensearch_dashboards_2`, running them through any applicable migrations
* Point the `.opensearch_dashboards` alias to `.opensearch_dashboards_2`

## Migrating OpenSearch Dashboards clusters

If OpenSearch Dashboards is being run in a cluster, migrations will be coordinated so that they only run on one OpenSearch Dashboards instance at a time. This is done in a fairly rudimentary way. Let's say we have two OpenSearch Dashboards instances, opensearch-dashboards-1 and opensearch-dashboards-2.

* opensearch-dashboards-1 and opensearch-dashboards-2 both start simultaneously and detect that the index requires migration
* opensearch-dashboards-1 begins the migration and creates index `.opensearch-dashboards_4`
* opensearch-dashboards-2 tries to begin the migration, but fails with the error `.opensearch-dashboards_4 already exists`
* opensearch-dashboards-1 begins the migration and creates index `.opensearch_dashboards_4`
* opensearch-dashboards-2 tries to begin the migration, but fails with the error `.opensearch_dashboards_4 already exists`
* opensearch-dashboards-2 logs that it failed to create the migration index, and instead begins polling
* Every few seconds, opensearch-dashboards-2 instance checks the `.opensearch-dashboards` index to see if it is done migrating
* Once `.opensearch-dashboards` is determined to be up to date, the opensearch-dashboards-2 instance continues booting
* Every few seconds, opensearch-dashboards-2 instance checks the `.opensearch_dashboards` index to see if it is done migrating
* Once `.opensearch_dashboards` is determined to be up to date, the opensearch-dashboards-2 instance continues booting

In this example, if the `.opensearch-dashboards_4` index existed prior to OpenSearch Dashboards booting, the entire migration process will fail, as all OpenSearch Dashboards instances will assume another instance is migrating to the `.opensearch-dashboards_4` index. This problem is only fixable by deleting the `.opensearch-dashboards_4` index.
In this example, if the `.opensearch_dashboards_4` index existed prior to OpenSearch Dashboards booting, the entire migration process will fail, as all OpenSearch Dashboards instances will assume another instance is migrating to the `.opensearch_dashboards_4` index. This problem is only fixable by deleting the `.opensearch_dashboards_4` index.

## Import / export

Expand Down Expand Up @@ -191,8 +191,8 @@ Note, the migrationVersion property has been added, and it contains information

The migrations source code is grouped into two folders:

* `core` - Contains index-agnostic, general migration logic, which could be reused for indices other than `.opensearch-dashboards`
* `opensearch-dashboards` - Contains a relatively light-weight wrapper around core, which provides `.opensearch-dashboards` index-specific logic
* `core` - Contains index-agnostic, general migration logic, which could be reused for indices other than `.opensearch_dashboards`
* `opensearch-dashboards` - Contains a relatively light-weight wrapper around core, which provides `.opensearch_dashboards` index-specific logic

Generally, the code eschews classes in favor of functions and basic data structures. The publicly exported code is all class-based, however, in an attempt to conform to OpenSearch Dashboards norms.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const createRegistry = (...types: Array<Partial<SavedObjectsType>>) => {

test('mappings without index pattern goes to default index', () => {
const result = createIndexMap({
opensearchDashboardsIndexName: '.opensearch-dashboards',
opensearchDashboardsIndexName: '.opensearch_dashboards',
registry: createRegistry({
name: 'type1',
namespaceType: 'single',
Expand All @@ -54,7 +54,7 @@ test('mappings without index pattern goes to default index', () => {
},
});
expect(result).toEqual({
'.opensearch-dashboards': {
'.opensearch_dashboards': {
typeMappings: {
type1: {
properties: {
Expand All @@ -70,7 +70,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: '.opensearch_dashboards',
registry: createRegistry({
name: 'type1',
namespaceType: 'single',
Expand Down Expand Up @@ -103,7 +103,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: '.opensearch_dashboards',
registry: createRegistry({
name: 'type1',
namespaceType: 'single',
Expand Down Expand Up @@ -137,7 +137,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 = '.opensearch_dashboards';
const registry = createRegistry(
{
name: 'type1',
Expand Down Expand Up @@ -174,6 +174,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 \\".opensearch_dashboards\\""`
);
});
Loading

0 comments on commit a9ef387

Please sign in to comment.