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

fix(opensearch): cannot disable cluster logging #29205

Merged
merged 8 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
63 changes: 33 additions & 30 deletions packages/aws-cdk-lib/aws-opensearchservice/lib/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1711,6 +1711,7 @@ export class Domain extends DomainBase implements IDomain, ec2.IConnectable {

// Setup logging
const logGroups: logs.ILogGroup[] = [];
const logPublishing: Record<string, any> = {};

if (props.logging?.slowSearchLogEnabled) {
this.slowSearchLogGroup = props.logging.slowSearchLogGroup ??
Expand All @@ -1719,6 +1720,14 @@ export class Domain extends DomainBase implements IDomain, ec2.IConnectable {
});

logGroups.push(this.slowSearchLogGroup);
logPublishing.SEARCH_SLOW_LOGS = {
enabled: true,
cloudWatchLogsLogGroupArn: this.slowSearchLogGroup.logGroupArn,
};
} else if (props.logging?.slowSearchLogEnabled === false) {
logPublishing.SEARCH_SLOW_LOGS = {
enabled: false,
};
};

if (props.logging?.slowIndexLogEnabled) {
Expand All @@ -1728,6 +1737,14 @@ export class Domain extends DomainBase implements IDomain, ec2.IConnectable {
});

logGroups.push(this.slowIndexLogGroup);
logPublishing.INDEX_SLOW_LOGS = {
enabled: true,
cloudWatchLogsLogGroupArn: this.slowIndexLogGroup.logGroupArn,
};
} else if (props.logging?.slowIndexLogEnabled === false) {
logPublishing.INDEX_SLOW_LOGS = {
enabled: false,
};
};

if (props.logging?.appLogEnabled) {
Expand All @@ -1737,6 +1754,14 @@ export class Domain extends DomainBase implements IDomain, ec2.IConnectable {
});

logGroups.push(this.appLogGroup);
logPublishing.ES_APPLICATION_LOGS = {
enabled: true,
cloudWatchLogsLogGroupArn: this.appLogGroup.logGroupArn,
};
} else if (props.logging?.appLogEnabled === false) {
logPublishing.ES_APPLICATION_LOGS = {
enabled: false,
};
};

if (props.logging?.auditLogEnabled) {
Expand All @@ -1746,6 +1771,14 @@ export class Domain extends DomainBase implements IDomain, ec2.IConnectable {
});

logGroups.push(this.auditLogGroup);
logPublishing.AUDIT_LOGS = {
enabled: this.auditLogGroup != null,
cloudWatchLogsLogGroupArn: this.auditLogGroup?.logGroupArn,
};
} else if (props.logging?.auditLogEnabled === false) {
logPublishing.AUDIT_LOGS = {
enabled: false,
};
};

let logGroupResourcePolicy: LogGroupResourcePolicy | null = null;
Expand All @@ -1766,36 +1799,6 @@ export class Domain extends DomainBase implements IDomain, ec2.IConnectable {
});
}

const logPublishing: Record<string, any> = {};

if (this.appLogGroup) {
logPublishing.ES_APPLICATION_LOGS = {
enabled: true,
cloudWatchLogsLogGroupArn: this.appLogGroup.logGroupArn,
};
}

if (this.slowSearchLogGroup) {
logPublishing.SEARCH_SLOW_LOGS = {
enabled: true,
cloudWatchLogsLogGroupArn: this.slowSearchLogGroup.logGroupArn,
};
}

if (this.slowIndexLogGroup) {
logPublishing.INDEX_SLOW_LOGS = {
enabled: true,
cloudWatchLogsLogGroupArn: this.slowIndexLogGroup.logGroupArn,
};
}

if (this.auditLogGroup) {
logPublishing.AUDIT_LOGS = {
enabled: this.auditLogGroup != null,
cloudWatchLogsLogGroupArn: this.auditLogGroup?.logGroupArn,
};
}

let customEndpointCertificate: acm.ICertificate | undefined;
if (props.customEndpoint) {
if (props.customEndpoint.certificate) {
Expand Down
84 changes: 84 additions & 0 deletions packages/aws-cdk-lib/aws-opensearchservice/test/domain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,90 @@ each([testedOpenSearchVersions]).describe('log groups', (engineVersion) => {
},
});
});

test('can disable application logs', () => {
new Domain(stack, 'Domain1', {
version: engineVersion,
logging: {
appLogEnabled: false,
},
});

Template.fromStack(stack).resourceCountIs('Custom::CloudwatchLogResourcePolicy', 0);
Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', {
LogPublishingOptions: {
ES_APPLICATION_LOGS: {
Enabled: false,
},
AUDIT_LOGS: Match.absent(),
SEARCH_SLOW_LOGS: Match.absent(),
INDEX_SLOW_LOGS: Match.absent(),
},
});
});

test('can disable audit logs', () => {
new Domain(stack, 'Domain1', {
version: engineVersion,
logging: {
auditLogEnabled: false,
},
});

Template.fromStack(stack).resourceCountIs('Custom::CloudwatchLogResourcePolicy', 0);
Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', {
LogPublishingOptions: {
ES_APPLICATION_LOGS: Match.absent(),
AUDIT_LOGS: {
Enabled: false,
},
SEARCH_SLOW_LOGS: Match.absent(),
INDEX_SLOW_LOGS: Match.absent(),
},
});
});

test('can disable slow search logs', () => {
new Domain(stack, 'Domain1', {
version: engineVersion,
logging: {
slowSearchLogEnabled: false,
},
});

Template.fromStack(stack).resourceCountIs('Custom::CloudwatchLogResourcePolicy', 0);
Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', {
LogPublishingOptions: {
ES_APPLICATION_LOGS: Match.absent(),
AUDIT_LOGS: Match.absent(),
SEARCH_SLOW_LOGS: {
Enabled: false,
},
INDEX_SLOW_LOGS: Match.absent(),
},
});
});

test('can disable slow index logs', () => {
new Domain(stack, 'Domain1', {
version: engineVersion,
logging: {
slowIndexLogEnabled: false,
},
});

Template.fromStack(stack).resourceCountIs('Custom::CloudwatchLogResourcePolicy', 0);
Template.fromStack(stack).hasResourceProperties('AWS::OpenSearchService::Domain', {
LogPublishingOptions: {
ES_APPLICATION_LOGS: Match.absent(),
AUDIT_LOGS: Match.absent(),
SEARCH_SLOW_LOGS: Match.absent(),
INDEX_SLOW_LOGS: {
Enabled: false,
},
},
});
});
});

each(testedOpenSearchVersions).describe('grants', (engineVersion) => {
Expand Down
Loading