-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(apprunner): add ObservabilityConfiguration for AppRunner Service (…
…#30359) ### Issue # (if applicable) Closes #22985 . ### Reason for this change At the moment, L2 Construct does not support a tracing setting for the AppRunner Service. ### Description of changes * Add `ObservabilityConfiguration` Class * Add `observabilityConfiguration` property to the `Service` Class ### Description of how you validated changes Add unit tests and integ tests. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
15 changed files
with
914 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
163 changes: 163 additions & 0 deletions
163
packages/@aws-cdk/aws-apprunner-alpha/lib/observability-configuration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
* | ||
* @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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...s.snapshot/AppRunnerObservabilityConfigurationDefaultTestDeployAssertFEB7E279.assets.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
...snapshot/AppRunnerObservabilityConfigurationDefaultTestDeployAssertFEB7E279.template.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
...dk/aws-apprunner-alpha/test/integ.service-observability-configuration.js.snapshot/cdk.out
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
...ability-configuration.js.snapshot/integ-apprunner-observability-configuration.assets.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.