Skip to content

Commit

Permalink
do not install component templates for disabled registration contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
mgiota committed Nov 25, 2021
1 parent 59c3b6e commit c4b9e72
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface ConstructorOptions {
getClusterClient: () => Promise<ElasticsearchClient>;
logger: Logger;
isWriteEnabled: boolean;
disabledRegistrationContexts: string[];
}

export class ResourceInstaller {
Expand All @@ -39,9 +40,11 @@ export class ResourceInstaller {
): Promise<void> {
try {
const installResources = async (): Promise<void> => {
const { logger, isWriteEnabled } = this.options;

if (!isWriteEnabled) {
const { logger, isWriteEnabled, disabledRegistrationContexts } = this.options;
const isResourceDisabled = disabledRegistrationContexts.some((registrationContext) =>
resources.includes(registrationContext)
);
if (!isWriteEnabled || isResourceDisabled) {
logger.info(`Write is disabled; not installing ${resources}`);
return;
}
Expand Down Expand Up @@ -113,7 +116,6 @@ export class ResourceInstaller {
public async installIndexLevelResources(indexInfo: IndexInfo): Promise<void> {
await this.installWithTimeout(`resources for index ${indexInfo.baseName}`, async () => {
const { componentTemplates, ilmPolicy } = indexInfo.indexOptions;

if (ilmPolicy != null) {
await this.createOrUpdateLifecyclePolicy({
name: indexInfo.getIlmPolicyName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ export class RuleDataService implements IRuleDataService {
constructor(private readonly options: ConstructorOptions) {
this.indicesByBaseName = new Map();
this.indicesByFeatureId = new Map();

this.resourceInstaller = new ResourceInstaller({
getResourceName: (name) => this.getResourceName(name),
getClusterClient: options.getClusterClient,
logger: options.logger,
disabledRegistrationContexts: options.disabledRegistrationContexts,
isWriteEnabled: options.isWriteEnabled,
});

Expand Down

0 comments on commit c4b9e72

Please sign in to comment.