Skip to content

Commit

Permalink
feat: Add CloudFormation telemetry (#10)
Browse files Browse the repository at this point in the history
* feat: Add CloudFormation telemtry

* Added tests

* assert => expect

* expect => expect().toStrictEqual()
  • Loading branch information
tobuck-aws authored Mar 8, 2024
1 parent 3945b18 commit 32dfc67
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/control-plane/control-plane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Services } from './services';
import { Tables } from './tables';
import { TenantConfigService } from './tenant-config/tenant-config-service';
import { DestroyPolicySetter } from '../cdk-aspect/destroy-policy-setter';
import { EventManager } from '../utils';
import { EventManager, setTemplateDesc } from '../utils';

export interface ControlPlaneProps {
readonly applicationPlaneEventSource: string;
Expand All @@ -33,6 +33,8 @@ export class ControlPlane extends Construct {

constructor(scope: Construct, id: string, props: ControlPlaneProps) {
super(scope, id);
setTemplateDesc(this, 'SaaS Builder Toolkit - CoreApplicationPlane (uksb-1tupboc57)');

cdk.Aspects.of(this).add(new DestroyPolicySetter());

const messaging = new Messaging(this, 'messaging-stack');
Expand Down
4 changes: 3 additions & 1 deletion src/core-app-plane/core-app-plane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Construct } from 'constructs';
import { BashJobOrchestrator } from './bash-job-orchestrator';
import { BashJobRunner } from './bash-job-runner';
import { DestroyPolicySetter } from '../cdk-aspect/destroy-policy-setter';
import { EventManager } from '../utils';
import { EventManager, setTemplateDesc } from '../utils';

/**
* Provides metadata for outgoing events.
Expand Down Expand Up @@ -133,6 +133,8 @@ export interface CoreApplicationPlaneProps {
export class CoreApplicationPlane extends Construct {
constructor(scope: Construct, id: string, props: CoreApplicationPlaneProps) {
super(scope, id);
setTemplateDesc(this, 'SaaS Builder Toolkit - CoreApplicationPlane (uksb-1tupboc57)');

cdk.Aspects.of(this).add(new DestroyPolicySetter());

const eventBus = EventBus.fromEventBusArn(this, 'eventBus', props.eventBusArn);
Expand Down
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
// SPDX-License-Identifier: Apache-2.0

export * from './event-manager';
export * from './utils';
11 changes: 11 additions & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { Stack } from 'aws-cdk-lib';
import { Construct } from 'constructs';

export const setTemplateDesc = (construct: Construct, sbtDesc: string) => {
const stackDesc = Stack.of(construct).templateOptions.description;
let description = stackDesc === undefined ? sbtDesc : stackDesc + ' - ' + sbtDesc;
Stack.of(construct).templateOptions.description = description;
};
18 changes: 17 additions & 1 deletion test/control-plane.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('No unsuppressed cdk-nag Warnings or Errors', () => {
});
});

describe('ControlPlane', () => {
describe('ControlPlane without Description', () => {
const app = new cdk.App();
interface TestStackProps extends cdk.StackProps {
systemAdminEmail: string;
Expand Down Expand Up @@ -113,4 +113,20 @@ describe('ControlPlane', () => {
expect(targetsCapture.asArray()).toHaveLength(1);
} while (targetsCapture.next());
});

it('should have a fixed template description, when the containing stack does not have description', () => {
const actual = controlPlaneTestStack.templateOptions.description;
const expected = 'SaaS Builder Toolkit - CoreApplicationPlane (uksb-1tupboc57)';
expect(actual).toStrictEqual(expected);
});

it('should have a concatenated template description, when the containing stack has an existing desc', () => {
const stackWithDescription = new TestStack(app, 'stackWithDescription', {
systemAdminEmail: '[email protected]',
description: 'ABC',
});
const actual = stackWithDescription.templateOptions.description;
const expected = 'ABC - SaaS Builder Toolkit - CoreApplicationPlane (uksb-1tupboc57)';
expect(expected).toStrictEqual(actual);
});
});

0 comments on commit 32dfc67

Please sign in to comment.