Skip to content
This repository was archived by the owner on Jul 16, 2024. It is now read-only.

Commit 4a35051

Browse files
flochazChazalvgkowski
authored
Add deployment trackers to evaluate adoption (#169)
* Track ref arch deployments * Add tracking code capability Co-authored-by: Chazal <chazalf@88665a14a6c3.ant.amazon.com> Co-authored-by: Vincent Gromakowski <vgkowski@users.noreply.github.com>
1 parent 9cf5cac commit 4a35051

File tree

6 files changed

+78
-5
lines changed

6 files changed

+78
-5
lines changed

core/src/common/context-options.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export enum ContextOptions {
2+
DISABLE_CONSTRUCTS_DEPLOYMENT_TRACKING = '@aws-analytics-reference-architecture/disableConstructsDeploymentTracking'
3+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as cdk from '@aws-cdk/core';
2+
3+
export interface TrackedConstructProps {
4+
trackingCode: string;
5+
}
6+
7+
export class TrackedConstruct extends cdk.Construct {
8+
constructor(scope: cdk.Construct, id: string, props: TrackedConstructProps) {
9+
super(scope, id);
10+
11+
if (!scope.node.tryGetContext('@aws-analytics-reference-architecture/disableConstructsDeploymentTracking')) {
12+
const stack = cdk.Stack.of(this);
13+
const description = `${stack.templateOptions.description} (${props.trackingCode})`;
14+
stack.templateOptions.description = description;
15+
}
16+
}
17+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: MIT-0
3+
4+
import { App, Stack } from '@aws-cdk/core';
5+
import { ContextOptions } from '../src/common/context-options';
6+
import * as trackedConstruct from '../src/common/tracked-construct';
7+
8+
import '@aws-cdk/assert/jest';
9+
10+
test('tracked construct add tracking code to description if not explicitely disabled', () => {
11+
12+
// GIVEN
13+
const initialStackDescription = 'My Analytics stack';
14+
const trackingCode = 'trackingcode';
15+
const testApp = new App();
16+
const exampleStack = new Stack(testApp, 'testTrackedConstruct', {
17+
description: initialStackDescription,
18+
});
19+
20+
// WHEN
21+
new trackedConstruct.TrackedConstruct(exampleStack, 'MyCoreAnalyticsConstruct', { trackingCode: trackingCode });
22+
23+
// THEN
24+
expect(exampleStack.templateOptions).toHaveProperty('description', `${initialStackDescription} (${trackingCode})`);
25+
});
26+
27+
28+
test('tracked construct don\'t add tracking code to description if explicitely disabled', () => {
29+
30+
// GIVEN
31+
const initialStackDescription = 'My Analytics stack';
32+
const trackingCode = 'trackingcode';
33+
const context: any = {};
34+
context[ContextOptions.DISABLE_CONSTRUCTS_DEPLOYMENT_TRACKING] = true;
35+
const testApp = new App({ context });
36+
const exampleStack = new Stack(testApp, 'testTrackedConstruct', {
37+
description: initialStackDescription,
38+
});
39+
40+
// WHEN
41+
new trackedConstruct.TrackedConstruct(exampleStack, 'MyCoreAnalyticsConstruct', { trackingCode: trackingCode });
42+
43+
// THEN
44+
expect(exampleStack.templateOptions).toHaveProperty('description', initialStackDescription);
45+
});

refarch/aws-native/cdk.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"EnableBatch": "true",
77
"EnableDWH": "true",
88
"EnableDataviz": "true",
9-
"EnableStreaming": "true"
9+
"EnableStreaming": "true",
10+
"EnableDeploymentTracking": "true"
1011
}
1112
}

refarch/aws-native/common/common_cdk/data_lake.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,20 @@
1414

1515

1616
def is_module_enabled(param: str):
17-
return param.lower() in ("yes", "true")
17+
return param and (param.lower() in ("yes", "true"))
1818

1919

2020
class DataLake(Stack):
2121

22-
def __init__(self, scope: Construct, id: str, **kwargs) -> None:
23-
super().__init__(scope, id, **kwargs)
22+
def __init__(self, scope: Construct, id: str, **kwargs) -> None:
23+
24+
# Set Stack description
25+
deployment_tracking_param = scope.node.try_get_context("EnableDeploymentTracking")
26+
stack_description = "Analytics Ref Arch - DataLake stack"
27+
if is_module_enabled(deployment_tracking_param):
28+
stack_description = stack_description + " (uksb-1scq97upu)"
29+
30+
super().__init__(scope, id, description = stack_description, **kwargs)
2431

2532
data_lake = DataLakeFoundations(self, "Foundations")
2633

refarch/aws-native/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"cdk_ec2_key_pair"
5050
],
5151

52-
python_requires=">=3.8,<3.9",
52+
python_requires=">=3.8",
5353

5454
classifiers=[
5555
"Development Status :: 4 - Beta",

0 commit comments

Comments
 (0)