Skip to content

Commit 055a412

Browse files
authored
Create spans on stack creation too (#34)
* Create spans on stack creation too * bump version to trigger a release
1 parent 66b28c9 commit 055a412

File tree

3 files changed

+100
-3
lines changed

3 files changed

+100
-3
lines changed

src/transformer/transform.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,8 @@ function createSpanDataUpdater(
315315
return;
316316
}
317317

318-
if (resourceStatus === "UPDATE_COMPLETE") {
318+
//TODO - deduplicate these constants with the ones defined in the cloudformation client adapter, or see if the AWS SDK already provides them
319+
if (resourceStatus === "UPDATE_COMPLETE" || resourceStatus === "CREATE_COMPLETE") {
319320
const currentTransformedState: ISpanData = spanDataByConstructedId.get(
320321
constructedIdForTheResource,
321322
) ?? {
@@ -334,7 +335,7 @@ function createSpanDataUpdater(
334335
);
335336
}
336337

337-
if (resourceStatus === "UPDATE_IN_PROGRESS") {
338+
if (resourceStatus === "UPDATE_IN_PROGRESS" || resourceStatus === "CREATE_IN_PROGRESS") {
338339
const currentTransformedState: ISpanData = spanDataByConstructedId.get(
339340
constructedIdForTheResource,
340341
) ?? {

src/transformer/transform_test.ts

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,102 @@ Deno.test("Correctly transforms the events from a 2-tier nested stack with 1 non
170170
assertEquals(outputs, expectedOutputs);
171171
});
172172

173+
Deno.test("Correctly transforms the events from a freshly created stack", async () => {
174+
//ARRANGE
175+
const inputs: IInputs = {
176+
stackName: "rootStackName",
177+
dependencies: {
178+
cloudformationClientAdapter: {
179+
getEventsFromMostRecentDeploy({ stackName }) {
180+
switch (stackName) {
181+
case "rootStackName":
182+
return Promise.resolve({
183+
stackEvents: [
184+
createStackEvent({
185+
resourceIdPerCloudformation: "rootStackName",
186+
resourceIdPerTheServiceItsFrom:
187+
"arn:aws:cloudformation:us-east-1:000000000000:stack/rootStackName/00aa00a0-a00a-00aa-0a00-00a0a0a00000",
188+
resourceStatus: "CREATE_COMPLETE",
189+
resourceType: "AWS::CloudFormation::Stack",
190+
timestamp: new Date("2022-04-11T00:00:30.000Z"),
191+
}),
192+
createStackEvent({
193+
resourceIdPerCloudformation: "TheEcsCluster",
194+
resourceIdPerTheServiceItsFrom: "TheClusterName",
195+
resourceStatus: "CREATE_COMPLETE",
196+
resourceType: "AWS::ECS::Cluster",
197+
timestamp: new Date("2022-04-11T00:00:15.000Z"),
198+
}),
199+
createStackEvent({
200+
resourceIdPerCloudformation: "TheEcsCluster",
201+
resourceIdPerTheServiceItsFrom: "TheClusterName",
202+
resourceStatus: "CREATE_IN_PROGRESS",
203+
resourceType: "AWS::ECS::Cluster",
204+
timestamp: new Date("2022-04-11T00:00:10.000Z"),
205+
}),
206+
createStackEvent({
207+
resourceIdPerCloudformation: "rootStackName",
208+
resourceIdPerTheServiceItsFrom:
209+
"arn:aws:cloudformation:us-east-1:000000000000:stack/rootStackName/00aa00a0-a00a-00aa-0a00-00a0a0a00000",
210+
resourceStatus: "CREATE_IN_PROGRESS",
211+
resourceType: "AWS::CloudFormation::Stack",
212+
timestamp: new Date("2022-04-11T00:00:05.000Z"),
213+
}),
214+
createStackEvent({
215+
resourceIdPerCloudformation: "rootStackName",
216+
resourceIdPerTheServiceItsFrom:
217+
"arn:aws:cloudformation:us-east-1:000000000000:stack/rootStackName/00aa00a0-a00a-00aa-0a00-00a0a0a00000",
218+
resourceStatus: "REVIEW_IN_PROGRESS",
219+
resourceType: "AWS::CloudFormation::Stack",
220+
timestamp: new Date("2022-04-11T00:00:00.000Z"),
221+
}),
222+
],
223+
});
224+
default:
225+
throw new Error(`${stackName} not found in the mock's setup`);
226+
}
227+
},
228+
},
229+
},
230+
};
231+
232+
//ACT
233+
const outputs = await transformStackEventDataIntoTracingData(inputs);
234+
235+
//ASSERT
236+
const spanDataByConstructedId = new Map<string, ISpanData>();
237+
238+
const rootConstructedId =
239+
"rootStackName-arn:aws:cloudformation:us-east-1:000000000000:stack/rootStackName/00aa00a0-a00a-00aa-0a00-00a0a0a00000-AWS::CloudFormation::Stack";
240+
241+
spanDataByConstructedId.set(
242+
"rootStackName-arn:aws:cloudformation:us-east-1:000000000000:stack/rootStackName/00aa00a0-a00a-00aa-0a00-00a0a0a00000-AWS::CloudFormation::Stack",
243+
{
244+
childSpanIds: new Set<string>(["TheEcsCluster-TheClusterName-AWS::ECS::Cluster"]),
245+
name: "rootStackName",
246+
startInstant: new Date("2022-04-11T00:00:05.000Z"),
247+
endInstant: new Date("2022-04-11T00:00:30.000Z"),
248+
},
249+
);
250+
251+
spanDataByConstructedId.set(
252+
"TheEcsCluster-TheClusterName-AWS::ECS::Cluster",
253+
{
254+
childSpanIds: new Set<string>(),
255+
name: "TheEcsCluster",
256+
startInstant: new Date("2022-04-11T00:00:10.000Z"),
257+
endInstant: new Date("2022-04-11T00:00:15.000Z"),
258+
},
259+
);
260+
261+
const expectedOutputs: ITracingData = {
262+
spanDataByConstructedId,
263+
rootConstructedId,
264+
};
265+
266+
assertEquals(outputs, expectedOutputs);
267+
});
268+
173269
function createStackEvent(
174270
partialStackEvent: Partial<IAdaptedStackEvent>,
175271
): IAdaptedStackEvent {

version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"version": "0.0.6"
2+
"version": "0.0.7"
33
}

0 commit comments

Comments
 (0)