Skip to content

Commit

Permalink
Pass logGroup rather than all log settings
Browse files Browse the repository at this point in the history
The trade off here is that we won't allow users to control the stream properties.
  • Loading branch information
Mitch Lloyd committed Feb 7, 2021
1 parent 36f9eb9 commit 5742d0a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 95 deletions.
51 changes: 6 additions & 45 deletions packages/@aws-cdk/aws-kinesisanalytics-flink/lib/application.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import * as iam from '@aws-cdk/aws-iam';
import * as ka from '@aws-cdk/aws-kinesisanalytics';
import * as kms from '@aws-cdk/aws-kms';
import * as logs from '@aws-cdk/aws-logs';
import * as core from '@aws-cdk/core';
import { Construct } from 'constructs';
import { ApplicationCode } from './application-code';
import { environmentProperties } from './private/environment-properties';
import { flinkApplicationConfiguration } from './private/flink-application-configuration';
import { validateFlinkApplicationProps as validateApplicationProps } from './private/validation';
import { LogLevel as LogLevel, MetricsLevel as MetricsLevel, PropertyGroups, Runtime as Runtime } from './types';
import { LogLevel, MetricsLevel, PropertyGroups, Runtime } from './types';

/**
* An interface expressing the public properties on both an imported and
Expand Down Expand Up @@ -178,39 +177,11 @@ export interface ApplicationProps {
readonly removalPolicy?: core.RemovalPolicy;

/**
* How long to retain logs.
* The log group to send log entries to.
*
* @default two years
* @default CDK's default LogGroup
*/
readonly logRetention?: core.Duration;

/**
* Whether to keep or delete logs when removing a FlinkApplication.
*
* @default RETAIN
*/
readonly logRemovalPolicy?: core.RemovalPolicy;

/**
* The name of the log group for CloudWatch logs.
*
* @default Cloudformation generated
*/
readonly logGroupName?: string;

/**
* The name of the log stream for CloudWatch logs.
*
* @default Cloudformation generated
*/
readonly logStreamName?: string;

/**
* The KMS encryption key to use for CloudWatch logs.
*
* @default No encryption used
*/
readonly logEncryptionKey?: kms.IKey;
readonly logGroup?: logs.LogGroup;
}

/**
Expand Down Expand Up @@ -314,18 +285,8 @@ export class Application extends ApplicationBase {
});
resource.node.addDependency(this.role);

const logGroup = new logs.LogGroup(this, 'LogGroup', {
logGroupName: props.logGroupName,
retention: props.logRetention?.toDays(),
removalPolicy: props.logRemovalPolicy,
encryptionKey: props.logEncryptionKey,
});

const logStream = new logs.LogStream(this, 'LogStream', {
logGroup,
logStreamName: props.logStreamName,
removalPolicy: props.logRemovalPolicy,
});
const logGroup = props.logGroup ?? new logs.LogGroup(this, 'LogGroup');
const logStream = new logs.LogStream(this, 'LogStream', { logGroup });

/* Permit logging */

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { arrayWith, objectLike, ResourcePart } from '@aws-cdk/assert';
import '@aws-cdk/assert/jest';
import * as iam from '@aws-cdk/aws-iam';
import * as kms from '@aws-cdk/aws-kms';
import * as logs from '@aws-cdk/aws-logs';
import * as s3 from '@aws-cdk/aws-s3';
import * as core from '@aws-cdk/core';
import * as path from 'path';
Expand Down Expand Up @@ -481,60 +481,16 @@ describe('Application', () => {
}, ResourcePart.CompleteDefinition);
});

test('logRetentionDays setting', () => {
test('logGroup setting', () => {
new flink.Application(stack, 'FlinkApplication', {
...requiredProps,
logRetention: core.Duration.days(5),
logGroup: new logs.LogGroup(stack, 'LogGroup', {
logGroupName: 'custom',
}),
});

expect(stack).toHaveResource('AWS::Logs::LogGroup', {
RetentionInDays: 5,
});
});

test('logRemovalPolicy setting', () => {
new flink.Application(stack, 'FlinkApplication', {
...requiredProps,
logRemovalPolicy: core.RemovalPolicy.DESTROY,
});

expect(stack).toHaveResourceLike('AWS::Logs::LogGroup', {
UpdateReplacePolicy: 'Delete',
DeletionPolicy: 'Delete',
}, ResourcePart.CompleteDefinition);
});

test('logGroupName setting', () => {
new flink.Application(stack, 'FlinkApplication', {
...requiredProps,
logGroupName: 'my-group',
});

expect(stack).toHaveResourceLike('AWS::Logs::LogGroup', {
LogGroupName: 'my-group',
});
});

test('logStreamName setting', () => {
new flink.Application(stack, 'FlinkApplication', {
...requiredProps,
logStreamName: 'my-stream',
});

expect(stack).toHaveResourceLike('AWS::Logs::LogStream', {
LogStreamName: 'my-stream',
});
});

test('logEncryptionKey setting', () => {
const key = new kms.Key(stack, 'Key');
new flink.Application(stack, 'FlinkApplication', {
...requiredProps,
logEncryptionKey: key,
});

expect(stack).toHaveResourceLike('AWS::Logs::LogGroup', {
KmsKeyId: stack.resolve(key.keyArn),
LogGroupName: 'custom',
});
});

Expand Down

0 comments on commit 5742d0a

Please sign in to comment.