Skip to content

Commit

Permalink
add ObservabilityConfiguration for AppRunner Service
Browse files Browse the repository at this point in the history
  • Loading branch information
mazyu36 committed May 28, 2024
1 parent ccbd99f commit a4e11b4
Show file tree
Hide file tree
Showing 15 changed files with 866 additions and 4 deletions.
23 changes: 21 additions & 2 deletions packages/@aws-cdk/aws-apprunner-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ The `Service` construct allows you to create AWS App Runner services with `ECR P
- `Source.fromEcr()` - To define the source repository from `ECR`.
- `Source.fromEcrPublic()` - To define the source repository from `ECR Public`.
- `Source.fromGitHub()` - To define the source repository from the `Github repository`.
- `Source.fromAsset()` - To define the source from local asset directory.
- `Source.fromAsset()` - To define the source from local asset directory.


The `Service` construct implements `IGrantable`.
Expand Down Expand Up @@ -183,7 +183,7 @@ new apprunner.Service(this, 'Service', {
## Secrets Manager

To include environment variables integrated with AWS Secrets Manager, use the `environmentSecrets` attribute.
You can use the `addSecret` method from the App Runner `Service` class to include secrets from outside the
You can use the `addSecret` method from the App Runner `Service` class to include secrets from outside the
service definition.

```ts
Expand Down Expand Up @@ -237,3 +237,22 @@ new apprunner.Service(this, 'Service', {
}),
});
```

## Observability Configuration

To associate an App Runner service with a custom Observability Configuration, define `observabilityConfiguration` for the service.

```ts
const observabilityConfiguration = new apprunner.ObservabilityConfiguration(this, 'ObservabilityConfiguration', {
observabilityConfigurationName: 'MyObservabilityConfiguration',
vendor: apprunner.Vendor.AWSXRAY,
});

new apprunner.Service(this, 'DemoService', {
source: apprunner.Source.fromEcrPublic({
imageConfiguration: { port: 8000 },
imageIdentifier: 'public.ecr.aws/aws-containers/hello-app-runner:latest',
}),
observabilityConfiguration,
});
```
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-apprunner-alpha/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// AWS::AppRunner CloudFormation Resources:
export * from './service';
export * from './vpc-connector';
export * from './observability-configuration';
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import * as cdk from 'aws-cdk-lib/core';
import { Construct } from 'constructs';
import { CfnObservabilityConfiguration } from 'aws-cdk-lib/aws-apprunner';

/**
* The implementation provider chosen for tracing App Runner services
*/
export enum Vendor {
/**
* AWS X-RAY
*/
AWSXRAY = 'AWSXRAY',
}

/**
* Properties of the AppRunner Observability configuration
*/
export interface ObservabilityConfigurationProps {
/**
* The name for the ObservabilityConfiguration.
*
* @default - a name generated by CloudFormation
*/
readonly observabilityConfigurationName?: string;

/**
* The implementation provider chosen for tracing App Runner services.
*
* @default Vendor.AWSXRAY
*/
readonly vendor?: Vendor;
}

/**
* Attributes for the App Runner Observability configuration
*/
export interface ObservabilityConfigurationAttributes {
/**
* The name of the Observability configuration.
*/
readonly observabilityConfigurationName: string;

/**
* The ARN of the Observability configuration.
*/
readonly observabilityConfigurationArn: string;

/**
* The revision of the Observability configuration.
*/
readonly observabilityConfigurationRevision: number;
}

/**
* Represents the App Runner Observability configuration.
*/
export interface IObservabilityConfiguration extends cdk.IResource {
/**
* The Name of the Observability configuration.
* @attribute
*/
readonly observabilityConfigurationName: string;

/**
* The ARN of the Observability configuration.
* @attribute
*/
readonly observabilityConfigurationArn: string;

/**
* The revision of the Observability configuration.
* @attribute
*/
readonly observabilityConfigurationRevision: number;
}

/**
* The App Runner Observability configuration
*
* @resource AWS::AppRunner::ObservabilityConfiguration
*/
export class ObservabilityConfiguration extends cdk.Resource implements IObservabilityConfiguration {
/**
* Import from Observability configuration attributes.
*/
public static fromObservabilityConfigurationAttributes(scope: Construct, id: string,
attrs: ObservabilityConfigurationAttributes): IObservabilityConfiguration {
const observabilityConfigurationArn = attrs.observabilityConfigurationArn;
const observabilityConfigurationName = attrs.observabilityConfigurationName;
const observabilityConfigurationRevision = attrs.observabilityConfigurationRevision;

class Import extends cdk.Resource {
public readonly observabilityConfigurationArn = observabilityConfigurationArn
public readonly observabilityConfigurationName = observabilityConfigurationName
public readonly observabilityConfigurationRevision = observabilityConfigurationRevision
}

return new Import(scope, id);
}

/**
* The ARN of the Observability configuration.
* @attribute
*/
readonly observabilityConfigurationArn: string;

/**
* The revision of the Observability configuration.
* @attribute
*/
readonly observabilityConfigurationRevision: number;

/**
* The name of the Observability configuration.
* @attribute
*/
readonly observabilityConfigurationName: string;

public constructor(scope: Construct, id: string, props: ObservabilityConfigurationProps = {}) {
super(scope, id, {
physicalName: props.observabilityConfigurationName,
});

const resource = new CfnObservabilityConfiguration(this, 'Resource', {
observabilityConfigurationName: props.observabilityConfigurationName,
traceConfiguration: {
vendor: props.vendor ?? Vendor.AWSXRAY,
},
});

this.observabilityConfigurationArn = resource.attrObservabilityConfigurationArn;
this.observabilityConfigurationRevision = resource.attrObservabilityConfigurationRevision;
this.observabilityConfigurationName = resource.ref;
}
}
14 changes: 13 additions & 1 deletion packages/@aws-cdk/aws-apprunner-alpha/lib/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Lazy } from 'aws-cdk-lib/core';
import { Construct } from 'constructs';
import { CfnService } from 'aws-cdk-lib/aws-apprunner';
import { IVpcConnector } from './vpc-connector';
import { IObservabilityConfiguration } from './observability-configuration';

/**
* The image repository types
Expand Down Expand Up @@ -79,7 +80,7 @@ export class Cpu {
*
* @param unit The unit of CPU.
*/
private constructor(public readonly unit: string) {}
private constructor(public readonly unit: string) { }
}

/**
Expand Down Expand Up @@ -715,6 +716,13 @@ export interface ServiceProps {
* @default - no health check configuration
*/
readonly healthCheck?: HealthCheck;

/**
* Settings for an App Runner tracing feature.
*
* @default - Not enable tracing
*/
readonly observabilityConfiguration?: IObservabilityConfiguration;
}

/**
Expand Down Expand Up @@ -1248,6 +1256,10 @@ export class Service extends cdk.Resource implements iam.IGrantable {
healthCheckConfiguration: this.props.healthCheck ?
this.props.healthCheck.bind() :
undefined,
observabilityConfiguration: props.observabilityConfiguration ? {
observabilityEnabled: true,
observabilityConfigurationArn: props.observabilityConfiguration?.observabilityConfigurationArn,
} : undefined,
});

// grant required privileges for the role
Expand Down

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

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

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

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

Loading

0 comments on commit a4e11b4

Please sign in to comment.