Skip to content

Commit

Permalink
feat: add option to enable logging on state machine
Browse files Browse the repository at this point in the history
  • Loading branch information
uid10804 committed Nov 20, 2022
1 parent ec0c20c commit 333e89e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
13 changes: 13 additions & 0 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 41 additions & 3 deletions src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import * as cdk from 'aws-cdk-lib';
import {
aws_ec2 as ec2,
aws_iam as iam,
aws_lambda as lambda,
aws_stepfunctions as stepfunctions,
aws_logs as logs,
aws_lambda as lambda, aws_stepfunctions as stepfunctions,
aws_stepfunctions_tasks as stepfunctions_tasks,
RemovalPolicy,
} from 'aws-cdk-lib';
import { FunctionUrlAuthType } from 'aws-cdk-lib/aws-lambda';
import { RetentionDays } from 'aws-cdk-lib/aws-logs';
import { LogOptions } from 'aws-cdk-lib/aws-stepfunctions';
import { Construct } from 'constructs';
import { CodeBuildRunner } from './providers/codebuild';
import { IRunnerProvider } from './providers/common';
Expand Down Expand Up @@ -82,6 +85,27 @@ export interface GitHubRunnersProps {
* @default 10 minutes
*/
readonly idleTimeout?: cdk.Duration;

/**
* The number of days log events are kept in CloudWatch Logs. When updating
* this property, unsetting it doesn't remove the log retention policy. To
* remove the retention policy, set the value to `INFINITE`.
*
* @default logs.RetentionDays.ONE_MONTH
*/
readonly logRetention?: logs.RetentionDays;


/**
* Removal policy for logs of image builds. If deployment fails on the custom resource, try setting this to `RemovalPolicy.RETAIN`. This way the CodeBuild logs can still be viewed, and you can see why the build failed.
*
* We try to not leave anything behind when removed. But sometimes a log staying behind is useful.
*
* @default RemovalPolicy.DESTROY
*/
readonly logRemovalPolicy?: RemovalPolicy;
}

}

/**
Expand Down Expand Up @@ -141,7 +165,7 @@ export class GitHubRunners extends Construct {
private readonly webhook: GithubWebhookHandler;
private readonly orchestrator: stepfunctions.StateMachine;
private readonly setupUrl: string;
private readonly extraLambdaEnv: {[p: string]: string} = {};
private readonly extraLambdaEnv: { [p: string]: string } = {};
private readonly extraLambdaProps: lambda.FunctionOptions;

constructor(scope: Construct, id: string, props?: GitHubRunnersProps) {
Expand Down Expand Up @@ -282,11 +306,25 @@ export class GitHubRunners extends Construct {
.when(stepfunctions.Condition.isNotPresent('$.labels.self-hosted'), new stepfunctions.Succeed(this, 'No'))
.otherwise(work);

const logGroup = new logs.LogGroup(
this,
'Logs',
{
retention: props?.logRetention ?? logs.RetentionDays.ONE_MONTH,
removalPolicy: props?.logRemovalPolicy ?? RemovalPolicy.DESTROY
},
);

return new stepfunctions.StateMachine(
this,
'Runner Orchestrator',
{
definition: check,
logs: {
destination: logGroup,
level: stepfunctions.LogLevel.ALL,
includeExecutionData: true,
},
},
);
}
Expand Down

0 comments on commit 333e89e

Please sign in to comment.