Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions packages/@aws-cdk/toolkit-lib/lib/actions/diagnose/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,30 @@ export interface TracedResourceError {
* (Not optional on purpose so we are not allowed to forget to call the code that should fill it)
*/
readonly sourceTrace: SourceTrace | undefined;

/**
* Additional context gathered from AWS service APIs to help diagnose the root cause.
*
* For example, CloudWatch Logs from an ECS service whose tasks failed to start.
*/
readonly additionalContext?: AdditionalDiagnosticContext[];
}

export interface AdditionalDiagnosticContext {
/**
* A short description of where this context came from
*
* @example "CloudWatch Logs (log-group-name)"
*/
readonly source: string;

/**
* The log lines or messages retrieved
*/
readonly messages: string[];

/**
* An optional console deep link for further investigation
*/
readonly link?: string;
}
17 changes: 17 additions & 0 deletions packages/@aws-cdk/toolkit-lib/lib/api/aws-auth/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ import {
} from '@aws-sdk/client-ecr';
import type {
DescribeServicesCommandInput,
DescribeServicesCommandOutput,
DescribeTaskDefinitionCommandInput,
DescribeTaskDefinitionCommandOutput,
DescribeTasksCommandInput,
DescribeTasksCommandOutput,
RegisterTaskDefinitionCommandInput,
ListClustersCommandInput,
ListClustersCommandOutput,
Expand All @@ -261,6 +266,9 @@ import type {
UpdateServiceCommandOutput,
} from '@aws-sdk/client-ecs';
import {
DescribeServicesCommand,
DescribeTaskDefinitionCommand,
DescribeTasksCommand,
ECSClient,
ListClustersCommand,
RegisterTaskDefinitionCommand,
Expand Down Expand Up @@ -555,6 +563,9 @@ export interface IECRClient {
}

export interface IECSClient {
describeServices(input: DescribeServicesCommandInput): Promise<DescribeServicesCommandOutput>;
describeTaskDefinition(input: DescribeTaskDefinitionCommandInput): Promise<DescribeTaskDefinitionCommandOutput>;
describeTasks(input: DescribeTasksCommandInput): Promise<DescribeTasksCommandOutput>;
listClusters(input: ListClustersCommandInput): Promise<ListClustersCommandOutput>;
registerTaskDefinition(input: RegisterTaskDefinitionCommandInput): Promise<RegisterTaskDefinitionCommandOutput>;
updateService(input: UpdateServiceCommandInput): Promise<UpdateServiceCommandOutput>;
Expand Down Expand Up @@ -950,6 +961,12 @@ export class SDK {
public ecs(): IECSClient {
const client = new ECSClient(this.config);
return {
describeServices: (input: DescribeServicesCommandInput): Promise<DescribeServicesCommandOutput> =>
client.send(new DescribeServicesCommand(input)),
describeTaskDefinition: (input: DescribeTaskDefinitionCommandInput): Promise<DescribeTaskDefinitionCommandOutput> =>
client.send(new DescribeTaskDefinitionCommand(input)),
describeTasks: (input: DescribeTasksCommandInput): Promise<DescribeTasksCommandOutput> =>
client.send(new DescribeTasksCommand(input)),
listClusters: (input: ListClustersCommandInput): Promise<ListClustersCommandOutput> =>
client.send(new ListClustersCommand(input)),
registerTaskDefinition: (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ export class Deployments {
sourceTracer: new StackArtifactSourceTracer(options.stack),
ioHelper: this.ioHelper,
topLevelStackHierarchicalId: options.stack.hierarchicalId,
additionalExplorationSdkProvider: async () => (await this.envs.accessStackForLookupBestEffort(options.stack)).sdk,
}),
}, this.ioHelper);
}
Expand Down Expand Up @@ -486,6 +487,7 @@ export class Deployments {
sourceTracer: new StackArtifactSourceTracer(stack),
ioHelper: this.ioHelper,
topLevelStackHierarchicalId: stack.hierarchicalId,
additionalExplorationSdkProvider: async () => (await this.envs.accessStackForLookupBestEffort(stack)).sdk,
}),
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,35 @@ function formatResourceErrors(es: TracedResourceError[]) {
const nodeText = b.nodeText(p);
nodeText.header = [`${lastPart} ${addendum(' ', e.resourceType, e.logicalId)}`.trim()];
nodeText.body.push(...sideBySide(['🛑'], ' ', wrapText(120, e.message)));
nodeText.body.push(...formatAdditionalContext(e));
nodeText.footer = e.sourceTrace?.creationStackTrace
? sideBySide(['Source Location:'], ' ', e.sourceTrace?.creationStackTrace)
: [];
}
return b.render();
}

function formatAdditionalContext(e: TracedResourceError): string[] {
if (!e.additionalContext || e.additionalContext.length === 0) {
return [];
}

const lines: string[] = [];
for (const ctx of e.additionalContext) {
lines.push('', `📋 ${ctx.source}:`);
for (const msg of ctx.messages.slice(0, 20)) {
lines.push(` ${msg}`);
}
if (ctx.messages.length > 20) {
lines.push(` ... (${ctx.messages.length - 20} more lines)`);
}
if (ctx.link) {
lines.push(` 🔗 ${ctx.link}`);
}
}
return lines;
}

/**
* Return a /-separated construct path for the given error, or try to build as close a represention as possible if we don't have a construct path
*
Expand Down
Loading
Loading