Skip to content

Commit

Permalink
feat(codeguruprofiler): add support for ComputePlatform in ProfilingG…
Browse files Browse the repository at this point in the history
…roup (aws#9391)

fixes aws#9285


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
SeekerWing authored Aug 14, 2020
1 parent 1c4eae8 commit 5a64bc5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
11 changes: 11 additions & 0 deletions packages/@aws-cdk/aws-codeguruprofiler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,14 @@ const publishAppRole = new Role(stack, 'PublishAppRole', {
const profilingGroup = new ProfilingGroup(stack, 'MyProfilingGroup');
profilingGroup.grantPublish(publishAppRole);
```

### Compute Platform configuration

Code Guru Profiler supports multiple compute environments.
They can be configured when creating a Profiling Group by using the `computePlatform` property:

```ts
const profilingGroup = new ProfilingGroup(stack, 'MyProfilingGroup', {
computePlatform: ComputePlatform.AWS_LAMBDA,
});
```
24 changes: 24 additions & 0 deletions packages/@aws-cdk/aws-codeguruprofiler/lib/profiling-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@ import { Grant, IGrantable } from '@aws-cdk/aws-iam';
import { Construct, IResource, Lazy, Resource, Stack } from '@aws-cdk/core';
import { CfnProfilingGroup } from './codeguruprofiler.generated';

/**
* The compute platform of the profiling group.
*/
export enum ComputePlatform {
/**
* Use AWS_LAMBDA if your application runs on AWS Lambda.
*/
AWS_LAMBDA = 'AWSLambda',

/**
* Use Default if your application runs on a compute platform that is not AWS Lambda,
* such an Amazon EC2 instance, an on-premises server, or a different platform.
*/
DEFAULT = 'Default',
}

/**
* IResource represents a Profiling Group.
*/
Expand Down Expand Up @@ -97,6 +113,13 @@ export interface ProfilingGroupProps {
*/
readonly profilingGroupName?: string;

/**
* The compute platform of the profiling group.
*
* @default ComputePlatform.DEFAULT
*/
readonly computePlatform?: ComputePlatform;

}

/**
Expand Down Expand Up @@ -158,6 +181,7 @@ export class ProfilingGroup extends ProfilingGroupBase {

const profilingGroup = new CfnProfilingGroup(this, 'ProfilingGroup', {
profilingGroupName: this.physicalName,
computePlatform: props.computePlatform,
});

this.profilingGroupName = this.getResourceNameAttribute(profilingGroup.ref);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@aws-cdk/assert';
import { expect, haveResourceLike } from '@aws-cdk/assert';
import { AccountRootPrincipal, Role } from '@aws-cdk/aws-iam';
import { Stack } from '@aws-cdk/core';
import { ProfilingGroup } from '../lib';
import { ProfilingGroup, ComputePlatform } from '../lib';

/* eslint-disable quote-props */

Expand Down Expand Up @@ -188,6 +188,18 @@ describe('profiling group', () => {
});
});

test('allows setting its ComputePlatform', () => {
const stack = new Stack();
new ProfilingGroup(stack, 'MyProfilingGroup', {
profilingGroupName: 'MyAwesomeProfilingGroup',
computePlatform: ComputePlatform.AWS_LAMBDA,
});

expect(stack).to(haveResourceLike('AWS::CodeGuruProfiler::ProfilingGroup', {
'ComputePlatform': 'AWSLambda',
}));
});

test('default profiling group without name', () => {
const stack = new Stack();
new ProfilingGroup(stack, 'MyProfilingGroup', {
Expand Down

0 comments on commit 5a64bc5

Please sign in to comment.