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 27, 2022
1 parent ec0c20c commit 282cad3
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 5 deletions.
91 changes: 91 additions & 0 deletions API.md

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

2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { Secrets } from './secrets';
export { GitHubRunners, GitHubRunnersProps } from './runner';
export { GitHubRunners, GitHubRunnersProps, LogOptions } from './runner';
export { CodeBuildRunner, CodeBuildRunnerProps } from './providers/codebuild';
export { LambdaRunner, LambdaRunnerProps } from './providers/lambda';
export { FargateRunner, FargateRunnerProps } from './providers/fargate';
Expand Down
62 changes: 58 additions & 4 deletions src/runner.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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_iam as iam, aws_lambda as lambda, aws_logs as logs, aws_stepfunctions as stepfunctions,
aws_stepfunctions_tasks as stepfunctions_tasks,
RemovalPolicy,
} from 'aws-cdk-lib';
import { FunctionUrlAuthType } from 'aws-cdk-lib/aws-lambda';
import { LogLevel } 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 +82,41 @@ export interface GitHubRunnersProps {
* @default 10 minutes
*/
readonly idleTimeout?: cdk.Duration;

/**
* Logging options for the state machine that manages the runners.
*/
readonly logOptions?: LogOptions;
}

/**
* Defines what execution history events are logged and where they are logged.
*/
export interface LogOptions {
/**
* The log group where the execution history events will be logged.
*/
readonly logGroupName?: string;
/**
* Determines whether execution data is included in your log.
*
* @default false
*/
readonly includeExecutionData?: boolean;
/**
* Defines which category of execution history events are logged.
*
* @default ERROR
*/
readonly level?: LogLevel;
/**
* 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;
}

/**
Expand Down Expand Up @@ -141,7 +176,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 +317,30 @@ export class GitHubRunners extends Construct {
.when(stepfunctions.Condition.isNotPresent('$.labels.self-hosted'), new stepfunctions.Succeed(this, 'No'))
.otherwise(work);

let logOptions: cdk.aws_stepfunctions.LogOptions | undefined;
if (this.props?.logOptions) {
const logGroup = new logs.LogGroup(
this,
'Logs',
{
logGroupName: props?.logOptions?.logGroupName ?? undefined,
retention: props?.logOptions?.logRetention ?? logs.RetentionDays.ONE_MONTH,
removalPolicy: RemovalPolicy.DESTROY,
},
);

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

0 comments on commit 282cad3

Please sign in to comment.