Skip to content

Commit

Permalink
[backend] Improve init mapping mode to help platform migration
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-julien committed Jan 7, 2025
1 parent ace5d12 commit b293e2e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions opencti-platform/opencti-graphql/src/database/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ const OPENSEARCH_ENGINE = 'opensearch';
export const ES_MAX_CONCURRENCY = conf.get('elasticsearch:max_concurrency');
export const ES_DEFAULT_WILDCARD_PREFIX = booleanConf('elasticsearch:search_wildcard_prefix', false);
export const ES_DEFAULT_FUZZY = booleanConf('elasticsearch:search_fuzzy', false);
export const ES_INIT_RETRO_MAPPING_MIGRATION = booleanConf('elasticsearch:internal_init_retro_compatible_mapping_migration', false);
export const ES_INIT_MAPPING_MIGRATION = conf.get('elasticsearch:internal_init_mapping_migration') || 'off'; // off / old / standard
export const ES_IS_OLD_MAPPING = ES_INIT_MAPPING_MIGRATION === 'old';
export const ES_IS_INIT_MIGRATION = ES_INIT_MAPPING_MIGRATION === 'standard' || ES_IS_OLD_MAPPING;
export const ES_MINIMUM_FIXED_PAGINATION = 20; // When really low pagination is better by default
export const ES_DEFAULT_PAGINATION = conf.get('elasticsearch:default_pagination_result') || 500;
export const ES_MAX_PAGINATION = conf.get('elasticsearch:max_pagination_result') || 5000;
Expand Down Expand Up @@ -992,7 +994,7 @@ const updateIndexTemplate = async (name, mapping_properties) => {
index_patterns: [index_pattern],
template: {
settings: computeIndexSettings(name),
mappings: ES_INIT_RETRO_MAPPING_MIGRATION ? {
mappings: ES_IS_OLD_MAPPING ? {
properties: getRetroCompatibleMappings()
} : {
// Global option to prevent elastic to try any magic
Expand Down
12 changes: 6 additions & 6 deletions opencti-platform/opencti-graphql/src/initialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { v4 as uuidv4 } from 'uuid';
import semver from 'semver';
import { ENABLED_FEATURE_FLAGS, logApp, PLATFORM_VERSION } from './config/conf';
import { elUpdateIndicesMappings, ES_INIT_RETRO_MAPPING_MIGRATION, initializeSchema, searchEngineInit } from './database/engine';
import { elUpdateIndicesMappings, ES_INIT_MAPPING_MIGRATION, ES_IS_INIT_MIGRATION, initializeSchema, searchEngineInit } from './database/engine';
import { initializeAdminUser } from './config/providers';
import { initializeBucket, storageInit } from './database/file-storage';
import { enforceQueuesConsistency, initializeInternalQueues, rabbitMQIsAlive } from './database/rabbitmq';
Expand Down Expand Up @@ -98,9 +98,9 @@ const platformInit = async (withMarkings = true) => {
await initializeInternalQueues();
await initializeBucket();
await initializeSchema();
if (ES_INIT_RETRO_MAPPING_MIGRATION) {
logApp.warn('Templates and indices created with retro compatible mapping protection. '
+ 'This is only used to help indices reindex and migration. Please reindex, restart and then '
if (ES_IS_INIT_MIGRATION) {
logApp.warn(`Templates and indices created with ${ES_INIT_MAPPING_MIGRATION} compatible mapping protection. `
+ 'This is only used to help indices reindex and migration. For retro option, please reindex, restart and then '
+ 'trigger a rollover to secure the new indices');
process.exit(1);
}
Expand All @@ -110,9 +110,9 @@ const platformInit = async (withMarkings = true) => {
await initDefaultNotifiers(context);
} else {
logApp.info('[INIT] Existing platform detected, initialization...');
if (ES_INIT_RETRO_MAPPING_MIGRATION) {
if (ES_IS_INIT_MIGRATION) {
// noinspection ExceptionCaughtLocallyJS
throw ConfigurationError('Internal option internal_init_retro_compatible_mapping_migration is only available for new platform init');
throw ConfigurationError('Internal option internal_init_mapping_migration is only available for new platform init');
}
await refreshMappingsAndIndices();
await initializeInternalQueues();
Expand Down

0 comments on commit b293e2e

Please sign in to comment.