Skip to content

Commit

Permalink
Create spans on stack creation too (#34)
Browse files Browse the repository at this point in the history
* Create spans on stack creation too

* bump version to trigger a release
  • Loading branch information
Grunet authored May 7, 2022
1 parent 66b28c9 commit 055a412
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/transformer/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ function createSpanDataUpdater(
return;
}

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

if (resourceStatus === "UPDATE_IN_PROGRESS") {
if (resourceStatus === "UPDATE_IN_PROGRESS" || resourceStatus === "CREATE_IN_PROGRESS") {
const currentTransformedState: ISpanData = spanDataByConstructedId.get(
constructedIdForTheResource,
) ?? {
Expand Down
96 changes: 96 additions & 0 deletions src/transformer/transform_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,102 @@ Deno.test("Correctly transforms the events from a 2-tier nested stack with 1 non
assertEquals(outputs, expectedOutputs);
});

Deno.test("Correctly transforms the events from a freshly created stack", async () => {
//ARRANGE
const inputs: IInputs = {
stackName: "rootStackName",
dependencies: {
cloudformationClientAdapter: {
getEventsFromMostRecentDeploy({ stackName }) {
switch (stackName) {
case "rootStackName":
return Promise.resolve({
stackEvents: [
createStackEvent({
resourceIdPerCloudformation: "rootStackName",
resourceIdPerTheServiceItsFrom:
"arn:aws:cloudformation:us-east-1:000000000000:stack/rootStackName/00aa00a0-a00a-00aa-0a00-00a0a0a00000",
resourceStatus: "CREATE_COMPLETE",
resourceType: "AWS::CloudFormation::Stack",
timestamp: new Date("2022-04-11T00:00:30.000Z"),
}),
createStackEvent({
resourceIdPerCloudformation: "TheEcsCluster",
resourceIdPerTheServiceItsFrom: "TheClusterName",
resourceStatus: "CREATE_COMPLETE",
resourceType: "AWS::ECS::Cluster",
timestamp: new Date("2022-04-11T00:00:15.000Z"),
}),
createStackEvent({
resourceIdPerCloudformation: "TheEcsCluster",
resourceIdPerTheServiceItsFrom: "TheClusterName",
resourceStatus: "CREATE_IN_PROGRESS",
resourceType: "AWS::ECS::Cluster",
timestamp: new Date("2022-04-11T00:00:10.000Z"),
}),
createStackEvent({
resourceIdPerCloudformation: "rootStackName",
resourceIdPerTheServiceItsFrom:
"arn:aws:cloudformation:us-east-1:000000000000:stack/rootStackName/00aa00a0-a00a-00aa-0a00-00a0a0a00000",
resourceStatus: "CREATE_IN_PROGRESS",
resourceType: "AWS::CloudFormation::Stack",
timestamp: new Date("2022-04-11T00:00:05.000Z"),
}),
createStackEvent({
resourceIdPerCloudformation: "rootStackName",
resourceIdPerTheServiceItsFrom:
"arn:aws:cloudformation:us-east-1:000000000000:stack/rootStackName/00aa00a0-a00a-00aa-0a00-00a0a0a00000",
resourceStatus: "REVIEW_IN_PROGRESS",
resourceType: "AWS::CloudFormation::Stack",
timestamp: new Date("2022-04-11T00:00:00.000Z"),
}),
],
});
default:
throw new Error(`${stackName} not found in the mock's setup`);
}
},
},
},
};

//ACT
const outputs = await transformStackEventDataIntoTracingData(inputs);

//ASSERT
const spanDataByConstructedId = new Map<string, ISpanData>();

const rootConstructedId =
"rootStackName-arn:aws:cloudformation:us-east-1:000000000000:stack/rootStackName/00aa00a0-a00a-00aa-0a00-00a0a0a00000-AWS::CloudFormation::Stack";

spanDataByConstructedId.set(
"rootStackName-arn:aws:cloudformation:us-east-1:000000000000:stack/rootStackName/00aa00a0-a00a-00aa-0a00-00a0a0a00000-AWS::CloudFormation::Stack",
{
childSpanIds: new Set<string>(["TheEcsCluster-TheClusterName-AWS::ECS::Cluster"]),
name: "rootStackName",
startInstant: new Date("2022-04-11T00:00:05.000Z"),
endInstant: new Date("2022-04-11T00:00:30.000Z"),
},
);

spanDataByConstructedId.set(
"TheEcsCluster-TheClusterName-AWS::ECS::Cluster",
{
childSpanIds: new Set<string>(),
name: "TheEcsCluster",
startInstant: new Date("2022-04-11T00:00:10.000Z"),
endInstant: new Date("2022-04-11T00:00:15.000Z"),
},
);

const expectedOutputs: ITracingData = {
spanDataByConstructedId,
rootConstructedId,
};

assertEquals(outputs, expectedOutputs);
});

function createStackEvent(
partialStackEvent: Partial<IAdaptedStackEvent>,
): IAdaptedStackEvent {
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "0.0.6"
"version": "0.0.7"
}

0 comments on commit 055a412

Please sign in to comment.