Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(apprunner): add ObservabilityConfiguration for AppRunner Service #30359

Merged
merged 25 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a4e11b4
add ObservabilityConfiguration for AppRunner Service
mazyu36 May 28, 2024
e73b10d
feat: add fromArn method
mazyu36 May 28, 2024
0027a86
Merge branch 'main' into apprunner-observability-22985
mazyu36 May 28, 2024
78629f1
Merge branch 'main' into apprunner-observability-22985
mazyu36 May 30, 2024
10277c4
Update packages/@aws-cdk/aws-apprunner-alpha/lib/service.ts
mazyu36 Jun 1, 2024
4af4868
Update packages/@aws-cdk/aws-apprunner-alpha/lib/service.ts
mazyu36 Jun 1, 2024
c532781
Update packages/@aws-cdk/aws-apprunner-alpha/README.md
mazyu36 Jun 1, 2024
8a7f2f7
Update packages/@aws-cdk/aws-apprunner-alpha/lib/observability-config…
mazyu36 Jun 1, 2024
b0cc774
Update packages/@aws-cdk/aws-apprunner-alpha/lib/observability-config…
mazyu36 Jun 1, 2024
71da222
Update packages/@aws-cdk/aws-apprunner-alpha/test/service.test.ts
mazyu36 Jun 1, 2024
b93cd9b
fix: incorporate review comments
mazyu36 Jun 2, 2024
d525912
Update packages/@aws-cdk/aws-apprunner-alpha/lib/observability-config…
mazyu36 Jun 2, 2024
4812423
Update packages/@aws-cdk/aws-apprunner-alpha/lib/observability-config…
mazyu36 Jun 2, 2024
d667bb4
Update packages/@aws-cdk/aws-apprunner-alpha/lib/observability-config…
mazyu36 Jun 2, 2024
f6e9e2c
Update packages/@aws-cdk/aws-apprunner-alpha/test/service.test.ts
mazyu36 Jun 2, 2024
2481648
Update packages/@aws-cdk/aws-apprunner-alpha/lib/observability-config…
mazyu36 Jun 2, 2024
8ac81d3
fix: incorporate review comments
mazyu36 Jun 2, 2024
0594cd0
Update packages/@aws-cdk/aws-apprunner-alpha/lib/observability-config…
mazyu36 Jun 3, 2024
6d5a86c
Merge branch 'main' into apprunner-observability-22985
mazyu36 Jun 11, 2024
1e5f12e
fix: update from method
mazyu36 Jun 19, 2024
db48ffe
add tag test
mazyu36 Jun 20, 2024
6eaaee0
Merge branch 'main' into apprunner-observability-22985
mergify[bot] Jun 20, 2024
8459f87
resolve conflict
mazyu36 Jun 21, 2024
4718de2
Merge branch 'main' into apprunner-observability-22985
mazyu36 Jun 21, 2024
c850eb3
Merge branch 'main' into apprunner-observability-22985
mergify[bot] Jun 24, 2024
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
19 changes: 19 additions & 0 deletions packages/@aws-cdk/aws-apprunner-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,22 @@ new apprunner.Service(this, 'Service', {
}),
});
```

## Observability Configuration

To associate an App Runner service with a custom observability configuration, use the `observabilityConfiguration` property.

```ts
const observabilityConfiguration = new apprunner.ObservabilityConfiguration(this, 'ObservabilityConfiguration', {
observabilityConfigurationName: 'MyObservabilityConfiguration',
traceConfigurationVendor: apprunner.TraceConfigurationVendor.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,4 +1,5 @@
// AWS::AppRunner CloudFormation Resources:
export * from './auto-scaling-configuration';
export * from './observability-configuration';
export * from './service';
export * from './vpc-connector';
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
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
mazyu36 marked this conversation as resolved.
Show resolved Hide resolved
*
* @see https://docs.aws.amazon.com/apprunner/latest/dg/monitor.html
*/
export enum TraceConfigurationVendor {
/**
* Tracing (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.
*/
readonly traceConfigurationVendor: TraceConfigurationVendor;
}

/**
* Attributes for the App Runner Observability configuration
*/
export interface ObservabilityConfigurationAttributes {
/**
* The name of the Observability configuration.
*/
readonly observabilityConfigurationName: 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 {
/**
* Imports an App Runner Observability Configuration from attributes.
*/
public static fromObservabilityConfigurationAttributes(scope: Construct, id: string,
attrs: ObservabilityConfigurationAttributes): IObservabilityConfiguration {
const observabilityConfigurationName = attrs.observabilityConfigurationName;
const observabilityConfigurationRevision = attrs.observabilityConfigurationRevision;

class Import extends cdk.Resource implements IObservabilityConfiguration {
public readonly observabilityConfigurationName = observabilityConfigurationName;
public readonly observabilityConfigurationRevision = observabilityConfigurationRevision;
public readonly observabilityConfigurationArn = cdk.Stack.of(this).formatArn({
resource: 'observabilityconfiguration',
service: 'apprunner',
resourceName: `${attrs.observabilityConfigurationName}/${attrs.observabilityConfigurationRevision}`,
});
}

return new Import(scope, id);
}

/**
* Imports an App Runner Observability Configuration from its ARN
*/
public static fromArn(scope: Construct, id: string, observabilityConfigurationArn: string): IObservabilityConfiguration {
const resourceParts = cdk.Fn.split('/', observabilityConfigurationArn);

if (!resourceParts || resourceParts.length < 3) {
throw new Error(`Unexpected ARN format: ${observabilityConfigurationArn}`);
}

const observabilityConfigurationName = cdk.Fn.select(0, resourceParts);
const observabilityConfigurationRevision = Number(cdk.Fn.select(1, resourceParts));

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

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,
});

if (
props.observabilityConfigurationName !== undefined &&
!cdk.Token.isUnresolved(props.observabilityConfigurationName) &&
!/^[A-Za-z0-9][A-Za-z0-9\-_]{3,31}$/.test(props.observabilityConfigurationName)
) {
throw new Error(`observabilityConfigurationName must match the \`^[A-Za-z0-9][A-Za-z0-9\-_]{3,31}$\` pattern, got ${props.observabilityConfigurationName}`);
}

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

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

/**
* The image repository types
Expand Down Expand Up @@ -743,6 +744,14 @@ export interface ServiceProps {
* @default - IpAddressType.IPV4
*/
readonly ipAddressType?: IpAddressType;

/**
* Settings for an App Runner observability configuration.
*
* @default - no observability configuration resource is associated with the service.
*/
readonly observabilityConfiguration?: IObservabilityConfiguration;

}

/**
Expand Down Expand Up @@ -1296,6 +1305,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