From 24a3d023dbacedf19c094cdad1798a296425e779 Mon Sep 17 00:00:00 2001 From: Zhou Date: Thu, 9 Jan 2025 13:44:15 -0800 Subject: [PATCH 1/4] Add application signals enablement L2 --- .../aws-applicationsignals-alpha/.eslintrc.js | 8 + .../aws-applicationsignals-alpha/.gitignore | 22 + .../aws-applicationsignals-alpha/.npmignore | 20 + .../aws-applicationsignals-alpha/LICENSE | 201 ++++ .../aws-applicationsignals-alpha/NOTICE | 2 + .../aws-applicationsignals-alpha/README.md | 119 +++ .../aws-applicationsignals-alpha/awslint.json | 4 + .../jest.config.js | 2 + .../lib/enablement/constants.ts | 102 +++ .../lib/enablement/ecs.ts | 748 +++++++++++++++ .../aws-applicationsignals-alpha/lib/index.ts | 3 + .../aws-applicationsignals-alpha/package.json | 117 +++ .../test/ecs-enablement.test.ts | 860 ++++++++++++++++++ ...efaultTestDeployAssert0A2A622F.assets.json | 19 + ...aultTestDeployAssert0A2A622F.template.json | 36 + .../cdk.out | 1 + .../ecs-enablement-integration.assets.json | 19 + .../ecs-enablement-integration.template.json | 172 ++++ .../integ.json | 12 + .../manifest.json | 122 +++ .../tree.json | 303 ++++++ .../test/integ.ecs-enablement-daemon.ts | 48 + ...efaultTestDeployAssert7F3E5290.assets.json | 19 + ...aultTestDeployAssert7F3E5290.template.json | 36 + .../cdk.out | 1 + .../ecs-enablement-integration.assets.json | 19 + .../ecs-enablement-integration.template.json | 220 +++++ .../integ.json | 12 + .../manifest.json | 119 +++ .../tree.json | 359 ++++++++ .../test/integ.ecs-enablement-sidecar.ts | 51 ++ 31 files changed, 3776 insertions(+) create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/.eslintrc.js create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/.gitignore create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/.npmignore create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/LICENSE create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/NOTICE create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/README.md create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/awslint.json create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/jest.config.js create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/constants.ts create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/ecs.ts create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/lib/index.ts create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/package.json create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/test/ecs-enablement.test.ts create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ApplicationSignalsIntegrationECSDaemonDefaultTestDeployAssert0A2A622F.assets.json create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ApplicationSignalsIntegrationECSDaemonDefaultTestDeployAssert0A2A622F.template.json create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/cdk.out create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ecs-enablement-integration.assets.json create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ecs-enablement-integration.template.json create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/integ.json create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/manifest.json create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/tree.json create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.ts create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ApplicationSignalsIntegrationECSSidecarDefaultTestDeployAssert7F3E5290.assets.json create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ApplicationSignalsIntegrationECSSidecarDefaultTestDeployAssert7F3E5290.template.json create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/cdk.out create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ecs-enablement-integration.assets.json create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ecs-enablement-integration.template.json create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/integ.json create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/manifest.json create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/tree.json create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.ts diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/.eslintrc.js b/packages/@aws-cdk/aws-applicationsignals-alpha/.eslintrc.js new file mode 100644 index 0000000000000..b284f20df26e9 --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/.eslintrc.js @@ -0,0 +1,8 @@ +const baseConfig = require('@aws-cdk/cdk-build-tools/config/eslintrc'); +baseConfig.parserOptions.project = __dirname + '/tsconfig.json'; + +baseConfig.rules['import/no-extraneous-dependencies'] = ['error', { devDependencies: true, peerDependencies: true } ]; +baseConfig.rules['import/order'] = 'off'; +baseConfig.rules['@aws-cdk/invalid-cfn-imports'] = 'off'; + +module.exports = baseConfig; diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/.gitignore b/packages/@aws-cdk/aws-applicationsignals-alpha/.gitignore new file mode 100644 index 0000000000000..1272e8254630e --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/.gitignore @@ -0,0 +1,22 @@ +*.js +*.d.ts +tsconfig.json +*.generated.ts +*.js.map +dist +coverage +.nyc_output +.jsii + +.LAST_BUILD +nyc.config.js +.LAST_PACKAGE +*.snk +!.eslintrc.js + +junit.xml +!jest.config.js +!**/*.snapshot/**/asset.*/*.js +!**/*.snapshot/**/asset.*/*.d.ts + +!**/*.snapshot/**/asset.*/** diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/.npmignore b/packages/@aws-cdk/aws-applicationsignals-alpha/.npmignore new file mode 100644 index 0000000000000..8deb62970f750 --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/.npmignore @@ -0,0 +1,20 @@ + +.LAST_BUILD +*.snk +junit.xml +*.ts +!*.d.ts +!*.js +!*.lit.ts +coverage +.nyc_output +*.tgz +.eslintrc.js +# exclude cdk artifacts +**/cdk.out +dist +.LAST_PACKAGE +*.tsbuildinfo +test/ +tsconfig.json +!.jsii \ No newline at end of file diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/LICENSE b/packages/@aws-cdk/aws-applicationsignals-alpha/LICENSE new file mode 100644 index 0000000000000..5ccf0c6780bab --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2018-2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/NOTICE b/packages/@aws-cdk/aws-applicationsignals-alpha/NOTICE new file mode 100644 index 0000000000000..cd0946c1cf193 --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/NOTICE @@ -0,0 +1,2 @@ +AWS Cloud Development Kit (AWS CDK) +Copyright 2018-2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/README.md b/packages/@aws-cdk/aws-applicationsignals-alpha/README.md new file mode 100644 index 0000000000000..00cc3ff255e1d --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/README.md @@ -0,0 +1,119 @@ +# AWS::ApplicationSignals Construct Library + + +--- + +![cdk-constructs: Experimental](https://img.shields.io/badge/cdk--constructs-experimental-important.svg?style=for-the-badge) + +> The APIs of higher level constructs in this module are experimental and under active development. +> They are subject to non-backward compatible changes or removal in any future version. These are +> not subject to the [Semantic Versioning](https://semver.org/) model and breaking changes will be +> announced in the release notes. This means that while you may use them, you may need to update +> your source code when upgrading to a newer version of this package. + +--- + + + +This module is part of the [AWS Cloud Development Kit](https://github.com/aws/aws-cdk) project. + +```ts nofixture +import * as appsignals from '@aws-cdk/aws-applicationsignals-alpha'; +``` + +## Enable Application Signals on ECS with sidecar mode + +```ts +new appsignals.ApplicationSignalsIntegration(this, 'ApplicationSignalsIntegration', { + taskDefinition, + instrumentation: { + language: appsignals.InstrumentationLanguage.JAVA, + sdkVersion: appsignals.Instrumentation.JAVA_1_32_6 + }, + serviceName: 'sample-app', + cloudWatchAgent: { + enableSidecar: true, + } +}); +``` + +## Enable Application Signals on ECS with daemon mode + +Since the daemon deployment strategy is not supported on ECS Fargate, this mode is only supported on ECS on EC2. + +```ts +import * as ecs from 'aws-cdk-lib/aws-ecs'; + +// create CloudWatch agent daemon service +const cwAgentContainer = cwAgentTaskDefinition.addContainer('ecs-cwagent', { + image: ecs.ContainerImage.fromRegistry("public.ecr.aws/cloudwatch-agent/cloudwatch-agent:latest"), + cpu: 128, + memoryLimitMiB: 64, + portMappings: [ + { + name: 'cwagent-4316', + containerPort: 4316, + hostPort: 4316, + }, + { + name: 'cwagent-2000', + containerPort: 2000, + hostPort: 2000, + }, + ], + logging: new ecs.AwsLogDriver({ + streamPrefix: 'ecs', + logGroup: new LogGroup(this, 'CwAgentLogGroup', { + logGroupName: '/ecs/ecs-cwagent-cdk-daemon', + removalPolicy: cdk.RemovalPolicy.DESTROY, + }), + }), + environment: { + CW_CONFIG_CONTENT: '{"traces": {"traces_collected": {"application_signals": {}}}, "logs": {"metrics_collected":{"application_signals": {}}}}' + } +}); + +const cwAgentService = new ecs.Ec2Service(this, 'CwAgentDaemonService', { + cluster, + taskDefinition: cwAgentTaskDefinition, + daemon: true, + serviceConnectConfiguration: { + namespace: namespace.namespaceArn, + services: [{ + portMappingName: 'cwagent-4316', + dnsName: 'cwagent-4316-http', + port: 4316 + }, { + portMappingName: 'cwagent-2000', + dnsName: 'cwagent-2000-http', + port: 2000 + }] + } +}); + +// configure ApplicationSignalsIntegration to use Service Connect to communicate to the CloudWatch agent server +new appsignals.ApplicationSignalsIntegration(this, 'ApplicationSignalsIntegration', taskDefinition, { + instrumentation: { + language: appsignals.InstrumentationLanguage.PYTHON, + sdkVersion: appsignals.Instrumentation.PYTHON_V0_7_0 + }, + overrideEnvironments: [{ + name: appsignals.CommonExporting.OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT, + // overwrite the endpoint to point to the created Service Connect + value: "http://cwagent-4316-http:4316/v1/metrics" + }, { + name: appsignals.TraceExporting.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, + // overwrite the endpoint to point to the created Service Connect + value: "http://cwagent-4316-http:4316/v1/traces" + }, { + name: appsignals.TraceExporting.OTEL_TRACES_SAMPLER_ARG, + // overwrite the endpoint to point to the created Service Connect + value: "endpoint=http://cwagent-2000-http:2000" + }], + serviceName: 'sample-app', + cloudWatchAgent: { + // disable sidecar mode + enableSidecar: false, + } +}) +``` diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/awslint.json b/packages/@aws-cdk/aws-applicationsignals-alpha/awslint.json new file mode 100644 index 0000000000000..218e7dcc5a888 --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/awslint.json @@ -0,0 +1,4 @@ +{ + "exclude": [ + ] +} diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/jest.config.js b/packages/@aws-cdk/aws-applicationsignals-alpha/jest.config.js new file mode 100644 index 0000000000000..3a2fd93a1228a --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/jest.config.js @@ -0,0 +1,2 @@ +const baseConfig = require('@aws-cdk/cdk-build-tools/config/jest.config'); +module.exports = baseConfig; diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/constants.ts b/packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/constants.ts new file mode 100644 index 0000000000000..8f5497ebe7bdf --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/constants.ts @@ -0,0 +1,102 @@ +export const CommonExporting = { + OTEL_EXPORTER_OTLP_PROTOCOL: 'OTEL_EXPORTER_OTLP_PROTOCOL', + OTEL_EXPORTER_OTLP_PROTOCOL_HTTP_PROTOBUF: 'http/protobuf', + + OTEL_RESOURCE_ATTRIBUTES: 'OTEL_RESOURCE_ATTRIBUTES', + + OTEL_AWS_APPLICATION_SIGNALS: 'OTEL_AWS_APPLICATION_SIGNALS_ENABLED', + OTEL_AWS_APPLICATION_SIGNALS_ENABLED: 'true', + OTEL_AWS_APPLICATION_SIGNALS_DISABLED: 'false', + OTEL_AWS_APPLICATION_SIGNALS_RUNTIME: 'OTEL_AWS_APPLICATION_SIGNALS_RUNTIME_ENABLED', + OTEL_AWS_APPLICATION_SIGNALS_RUNTIME_ENABLED: 'true', + OTEL_AWS_APPLICATION_SIGNALS_RUNTIME_DISABLED: 'false', + + OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT: 'OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT', + OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT_LOCAL_CWA: 'http://localhost:4316/v1/metrics', +}; + +export const LogsExporting = { + OTEL_LOGS_EXPORTER: 'OTEL_LOGS_EXPORTER', + OTEL_LOGS_EXPORTER_NONE: 'none', + OTEL_LOGS_EXPORTER_OTLP: 'otlp', +} as const; + +export const MetricsExporting = { + OTEL_METRICS_EXPORTER: 'OTEL_METRICS_EXPORTER', + OTEL_METRICS_EXPORTER_NONE: 'none', + OTEL_METRICS_EXPORTER_OTLP: 'otlp', +} as const; + +export const TraceExporting = { + OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: 'OTEL_EXPORTER_OTLP_TRACES_ENDPOINT', + OTEL_EXPORTER_OTLP_TRACES_ENDPOINT_LOCAL_CWA: 'http://localhost:4316/v1/traces', + + OTEL_TRACES_SAMPLER: 'OTEL_TRACES_SAMPLER', + OTEL_TRACES_SAMPLER_XRAY: 'xray', + OTEL_TRACES_SAMPLER_TRACEID_RATIO: 'traceidratio', + OTEL_TRACES_SAMPLER_ALWAYS_ON: 'always_on', + OTEL_TRACES_SAMPLER_ALWAYS_OFF: 'always_off', + OTEL_TRACES_SAMPLER_PARENT_BASED_TRACEID_RATIO: 'parentbased_traceidratio', + OTEL_TRACES_SAMPLER_PARENT_BASED_ALWAYS_ON: 'parentbased_always_on', + OTEL_TRACES_SAMPLER_PARENT_BASED_ALWAYS_OFF: 'parentbased_always_off', + + OTEL_TRACES_SAMPLER_ARG: 'OTEL_TRACES_SAMPLER_ARG', + OTEL_TRACES_SAMPLER_ARG_LOCAL_CWA: 'endpoint=http://localhost:2000', + + OTEL_PROPAGATORS: 'OTEL_PROPAGATORS', + OTEL_PROPAGATORS_APPLICATION_SIGNALS: 'tracecontext,baggage,b3,xray', +} as const; + +export const JavaInstrumentation = { + JAVA_TOOL_OPTIONS: 'JAVA_TOOL_OPTIONS', + JAVA_TOOL_OPTIONS_ADOT: ' -javaagent:/otel-auto-instrumentation/javaagent.jar', +} as const; + +export const PythonInstrumentation = { + OTEL_PYTHON_DISTRO: 'OTEL_PYTHON_DISTRO', + OTEL_PYTHON_DISTRO_AWS_DISTRO: 'aws_distro', + + OTEL_PYTHON_CONFIGURATOR: 'OTEL_PYTHON_CONFIGURATOR', + OTEL_PYTHON_CONFIGURATOR_AWS_CONFIGURATOR: 'aws_configurator', + + PYTHONPATH: 'PYTHONPATH', + PYTHONPATH_ADOT: '/otel-auto-instrumentation-python/opentelemetry/instrumentation/auto_instrumentation:/otel-auto-instrumentation-python', +} as const; + +export const DotnetInstrumentation = { + OTEL_DOTNET_DISTRO: 'OTEL_DOTNET_DISTRO', + OTEL_DOTNET_DISTRO_AWS_DISTRO: 'aws_distro', + + OTEL_DOTNET_CONFIGURATOR: 'OTEL_DOTNET_CONFIGURATOR', + OTEL_DOTNET_CONFIGURATOR_AWS_CONFIGURATOR: 'aws_configurator', + + OTEL_DOTNET_AUTO_PLUGINS: 'OTEL_DOTNET_AUTO_PLUGINS', + OTEL_DOTNET_AUTO_PLUGINS_ADOT: 'AWS.Distro.OpenTelemetry.AutoInstrumentation.Plugin, AWS.Distro.OpenTelemetry.AutoInstrumentation', + + CORECLR_ENABLE_PROFILING: 'CORECLR_ENABLE_PROFILING', + CORECLR_ENABLE_PROFILING_ENABLED: '1', + CORECLR_ENABLE_PROFILING_DISABLED: '0', + + CORECLR_PROFILER: 'CORECLR_PROFILER', + CORECLR_PROFILER_OTEL: '{918728DD-259F-4A6A-AC2B-B85E1B658318}', + + CORECLR_PROFILER_PATH: 'CORECLR_PROFILER_PATH', + CORECLR_PROFILER_PATH_LINUX_X64: '/otel-auto-instrumentation-dotnet/linux-x64/OpenTelemetry.AutoInstrumentation.Native.so', + CORECLR_PROFILER_PATH_WINDOWS_X64: 'C:\\otel-auto-instrumentation-dotnet\\win-x64\\OpenTelemetry.AutoInstrumentation.Native.dll', + + DOTNET_STARTUP_HOOKS: 'DOTNET_STARTUP_HOOKS', + DOTNET_STARTUP_HOOKS_LINUX_ADOT: '/otel-auto-instrumentation-dotnet/net/OpenTelemetry.AutoInstrumentation.StartupHook.dll', + DOTNET_STARTUP_HOOKS_WINDOWS_ADOT: 'C:\\otel-auto-instrumentation-dotnet\\net\\OpenTelemetry.AutoInstrumentation.StartupHook.dll', + + DOTNET_ADDITIONAL_DEPS: 'DOTNET_ADDITIONAL_DEPS', + DOTNET_ADDITIONAL_DEPS_LINUX_ADOT: '/otel-auto-instrumentation-dotnet/AdditionalDeps', + DOTNET_ADDITIONAL_DEPS_WINDOWS_ADOT: 'C:\\otel-auto-instrumentation-dotnet\\AdditionalDeps', + + OTEL_DOTNET_AUTO_HOME: 'OTEL_DOTNET_AUTO_HOME', + OTEL_DOTNET_AUTO_HOME_LINUX_ADOT: '/otel-auto-instrumentation-dotnet', + OTEL_DOTNET_AUTO_HOME_WINDOWS_ADOT: 'C:\\otel-auto-instrumentation-dotnet', + + DOTNET_SHARED_STORE: 'DOTNET_SHARED_STORE', + DOTNET_SHARED_STORE_LINUX_ADOT: '/otel-auto-instrumentation-dotnet/store', + DOTNET_SHARED_STORE_WINDOWS_ADOT: 'C:\\otel-auto-instrumentation-dotnet\\store', +} as const; diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/ecs.ts b/packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/ecs.ts new file mode 100644 index 0000000000000..4b8de965bf876 --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/ecs.ts @@ -0,0 +1,748 @@ +import * as ecs from 'aws-cdk-lib/aws-ecs'; +import { Construct } from 'constructs'; +import * as constants from './constants'; +import { ManagedPolicy } from 'aws-cdk-lib/aws-iam'; + +/** + * Supported instrumentation languages for Application Signals. + */ +export enum InstrumentationLanguage { + /** + * Java instrumentation language. + */ + JAVA, + /** + * Python instrumentation language. + */ + PYTHON, + /** + * .NET instrumentation language. + */ + DOTNET, + /** + * Node.js instrumentation language. + */ + NODEJS, +} + +/** + * Base class for instrumentation versions. + * Provides functionality to generate image URIs for different instrumentation types. + */ +export abstract class InstrumentationVersion { + public constructor(protected readonly imageRepo: string, protected readonly version: string) {} + + /** + * Get the image URI for the instrumentation version. + * @returns The image URI. + */ + public imageURI(): string { + return `${this.imageRepo}:${this.version}`; + } +} + +/** + * Available versions for Java instrumentation. + */ +/* eslint-disable @typescript-eslint/member-ordering */ +export class JavaInstrumentationVersion extends InstrumentationVersion { + private static readonly IMAGE_REPO = 'public.ecr.aws/aws-observability/adot-autoinstrumentation-java'; + /** + * ADOT Java Instrumentation version 1.33.0 + */ + public static readonly V1_33_0 = new JavaInstrumentationVersion(JavaInstrumentationVersion.IMAGE_REPO, 'v1.33.0'); + /** + * ADOT Java Instrumentation version 1.32.6 + */ + public static readonly V1_32_6 = new JavaInstrumentationVersion(JavaInstrumentationVersion.IMAGE_REPO, 'v1.32.6'); +} +/* eslint-enable */ + +/** + * Available versions for .NET instrumentation. + */ +/** + * Available versions for Python instrumentation. + */ +/* eslint-disable @typescript-eslint/member-ordering */ +export class PythonInstrumentationVersion extends InstrumentationVersion { + private static readonly IMAGE_REPO = 'public.ecr.aws/aws-observability/adot-autoinstrumentation-python'; + /** + * ADOT Python Instrumentation version 0.8.0 + */ + public static readonly V0_8_0 = new PythonInstrumentationVersion(PythonInstrumentationVersion.IMAGE_REPO, 'v0.8.0'); +} +/* eslint-enable */ + +/** + * Available versions for .NET instrumentation. + */ +/* eslint-disable @typescript-eslint/member-ordering */ +export class DotnetInstrumentationVersion extends InstrumentationVersion { + private static readonly IMAGE_REPO = 'public.ecr.aws/aws-observability/adot-autoinstrumentation-dotnet'; + /** + * ADOT .NET Instrumentation version 1.6.0 + */ + public static readonly V1_6_0 = new DotnetInstrumentationVersion(DotnetInstrumentationVersion.IMAGE_REPO, 'v1.6.0'); + /** + * ADOT .NET Instrumentation version 1.6.0 for ARM64 + */ + public static readonly V1_6_0_ARM64 = new DotnetInstrumentationVersion(DotnetInstrumentationVersion.IMAGE_REPO, 'v1.6.0-arm64'); + /** + * ADOT .NET Instrumentation version 1.6.0 for AMD64 + */ + public static readonly V1_6_0_AMD64 = new DotnetInstrumentationVersion(DotnetInstrumentationVersion.IMAGE_REPO, 'v1.6.0-amd64'); + /** + * ADOT .NET Instrumentation version 1.6.0 for Windows 2022 + */ + public static readonly V1_6_0_WINDOWS2022 = new DotnetInstrumentationVersion(DotnetInstrumentationVersion.IMAGE_REPO, 'v1.6.0-windows2022'); + /** + * ADOT .NET Instrumentation version 1.6.0 for Windows 2019 + */ + public static readonly V1_6_0_WINDOWS2019 = new DotnetInstrumentationVersion(DotnetInstrumentationVersion.IMAGE_REPO, 'v1.6.0-windows2019'); +} +/* eslint-enable */ + +/** + * Available versions for Node.js instrumentation. + */ +/* eslint-disable @typescript-eslint/member-ordering */ +export class NodeInstrumentationVersion extends InstrumentationVersion { + private static readonly IMAGE_REPO = 'public.ecr.aws/aws-observability/adot-autoinstrumentation-node'; + /** + * ADOT Node.js Instrumentation version 0.5.0 + */ + public static readonly V0_5_0 = new NodeInstrumentationVersion(NodeInstrumentationVersion.IMAGE_REPO, 'v0.5.0'); +} +/* eslint-enable */ + +/** + * Interface for environment extensions. + */ +export interface EnvironmentExtension { + /** + * The name of the environment variable. + */ + readonly name: string; + /** + * The value of the environment variable. + */ + readonly value: string; +} + +/** + * Interface for instrumentation properties. + */ +export interface InstrumentationProps { + /** + * The language of the instrumentation. + */ + readonly language: InstrumentationLanguage; + /** + * The version of the instrumentation. + */ + readonly sdkVersion: InstrumentationVersion; + /** + * The runtime platform of the instrumentation. + * + * @default - the runtime platform specified through the input TaskDefinition. + */ + readonly runtimePlatform?: ecs.RuntimePlatform; +} + +/** + * Interface for Application Signals properties. + */ +export interface ApplicationSignalsIntegrationProps { + + /** + * The name of the service. + * + * @default - task definition family name + */ + readonly serviceName?: string; + + /** + * The task definition to integrate Application Signals into. + * + * [disable-awslint:ref-via-interface] + */ + readonly taskDefinition: ecs.TaskDefinition; + + /** + * The instrumentation properties. + */ + readonly instrumentation: InstrumentationProps; + + /** + * The environment variables to override. + * + * @default - no environment variables to override. + */ + readonly overrideEnvironments?: EnvironmentExtension[]; + + /** + * The CloudWatch Agent properties. + * + * @default - a basic agent sidecar container with latest public image + */ + readonly cloudWatchAgent?: CloudWatchAgentProps; +} + +/** + * Interface for CloudWatch Agent properties. + */ +export interface CloudWatchAgentProps { + + /** + * Whether to enable the CloudWatch Agent sidecar. + * + * @default - true + */ + readonly enableSidecar: boolean; + + /** + * The container definition options for the CloudWatch Agent. + * + * @default - a basic CloudWatch Agent container with latest public image. + */ + readonly container?: ecs.ContainerDefinitionOptions; +} + +const DEFAULT_ENVS = [ + { + name: constants.LogsExporting.OTEL_LOGS_EXPORTER, + value: constants.LogsExporting.OTEL_LOGS_EXPORTER_NONE, + }, + { + name: constants.MetricsExporting.OTEL_METRICS_EXPORTER, + value: constants.MetricsExporting.OTEL_METRICS_EXPORTER_NONE, + }, + { + name: constants.CommonExporting.OTEL_EXPORTER_OTLP_PROTOCOL, + value: constants.CommonExporting.OTEL_EXPORTER_OTLP_PROTOCOL_HTTP_PROTOBUF, + }, + { + name: constants.CommonExporting.OTEL_AWS_APPLICATION_SIGNALS, + value: constants.CommonExporting.OTEL_AWS_APPLICATION_SIGNALS_ENABLED, + }, + { + name: constants.CommonExporting.OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT, + value: constants.CommonExporting.OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT_LOCAL_CWA, + }, + { + name: constants.TraceExporting.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, + value: constants.TraceExporting.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT_LOCAL_CWA, + }, + { + name: constants.TraceExporting.OTEL_TRACES_SAMPLER, + value: constants.TraceExporting.OTEL_TRACES_SAMPLER_XRAY, + }, + { + name: constants.TraceExporting.OTEL_TRACES_SAMPLER_ARG, + value: constants.TraceExporting.OTEL_TRACES_SAMPLER_ARG_LOCAL_CWA, + }, + { + name: constants.TraceExporting.OTEL_PROPAGATORS, + value: constants.TraceExporting.OTEL_PROPAGATORS_APPLICATION_SIGNALS, + }, +]; + +const JAVA_ENVS = [ + { + name: constants.JavaInstrumentation.JAVA_TOOL_OPTIONS, + value: constants.JavaInstrumentation.JAVA_TOOL_OPTIONS_ADOT, + }, +]; + +const PYTHON_ENVS = [ + { + name: constants.PythonInstrumentation.OTEL_PYTHON_DISTRO, + value: constants.PythonInstrumentation.OTEL_PYTHON_DISTRO_AWS_DISTRO, + }, + { + name: constants.PythonInstrumentation.OTEL_PYTHON_CONFIGURATOR, + value: constants.PythonInstrumentation.OTEL_PYTHON_CONFIGURATOR_AWS_CONFIGURATOR, + }, + { + name: constants.PythonInstrumentation.PYTHONPATH, + value: constants.PythonInstrumentation.PYTHONPATH_ADOT, + }, +]; + +const DOTNET_COMMON_ENVS = [ + { + name: constants.DotnetInstrumentation.OTEL_DOTNET_DISTRO, + value: constants.DotnetInstrumentation.OTEL_DOTNET_DISTRO_AWS_DISTRO, + }, + { + name: constants.DotnetInstrumentation.OTEL_DOTNET_CONFIGURATOR, + value: constants.DotnetInstrumentation.OTEL_DOTNET_CONFIGURATOR_AWS_CONFIGURATOR, + }, + { + name: constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_PLUGINS, + value: constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_PLUGINS_ADOT, + }, +]; + +const DOTNET_LINUX_ENVS = [ + { + name: constants.DotnetInstrumentation.CORECLR_ENABLE_PROFILING, + value: constants.DotnetInstrumentation.CORECLR_ENABLE_PROFILING_ENABLED, + }, + { + name: constants.DotnetInstrumentation.CORECLR_PROFILER, + value: constants.DotnetInstrumentation.CORECLR_PROFILER_OTEL, + }, + { + name: constants.DotnetInstrumentation.CORECLR_PROFILER_PATH, + value: constants.DotnetInstrumentation.CORECLR_PROFILER_PATH_LINUX_X64, + }, + { + name: constants.DotnetInstrumentation.DOTNET_STARTUP_HOOKS, + value: constants.DotnetInstrumentation.DOTNET_STARTUP_HOOKS_LINUX_ADOT, + }, + { + name: constants.DotnetInstrumentation.DOTNET_ADDITIONAL_DEPS, + value: constants.DotnetInstrumentation.DOTNET_ADDITIONAL_DEPS_LINUX_ADOT, + }, + { + name: constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_HOME, + value: constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_HOME_LINUX_ADOT, + }, + { + name: constants.DotnetInstrumentation.DOTNET_SHARED_STORE, + value: constants.DotnetInstrumentation.DOTNET_SHARED_STORE_LINUX_ADOT, + }, +]; + +const DOTNET_WINDOWS_ENVS = [ + { + name: constants.DotnetInstrumentation.CORECLR_ENABLE_PROFILING, + value: constants.DotnetInstrumentation.CORECLR_ENABLE_PROFILING_ENABLED, + }, + { + name: constants.DotnetInstrumentation.CORECLR_PROFILER, + value: constants.DotnetInstrumentation.CORECLR_PROFILER_OTEL, + }, + { + name: constants.DotnetInstrumentation.CORECLR_PROFILER_PATH, + value: constants.DotnetInstrumentation.CORECLR_PROFILER_PATH_WINDOWS_X64, + }, + { + name: constants.DotnetInstrumentation.DOTNET_STARTUP_HOOKS, + value: constants.DotnetInstrumentation.DOTNET_STARTUP_HOOKS_WINDOWS_ADOT, + }, + { + name: constants.DotnetInstrumentation.DOTNET_ADDITIONAL_DEPS, + value: constants.DotnetInstrumentation.DOTNET_ADDITIONAL_DEPS_WINDOWS_ADOT, + }, + { + name: constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_HOME, + value: constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_HOME_WINDOWS_ADOT, + }, + { + name: constants.DotnetInstrumentation.DOTNET_SHARED_STORE, + value: constants.DotnetInstrumentation.DOTNET_SHARED_STORE_WINDOWS_ADOT, + }, +]; + +abstract class SDKInject { + protected taskDefinition: ecs.TaskDefinition; + protected sharedVolumeName: string; + protected adotImage: string; + private overrideEnvironments?: EnvironmentExtension[]; + + constructor( + taskDefinition: ecs.TaskDefinition, + sharedVolumeName: string, + adotImage: string, + overrideEnvironments?: EnvironmentExtension[]) { + this.taskDefinition = taskDefinition; + this.sharedVolumeName = sharedVolumeName; + this.adotImage = adotImage; + this.overrideEnvironments = overrideEnvironments; + } + + abstract get command(): string[]; + abstract get memoryLimitMiB(): number; + + protected abstract get containerPath(): string; + protected abstract applyAdditionalEnvironments(container: ecs.ContainerDefinition): void; + + public injectInitContainer(): ecs.ContainerDefinition { + const initContainer = this.taskDefinition.addContainer('adot-init', { + image: ecs.ContainerImage.fromRegistry(this.adotImage), + essential: false, + command: this.command, + cpu: 0, + memoryLimitMiB: this.memoryLimitMiB, + }); + initContainer.addMountPoints({ + sourceVolume: this.sharedVolumeName, + containerPath: this.containerPath, + // double check + readOnly: false, + }); + return initContainer; + } + + public renderDefaultContainer(container: ecs.ContainerDefinition) { + for (const env of DEFAULT_ENVS) { + container.addEnvironment(env.name, env.value); + } + this.applyAdditionalEnvironments(container); + for (const env of this.overrideEnvironments??[]) { + container.addEnvironment(env.name, env.value); + } + container.addMountPoints({ + sourceVolume: this.sharedVolumeName, + containerPath: this.containerPath, + // double check + readOnly: false, + }); + } +} + +class JavaSDKInject extends SDKInject { + get command(): string[] { + return ['cp', '/javaagent.jar', '/otel-auto-instrumentation/javaagent.jar']; + } + + get memoryLimitMiB(): number { + return 64; + } + + protected get containerPath(): string { + return '/otel-auto-instrumentation'; + } + + protected applyAdditionalEnvironments(container: ecs.ContainerDefinition) { + const environments = (container as any).environment; + for (const env of JAVA_ENVS) { + if (!environments[env.name]) { + container.addEnvironment(env.name, env.value); + } + } + } +} + +class PythonSDKInject extends SDKInject { + get command(): string[] { + return ['cp', '-a', '/autoinstrumentation/.', '/otel-auto-instrumentation-python']; + } + + get memoryLimitMiB(): number { + return 32; + } + + public applyAdditionalEnvironments(container: ecs.ContainerDefinition): void { + const environments = (container as any).environment; + for (const env of PYTHON_ENVS) { + if (!environments[env.name]) { + container.addEnvironment(env.name, env.value); + } else if ('PYTHONPATH' === env.name) { + const pythonPath = environments[env.name]; + container.addEnvironment(env.name, `/otel-auto-instrumentation-python/opentelemetry/instrumentation/auto_instrumentation:${pythonPath}:/otel-auto-instrumentation-python`); + } + } + } + + protected get containerPath(): string { + return '/otel-auto-instrumentation-python'; + } +} + +class DotNetSDKOnLinuxInject extends SDKInject { + private cpuArch: ecs.CpuArchitecture; + + constructor( + taskDefinition: ecs.TaskDefinition, + sharedVolumeName: string, + adotImage: string, + cpuArch: ecs.CpuArchitecture, + overrideEnvironments?: EnvironmentExtension[]) { + super(taskDefinition, sharedVolumeName, adotImage, overrideEnvironments); + this.cpuArch = cpuArch; + } + + get command(): string[] { + return ['cp', '-a', '/autoinstrumentation/.', '/otel-auto-instrumentation-dotnet']; + } + + get memoryLimitMiB(): number { + return 128; + } + + public applyAdditionalEnvironments(container: ecs.ContainerDefinition): void { + const environments = (container as any).environment; + let libPath = 'linux-x64'; + if (this.cpuArch == ecs.CpuArchitecture.ARM64) { + libPath = 'linux-arm64'; + } + for (const env of [...DOTNET_COMMON_ENVS, { + name: 'CORECLR_PROFILER_PATH', + value: `/otel-auto-instrumentation-dotnet/${libPath}/OpenTelemetry.AutoInstrumentation.Native.so`, + }]) { + if (!environments[env.name]) { + container.addEnvironment(env.name, env.value); + } + } + + if (environments.OTEL_DOTNET_AUTO_HOME) { + // If OTEL_DOTNET_AUTO_HOME env var is already set, we will assume that .NET Auto-instrumentation is already configured. + return; + } + + for (const env of DOTNET_LINUX_ENVS) { + if (!environments[env.name]) { + container.addEnvironment(env.name, env.value); + } + } + } + + protected get containerPath(): string { + return '/otel-auto-instrumentation-dotnet'; + } +} + +class DotNetSDKOnWindowsInject extends SDKInject { + get command(): string[] { + return ['CMD', + '/c', + 'xcopy', + '/e', + 'C:\\autoinstrumentation\\*', + 'C:\\otel-auto-instrumentation-dotnet', + '&&', + 'icacls', + 'C:\\otel-auto-instrumentation-dotnet', + '/grant', + '*S-1-1-0:R', + '/T']; + } + + get memoryLimitMiB(): number { + return 128; + } + + public applyAdditionalEnvironments(container: ecs.ContainerDefinition): void { + const environments = (container as any).environment; + for (const env of DOTNET_COMMON_ENVS) { + if (!environments[env.name]) { + container.addEnvironment(env.name, env.value); + } + } + if (environments.OTEL_DOTNET_AUTO_HOME) { + // If OTEL_DOTNET_AUTO_HOME env var is already set, we will assume that .NET Auto-instrumentation is already configured. + return; + } + for (const env of DOTNET_WINDOWS_ENVS) { + if (!environments[env.name]) { + container.addEnvironment(env.name, env.value); + } + } + } + + protected get containerPath(): string { + return 'C:\\otel-auto-instrumentation-dotnet'; + } +} + +class NodeSDKInject extends SDKInject { + get command(): string[] { + return ['cp', '-a', '/autoinstrumentation/.', '/otel-auto-instrumentation-nodejs']; + } + + get memoryLimitMiB(): number { + return 128; + } + + public applyAdditionalEnvironments(container: ecs.ContainerDefinition): void { + const environments = (container as any).environment; + const originalNodeOptions = environments.NODE_OPTIONS ?? ''; + let renderedNodeOptions = `${originalNodeOptions} --require /otel-auto-instrumentation-nodejs/autoinstrumentation.js`; + container.addEnvironment('NODE_OPTIONS', renderedNodeOptions); + } + + protected get containerPath(): string { + return '/otel-auto-instrumentation-nodejs'; + } +} + +const CLOUDWATCH_AGENT_IMAGE = 'amazon/cloudwatch-agent:latest'; +const CLOUDWATCH_AGENT_IMAGE_WIN2019 = 'public.ecr.aws/cloudwatch-agent/cloudwatch-agent:latest-windowsservercore2019'; +const CLOUDWATCH_AGENT_IMAGE_WIN2022 ='public.ecr.aws/cloudwatch-agent/cloudwatch-agent:latest-windowsservercore2022'; +const CW_CONFIG_CONTENT = { + logs: { + metrics_collected: { + application_signals: { + enabled: true, + }, + }, + }, + traces: { + traces_collected: { + application_signals: { + enabled: true, + }, + }, + }, +}; + +/** + * Class for integrating Application Signals into an ECS task definition. + */ +export class ApplicationSignalsIntegration extends Construct { + private sdkInject?: SDKInject; + private mountVolumeName: string = 'opentelemetry-auto-instrumentation'; + + constructor( + scope: Construct, + id: string, + props: ApplicationSignalsIntegrationProps) { + super(scope, id); + let serviceName = props.serviceName; + if (!serviceName) { + serviceName = props.taskDefinition.family; + } + + let overrideEnvironments: EnvironmentExtension[] = [{ + name: constants.CommonExporting.OTEL_RESOURCE_ATTRIBUTES, + value: `service.name=${serviceName}`, + }]; + + let runtimePlatformObj = props.instrumentation.runtimePlatform ?? (props.taskDefinition as any).runtimePlatform; + let cloudWatchAgentImage = CLOUDWATCH_AGENT_IMAGE; + let cpuArch = ecs.CpuArchitecture.X86_64; + let isWindows = false; + if (runtimePlatformObj) { + const runtimePlatform = runtimePlatformObj as ecs.RuntimePlatform; + if (runtimePlatform.operatingSystemFamily) { + switch (runtimePlatform.operatingSystemFamily) { + case ecs.OperatingSystemFamily.WINDOWS_SERVER_2019_CORE: + case ecs.OperatingSystemFamily.WINDOWS_SERVER_2019_FULL: + cloudWatchAgentImage = CLOUDWATCH_AGENT_IMAGE_WIN2019; + isWindows = true; + break; + case ecs.OperatingSystemFamily.WINDOWS_SERVER_2022_CORE: + case ecs.OperatingSystemFamily.WINDOWS_SERVER_2022_FULL: + cloudWatchAgentImage = CLOUDWATCH_AGENT_IMAGE_WIN2022; + isWindows = true; + break; + } + if (runtimePlatform.cpuArchitecture) { + cpuArch = runtimePlatform.cpuArchitecture; + } + } + } + + const cloudWatchAgentConfig = props.cloudWatchAgent ?? { enableSidecar: true }; + + if (props.taskDefinition.compatibility === ecs.Compatibility.FARGATE && !cloudWatchAgentConfig.enableSidecar) { + throw new Error('Fargate tasks must deploy CloudWatch Agent as a sidecar container'); + } + if (cloudWatchAgentConfig.enableSidecar) { + props.taskDefinition.taskRole.addManagedPolicy(ManagedPolicy.fromAwsManagedPolicyName('CloudWatchAgentServerPolicy')); + } + + overrideEnvironments.push(...props.overrideEnvironments ?? []); + switch (props.instrumentation.language) { + case InstrumentationLanguage.JAVA: + this.sdkInject = new JavaSDKInject( + props.taskDefinition, + this.mountVolumeName, + props.instrumentation.sdkVersion.imageURI(), + overrideEnvironments, + ); + break; + case InstrumentationLanguage.PYTHON: + this.sdkInject = new PythonSDKInject( + props.taskDefinition, + this.mountVolumeName, + props.instrumentation.sdkVersion.imageURI(), + overrideEnvironments, + ); + break; + case InstrumentationLanguage.DOTNET: + if (isWindows) { + this.sdkInject = new DotNetSDKOnWindowsInject( + props.taskDefinition, + this.mountVolumeName, + props.instrumentation.sdkVersion.imageURI(), + overrideEnvironments, + ); + } else { + this.sdkInject = new DotNetSDKOnLinuxInject( + props.taskDefinition, + this.mountVolumeName, + props.instrumentation.sdkVersion.imageURI(), + cpuArch, + overrideEnvironments, + ); + } + break; + case InstrumentationLanguage.NODEJS: + this.sdkInject = new NodeSDKInject( + props.taskDefinition, + this.mountVolumeName, + props.instrumentation.sdkVersion.imageURI(), + overrideEnvironments, + ); + break; + } + + let cwaContainer: ecs.ContainerDefinitionOptions | undefined; + if (cloudWatchAgentConfig.enableSidecar) { + cwaContainer = cloudWatchAgentConfig.container ?? this.getCloudWatchAgentContainer(cloudWatchAgentImage); + } + + this.mutateTaskDefinition(props.taskDefinition, cwaContainer); + } + + private mutateTaskDefinition(taskDefinition: ecs.TaskDefinition, cwaContainer?: ecs.ContainerDefinitionOptions) { + taskDefinition.addVolume({ + name: this.mountVolumeName, + }); + + let defaultContainer = taskDefinition.defaultContainer!; + if (this.sdkInject) { + this.sdkInject.renderDefaultContainer(defaultContainer); + let initContainer = this.sdkInject.injectInitContainer(); + defaultContainer.addContainerDependencies({ + container: initContainer, + condition: ecs.ContainerDependencyCondition.SUCCESS, + }); + } + + if (cwaContainer) { + let cwagentContainer = taskDefinition.addContainer('cloudwatch-agent', cwaContainer); + defaultContainer.addContainerDependencies({ + container: cwagentContainer, + condition: ecs.ContainerDependencyCondition.START, + }); + } + } + + private getCloudWatchAgentContainer(image: string): ecs.ContainerDefinitionOptions { + return { + image: ecs.ContainerImage.fromRegistry(image), + environment: { + CW_CONFIG_CONTENT: JSON.stringify(CW_CONFIG_CONTENT), + }, + logging: new ecs.AwsLogDriver({ streamPrefix: 'cloudwatch-agent' }), + user: '0:1338', + memoryReservationMiB: 50, + portMappings: [ + { + containerPort: 4316, + hostPort: 4316, + }, + { + containerPort: 2000, + hostPort: 2000, + }, + ], + }; + } +} diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/lib/index.ts b/packages/@aws-cdk/aws-applicationsignals-alpha/lib/index.ts new file mode 100644 index 0000000000000..5851f9f70949c --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/lib/index.ts @@ -0,0 +1,3 @@ +// AWS::ApplicationSignals Cloudformation Resources +export * from './enablement/ecs'; +export * from './enablement/constants'; diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/package.json b/packages/@aws-cdk/aws-applicationsignals-alpha/package.json new file mode 100644 index 0000000000000..9056b0c49426b --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/package.json @@ -0,0 +1,117 @@ +{ + "name": "@aws-cdk/aws-applicationsignals-alpha", + "version": "0.0.0", + "private": false, + "description": "The CDK Construct Library for AWS::Amplify", + "main": "lib/index.js", + "types": "lib/index.d.ts", + "jsii": { + "outdir": "dist", + "targets": { + "dotnet": { + "namespace": "Amazon.CDK.AWS.ApplicationSignals.Alpha", + "packageId": "Amazon.CDK.AWS.ApplicationSignals.Alpha", + "iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/main/logo/default-256-dark.png" + }, + "java": { + "package": "software.amazon.awscdk.services.applicationsignals.alpha", + "maven": { + "groupId": "software.amazon.awscdk", + "artifactId": "applicationsignals-alpha" + } + }, + "python": { + "distName": "aws-cdk.aws-applicationsignals-alpha", + "module": "aws_cdk.aws_applicationsignals_alpha", + "classifiers": [ + "Framework :: AWS CDK", + "Framework :: AWS CDK :: 2" + ] + }, + "go": { + "moduleName": "github.com/aws/aws-cdk-go", + "packageName": "awscdkapplicationsignalsalpha" + } + }, + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } + }, + "repository": { + "type": "git", + "url": "https://github.com/aws/aws-cdk.git", + "directory": "packages/@aws-cdk/aws-applicationsignals-alpha" + }, + "homepage": "https://github.com/aws/aws-cdk", + "scripts": { + "build": "cdk-build", + "integ": "integ-runner --language javascript", + "lint": "cdk-lint", + "package": "cdk-package", + "awslint": "cdk-awslint", + "pkglint": "pkglint -f", + "test": "cdk-test", + "watch": "cdk-watch", + "build+test": "yarn build && yarn test", + "build+test+package": "yarn build+test && yarn package", + "compat": "cdk-compat", + "rosetta:extract": "yarn --silent jsii-rosetta extract", + "build+extract": "yarn build && yarn rosetta:extract", + "build+test+extract": "yarn build+test && yarn rosetta:extract" + }, + "cdk-build": { + "env": { + "AWSLINT_BASE_CONSTRUCT": true + } + }, + "keywords": [ + "aws", + "cdk", + "constructs", + "AWS::ApplicationSignals", + "applicationsignals" + ], + "author": { + "name": "Amazon Web Services", + "url": "https://aws.amazon.com", + "organization": true + }, + "license": "Apache-2.0", + "devDependencies": { + "@aws-cdk/cdk-build-tools": "0.0.0", + "@aws-cdk/integ-runner": "0.0.0", + "@aws-cdk/integ-tests-alpha": "0.0.0", + "@aws-cdk/pkglint": "0.0.0", + "@aws-cdk/aws-ecs": "^1.204.0", + "@types/jest": "^29.5.14", + "aws-cdk-lib": "0.0.0", + "constructs": "^10.0.0" + }, + "dependencies": {}, + "peerDependencies": { + "aws-cdk-lib": "^0.0.0", + "constructs": "^10.0.0" + }, + "engines": { + "node": ">= 14.15.0" + }, + "stability": "experimental", + "maturity": "experimental", + "awscdkio": { + "announce": false + }, + "publishConfig": { + "tag": "latest" + }, + "pkglint": { + "exclude": [ + "naming/package-matches-directory", + "assert/assert-dependency" + ] + } +} diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/ecs-enablement.test.ts b/packages/@aws-cdk/aws-applicationsignals-alpha/test/ecs-enablement.test.ts new file mode 100644 index 0000000000000..8a4f3f4c4af6d --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/ecs-enablement.test.ts @@ -0,0 +1,860 @@ + +import { Stack } from 'aws-cdk-lib'; +import { Template } from 'aws-cdk-lib/assertions'; +import * as ecs from 'aws-cdk-lib/aws-ecs'; +import { ApplicationSignalsIntegration, InstrumentationLanguage, DotnetInstrumentationVersion, PythonInstrumentationVersion, JavaInstrumentationVersion, NodeInstrumentationVersion } from '../lib'; + +describe('application signals integration', () => { + test('should create basic application signals configurations with java', () => { + // GIVEN + const stack = new Stack(); + + // WHEN + const fargateTaskDefinition = new ecs.FargateTaskDefinition(stack, 'TestTaskDefinition', { + cpu: 256, + memoryLimitMiB: 512, + }); + fargateTaskDefinition.addContainer('app', { + image: ecs.ContainerImage.fromRegistry('nathanpeck/name'), + }); + new ApplicationSignalsIntegration(stack, 'TestIntegration', { + taskDefinition: fargateTaskDefinition, + instrumentation: { + language: InstrumentationLanguage.JAVA, + sdkVersion: JavaInstrumentationVersion.V1_32_6, + }, + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { + ContainerDefinitions: [ + { + Environment: [ + { + Name: 'OTEL_LOGS_EXPORTER', + Value: 'none', + }, + { + Name: 'OTEL_METRICS_EXPORTER', + Value: 'none', + }, + { + Name: 'OTEL_EXPORTER_OTLP_PROTOCOL', + Value: 'http/protobuf', + }, + { + Name: 'OTEL_AWS_APPLICATION_SIGNALS_ENABLED', + Value: 'true', + }, + { + Name: 'OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT', + Value: 'http://localhost:4316/v1/metrics', + }, + { + Name: 'OTEL_EXPORTER_OTLP_TRACES_ENDPOINT', + Value: 'http://localhost:4316/v1/traces', + }, + { + Name: 'OTEL_TRACES_SAMPLER', + Value: 'xray', + }, + { + Name: 'OTEL_TRACES_SAMPLER_ARG', + Value: 'endpoint=http://localhost:2000', + }, + { + Name: 'OTEL_PROPAGATORS', + Value: 'tracecontext,baggage,b3,xray', + }, + { + Name: 'JAVA_TOOL_OPTIONS', + Value: ' -javaagent:/otel-auto-instrumentation/javaagent.jar', + }, + { + Name: 'OTEL_RESOURCE_ATTRIBUTES', + Value: 'service.name=TestTaskDefinition', + }, + ], + Essential: true, + Image: 'nathanpeck/name', + MountPoints: [ + { + ContainerPath: '/otel-auto-instrumentation', + ReadOnly: false, + SourceVolume: 'opentelemetry-auto-instrumentation', + }, + ], + Name: 'app', + DependsOn: [ + { + Condition: 'SUCCESS', + ContainerName: 'adot-init', + }, + { + Condition: 'START', + ContainerName: 'cloudwatch-agent', + }, + ], + }, + { + Command: [ + 'cp', + '/javaagent.jar', + '/otel-auto-instrumentation/javaagent.jar', + ], + Essential: false, + Image: 'public.ecr.aws/aws-observability/adot-autoinstrumentation-java:v1.32.6', + MountPoints: [ + { + ContainerPath: '/otel-auto-instrumentation', + ReadOnly: false, + SourceVolume: 'opentelemetry-auto-instrumentation', + }, + ], + Name: 'adot-init', + Cpu: 0, + Memory: 64, + }, + { + Environment: [ + { + Name: 'CW_CONFIG_CONTENT', + Value: '{"logs":{"metrics_collected":{"application_signals":{"enabled":true}}},"traces":{"traces_collected":{"application_signals":{"enabled":true}}}}', + }, + ], + Essential: true, + Image: 'amazon/cloudwatch-agent:latest', + LogConfiguration: { + LogDriver: 'awslogs', + Options: { + 'awslogs-group': { + Ref: 'TestTaskDefinitioncloudwatchagentLogGroupE9E41850', + }, + 'awslogs-stream-prefix': 'cloudwatch-agent', + 'awslogs-region': { + Ref: 'AWS::Region', + }, + }, + }, + MemoryReservation: 50, + Name: 'cloudwatch-agent', + PortMappings: [ + { + ContainerPort: 4316, + HostPort: 4316, + Protocol: 'tcp', + }, + { + ContainerPort: 2000, + HostPort: 2000, + Protocol: 'tcp', + }, + ], + User: '0:1338', + }, + ], + Cpu: '256', + ExecutionRoleArn: { + 'Fn::GetAtt': [ + 'TestTaskDefinitionExecutionRole7F5683B5', + 'Arn', + ], + }, + Family: 'TestTaskDefinition', + Memory: '512', + NetworkMode: 'awsvpc', + RequiresCompatibilities: [ + 'FARGATE', + ], + TaskRoleArn: { + 'Fn::GetAtt': [ + 'TestTaskDefinitionTaskRole38EA0D26', + 'Arn', + ], + }, + Volumes: [ + { + Name: 'opentelemetry-auto-instrumentation', + }, + ], + }); + }); + + test('should fail if fargate task definition does not have a sidecar', () => { + + expect(() => { + // GIVEN + const stack = new Stack(); + + // WHEN + const fargateTaskDefinition = new ecs.FargateTaskDefinition(stack, 'TestTaskDefinition', { + cpu: 256, + memoryLimitMiB: 512, + }); + fargateTaskDefinition.addContainer('app', { + image: ecs.ContainerImage.fromRegistry('nathanpeck/name'), + }); + new ApplicationSignalsIntegration(stack, 'TestFailure', { + taskDefinition: fargateTaskDefinition, + instrumentation: { + language: InstrumentationLanguage.JAVA, + sdkVersion: JavaInstrumentationVersion.V1_32_6, + }, + serviceName: 'demo', + cloudWatchAgent: { + enableSidecar: false, + }, + }); + }).toThrow(/Fargate tasks must deploy CloudWatch Agent as a sidecar container/); + }); + + test('should create application signals configurations with python and external cwagent', () => { + // GIVEN + const stack = new Stack(); + + // WHEN + const ec2TaskDefinition = new ecs.Ec2TaskDefinition(stack, 'TestTaskDefinition', { + networkMode: ecs.NetworkMode.HOST, + }); + const defaultContainer = ec2TaskDefinition.addContainer('app', { + image: ecs.ContainerImage.fromRegistry('nathanpeck/name'), + cpu: 0, + memoryLimitMiB: 512, + }); + defaultContainer.addEnvironment('PYTHONPATH', '/mysite'); + + new ApplicationSignalsIntegration(stack, 'TestIntegration', { + taskDefinition: ec2TaskDefinition, + instrumentation: { + language: InstrumentationLanguage.PYTHON, + sdkVersion: PythonInstrumentationVersion.V0_8_0, + }, + serviceName: 'demo', + overrideEnvironments: [ + { + name: 'OTEL_RESOURCE_ATTRIBUTES', + value: 'service.name=overriden-demo', + }, + { + name: 'OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT', + value: 'http://cwagent.local:4316/v1/metrics', + }, { + name: 'OTEL_EXPORTER_OTLP_TRACES_ENDPOINT', + value: 'http://cwagent.local:4316/v1/traces', + }, { + name: 'OTEL_TRACES_SAMPLER_ARG', + value: 'endpoint=http://cwagent.local:2000', + }, + ], + cloudWatchAgent: { + enableSidecar: false, + }, + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { + ContainerDefinitions: [ + { + Environment: [ + { + Name: 'PYTHONPATH', + Value: '/otel-auto-instrumentation-python/opentelemetry/instrumentation/auto_instrumentation:/mysite:/otel-auto-instrumentation-python', + }, + { + Name: 'OTEL_LOGS_EXPORTER', + Value: 'none', + }, + { + Name: 'OTEL_METRICS_EXPORTER', + Value: 'none', + }, + { + Name: 'OTEL_EXPORTER_OTLP_PROTOCOL', + Value: 'http/protobuf', + }, + { + Name: 'OTEL_AWS_APPLICATION_SIGNALS_ENABLED', + Value: 'true', + }, + { + Name: 'OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT', + Value: 'http://cwagent.local:4316/v1/metrics', + }, + { + Name: 'OTEL_EXPORTER_OTLP_TRACES_ENDPOINT', + Value: 'http://cwagent.local:4316/v1/traces', + }, + { + Name: 'OTEL_TRACES_SAMPLER', + Value: 'xray', + }, + { + Name: 'OTEL_TRACES_SAMPLER_ARG', + Value: 'endpoint=http://cwagent.local:2000', + }, + { + Name: 'OTEL_PROPAGATORS', + Value: 'tracecontext,baggage,b3,xray', + }, + { + Name: 'OTEL_PYTHON_DISTRO', + Value: 'aws_distro', + }, + { + Name: 'OTEL_PYTHON_CONFIGURATOR', + Value: 'aws_configurator', + }, + { + Name: 'OTEL_RESOURCE_ATTRIBUTES', + Value: 'service.name=overriden-demo', + }, + ], + Essential: true, + Image: 'nathanpeck/name', + MountPoints: [ + { + ContainerPath: '/otel-auto-instrumentation-python', + ReadOnly: false, + SourceVolume: 'opentelemetry-auto-instrumentation', + }, + ], + Cpu: 0, + Memory: 512, + Name: 'app', + DependsOn: [ + { + Condition: 'SUCCESS', + ContainerName: 'adot-init', + }, + ], + }, + { + Command: [ + 'cp', + '-a', + '/autoinstrumentation/.', + '/otel-auto-instrumentation-python', + ], + Essential: false, + Image: 'public.ecr.aws/aws-observability/adot-autoinstrumentation-python:v0.8.0', + MountPoints: [ + { + ContainerPath: '/otel-auto-instrumentation-python', + ReadOnly: false, + SourceVolume: 'opentelemetry-auto-instrumentation', + }, + ], + Name: 'adot-init', + Cpu: 0, + Memory: 32, + }, + ], + Family: 'TestTaskDefinition', + NetworkMode: 'host', + RequiresCompatibilities: [ + 'EC2', + ], + TaskRoleArn: { + 'Fn::GetAtt': [ + 'TestTaskDefinitionTaskRole38EA0D26', + 'Arn', + ], + }, + Volumes: [ + { + Name: 'opentelemetry-auto-instrumentation', + }, + ], + }); + }); + + test('should create application signals configurations with dotnet on linux', () => { + // GIVEN + const stack = new Stack(); + + // WHEN + const ec2TaskDefinition = new ecs.Ec2TaskDefinition(stack, 'TestTaskDefinition', { + networkMode: ecs.NetworkMode.HOST, + }); + ec2TaskDefinition.addContainer('app', { + image: ecs.ContainerImage.fromRegistry('nathanpeck/name'), + cpu: 0, + memoryLimitMiB: 512, + }); + + new ApplicationSignalsIntegration(stack, 'TestIntegration', { + taskDefinition: ec2TaskDefinition, + instrumentation: { + language: InstrumentationLanguage.DOTNET, + sdkVersion: DotnetInstrumentationVersion.V1_6_0, + }, + serviceName: 'demo', + cloudWatchAgent: { + enableSidecar: false, + }, + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { + ContainerDefinitions: [ + { + Environment: [ + { + Name: 'OTEL_LOGS_EXPORTER', + Value: 'none', + }, + { + Name: 'OTEL_METRICS_EXPORTER', + Value: 'none', + }, + { + Name: 'OTEL_EXPORTER_OTLP_PROTOCOL', + Value: 'http/protobuf', + }, + { + Name: 'OTEL_AWS_APPLICATION_SIGNALS_ENABLED', + Value: 'true', + }, + { + Name: 'OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT', + Value: 'http://localhost:4316/v1/metrics', + }, + { + Name: 'OTEL_EXPORTER_OTLP_TRACES_ENDPOINT', + Value: 'http://localhost:4316/v1/traces', + }, + { + Name: 'OTEL_TRACES_SAMPLER', + Value: 'xray', + }, + { + Name: 'OTEL_TRACES_SAMPLER_ARG', + Value: 'endpoint=http://localhost:2000', + }, + { + Name: 'OTEL_PROPAGATORS', + Value: 'tracecontext,baggage,b3,xray', + }, + { + Name: 'OTEL_DOTNET_DISTRO', + Value: 'aws_distro', + }, + { + Name: 'OTEL_DOTNET_CONFIGURATOR', + Value: 'aws_configurator', + }, + { + Name: 'OTEL_DOTNET_AUTO_PLUGINS', + Value: 'AWS.Distro.OpenTelemetry.AutoInstrumentation.Plugin, AWS.Distro.OpenTelemetry.AutoInstrumentation', + }, + { + Name: 'CORECLR_PROFILER_PATH', + Value: '/otel-auto-instrumentation-dotnet/linux-x64/OpenTelemetry.AutoInstrumentation.Native.so', + }, + { + Name: 'CORECLR_ENABLE_PROFILING', + Value: '1', + }, + { + Name: 'CORECLR_PROFILER', + Value: '{918728DD-259F-4A6A-AC2B-B85E1B658318}', + }, + { + Name: 'DOTNET_STARTUP_HOOKS', + Value: '/otel-auto-instrumentation-dotnet/net/OpenTelemetry.AutoInstrumentation.StartupHook.dll', + }, + { + Name: 'DOTNET_ADDITIONAL_DEPS', + Value: '/otel-auto-instrumentation-dotnet/AdditionalDeps', + }, + { + Name: 'OTEL_DOTNET_AUTO_HOME', + Value: '/otel-auto-instrumentation-dotnet', + }, + { + Name: 'DOTNET_SHARED_STORE', + Value: '/otel-auto-instrumentation-dotnet/store', + }, + { + Name: 'OTEL_RESOURCE_ATTRIBUTES', + Value: 'service.name=demo', + }, + ], + Essential: true, + Image: 'nathanpeck/name', + MountPoints: [ + { + ContainerPath: '/otel-auto-instrumentation-dotnet', + ReadOnly: false, + SourceVolume: 'opentelemetry-auto-instrumentation', + }, + ], + Cpu: 0, + Memory: 512, + Name: 'app', + DependsOn: [ + { + Condition: 'SUCCESS', + ContainerName: 'adot-init', + }, + ], + }, + { + Command: [ + 'cp', + '-a', + '/autoinstrumentation/.', + '/otel-auto-instrumentation-dotnet', + ], + Essential: false, + Image: 'public.ecr.aws/aws-observability/adot-autoinstrumentation-dotnet:v1.6.0', + MountPoints: [ + { + ContainerPath: '/otel-auto-instrumentation-dotnet', + ReadOnly: false, + SourceVolume: 'opentelemetry-auto-instrumentation', + }, + ], + Name: 'adot-init', + Cpu: 0, + Memory: 128, + }, + ], + Family: 'TestTaskDefinition', + NetworkMode: 'host', + RequiresCompatibilities: [ + 'EC2', + ], + TaskRoleArn: { + 'Fn::GetAtt': [ + 'TestTaskDefinitionTaskRole38EA0D26', + 'Arn', + ], + }, + Volumes: [ + { + Name: 'opentelemetry-auto-instrumentation', + }, + ], + }); + }); + + test('should create application signals configurations with dotnet on windows', () => { + // GIVEN + const stack = new Stack(); + + // WHEN + const ec2TaskDefinition = new ecs.Ec2TaskDefinition(stack, 'TestTaskDefinition', { + networkMode: ecs.NetworkMode.HOST, + }); + ec2TaskDefinition.addContainer('app', { + image: ecs.ContainerImage.fromRegistry('nathanpeck/name'), + cpu: 0, + memoryLimitMiB: 512, + }); + + new ApplicationSignalsIntegration(stack, 'TestIntegration', { + taskDefinition: ec2TaskDefinition, + instrumentation: { + language: InstrumentationLanguage.DOTNET, + sdkVersion: DotnetInstrumentationVersion.V1_6_0_WINDOWS2019, + runtimePlatform: { + operatingSystemFamily: ecs.OperatingSystemFamily.WINDOWS_SERVER_2019_CORE, + }, + }, + serviceName: 'demo', + cloudWatchAgent: { + enableSidecar: false, + }, + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { + ContainerDefinitions: [ + { + Environment: [ + { + Name: 'OTEL_LOGS_EXPORTER', + Value: 'none', + }, + { + Name: 'OTEL_METRICS_EXPORTER', + Value: 'none', + }, + { + Name: 'OTEL_EXPORTER_OTLP_PROTOCOL', + Value: 'http/protobuf', + }, + { + Name: 'OTEL_AWS_APPLICATION_SIGNALS_ENABLED', + Value: 'true', + }, + { + Name: 'OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT', + Value: 'http://localhost:4316/v1/metrics', + }, + { + Name: 'OTEL_EXPORTER_OTLP_TRACES_ENDPOINT', + Value: 'http://localhost:4316/v1/traces', + }, + { + Name: 'OTEL_TRACES_SAMPLER', + Value: 'xray', + }, + { + Name: 'OTEL_TRACES_SAMPLER_ARG', + Value: 'endpoint=http://localhost:2000', + }, + { + Name: 'OTEL_PROPAGATORS', + Value: 'tracecontext,baggage,b3,xray', + }, + { + Name: 'OTEL_DOTNET_DISTRO', + Value: 'aws_distro', + }, + { + Name: 'OTEL_DOTNET_CONFIGURATOR', + Value: 'aws_configurator', + }, + { + Name: 'OTEL_DOTNET_AUTO_PLUGINS', + Value: 'AWS.Distro.OpenTelemetry.AutoInstrumentation.Plugin, AWS.Distro.OpenTelemetry.AutoInstrumentation', + }, + { + Name: 'CORECLR_ENABLE_PROFILING', + Value: '1', + }, + { + Name: 'CORECLR_PROFILER', + Value: '{918728DD-259F-4A6A-AC2B-B85E1B658318}', + }, + { + Name: 'CORECLR_PROFILER_PATH', + Value: 'C:\\otel-auto-instrumentation-dotnet\\win-x64\\OpenTelemetry.AutoInstrumentation.Native.dll', + }, + { + Name: 'DOTNET_STARTUP_HOOKS', + Value: 'C:\\otel-auto-instrumentation-dotnet\\net\\OpenTelemetry.AutoInstrumentation.StartupHook.dll', + }, + { + Name: 'DOTNET_ADDITIONAL_DEPS', + Value: 'C:\\otel-auto-instrumentation-dotnet\\AdditionalDeps', + }, + { + Name: 'OTEL_DOTNET_AUTO_HOME', + Value: 'C:\\otel-auto-instrumentation-dotnet', + }, + { + Name: 'DOTNET_SHARED_STORE', + Value: 'C:\\otel-auto-instrumentation-dotnet\\store', + }, + { + Name: 'OTEL_RESOURCE_ATTRIBUTES', + Value: 'service.name=demo', + }, + ], + Essential: true, + Image: 'nathanpeck/name', + MountPoints: [ + { + ContainerPath: 'C:\\otel-auto-instrumentation-dotnet', + ReadOnly: false, + SourceVolume: 'opentelemetry-auto-instrumentation', + }, + ], + Cpu: 0, + Memory: 512, + Name: 'app', + DependsOn: [ + { + Condition: 'SUCCESS', + ContainerName: 'adot-init', + }, + ], + }, + { + Command: [ + 'CMD', + '/c', + 'xcopy', + '/e', + 'C:\\autoinstrumentation\\*', + 'C:\\otel-auto-instrumentation-dotnet', + '&&', + 'icacls', + 'C:\\otel-auto-instrumentation-dotnet', + '/grant', + '*S-1-1-0:R', + '/T', + ], + Essential: false, + Image: 'public.ecr.aws/aws-observability/adot-autoinstrumentation-dotnet:v1.6.0-windows2019', + MountPoints: [ + { + ContainerPath: 'C:\\otel-auto-instrumentation-dotnet', + ReadOnly: false, + SourceVolume: 'opentelemetry-auto-instrumentation', + }, + ], + Name: 'adot-init', + Cpu: 0, + Memory: 128, + }, + ], + Family: 'TestTaskDefinition', + NetworkMode: 'host', + RequiresCompatibilities: [ + 'EC2', + ], + TaskRoleArn: { + 'Fn::GetAtt': [ + 'TestTaskDefinitionTaskRole38EA0D26', + 'Arn', + ], + }, + Volumes: [ + { + Name: 'opentelemetry-auto-instrumentation', + }, + ], + }); + }); + + test('should create application signals configurations with node', () => { + // GIVEN + const stack = new Stack(); + + // WHEN + const ec2TaskDefinition = new ecs.Ec2TaskDefinition(stack, 'TestTaskDefinition', { + networkMode: ecs.NetworkMode.HOST, + }); + ec2TaskDefinition.addContainer('app', { + image: ecs.ContainerImage.fromRegistry('nathanpeck/name'), + cpu: 0, + memoryLimitMiB: 512, + }); + + new ApplicationSignalsIntegration(stack, 'TestIntegration', { + taskDefinition: ec2TaskDefinition, + instrumentation: { + language: InstrumentationLanguage.NODEJS, + sdkVersion: NodeInstrumentationVersion.V0_5_0, + + }, + serviceName: 'demo', + cloudWatchAgent: { + enableSidecar: false, + }, + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { + ContainerDefinitions: [ + { + Environment: [ + { + Name: 'OTEL_LOGS_EXPORTER', + Value: 'none', + }, + { + Name: 'OTEL_METRICS_EXPORTER', + Value: 'none', + }, + { + Name: 'OTEL_EXPORTER_OTLP_PROTOCOL', + Value: 'http/protobuf', + }, + { + Name: 'OTEL_AWS_APPLICATION_SIGNALS_ENABLED', + Value: 'true', + }, + { + Name: 'OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT', + Value: 'http://localhost:4316/v1/metrics', + }, + { + Name: 'OTEL_EXPORTER_OTLP_TRACES_ENDPOINT', + Value: 'http://localhost:4316/v1/traces', + }, + { + Name: 'OTEL_TRACES_SAMPLER', + Value: 'xray', + }, + { + Name: 'OTEL_TRACES_SAMPLER_ARG', + Value: 'endpoint=http://localhost:2000', + }, + { + Name: 'OTEL_PROPAGATORS', + Value: 'tracecontext,baggage,b3,xray', + }, + { + Name: 'NODE_OPTIONS', + Value: ' --require /otel-auto-instrumentation-nodejs/autoinstrumentation.js', + }, + { + Name: 'OTEL_RESOURCE_ATTRIBUTES', + Value: 'service.name=demo', + }, + ], + Essential: true, + Image: 'nathanpeck/name', + MountPoints: [ + { + ContainerPath: '/otel-auto-instrumentation-nodejs', + ReadOnly: false, + SourceVolume: 'opentelemetry-auto-instrumentation', + }, + ], + Cpu: 0, + Memory: 512, + Name: 'app', + DependsOn: [ + { + Condition: 'SUCCESS', + ContainerName: 'adot-init', + }, + ], + }, + { + Command: [ + 'cp', + '-a', + '/autoinstrumentation/.', + '/otel-auto-instrumentation-nodejs', + ], + Essential: false, + Image: 'public.ecr.aws/aws-observability/adot-autoinstrumentation-node:v0.5.0', + MountPoints: [ + { + ContainerPath: '/otel-auto-instrumentation-nodejs', + ReadOnly: false, + SourceVolume: 'opentelemetry-auto-instrumentation', + }, + ], + Name: 'adot-init', + Cpu: 0, + Memory: 128, + }, + ], + Family: 'TestTaskDefinition', + NetworkMode: 'host', + RequiresCompatibilities: [ + 'EC2', + ], + TaskRoleArn: { + 'Fn::GetAtt': [ + 'TestTaskDefinitionTaskRole38EA0D26', + 'Arn', + ], + }, + Volumes: [ + { + Name: 'opentelemetry-auto-instrumentation', + }, + ], + }); + }); + +}); diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ApplicationSignalsIntegrationECSDaemonDefaultTestDeployAssert0A2A622F.assets.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ApplicationSignalsIntegrationECSDaemonDefaultTestDeployAssert0A2A622F.assets.json new file mode 100644 index 0000000000000..a2984d23111d5 --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ApplicationSignalsIntegrationECSDaemonDefaultTestDeployAssert0A2A622F.assets.json @@ -0,0 +1,19 @@ +{ + "version": "39.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "ApplicationSignalsIntegrationECSDaemonDefaultTestDeployAssert0A2A622F.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ApplicationSignalsIntegrationECSDaemonDefaultTestDeployAssert0A2A622F.template.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ApplicationSignalsIntegrationECSDaemonDefaultTestDeployAssert0A2A622F.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ApplicationSignalsIntegrationECSDaemonDefaultTestDeployAssert0A2A622F.template.json @@ -0,0 +1,36 @@ +{ + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/cdk.out b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/cdk.out new file mode 100644 index 0000000000000..91e1a8b9901d5 --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"39.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ecs-enablement-integration.assets.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ecs-enablement-integration.assets.json new file mode 100644 index 0000000000000..0aefe5b5f33cf --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ecs-enablement-integration.assets.json @@ -0,0 +1,19 @@ +{ + "version": "39.0.0", + "files": { + "76ae201d6ac397b6a3ba171c80e8d2e82bb0be5818af316bc2d5816068334084": { + "source": { + "path": "ecs-enablement-integration.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "76ae201d6ac397b6a3ba171c80e8d2e82bb0be5818af316bc2d5816068334084.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ecs-enablement-integration.template.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ecs-enablement-integration.template.json new file mode 100644 index 0000000000000..617d823c916fa --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ecs-enablement-integration.template.json @@ -0,0 +1,172 @@ +{ + "Resources": { + "Ec2TaskDefinitionTaskRole0B78BC85": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "ecs-tasks.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "Ec2TaskDefinitionB25030BE": { + "Type": "AWS::ECS::TaskDefinition", + "Properties": { + "ContainerDefinitions": [ + { + "Cpu": 0, + "DependsOn": [ + { + "Condition": "SUCCESS", + "ContainerName": "adot-init" + } + ], + "Environment": [ + { + "Name": "OTEL_LOGS_EXPORTER", + "Value": "none" + }, + { + "Name": "OTEL_METRICS_EXPORTER", + "Value": "none" + }, + { + "Name": "OTEL_EXPORTER_OTLP_PROTOCOL", + "Value": "http/protobuf" + }, + { + "Name": "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", + "Value": "true" + }, + { + "Name": "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", + "Value": "http://cwagent.local:4316/v1/metrics" + }, + { + "Name": "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", + "Value": "http://cwagent.local:4316/v1/traces" + }, + { + "Name": "OTEL_TRACES_SAMPLER", + "Value": "xray" + }, + { + "Name": "OTEL_TRACES_SAMPLER_ARG", + "Value": "endpoint=http://ccwagent.local:2000" + }, + { + "Name": "OTEL_PROPAGATORS", + "Value": "tracecontext,baggage,b3,xray" + }, + { + "Name": "OTEL_PYTHON_DISTRO", + "Value": "aws_distro" + }, + { + "Name": "OTEL_PYTHON_CONFIGURATOR", + "Value": "aws_configurator" + }, + { + "Name": "PYTHONPATH", + "Value": "/otel-auto-instrumentation-python/opentelemetry/instrumentation/auto_instrumentation:/otel-auto-instrumentation-python" + }, + { + "Name": "OTEL_RESOURCE_ATTRIBUTES", + "Value": "service.name=demo" + } + ], + "Essential": true, + "Image": "nathanpeck/name", + "Memory": 512, + "MountPoints": [ + { + "ContainerPath": "/otel-auto-instrumentation-python", + "ReadOnly": false, + "SourceVolume": "opentelemetry-auto-instrumentation" + } + ], + "Name": "app" + }, + { + "Command": [ + "cp", + "-a", + "/autoinstrumentation/.", + "/otel-auto-instrumentation-python" + ], + "Cpu": 0, + "Essential": false, + "Image": "public.ecr.aws/aws-observability/adot-autoinstrumentation-python:v0.8.0", + "Memory": 32, + "MountPoints": [ + { + "ContainerPath": "/otel-auto-instrumentation-python", + "ReadOnly": false, + "SourceVolume": "opentelemetry-auto-instrumentation" + } + ], + "Name": "adot-init" + } + ], + "Family": "ecsenablementintegrationEc2TaskDefinition9DAAE5F5", + "NetworkMode": "host", + "RequiresCompatibilities": [ + "EC2" + ], + "TaskRoleArn": { + "Fn::GetAtt": [ + "Ec2TaskDefinitionTaskRole0B78BC85", + "Arn" + ] + }, + "Volumes": [ + { + "Name": "opentelemetry-auto-instrumentation" + } + ] + } + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/integ.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/integ.json new file mode 100644 index 0000000000000..157fde561b72e --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/integ.json @@ -0,0 +1,12 @@ +{ + "version": "39.0.0", + "testCases": { + "ApplicationSignalsIntegrationECSDaemon/DefaultTest": { + "stacks": [ + "ecs-enablement-integration" + ], + "assertionStack": "ApplicationSignalsIntegrationECSDaemon/DefaultTest/DeployAssert", + "assertionStackName": "ApplicationSignalsIntegrationECSDaemonDefaultTestDeployAssert0A2A622F" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/manifest.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/manifest.json new file mode 100644 index 0000000000000..463906efcbd07 --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/manifest.json @@ -0,0 +1,122 @@ +{ + "version": "39.0.0", + "artifacts": { + "ecs-enablement-integration.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "ecs-enablement-integration.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "ecs-enablement-integration": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "ecs-enablement-integration.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/76ae201d6ac397b6a3ba171c80e8d2e82bb0be5818af316bc2d5816068334084.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "ecs-enablement-integration.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "ecs-enablement-integration.assets" + ], + "metadata": { + "/ecs-enablement-integration/Ec2TaskDefinition/TaskRole/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "Ec2TaskDefinitionTaskRole0B78BC85" + } + ], + "/ecs-enablement-integration/Ec2TaskDefinition/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "Ec2TaskDefinitionB25030BE", + "trace": [ + "!!DESTRUCTIVE_CHANGES: WILL_REPLACE" + ] + } + ], + "/ecs-enablement-integration/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/ecs-enablement-integration/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "ecs-enablement-integration" + }, + "ApplicationSignalsIntegrationECSDaemonDefaultTestDeployAssert0A2A622F.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "ApplicationSignalsIntegrationECSDaemonDefaultTestDeployAssert0A2A622F.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "ApplicationSignalsIntegrationECSDaemonDefaultTestDeployAssert0A2A622F": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "ApplicationSignalsIntegrationECSDaemonDefaultTestDeployAssert0A2A622F.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "ApplicationSignalsIntegrationECSDaemonDefaultTestDeployAssert0A2A622F.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "ApplicationSignalsIntegrationECSDaemonDefaultTestDeployAssert0A2A622F.assets" + ], + "metadata": { + "/ApplicationSignalsIntegrationECSDaemon/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/ApplicationSignalsIntegrationECSDaemon/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "ApplicationSignalsIntegrationECSDaemon/DefaultTest/DeployAssert" + }, + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/tree.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/tree.json new file mode 100644 index 0000000000000..a624d6107394e --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/tree.json @@ -0,0 +1,303 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "ecs-enablement-integration": { + "id": "ecs-enablement-integration", + "path": "ecs-enablement-integration", + "children": { + "Ec2TaskDefinition": { + "id": "Ec2TaskDefinition", + "path": "ecs-enablement-integration/Ec2TaskDefinition", + "children": { + "TaskRole": { + "id": "TaskRole", + "path": "ecs-enablement-integration/Ec2TaskDefinition/TaskRole", + "children": { + "ImportTaskRole": { + "id": "ImportTaskRole", + "path": "ecs-enablement-integration/Ec2TaskDefinition/TaskRole/ImportTaskRole", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "ecs-enablement-integration/Ec2TaskDefinition/TaskRole/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "assumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "ecs-tasks.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnRole", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Role", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "ecs-enablement-integration/Ec2TaskDefinition/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ECS::TaskDefinition", + "aws:cdk:cloudformation:props": { + "containerDefinitions": [ + { + "cpu": 0, + "dependsOn": [ + { + "containerName": "adot-init", + "condition": "SUCCESS" + } + ], + "essential": true, + "image": "nathanpeck/name", + "memory": 512, + "mountPoints": [ + { + "containerPath": "/otel-auto-instrumentation-python", + "readOnly": false, + "sourceVolume": "opentelemetry-auto-instrumentation" + } + ], + "name": "app", + "environment": [ + { + "name": "OTEL_LOGS_EXPORTER", + "value": "none" + }, + { + "name": "OTEL_METRICS_EXPORTER", + "value": "none" + }, + { + "name": "OTEL_EXPORTER_OTLP_PROTOCOL", + "value": "http/protobuf" + }, + { + "name": "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", + "value": "true" + }, + { + "name": "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", + "value": "http://cwagent.local:4316/v1/metrics" + }, + { + "name": "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", + "value": "http://cwagent.local:4316/v1/traces" + }, + { + "name": "OTEL_TRACES_SAMPLER", + "value": "xray" + }, + { + "name": "OTEL_TRACES_SAMPLER_ARG", + "value": "endpoint=http://ccwagent.local:2000" + }, + { + "name": "OTEL_PROPAGATORS", + "value": "tracecontext,baggage,b3,xray" + }, + { + "name": "OTEL_PYTHON_DISTRO", + "value": "aws_distro" + }, + { + "name": "OTEL_PYTHON_CONFIGURATOR", + "value": "aws_configurator" + }, + { + "name": "PYTHONPATH", + "value": "/otel-auto-instrumentation-python/opentelemetry/instrumentation/auto_instrumentation:/otel-auto-instrumentation-python" + }, + { + "name": "OTEL_RESOURCE_ATTRIBUTES", + "value": "service.name=demo" + } + ] + }, + { + "command": [ + "cp", + "-a", + "/autoinstrumentation/.", + "/otel-auto-instrumentation-python" + ], + "cpu": 0, + "essential": false, + "image": "public.ecr.aws/aws-observability/adot-autoinstrumentation-python:v0.8.0", + "memory": 32, + "mountPoints": [ + { + "containerPath": "/otel-auto-instrumentation-python", + "readOnly": false, + "sourceVolume": "opentelemetry-auto-instrumentation" + } + ], + "name": "adot-init" + } + ], + "family": "ecsenablementintegrationEc2TaskDefinition9DAAE5F5", + "networkMode": "host", + "requiresCompatibilities": [ + "EC2" + ], + "taskRoleArn": { + "Fn::GetAtt": [ + "Ec2TaskDefinitionTaskRole0B78BC85", + "Arn" + ] + }, + "volumes": [ + { + "name": "opentelemetry-auto-instrumentation" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ecs.CfnTaskDefinition", + "version": "0.0.0" + } + }, + "app": { + "id": "app", + "path": "ecs-enablement-integration/Ec2TaskDefinition/app", + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ecs.ContainerDefinition", + "version": "0.0.0" + } + }, + "adot-init": { + "id": "adot-init", + "path": "ecs-enablement-integration/Ec2TaskDefinition/adot-init", + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ecs.ContainerDefinition", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ecs.Ec2TaskDefinition", + "version": "0.0.0" + } + }, + "TestEc2TaskDefinitionIntegration": { + "id": "TestEc2TaskDefinitionIntegration", + "path": "ecs-enablement-integration/TestEc2TaskDefinitionIntegration", + "constructInfo": { + "fqn": "@aws-cdk/aws-applicationsignals-alpha.ApplicationSignalsIntegration", + "version": "0.0.0" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "ecs-enablement-integration/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "ecs-enablement-integration/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + }, + "ApplicationSignalsIntegrationECSDaemon": { + "id": "ApplicationSignalsIntegrationECSDaemon", + "path": "ApplicationSignalsIntegrationECSDaemon", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "ApplicationSignalsIntegrationECSDaemon/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "ApplicationSignalsIntegrationECSDaemon/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "ApplicationSignalsIntegrationECSDaemon/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "ApplicationSignalsIntegrationECSDaemon/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "ApplicationSignalsIntegrationECSDaemon/DefaultTest/DeployAssert/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTestCase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTest", + "version": "0.0.0" + } + }, + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.App", + "version": "0.0.0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.ts b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.ts new file mode 100644 index 0000000000000..a61e5132b4094 --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.ts @@ -0,0 +1,48 @@ + +import * as cdk from 'aws-cdk-lib'; +import * as ecs from 'aws-cdk-lib/aws-ecs'; +import * as integ from '@aws-cdk/integ-tests-alpha'; +import * as appsignals from '../lib'; + +const app = new cdk.App(); + +const stack = new cdk.Stack(app, 'ecs-enablement-integration'); + +const ec2TaskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDefinition', { + networkMode: ecs.NetworkMode.HOST, +}); +ec2TaskDefinition.addContainer('app', { + image: ecs.ContainerImage.fromRegistry('nathanpeck/name'), + cpu: 0, + memoryLimitMiB: 512, +}); + +new appsignals.ApplicationSignalsIntegration(stack, 'TestEc2TaskDefinitionIntegration', { + taskDefinition: ec2TaskDefinition, + instrumentation: { + language: appsignals.InstrumentationLanguage.PYTHON, + sdkVersion: appsignals.PythonInstrumentationVersion.V0_8_0, + }, + serviceName: 'demo', + overrideEnvironments: [ + { + name: appsignals.CommonExporting.OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT, + value: 'http://cwagent.local:4316/v1/metrics', + }, { + name: appsignals.TraceExporting.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, + value: 'http://cwagent.local:4316/v1/traces', + }, { + name: appsignals.TraceExporting.OTEL_TRACES_SAMPLER_ARG, + value: 'endpoint=http://ccwagent.local:2000', + }, + ], + cloudWatchAgent: { + enableSidecar: false, + }, +}); + +new integ.IntegTest(app, 'ApplicationSignalsIntegrationECSDaemon', { + testCases: [stack], +}); + +app.synth(); diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ApplicationSignalsIntegrationECSSidecarDefaultTestDeployAssert7F3E5290.assets.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ApplicationSignalsIntegrationECSSidecarDefaultTestDeployAssert7F3E5290.assets.json new file mode 100644 index 0000000000000..42598b49363da --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ApplicationSignalsIntegrationECSSidecarDefaultTestDeployAssert7F3E5290.assets.json @@ -0,0 +1,19 @@ +{ + "version": "39.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "ApplicationSignalsIntegrationECSSidecarDefaultTestDeployAssert7F3E5290.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ApplicationSignalsIntegrationECSSidecarDefaultTestDeployAssert7F3E5290.template.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ApplicationSignalsIntegrationECSSidecarDefaultTestDeployAssert7F3E5290.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ApplicationSignalsIntegrationECSSidecarDefaultTestDeployAssert7F3E5290.template.json @@ -0,0 +1,36 @@ +{ + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/cdk.out b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/cdk.out new file mode 100644 index 0000000000000..91e1a8b9901d5 --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"39.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ecs-enablement-integration.assets.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ecs-enablement-integration.assets.json new file mode 100644 index 0000000000000..a95c7bd409712 --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ecs-enablement-integration.assets.json @@ -0,0 +1,19 @@ +{ + "version": "39.0.0", + "files": { + "5c65e2c03af1ab7b150357b60fef1da93e0a8f604070524542fc31d7765edaec": { + "source": { + "path": "ecs-enablement-integration.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "5c65e2c03af1ab7b150357b60fef1da93e0a8f604070524542fc31d7765edaec.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ecs-enablement-integration.template.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ecs-enablement-integration.template.json new file mode 100644 index 0000000000000..ceb9df82e8d17 --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ecs-enablement-integration.template.json @@ -0,0 +1,220 @@ +{ + "Resources": { + "FargateTaskDefinitionTaskRoleE3C2BCAA": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "ecs-tasks.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "FargateTaskDefinition8E3B365E": { + "Type": "AWS::ECS::TaskDefinition", + "Properties": { + "ContainerDefinitions": [ + { + "DependsOn": [ + { + "Condition": "SUCCESS", + "ContainerName": "adot-init" + }, + { + "Condition": "START", + "ContainerName": "cwagent" + } + ], + "Environment": [ + { + "Name": "OTEL_LOGS_EXPORTER", + "Value": "none" + }, + { + "Name": "OTEL_METRICS_EXPORTER", + "Value": "none" + }, + { + "Name": "OTEL_EXPORTER_OTLP_PROTOCOL", + "Value": "http/protobuf" + }, + { + "Name": "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", + "Value": "true" + }, + { + "Name": "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", + "Value": "http://localhost:4316/v1/metrics" + }, + { + "Name": "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", + "Value": "http://localhost:4316/v1/traces" + }, + { + "Name": "OTEL_TRACES_SAMPLER", + "Value": "xray" + }, + { + "Name": "OTEL_TRACES_SAMPLER_ARG", + "Value": "endpoint=http://localhost:2000" + }, + { + "Name": "OTEL_PROPAGATORS", + "Value": "tracecontext,baggage,b3,xray" + }, + { + "Name": "OTEL_DOTNET_DISTRO", + "Value": "aws_distro" + }, + { + "Name": "OTEL_DOTNET_CONFIGURATOR", + "Value": "aws_configurator" + }, + { + "Name": "OTEL_DOTNET_AUTO_PLUGINS", + "Value": "AWS.Distro.OpenTelemetry.AutoInstrumentation.Plugin, AWS.Distro.OpenTelemetry.AutoInstrumentation" + }, + { + "Name": "CORECLR_ENABLE_PROFILING", + "Value": "1" + }, + { + "Name": "CORECLR_PROFILER", + "Value": "{918728DD-259F-4A6A-AC2B-B85E1B658318}" + }, + { + "Name": "CORECLR_PROFILER_PATH", + "Value": "C:\\otel-auto-instrumentation-dotnet\\win-x64\\OpenTelemetry.AutoInstrumentation.Native.dll" + }, + { + "Name": "DOTNET_STARTUP_HOOKS", + "Value": "C:\\otel-auto-instrumentation-dotnet\\net\\OpenTelemetry.AutoInstrumentation.StartupHook.dll" + }, + { + "Name": "DOTNET_ADDITIONAL_DEPS", + "Value": "C:\\otel-auto-instrumentation-dotnet\\AdditionalDeps" + }, + { + "Name": "OTEL_DOTNET_AUTO_HOME", + "Value": "C:\\otel-auto-instrumentation-dotnet" + }, + { + "Name": "DOTNET_SHARED_STORE", + "Value": "C:\\otel-auto-instrumentation-dotnet\\store" + }, + { + "Name": "OTEL_RESOURCE_ATTRIBUTES", + "Value": "service.name=demo" + } + ], + "Essential": true, + "Image": "nathanpeck/name", + "MountPoints": [ + { + "ContainerPath": "C:\\otel-auto-instrumentation-dotnet", + "ReadOnly": false, + "SourceVolume": "opentelemetry-auto-instrumentation" + } + ], + "Name": "app" + }, + { + "Command": [ + "CMD", + "/c", + "xcopy", + "/e", + "C:\\autoinstrumentation\\*", + "C:\\otel-auto-instrumentation-dotnet", + "&&", + "icacls", + "C:\\otel-auto-instrumentation-dotnet", + "/grant", + "*S-1-1-0:R", + "/T" + ], + "Cpu": 0, + "Essential": false, + "Image": "public.ecr.aws/aws-observability/adot-autoinstrumentation-dotnet:v1.6.0-windows2019", + "Memory": 128, + "MountPoints": [ + { + "ContainerPath": "C:\\otel-auto-instrumentation-dotnet", + "ReadOnly": false, + "SourceVolume": "opentelemetry-auto-instrumentation" + } + ], + "Name": "adot-init" + }, + { + "Essential": true, + "Image": "public.ecr.aws/cloudwatch-agent/cloudwatch-agent:1.300051.0b992-windowsservercore2019", + "Name": "cwagent" + } + ], + "Cpu": "2048", + "Family": "ecsenablementintegrationFargateTaskDefinition0E588E5D", + "Memory": "4096", + "NetworkMode": "awsvpc", + "RequiresCompatibilities": [ + "FARGATE" + ], + "RuntimePlatform": { + "OperatingSystemFamily": "WINDOWS_SERVER_2019_CORE" + }, + "TaskRoleArn": { + "Fn::GetAtt": [ + "FargateTaskDefinitionTaskRoleE3C2BCAA", + "Arn" + ] + }, + "Volumes": [ + { + "Name": "opentelemetry-auto-instrumentation" + } + ] + } + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/integ.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/integ.json new file mode 100644 index 0000000000000..787cf0357c4c1 --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/integ.json @@ -0,0 +1,12 @@ +{ + "version": "39.0.0", + "testCases": { + "ApplicationSignalsIntegrationECSSidecar/DefaultTest": { + "stacks": [ + "ecs-enablement-integration" + ], + "assertionStack": "ApplicationSignalsIntegrationECSSidecar/DefaultTest/DeployAssert", + "assertionStackName": "ApplicationSignalsIntegrationECSSidecarDefaultTestDeployAssert7F3E5290" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/manifest.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/manifest.json new file mode 100644 index 0000000000000..0ebbdc7e8bbd1 --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/manifest.json @@ -0,0 +1,119 @@ +{ + "version": "39.0.0", + "artifacts": { + "ecs-enablement-integration.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "ecs-enablement-integration.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "ecs-enablement-integration": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "ecs-enablement-integration.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/5c65e2c03af1ab7b150357b60fef1da93e0a8f604070524542fc31d7765edaec.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "ecs-enablement-integration.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "ecs-enablement-integration.assets" + ], + "metadata": { + "/ecs-enablement-integration/FargateTaskDefinition/TaskRole/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "FargateTaskDefinitionTaskRoleE3C2BCAA" + } + ], + "/ecs-enablement-integration/FargateTaskDefinition/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "FargateTaskDefinition8E3B365E" + } + ], + "/ecs-enablement-integration/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/ecs-enablement-integration/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "ecs-enablement-integration" + }, + "ApplicationSignalsIntegrationECSSidecarDefaultTestDeployAssert7F3E5290.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "ApplicationSignalsIntegrationECSSidecarDefaultTestDeployAssert7F3E5290.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "ApplicationSignalsIntegrationECSSidecarDefaultTestDeployAssert7F3E5290": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "ApplicationSignalsIntegrationECSSidecarDefaultTestDeployAssert7F3E5290.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "ApplicationSignalsIntegrationECSSidecarDefaultTestDeployAssert7F3E5290.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "ApplicationSignalsIntegrationECSSidecarDefaultTestDeployAssert7F3E5290.assets" + ], + "metadata": { + "/ApplicationSignalsIntegrationECSSidecar/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/ApplicationSignalsIntegrationECSSidecar/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "ApplicationSignalsIntegrationECSSidecar/DefaultTest/DeployAssert" + }, + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/tree.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/tree.json new file mode 100644 index 0000000000000..05d0a597e0461 --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/tree.json @@ -0,0 +1,359 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "ecs-enablement-integration": { + "id": "ecs-enablement-integration", + "path": "ecs-enablement-integration", + "children": { + "FargateTaskDefinition": { + "id": "FargateTaskDefinition", + "path": "ecs-enablement-integration/FargateTaskDefinition", + "children": { + "TaskRole": { + "id": "TaskRole", + "path": "ecs-enablement-integration/FargateTaskDefinition/TaskRole", + "children": { + "ImportTaskRole": { + "id": "ImportTaskRole", + "path": "ecs-enablement-integration/FargateTaskDefinition/TaskRole/ImportTaskRole", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "ecs-enablement-integration/FargateTaskDefinition/TaskRole/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "assumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "ecs-tasks.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnRole", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Role", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "ecs-enablement-integration/FargateTaskDefinition/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ECS::TaskDefinition", + "aws:cdk:cloudformation:props": { + "containerDefinitions": [ + { + "dependsOn": [ + { + "containerName": "adot-init", + "condition": "SUCCESS" + }, + { + "containerName": "cwagent", + "condition": "START" + } + ], + "essential": true, + "image": "nathanpeck/name", + "mountPoints": [ + { + "containerPath": "C:\\otel-auto-instrumentation-dotnet", + "readOnly": false, + "sourceVolume": "opentelemetry-auto-instrumentation" + } + ], + "name": "app", + "environment": [ + { + "name": "OTEL_LOGS_EXPORTER", + "value": "none" + }, + { + "name": "OTEL_METRICS_EXPORTER", + "value": "none" + }, + { + "name": "OTEL_EXPORTER_OTLP_PROTOCOL", + "value": "http/protobuf" + }, + { + "name": "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", + "value": "true" + }, + { + "name": "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", + "value": "http://localhost:4316/v1/metrics" + }, + { + "name": "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", + "value": "http://localhost:4316/v1/traces" + }, + { + "name": "OTEL_TRACES_SAMPLER", + "value": "xray" + }, + { + "name": "OTEL_TRACES_SAMPLER_ARG", + "value": "endpoint=http://localhost:2000" + }, + { + "name": "OTEL_PROPAGATORS", + "value": "tracecontext,baggage,b3,xray" + }, + { + "name": "OTEL_DOTNET_DISTRO", + "value": "aws_distro" + }, + { + "name": "OTEL_DOTNET_CONFIGURATOR", + "value": "aws_configurator" + }, + { + "name": "OTEL_DOTNET_AUTO_PLUGINS", + "value": "AWS.Distro.OpenTelemetry.AutoInstrumentation.Plugin, AWS.Distro.OpenTelemetry.AutoInstrumentation" + }, + { + "name": "CORECLR_ENABLE_PROFILING", + "value": "1" + }, + { + "name": "CORECLR_PROFILER", + "value": "{918728DD-259F-4A6A-AC2B-B85E1B658318}" + }, + { + "name": "CORECLR_PROFILER_PATH", + "value": "C:\\otel-auto-instrumentation-dotnet\\win-x64\\OpenTelemetry.AutoInstrumentation.Native.dll" + }, + { + "name": "DOTNET_STARTUP_HOOKS", + "value": "C:\\otel-auto-instrumentation-dotnet\\net\\OpenTelemetry.AutoInstrumentation.StartupHook.dll" + }, + { + "name": "DOTNET_ADDITIONAL_DEPS", + "value": "C:\\otel-auto-instrumentation-dotnet\\AdditionalDeps" + }, + { + "name": "OTEL_DOTNET_AUTO_HOME", + "value": "C:\\otel-auto-instrumentation-dotnet" + }, + { + "name": "DOTNET_SHARED_STORE", + "value": "C:\\otel-auto-instrumentation-dotnet\\store" + }, + { + "name": "OTEL_RESOURCE_ATTRIBUTES", + "value": "service.name=demo" + } + ] + }, + { + "command": [ + "CMD", + "/c", + "xcopy", + "/e", + "C:\\autoinstrumentation\\*", + "C:\\otel-auto-instrumentation-dotnet", + "&&", + "icacls", + "C:\\otel-auto-instrumentation-dotnet", + "/grant", + "*S-1-1-0:R", + "/T" + ], + "cpu": 0, + "essential": false, + "image": "public.ecr.aws/aws-observability/adot-autoinstrumentation-dotnet:v1.6.0-windows2019", + "memory": 128, + "mountPoints": [ + { + "containerPath": "C:\\otel-auto-instrumentation-dotnet", + "readOnly": false, + "sourceVolume": "opentelemetry-auto-instrumentation" + } + ], + "name": "adot-init" + }, + { + "essential": true, + "image": "public.ecr.aws/cloudwatch-agent/cloudwatch-agent:1.300051.0b992-windowsservercore2019", + "name": "cwagent" + } + ], + "cpu": "2048", + "family": "ecsenablementintegrationFargateTaskDefinition0E588E5D", + "memory": "4096", + "networkMode": "awsvpc", + "requiresCompatibilities": [ + "FARGATE" + ], + "runtimePlatform": { + "operatingSystemFamily": "WINDOWS_SERVER_2019_CORE" + }, + "taskRoleArn": { + "Fn::GetAtt": [ + "FargateTaskDefinitionTaskRoleE3C2BCAA", + "Arn" + ] + }, + "volumes": [ + { + "name": "opentelemetry-auto-instrumentation" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ecs.CfnTaskDefinition", + "version": "0.0.0" + } + }, + "app": { + "id": "app", + "path": "ecs-enablement-integration/FargateTaskDefinition/app", + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ecs.ContainerDefinition", + "version": "0.0.0" + } + }, + "adot-init": { + "id": "adot-init", + "path": "ecs-enablement-integration/FargateTaskDefinition/adot-init", + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ecs.ContainerDefinition", + "version": "0.0.0" + } + }, + "cloudwatch-agent": { + "id": "cloudwatch-agent", + "path": "ecs-enablement-integration/FargateTaskDefinition/cloudwatch-agent", + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ecs.ContainerDefinition", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ecs.FargateTaskDefinition", + "version": "0.0.0" + } + }, + "TestFargateSidecarIntegration": { + "id": "TestFargateSidecarIntegration", + "path": "ecs-enablement-integration/TestFargateSidecarIntegration", + "constructInfo": { + "fqn": "@aws-cdk/aws-applicationsignals-alpha.ApplicationSignalsIntegration", + "version": "0.0.0" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "ecs-enablement-integration/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "ecs-enablement-integration/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + }, + "ApplicationSignalsIntegrationECSSidecar": { + "id": "ApplicationSignalsIntegrationECSSidecar", + "path": "ApplicationSignalsIntegrationECSSidecar", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "ApplicationSignalsIntegrationECSSidecar/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "ApplicationSignalsIntegrationECSSidecar/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "ApplicationSignalsIntegrationECSSidecar/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "ApplicationSignalsIntegrationECSSidecar/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "ApplicationSignalsIntegrationECSSidecar/DefaultTest/DeployAssert/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTestCase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTest", + "version": "0.0.0" + } + }, + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.App", + "version": "0.0.0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.ts b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.ts new file mode 100644 index 0000000000000..40248a8d90a59 --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.ts @@ -0,0 +1,51 @@ + +import * as cdk from 'aws-cdk-lib'; +import * as ecs from 'aws-cdk-lib/aws-ecs'; +import * as integ from '@aws-cdk/integ-tests-alpha'; +import { ApplicationSignalsIntegration, InstrumentationLanguage, DotnetInstrumentationVersion } from '../lib'; +import { Role, ManagedPolicy, ServicePrincipal } from 'aws-cdk-lib/aws-iam'; +const app = new cdk.App(); + +const stack = new cdk.Stack(app, 'ecs-enablement-integration'); +const taskRole = new Role(app, 'TestRole', { + roleName: 'TestRole', + assumedBy: new ServicePrincipal('ecs-tasks.amazonaws.com'), + managedPolicies: [ + ManagedPolicy.fromAwsManagedPolicyName('CloudWatchAgentServerPolicy'), + ], +}); + +const fargateTaskDefinition = new ecs.FargateTaskDefinition(stack, 'FargateTaskDefinition', { + taskRole: taskRole, + cpu: 2048, + memoryLimitMiB: 4096, + runtimePlatform: { + operatingSystemFamily: ecs.OperatingSystemFamily.WINDOWS_SERVER_2019_CORE, + }, +}); + +fargateTaskDefinition.addContainer('app', { + image: ecs.ContainerImage.fromRegistry('nathanpeck/name'), +}); +new ApplicationSignalsIntegration(stack, 'TestFargateSidecarIntegration', { + taskDefinition: fargateTaskDefinition, + instrumentation: { + language: InstrumentationLanguage.DOTNET, + sdkVersion: DotnetInstrumentationVersion.V1_6_0_WINDOWS2019, + }, + serviceName: 'demo', + cloudWatchAgent: { + enableSidecar: true, + container: { + containerName: 'cwagent', + image: ecs.ContainerImage.fromRegistry('public.ecr.aws/cloudwatch-agent/cloudwatch-agent:1.300051.0b992-windowsservercore2019'), + }, + }, +}); + +new integ.IntegTest(app, 'ApplicationSignalsIntegrationECSSidecar', { + testCases: [stack], +}); + +app.synth(); + From a9cd56f2c99eb5defa4d679a43888239753abc28 Mon Sep 17 00:00:00 2001 From: Zhou Date: Tue, 21 Jan 2025 20:19:07 -0800 Subject: [PATCH 2/4] Address comments --- .../aws-applicationsignals-alpha/.eslintrc.js | 2 - .../aws-applicationsignals-alpha/README.md | 135 ++++- .../lib/enablement/constants.ts | 309 ++++++---- .../lib/enablement/ecs.ts | 564 +++++++++--------- .../aws-applicationsignals-alpha/package.json | 6 +- .../test/ecs-enablement.test.ts | 329 +++++++++- .../test/integ.ecs-enablement-daemon.ts | 4 +- .../ecs-enablement-integration.assets.json | 4 +- .../ecs-enablement-integration.template.json | 21 +- .../manifest.json | 6 +- .../tree.json | 95 +-- .../test/integ.ecs-enablement-sidecar.ts | 10 +- 12 files changed, 1025 insertions(+), 460 deletions(-) diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/.eslintrc.js b/packages/@aws-cdk/aws-applicationsignals-alpha/.eslintrc.js index b284f20df26e9..6748a5a2bad12 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/.eslintrc.js +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/.eslintrc.js @@ -2,7 +2,5 @@ const baseConfig = require('@aws-cdk/cdk-build-tools/config/eslintrc'); baseConfig.parserOptions.project = __dirname + '/tsconfig.json'; baseConfig.rules['import/no-extraneous-dependencies'] = ['error', { devDependencies: true, peerDependencies: true } ]; -baseConfig.rules['import/order'] = 'off'; -baseConfig.rules['@aws-cdk/invalid-cfn-imports'] = 'off'; module.exports = baseConfig; diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/README.md b/packages/@aws-cdk/aws-applicationsignals-alpha/README.md index 00cc3ff255e1d..a33bd95a290ba 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/README.md +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/README.md @@ -15,20 +15,79 @@ + + +--- + +![cdk-constructs: Experimental](https://img.shields.io/badge/cdk--constructs-experimental-important.svg?style=for-the-badge) + +> The APIs of higher level constructs in this module are experimental and under active development. +> They are subject to non-backward compatible changes or removal in any future version. These are +> not subject to the [Semantic Versioning](https://semver.org/) model and breaking changes will be +> announced in the release notes. This means that while you may use them, you may need to update +> your source code when upgrading to a newer version of this package. + +--- + +## Application Signals + +CloudWatch Application Signals is an auto-instrumentation solution built on OpenTelemetry that enables zero-code collection of monitoring data, such +as traces and metrics, from applications running across multiple platforms. It also supports topology auto-discovery based on collected monitoring +data and includes a new feature for managing service-level objectives (SLOs). + +It supports Java, Python, .NET, and Node.js on platforms including EKS (and native Kubernetes), Lambda, ECS, and EC2. For more details, visit +[Application Signals](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Application-Monitoring-Sections.html) on the AWS +public website. + +## Application Signals L2 CDK for enablement + +This module is a collection of L2 constructs which leverages native L1 CFN resources, simplifying the enablement steps and the creation of Application +Signals resources. + This module is part of the [AWS Cloud Development Kit](https://github.com/aws/aws-cdk) project. ```ts nofixture import * as appsignals from '@aws-cdk/aws-applicationsignals-alpha'; ``` -## Enable Application Signals on ECS with sidecar mode +### ApplicationSignalsIntegration + +`ApplicationSignalsIntegration` aims to address key challenges in the current CDK enablement process, which requires complex manual configurations for +ECS customers. Application Signals is designed to be flexible and is supported for other platforms as well. However, the initial focus is on supporting +ECS, with plans to potentially extend support to other platforms in the future. + +#### 1. Enable Application Signals on ECS with sidecar mode + +##### 1.1. Create a TaskDefinition for application + +```ts +import * as ecs from 'aws-cdk-lib/aws-ecs'; + +const fargateTaskDefinition = new ecs.FargateTaskDefinition(stack, 'FargateTaskDefinition', { + taskRole: taskRole, + cpu: 2048, + memoryLimitMiB: 4096 +}); + +fargateTaskDefinition.addContainer('app', { + image: ..., + ... +}); +``` + +##### 1.2. Configure ApplicationSignalsIntegration + +Key steps: + +1. Configure `instrumentation` to instrument the application with the ADOT Java Agent. +2. Setting `enableSidecar` to true to add the CloudWatch Agent as a sidecar container. ```ts new appsignals.ApplicationSignalsIntegration(this, 'ApplicationSignalsIntegration', { taskDefinition, instrumentation: { language: appsignals.InstrumentationLanguage.JAVA, - sdkVersion: appsignals.Instrumentation.JAVA_1_32_6 + sdkVersion: appsignals.JavaInstrumentationVersion.V1_32_6 }, serviceName: 'sample-app', cloudWatchAgent: { @@ -37,14 +96,20 @@ new appsignals.ApplicationSignalsIntegration(this, 'ApplicationSignalsIntegratio }); ``` -## Enable Application Signals on ECS with daemon mode +#### 2. Enable Application Signals on ECS with daemon mode -Since the daemon deployment strategy is not supported on ECS Fargate, this mode is only supported on ECS on EC2. +Note: Since the daemon deployment strategy is not supported on ECS Fargate, this mode is only supported on ECS on EC2. + +##### 2.1. Run CloudWatch Agent as a daemon service ```ts import * as ecs from 'aws-cdk-lib/aws-ecs'; +import * as logs from 'aws-cdk-lib/aws-logs'; + +// Create a task definition for CloudWatch agent +const cwAgentTaskDefinition = new ecs.Ec2TaskDefinition(this, 'CloudWatchAgentTaskDefinition'); -// create CloudWatch agent daemon service +// Add CloudWatch agent container const cwAgentContainer = cwAgentTaskDefinition.addContainer('ecs-cwagent', { image: ecs.ContainerImage.fromRegistry("public.ecr.aws/cloudwatch-agent/cloudwatch-agent:latest"), cpu: 128, @@ -63,7 +128,7 @@ const cwAgentContainer = cwAgentTaskDefinition.addContainer('ecs-cwagent', { ], logging: new ecs.AwsLogDriver({ streamPrefix: 'ecs', - logGroup: new LogGroup(this, 'CwAgentLogGroup', { + logGroup: new logs.LogGroup(this, 'CwAgentLogGroup', { logGroupName: '/ecs/ecs-cwagent-cdk-daemon', removalPolicy: cdk.RemovalPolicy.DESTROY, }), @@ -73,29 +138,55 @@ const cwAgentContainer = cwAgentTaskDefinition.addContainer('ecs-cwagent', { } }); -const cwAgentService = new ecs.Ec2Service(this, 'CwAgentDaemonService', { - cluster, - taskDefinition: cwAgentTaskDefinition, - daemon: true, - serviceConnectConfiguration: { +// Create the CloudWatch agent daemon service +new ecs.Ec2Service(this, 'CloudWatchAgentDaemon', { + cluster, + taskDefinition: cwAgentTaskDefinition, + daemon: true, // Runs one container per EC2 instance + serviceConnectConfiguration: { // Create service connect namespace: namespace.namespaceArn, services: [{ - portMappingName: 'cwagent-4316', - dnsName: 'cwagent-4316-http', - port: 4316 + portMappingName: 'cwagent-4316', + dnsName: 'cwagent-4316-http', + port: 4316 }, { - portMappingName: 'cwagent-2000', - dnsName: 'cwagent-2000-http', - port: 2000 + portMappingName: 'cwagent-2000', + dnsName: 'cwagent-2000-http', + port: 2000 }] - } + } +}); +``` + +##### 2.2. Create a TaskDefinition for application + +```ts +import * as ecs from 'aws-cdk-lib/aws-ecs'; + +const ec2TaskDefinition = new ecs.Ec2TaskDefinition(this, 'EC2TaskDefinition', { + taskRole: taskRole, + ... }); -// configure ApplicationSignalsIntegration to use Service Connect to communicate to the CloudWatch agent server -new appsignals.ApplicationSignalsIntegration(this, 'ApplicationSignalsIntegration', taskDefinition, { +ec2TaskDefinition.addContainer('app', { + image: ..., + ... +}); +``` + +##### 2.3. Configure ApplicationSignalsIntegration + +Key steps: + +1. Configure `instrumentation` to instrument the application with the ADOT Python Agent. +2. Set `enableSidecar` to false to disable running CloudWatch agent as a sidecar. +3. Override environment variables by configuring `overrideEnvironments` to use Service Connect to communicate to the CloudWatch agent server + +```ts +new appsignals.ApplicationSignalsIntegration(this, 'ApplicationSignalsIntegration', ec2TaskDefinition, { instrumentation: { language: appsignals.InstrumentationLanguage.PYTHON, - sdkVersion: appsignals.Instrumentation.PYTHON_V0_7_0 + sdkVersion: appsignals.PythonInstrumentationVersion.V0_8_0 }, overrideEnvironments: [{ name: appsignals.CommonExporting.OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT, @@ -115,5 +206,5 @@ new appsignals.ApplicationSignalsIntegration(this, 'ApplicationSignalsIntegratio // disable sidecar mode enableSidecar: false, } -}) +}); ``` diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/constants.ts b/packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/constants.ts index 8f5497ebe7bdf..427b1a074a8df 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/constants.ts +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/constants.ts @@ -1,102 +1,207 @@ -export const CommonExporting = { - OTEL_EXPORTER_OTLP_PROTOCOL: 'OTEL_EXPORTER_OTLP_PROTOCOL', - OTEL_EXPORTER_OTLP_PROTOCOL_HTTP_PROTOBUF: 'http/protobuf', - - OTEL_RESOURCE_ATTRIBUTES: 'OTEL_RESOURCE_ATTRIBUTES', - - OTEL_AWS_APPLICATION_SIGNALS: 'OTEL_AWS_APPLICATION_SIGNALS_ENABLED', - OTEL_AWS_APPLICATION_SIGNALS_ENABLED: 'true', - OTEL_AWS_APPLICATION_SIGNALS_DISABLED: 'false', - OTEL_AWS_APPLICATION_SIGNALS_RUNTIME: 'OTEL_AWS_APPLICATION_SIGNALS_RUNTIME_ENABLED', - OTEL_AWS_APPLICATION_SIGNALS_RUNTIME_ENABLED: 'true', - OTEL_AWS_APPLICATION_SIGNALS_RUNTIME_DISABLED: 'false', - - OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT: 'OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT', - OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT_LOCAL_CWA: 'http://localhost:4316/v1/metrics', -}; - -export const LogsExporting = { - OTEL_LOGS_EXPORTER: 'OTEL_LOGS_EXPORTER', - OTEL_LOGS_EXPORTER_NONE: 'none', - OTEL_LOGS_EXPORTER_OTLP: 'otlp', -} as const; - -export const MetricsExporting = { - OTEL_METRICS_EXPORTER: 'OTEL_METRICS_EXPORTER', - OTEL_METRICS_EXPORTER_NONE: 'none', - OTEL_METRICS_EXPORTER_OTLP: 'otlp', -} as const; - -export const TraceExporting = { - OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: 'OTEL_EXPORTER_OTLP_TRACES_ENDPOINT', - OTEL_EXPORTER_OTLP_TRACES_ENDPOINT_LOCAL_CWA: 'http://localhost:4316/v1/traces', - - OTEL_TRACES_SAMPLER: 'OTEL_TRACES_SAMPLER', - OTEL_TRACES_SAMPLER_XRAY: 'xray', - OTEL_TRACES_SAMPLER_TRACEID_RATIO: 'traceidratio', - OTEL_TRACES_SAMPLER_ALWAYS_ON: 'always_on', - OTEL_TRACES_SAMPLER_ALWAYS_OFF: 'always_off', - OTEL_TRACES_SAMPLER_PARENT_BASED_TRACEID_RATIO: 'parentbased_traceidratio', - OTEL_TRACES_SAMPLER_PARENT_BASED_ALWAYS_ON: 'parentbased_always_on', - OTEL_TRACES_SAMPLER_PARENT_BASED_ALWAYS_OFF: 'parentbased_always_off', - - OTEL_TRACES_SAMPLER_ARG: 'OTEL_TRACES_SAMPLER_ARG', - OTEL_TRACES_SAMPLER_ARG_LOCAL_CWA: 'endpoint=http://localhost:2000', - - OTEL_PROPAGATORS: 'OTEL_PROPAGATORS', - OTEL_PROPAGATORS_APPLICATION_SIGNALS: 'tracecontext,baggage,b3,xray', -} as const; - -export const JavaInstrumentation = { - JAVA_TOOL_OPTIONS: 'JAVA_TOOL_OPTIONS', - JAVA_TOOL_OPTIONS_ADOT: ' -javaagent:/otel-auto-instrumentation/javaagent.jar', -} as const; - -export const PythonInstrumentation = { - OTEL_PYTHON_DISTRO: 'OTEL_PYTHON_DISTRO', - OTEL_PYTHON_DISTRO_AWS_DISTRO: 'aws_distro', - - OTEL_PYTHON_CONFIGURATOR: 'OTEL_PYTHON_CONFIGURATOR', - OTEL_PYTHON_CONFIGURATOR_AWS_CONFIGURATOR: 'aws_configurator', - - PYTHONPATH: 'PYTHONPATH', - PYTHONPATH_ADOT: '/otel-auto-instrumentation-python/opentelemetry/instrumentation/auto_instrumentation:/otel-auto-instrumentation-python', -} as const; - -export const DotnetInstrumentation = { - OTEL_DOTNET_DISTRO: 'OTEL_DOTNET_DISTRO', - OTEL_DOTNET_DISTRO_AWS_DISTRO: 'aws_distro', - - OTEL_DOTNET_CONFIGURATOR: 'OTEL_DOTNET_CONFIGURATOR', - OTEL_DOTNET_CONFIGURATOR_AWS_CONFIGURATOR: 'aws_configurator', - - OTEL_DOTNET_AUTO_PLUGINS: 'OTEL_DOTNET_AUTO_PLUGINS', - OTEL_DOTNET_AUTO_PLUGINS_ADOT: 'AWS.Distro.OpenTelemetry.AutoInstrumentation.Plugin, AWS.Distro.OpenTelemetry.AutoInstrumentation', - - CORECLR_ENABLE_PROFILING: 'CORECLR_ENABLE_PROFILING', - CORECLR_ENABLE_PROFILING_ENABLED: '1', - CORECLR_ENABLE_PROFILING_DISABLED: '0', - - CORECLR_PROFILER: 'CORECLR_PROFILER', - CORECLR_PROFILER_OTEL: '{918728DD-259F-4A6A-AC2B-B85E1B658318}', - - CORECLR_PROFILER_PATH: 'CORECLR_PROFILER_PATH', - CORECLR_PROFILER_PATH_LINUX_X64: '/otel-auto-instrumentation-dotnet/linux-x64/OpenTelemetry.AutoInstrumentation.Native.so', - CORECLR_PROFILER_PATH_WINDOWS_X64: 'C:\\otel-auto-instrumentation-dotnet\\win-x64\\OpenTelemetry.AutoInstrumentation.Native.dll', - - DOTNET_STARTUP_HOOKS: 'DOTNET_STARTUP_HOOKS', - DOTNET_STARTUP_HOOKS_LINUX_ADOT: '/otel-auto-instrumentation-dotnet/net/OpenTelemetry.AutoInstrumentation.StartupHook.dll', - DOTNET_STARTUP_HOOKS_WINDOWS_ADOT: 'C:\\otel-auto-instrumentation-dotnet\\net\\OpenTelemetry.AutoInstrumentation.StartupHook.dll', - - DOTNET_ADDITIONAL_DEPS: 'DOTNET_ADDITIONAL_DEPS', - DOTNET_ADDITIONAL_DEPS_LINUX_ADOT: '/otel-auto-instrumentation-dotnet/AdditionalDeps', - DOTNET_ADDITIONAL_DEPS_WINDOWS_ADOT: 'C:\\otel-auto-instrumentation-dotnet\\AdditionalDeps', - - OTEL_DOTNET_AUTO_HOME: 'OTEL_DOTNET_AUTO_HOME', - OTEL_DOTNET_AUTO_HOME_LINUX_ADOT: '/otel-auto-instrumentation-dotnet', - OTEL_DOTNET_AUTO_HOME_WINDOWS_ADOT: 'C:\\otel-auto-instrumentation-dotnet', - - DOTNET_SHARED_STORE: 'DOTNET_SHARED_STORE', - DOTNET_SHARED_STORE_LINUX_ADOT: '/otel-auto-instrumentation-dotnet/store', - DOTNET_SHARED_STORE_WINDOWS_ADOT: 'C:\\otel-auto-instrumentation-dotnet\\store', -} as const; +/** + * Common OpenTelemetry exporter configurations and AWS Application Signals settings. + * Contains constants for OTLP protocol, resource attributes, and Application Signals enablement. + */ +export class CommonExporting { + /** Protocol configuration for OpenTelemetry OTLP exporter */ + public static readonly OTEL_EXPORTER_OTLP_PROTOCOL = 'OTEL_EXPORTER_OTLP_PROTOCOL'; + /** HTTP/Protobuf protocol setting for OTLP exporter */ + public static readonly OTEL_EXPORTER_OTLP_PROTOCOL_HTTP_PROTOBUF = 'http/protobuf'; + + /** Resource attributes configuration for OpenTelemetry */ + public static readonly OTEL_RESOURCE_ATTRIBUTES = 'OTEL_RESOURCE_ATTRIBUTES'; + + /** Flag to enable/disable AWS Application Signals */ + public static readonly OTEL_AWS_APPLICATION_SIGNALS = 'OTEL_AWS_APPLICATION_SIGNALS_ENABLED'; + /** Value to enable AWS Application Signals */ + public static readonly OTEL_AWS_APPLICATION_SIGNALS_ENABLED = 'true'; + /** Value to disable AWS Application Signals */ + public static readonly OTEL_AWS_APPLICATION_SIGNALS_DISABLED = 'false'; + /** Runtime configuration for AWS Application Signals */ + public static readonly OTEL_AWS_APPLICATION_SIGNALS_RUNTIME = 'OTEL_AWS_APPLICATION_SIGNALS_RUNTIME_ENABLED'; + /** Value to enable AWS Application Signals runtime */ + public static readonly OTEL_AWS_APPLICATION_SIGNALS_RUNTIME_ENABLED = 'true'; + /** Value to disable AWS Application Signals runtime */ + public static readonly OTEL_AWS_APPLICATION_SIGNALS_RUNTIME_DISABLED = 'false'; + + /** Endpoint configuration for AWS Application Signals exporter */ + public static readonly OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT = 'OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT'; + /** Local CloudWatch Agent endpoint for metrics */ + public static readonly OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT_LOCAL_CWA = 'http://localhost:4316/v1/metrics'; +} + +/** + * OpenTelemetry logs exporter configurations. + * Contains constants for configuring log export behavior. + */ +export class LogsExporting { + /** Configuration for OpenTelemetry logs exporter */ + public static readonly OTEL_LOGS_EXPORTER = 'OTEL_LOGS_EXPORTER'; + /** Disable logs export */ + public static readonly OTEL_LOGS_EXPORTER_NONE = 'none'; + /** Enable OTLP logs export */ + public static readonly OTEL_LOGS_EXPORTER_OTLP = 'otlp'; +} + +/** + * OpenTelemetry metrics exporter configurations. + * Contains constants for configuring metrics export behavior. + */ +export class MetricsExporting { + /** Configuration for OpenTelemetry metrics exporter */ + public static readonly OTEL_METRICS_EXPORTER = 'OTEL_METRICS_EXPORTER'; + /** Disable metrics export */ + public static readonly OTEL_METRICS_EXPORTER_NONE = 'none'; + /** Enable OTLP metrics export */ + public static readonly OTEL_METRICS_EXPORTER_OTLP = 'otlp'; +} + +/** + * OpenTelemetry trace exporter and sampling configurations. + * Contains constants for trace endpoints, sampling strategies, and propagation formats. + */ +export class TraceExporting { + /** Endpoint configuration for OTLP traces */ + public static readonly OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'OTEL_EXPORTER_OTLP_TRACES_ENDPOINT'; + /** Local CloudWatch Agent endpoint for traces */ + public static readonly OTEL_EXPORTER_OTLP_TRACES_ENDPOINT_LOCAL_CWA = 'http://localhost:4316/v1/traces'; + + /** Sampling configuration for traces */ + public static readonly OTEL_TRACES_SAMPLER = 'OTEL_TRACES_SAMPLER'; + /** X-Ray sampling strategy */ + public static readonly OTEL_TRACES_SAMPLER_XRAY = 'xray'; + /** Trace ID ratio based sampling */ + public static readonly OTEL_TRACES_SAMPLER_TRACEID_RATIO = 'traceidratio'; + /** Sample all traces */ + public static readonly OTEL_TRACES_SAMPLER_ALWAYS_ON = 'always_on'; + /** Sample no traces */ + public static readonly OTEL_TRACES_SAMPLER_ALWAYS_OFF = 'always_off'; + /** Parent-based trace ID ratio sampling */ + public static readonly OTEL_TRACES_SAMPLER_PARENT_BASED_TRACEID_RATIO = 'parentbased_traceidratio'; + /** Parent-based always on sampling */ + public static readonly OTEL_TRACES_SAMPLER_PARENT_BASED_ALWAYS_ON = 'parentbased_always_on'; + /** Parent-based always off sampling */ + public static readonly OTEL_TRACES_SAMPLER_PARENT_BASED_ALWAYS_OFF = 'parentbased_always_off'; + + /** Arguments for trace sampler configuration */ + public static readonly OTEL_TRACES_SAMPLER_ARG = 'OTEL_TRACES_SAMPLER_ARG'; + /** Local CloudWatch Agent endpoint for sampler */ + public static readonly OTEL_TRACES_SAMPLER_ARG_LOCAL_CWA = 'endpoint=http://localhost:2000'; + + /** Configuration for trace context propagation */ + public static readonly OTEL_PROPAGATORS = 'OTEL_PROPAGATORS'; + /** Supported propagation formats for Application Signals */ + public static readonly OTEL_PROPAGATORS_APPLICATION_SIGNALS = 'tracecontext,baggage,b3,xray'; +} + +/** + * Java-specific OpenTelemetry instrumentation configurations. + * Contains constants for Java agent setup and tool options. + */ +export class JavaInstrumentation { + /** Java tool options environment variable */ + public static readonly JAVA_TOOL_OPTIONS = 'JAVA_TOOL_OPTIONS'; + /** Java agent configuration for ADOT */ + public static readonly JAVA_TOOL_OPTIONS_ADOT = ' -javaagent:/otel-auto-instrumentation/javaagent.jar'; +} + +/** + * Python-specific OpenTelemetry instrumentation configurations. + * Contains constants for Python distribution, configurator, and path settings. + */ +export class PythonInstrumentation { + /** Python OpenTelemetry distribution configuration */ + public static readonly OTEL_PYTHON_DISTRO = 'OTEL_PYTHON_DISTRO'; + /** AWS distribution for Python OpenTelemetry */ + public static readonly OTEL_PYTHON_DISTRO_AWS_DISTRO = 'aws_distro'; + + /** Python OpenTelemetry configurator setting */ + public static readonly OTEL_PYTHON_CONFIGURATOR = 'OTEL_PYTHON_CONFIGURATOR'; + /** AWS configurator for Python OpenTelemetry */ + public static readonly OTEL_PYTHON_CONFIGURATOR_AWS_CONFIGURATOR = 'aws_configurator'; + + /** Python path environment variable */ + public static readonly PYTHONPATH = 'PYTHONPATH'; + /** ADOT Python auto-instrumentation path */ + public static readonly PYTHONPATH_ADOT = '/otel-auto-instrumentation-python/opentelemetry/instrumentation/auto_instrumentation:/otel-auto-instrumentation-python'; +} + +/** + * .NET-specific OpenTelemetry instrumentation configurations. + * Contains constants for .NET runtime settings, profiler configurations, and paths + * for both Linux and Windows environments. + */ +export class DotnetInstrumentation { + /** .NET OpenTelemetry distribution configuration */ + public static readonly OTEL_DOTNET_DISTRO = 'OTEL_DOTNET_DISTRO'; + /** AWS distribution for .NET OpenTelemetry */ + public static readonly OTEL_DOTNET_DISTRO_AWS_DISTRO = 'aws_distro'; + + /** .NET OpenTelemetry configurator setting */ + public static readonly OTEL_DOTNET_CONFIGURATOR = 'OTEL_DOTNET_CONFIGURATOR'; + /** AWS configurator for .NET OpenTelemetry */ + public static readonly OTEL_DOTNET_CONFIGURATOR_AWS_CONFIGURATOR = 'aws_configurator'; + + /** .NET auto-instrumentation plugins configuration */ + public static readonly OTEL_DOTNET_AUTO_PLUGINS = 'OTEL_DOTNET_AUTO_PLUGINS'; + /** ADOT auto-instrumentation plugin for .NET */ + public static readonly OTEL_DOTNET_AUTO_PLUGINS_ADOT = 'AWS.Distro.OpenTelemetry.AutoInstrumentation.Plugin, AWS.Distro.OpenTelemetry.AutoInstrumentation'; + + /** CoreCLR profiling enable flag */ + public static readonly CORECLR_ENABLE_PROFILING = 'CORECLR_ENABLE_PROFILING'; + /** Enable CoreCLR profiling */ + public static readonly CORECLR_ENABLE_PROFILING_ENABLED = '1'; + /** Disable CoreCLR profiling */ + public static readonly CORECLR_ENABLE_PROFILING_DISABLED = '0'; + + /** CoreCLR profiler GUID */ + public static readonly CORECLR_PROFILER = 'CORECLR_PROFILER'; + /** OpenTelemetry CoreCLR profiler ID */ + public static readonly CORECLR_PROFILER_OTEL = '{918728DD-259F-4A6A-AC2B-B85E1B658318}'; + + /** Path to CoreCLR profiler */ + public static readonly CORECLR_PROFILER_PATH = 'CORECLR_PROFILER_PATH'; + /** Linux x64 CoreCLR profiler path */ + public static readonly CORECLR_PROFILER_PATH_LINUX_X64 = '/otel-auto-instrumentation-dotnet/linux-x64/OpenTelemetry.AutoInstrumentation.Native.so'; + /** Windows x64 CoreCLR profiler path */ + public static readonly CORECLR_PROFILER_PATH_WINDOWS_X64 = 'C:\\otel-auto-instrumentation-dotnet\\win-x64\\OpenTelemetry.AutoInstrumentation.Native.dll'; + + /** .NET startup hooks configuration */ + public static readonly DOTNET_STARTUP_HOOKS = 'DOTNET_STARTUP_HOOKS'; + /** Linux ADOT startup hooks path */ + public static readonly DOTNET_STARTUP_HOOKS_LINUX_ADOT = '/otel-auto-instrumentation-dotnet/net/OpenTelemetry.AutoInstrumentation.StartupHook.dll'; + /** Windows ADOT startup hooks path */ + public static readonly DOTNET_STARTUP_HOOKS_WINDOWS_ADOT = 'C:\\otel-auto-instrumentation-dotnet\\net\\OpenTelemetry.AutoInstrumentation.StartupHook.dll'; + + /** Additional .NET dependencies configuration */ + public static readonly DOTNET_ADDITIONAL_DEPS = 'DOTNET_ADDITIONAL_DEPS'; + /** Linux ADOT additional dependencies path */ + public static readonly DOTNET_ADDITIONAL_DEPS_LINUX_ADOT = '/otel-auto-instrumentation-dotnet/AdditionalDeps'; + /** Windows ADOT additional dependencies path */ + public static readonly DOTNET_ADDITIONAL_DEPS_WINDOWS_ADOT = 'C:\\otel-auto-instrumentation-dotnet\\AdditionalDeps'; + + /** .NET auto-instrumentation home directory */ + public static readonly OTEL_DOTNET_AUTO_HOME = 'OTEL_DOTNET_AUTO_HOME'; + /** Linux ADOT home directory */ + public static readonly OTEL_DOTNET_AUTO_HOME_LINUX_ADOT = '/otel-auto-instrumentation-dotnet'; + /** Windows ADOT home directory */ + public static readonly OTEL_DOTNET_AUTO_HOME_WINDOWS_ADOT = 'C:\\otel-auto-instrumentation-dotnet'; + + /** .NET shared store configuration */ + public static readonly DOTNET_SHARED_STORE = 'DOTNET_SHARED_STORE'; + /** Linux ADOT shared store path */ + public static readonly DOTNET_SHARED_STORE_LINUX_ADOT = '/otel-auto-instrumentation-dotnet/store'; + /** Windows ADOT shared store path */ + public static readonly DOTNET_SHARED_STORE_WINDOWS_ADOT = 'C:\\otel-auto-instrumentation-dotnet\\store'; +} + +/** + * Node-specific OpenTelemetry instrumentation configurations. + * Contains constants for Node.js runtime settings and options. + */ +export class NodeInstrumentation { + /** Node.js options environment variable */ + public static readonly NODE_OPTIONS = 'NODE_OPTIONS'; + /** ADOT Node.js instrumentation option */ + public static readonly NODE_OPTIONS_ADOT = '--require=/otel-auto-instrumentation-nodejs/opentelemetry-node-instrumentation.js'; +} diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/ecs.ts b/packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/ecs.ts index 4b8de965bf876..ba4409450efca 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/ecs.ts +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/ecs.ts @@ -1,36 +1,14 @@ import * as ecs from 'aws-cdk-lib/aws-ecs'; +import { ManagedPolicy } from 'aws-cdk-lib/aws-iam'; import { Construct } from 'constructs'; import * as constants from './constants'; -import { ManagedPolicy } from 'aws-cdk-lib/aws-iam'; - -/** - * Supported instrumentation languages for Application Signals. - */ -export enum InstrumentationLanguage { - /** - * Java instrumentation language. - */ - JAVA, - /** - * Python instrumentation language. - */ - PYTHON, - /** - * .NET instrumentation language. - */ - DOTNET, - /** - * Node.js instrumentation language. - */ - NODEJS, -} /** * Base class for instrumentation versions. * Provides functionality to generate image URIs for different instrumentation types. */ export abstract class InstrumentationVersion { - public constructor(protected readonly imageRepo: string, protected readonly version: string) {} + public constructor(protected readonly imageRepo: string, protected readonly version: string) { } /** * Get the image URI for the instrumentation version. @@ -44,9 +22,11 @@ export abstract class InstrumentationVersion { /** * Available versions for Java instrumentation. */ -/* eslint-disable @typescript-eslint/member-ordering */ export class JavaInstrumentationVersion extends InstrumentationVersion { - private static readonly IMAGE_REPO = 'public.ecr.aws/aws-observability/adot-autoinstrumentation-java'; + /** + * The image repository for Java instrumentation. + */ + public static readonly IMAGE_REPO = 'public.ecr.aws/aws-observability/adot-autoinstrumentation-java'; /** * ADOT Java Instrumentation version 1.33.0 */ @@ -56,7 +36,6 @@ export class JavaInstrumentationVersion extends InstrumentationVersion { */ public static readonly V1_32_6 = new JavaInstrumentationVersion(JavaInstrumentationVersion.IMAGE_REPO, 'v1.32.6'); } -/* eslint-enable */ /** * Available versions for .NET instrumentation. @@ -64,22 +43,25 @@ export class JavaInstrumentationVersion extends InstrumentationVersion { /** * Available versions for Python instrumentation. */ -/* eslint-disable @typescript-eslint/member-ordering */ export class PythonInstrumentationVersion extends InstrumentationVersion { - private static readonly IMAGE_REPO = 'public.ecr.aws/aws-observability/adot-autoinstrumentation-python'; + /** + * The image repository for Python instrumentation. + */ + public static readonly IMAGE_REPO = 'public.ecr.aws/aws-observability/adot-autoinstrumentation-python'; /** * ADOT Python Instrumentation version 0.8.0 */ public static readonly V0_8_0 = new PythonInstrumentationVersion(PythonInstrumentationVersion.IMAGE_REPO, 'v0.8.0'); } -/* eslint-enable */ /** * Available versions for .NET instrumentation. */ -/* eslint-disable @typescript-eslint/member-ordering */ export class DotnetInstrumentationVersion extends InstrumentationVersion { - private static readonly IMAGE_REPO = 'public.ecr.aws/aws-observability/adot-autoinstrumentation-dotnet'; + /** + * The image repository for .NET instrumentation. + */ + public static readonly IMAGE_REPO = 'public.ecr.aws/aws-observability/adot-autoinstrumentation-dotnet'; /** * ADOT .NET Instrumentation version 1.6.0 */ @@ -101,20 +83,20 @@ export class DotnetInstrumentationVersion extends InstrumentationVersion { */ public static readonly V1_6_0_WINDOWS2019 = new DotnetInstrumentationVersion(DotnetInstrumentationVersion.IMAGE_REPO, 'v1.6.0-windows2019'); } -/* eslint-enable */ /** * Available versions for Node.js instrumentation. */ -/* eslint-disable @typescript-eslint/member-ordering */ export class NodeInstrumentationVersion extends InstrumentationVersion { - private static readonly IMAGE_REPO = 'public.ecr.aws/aws-observability/adot-autoinstrumentation-node'; + /** + * The image repository for Node.js instrumentation. + */ + public static readonly IMAGE_REPO = 'public.ecr.aws/aws-observability/adot-autoinstrumentation-node'; /** * ADOT Node.js Instrumentation version 0.5.0 */ public static readonly V0_5_0 = new NodeInstrumentationVersion(NodeInstrumentationVersion.IMAGE_REPO, 'v0.5.0'); } -/* eslint-enable */ /** * Interface for environment extensions. @@ -134,10 +116,6 @@ export interface EnvironmentExtension { * Interface for instrumentation properties. */ export interface InstrumentationProps { - /** - * The language of the instrumentation. - */ - readonly language: InstrumentationLanguage; /** * The version of the instrumentation. */ @@ -194,6 +172,13 @@ export interface ApplicationSignalsIntegrationProps { */ export interface CloudWatchAgentProps { + /** + * The name of the CloudWatch Agent container. + * + * @default - cloudwatch-agent + */ + readonly containerName?: string; + /** * Whether to enable the CloudWatch Agent sidecar. * @@ -209,145 +194,54 @@ export interface CloudWatchAgentProps { readonly container?: ecs.ContainerDefinitionOptions; } -const DEFAULT_ENVS = [ - { - name: constants.LogsExporting.OTEL_LOGS_EXPORTER, - value: constants.LogsExporting.OTEL_LOGS_EXPORTER_NONE, - }, - { - name: constants.MetricsExporting.OTEL_METRICS_EXPORTER, - value: constants.MetricsExporting.OTEL_METRICS_EXPORTER_NONE, - }, - { - name: constants.CommonExporting.OTEL_EXPORTER_OTLP_PROTOCOL, - value: constants.CommonExporting.OTEL_EXPORTER_OTLP_PROTOCOL_HTTP_PROTOBUF, - }, - { - name: constants.CommonExporting.OTEL_AWS_APPLICATION_SIGNALS, - value: constants.CommonExporting.OTEL_AWS_APPLICATION_SIGNALS_ENABLED, - }, - { - name: constants.CommonExporting.OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT, - value: constants.CommonExporting.OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT_LOCAL_CWA, - }, - { - name: constants.TraceExporting.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, - value: constants.TraceExporting.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT_LOCAL_CWA, - }, - { - name: constants.TraceExporting.OTEL_TRACES_SAMPLER, - value: constants.TraceExporting.OTEL_TRACES_SAMPLER_XRAY, - }, - { - name: constants.TraceExporting.OTEL_TRACES_SAMPLER_ARG, - value: constants.TraceExporting.OTEL_TRACES_SAMPLER_ARG_LOCAL_CWA, - }, - { - name: constants.TraceExporting.OTEL_PROPAGATORS, - value: constants.TraceExporting.OTEL_PROPAGATORS_APPLICATION_SIGNALS, - }, -]; - -const JAVA_ENVS = [ - { - name: constants.JavaInstrumentation.JAVA_TOOL_OPTIONS, - value: constants.JavaInstrumentation.JAVA_TOOL_OPTIONS_ADOT, - }, -]; - -const PYTHON_ENVS = [ - { - name: constants.PythonInstrumentation.OTEL_PYTHON_DISTRO, - value: constants.PythonInstrumentation.OTEL_PYTHON_DISTRO_AWS_DISTRO, - }, - { - name: constants.PythonInstrumentation.OTEL_PYTHON_CONFIGURATOR, - value: constants.PythonInstrumentation.OTEL_PYTHON_CONFIGURATOR_AWS_CONFIGURATOR, - }, - { - name: constants.PythonInstrumentation.PYTHONPATH, - value: constants.PythonInstrumentation.PYTHONPATH_ADOT, - }, -]; - -const DOTNET_COMMON_ENVS = [ - { - name: constants.DotnetInstrumentation.OTEL_DOTNET_DISTRO, - value: constants.DotnetInstrumentation.OTEL_DOTNET_DISTRO_AWS_DISTRO, - }, - { - name: constants.DotnetInstrumentation.OTEL_DOTNET_CONFIGURATOR, - value: constants.DotnetInstrumentation.OTEL_DOTNET_CONFIGURATOR_AWS_CONFIGURATOR, - }, - { - name: constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_PLUGINS, - value: constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_PLUGINS_ADOT, - }, -]; +const DEFAULT_CONTAINER_NAME = 'cloudwatch-agent'; -const DOTNET_LINUX_ENVS = [ - { - name: constants.DotnetInstrumentation.CORECLR_ENABLE_PROFILING, - value: constants.DotnetInstrumentation.CORECLR_ENABLE_PROFILING_ENABLED, - }, - { - name: constants.DotnetInstrumentation.CORECLR_PROFILER, - value: constants.DotnetInstrumentation.CORECLR_PROFILER_OTEL, - }, - { - name: constants.DotnetInstrumentation.CORECLR_PROFILER_PATH, - value: constants.DotnetInstrumentation.CORECLR_PROFILER_PATH_LINUX_X64, - }, - { - name: constants.DotnetInstrumentation.DOTNET_STARTUP_HOOKS, - value: constants.DotnetInstrumentation.DOTNET_STARTUP_HOOKS_LINUX_ADOT, - }, - { - name: constants.DotnetInstrumentation.DOTNET_ADDITIONAL_DEPS, - value: constants.DotnetInstrumentation.DOTNET_ADDITIONAL_DEPS_LINUX_ADOT, - }, - { - name: constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_HOME, - value: constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_HOME_LINUX_ADOT, - }, - { - name: constants.DotnetInstrumentation.DOTNET_SHARED_STORE, - value: constants.DotnetInstrumentation.DOTNET_SHARED_STORE_LINUX_ADOT, - }, -]; +/** + * SDKInject is a base class for all SDK injects to mutate the task definition + * to inject the ADOT init container and configure the application container with + * the necessary environment variables. + */ +abstract class SDKInject { -const DOTNET_WINDOWS_ENVS = [ - { - name: constants.DotnetInstrumentation.CORECLR_ENABLE_PROFILING, - value: constants.DotnetInstrumentation.CORECLR_ENABLE_PROFILING_ENABLED, - }, - { - name: constants.DotnetInstrumentation.CORECLR_PROFILER, - value: constants.DotnetInstrumentation.CORECLR_PROFILER_OTEL, - }, - { - name: constants.DotnetInstrumentation.CORECLR_PROFILER_PATH, - value: constants.DotnetInstrumentation.CORECLR_PROFILER_PATH_WINDOWS_X64, - }, - { - name: constants.DotnetInstrumentation.DOTNET_STARTUP_HOOKS, - value: constants.DotnetInstrumentation.DOTNET_STARTUP_HOOKS_WINDOWS_ADOT, - }, - { - name: constants.DotnetInstrumentation.DOTNET_ADDITIONAL_DEPS, - value: constants.DotnetInstrumentation.DOTNET_ADDITIONAL_DEPS_WINDOWS_ADOT, - }, - { - name: constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_HOME, - value: constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_HOME_WINDOWS_ADOT, - }, - { - name: constants.DotnetInstrumentation.DOTNET_SHARED_STORE, - value: constants.DotnetInstrumentation.DOTNET_SHARED_STORE_WINDOWS_ADOT, - }, -]; + private static readonly DEFAULT_ENVS = [ + { + name: constants.LogsExporting.OTEL_LOGS_EXPORTER, + value: constants.LogsExporting.OTEL_LOGS_EXPORTER_NONE, + }, + { + name: constants.MetricsExporting.OTEL_METRICS_EXPORTER, + value: constants.MetricsExporting.OTEL_METRICS_EXPORTER_NONE, + }, + { + name: constants.CommonExporting.OTEL_EXPORTER_OTLP_PROTOCOL, + value: constants.CommonExporting.OTEL_EXPORTER_OTLP_PROTOCOL_HTTP_PROTOBUF, + }, + { + name: constants.CommonExporting.OTEL_AWS_APPLICATION_SIGNALS, + value: constants.CommonExporting.OTEL_AWS_APPLICATION_SIGNALS_ENABLED, + }, + { + name: constants.CommonExporting.OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT, + value: constants.CommonExporting.OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT_LOCAL_CWA, + }, + { + name: constants.TraceExporting.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, + value: constants.TraceExporting.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT_LOCAL_CWA, + }, + { + name: constants.TraceExporting.OTEL_TRACES_SAMPLER, + value: constants.TraceExporting.OTEL_TRACES_SAMPLER_XRAY, + }, + { + name: constants.TraceExporting.OTEL_TRACES_SAMPLER_ARG, + value: constants.TraceExporting.OTEL_TRACES_SAMPLER_ARG_LOCAL_CWA, + }, + { + name: constants.TraceExporting.OTEL_PROPAGATORS, + value: constants.TraceExporting.OTEL_PROPAGATORS_APPLICATION_SIGNALS, + }, + ]; -abstract class SDKInject { protected taskDefinition: ecs.TaskDefinition; protected sharedVolumeName: string; protected adotImage: string; @@ -364,11 +258,28 @@ abstract class SDKInject { this.overrideEnvironments = overrideEnvironments; } + /** + * The command to run the init container. + */ abstract get command(): string[]; + /** + * The memory limit for the init container. + */ abstract get memoryLimitMiB(): number; - + /** + * The path to ADOT SDK agent in the init container. + */ protected abstract get containerPath(): string; - protected abstract applyAdditionalEnvironments(container: ecs.ContainerDefinition): void; + /** + * Inject additional environment variables to the application container + * other than the DEFAULT_ENVS. + */ + protected abstract injectAdditionalEnvironments(envsToInject: { [key: string]: string }, envsFromTaskDef: { [key: string]: string }): void; + /** + * Override additional environment variables to the application container + * other than the DEFAULT_ENVS. + */ + protected abstract overrideAdditionalEnvironments(envsToOverride: { [key: string]: string }, envsFromTaskDef: { [key: string]: string }): void; public injectInitContainer(): ecs.ContainerDefinition { const initContainer = this.taskDefinition.addContainer('adot-init', { @@ -388,13 +299,30 @@ abstract class SDKInject { } public renderDefaultContainer(container: ecs.ContainerDefinition) { - for (const env of DEFAULT_ENVS) { - container.addEnvironment(env.name, env.value); + const envsToInject: { [key: string]: string } = {}; + const envsFromTaskDef = (container as any).environment; + + for (const env of SDKInject.DEFAULT_ENVS) { + envsToInject[env.name] = env.value; + } + this.injectAdditionalEnvironments(envsToInject, envsFromTaskDef); + + const envsToOverride: { [key: string]: string } = {}; + this.overrideAdditionalEnvironments(envsToOverride, envsFromTaskDef); + + for (const [key, value] of Object.entries(envsToInject)) { + if (!envsFromTaskDef[key]) { + container.addEnvironment(key, value); + } + } + + for (const [key, value] of Object.entries(envsToOverride)) { + container.addEnvironment(key, value); } - this.applyAdditionalEnvironments(container); - for (const env of this.overrideEnvironments??[]) { + for (const env of this.overrideEnvironments ?? []) { container.addEnvironment(env.name, env.value); } + container.addMountPoints({ sourceVolume: this.sharedVolumeName, containerPath: this.containerPath, @@ -405,6 +333,13 @@ abstract class SDKInject { } class JavaSDKInject extends SDKInject { + private static readonly JAVA_ENVS = [ + { + name: constants.JavaInstrumentation.JAVA_TOOL_OPTIONS, + value: constants.JavaInstrumentation.JAVA_TOOL_OPTIONS_ADOT, + }, + ]; + get command(): string[] { return ['cp', '/javaagent.jar', '/otel-auto-instrumentation/javaagent.jar']; } @@ -417,17 +352,32 @@ class JavaSDKInject extends SDKInject { return '/otel-auto-instrumentation'; } - protected applyAdditionalEnvironments(container: ecs.ContainerDefinition) { - const environments = (container as any).environment; - for (const env of JAVA_ENVS) { - if (!environments[env.name]) { - container.addEnvironment(env.name, env.value); - } + protected injectAdditionalEnvironments(envs: { [key: string]: string }) { + for (const env of JavaSDKInject.JAVA_ENVS) { + envs[env.name] = env.value; } } + + protected overrideAdditionalEnvironments(_envsToOverride: { [key: string]: string }, _overrideEnvironments: { [key: string]: string }): void { + // No additional overrides needed for Java + } } class PythonSDKInject extends SDKInject { + private static readonly PYTHON_ENVS = [ + { + name: constants.PythonInstrumentation.OTEL_PYTHON_DISTRO, + value: constants.PythonInstrumentation.OTEL_PYTHON_DISTRO_AWS_DISTRO, + }, + { + name: constants.PythonInstrumentation.OTEL_PYTHON_CONFIGURATOR, + value: constants.PythonInstrumentation.OTEL_PYTHON_CONFIGURATOR_AWS_CONFIGURATOR, + }, + { + name: constants.PythonInstrumentation.PYTHONPATH, + value: constants.PythonInstrumentation.PYTHONPATH_ADOT, + }, + ]; get command(): string[] { return ['cp', '-a', '/autoinstrumentation/.', '/otel-auto-instrumentation-python']; } @@ -436,14 +386,11 @@ class PythonSDKInject extends SDKInject { return 32; } - public applyAdditionalEnvironments(container: ecs.ContainerDefinition): void { - const environments = (container as any).environment; - for (const env of PYTHON_ENVS) { - if (!environments[env.name]) { - container.addEnvironment(env.name, env.value); - } else if ('PYTHONPATH' === env.name) { - const pythonPath = environments[env.name]; - container.addEnvironment(env.name, `/otel-auto-instrumentation-python/opentelemetry/instrumentation/auto_instrumentation:${pythonPath}:/otel-auto-instrumentation-python`); + public injectAdditionalEnvironments(envsToInject: { [key: string]: string }, envsFromTaskDef: { [key: string]: string }): void { + for (const env of PythonSDKInject.PYTHON_ENVS) { + envsToInject[env.name] = env.value; + if (!envsFromTaskDef[env.name]) { + envsToInject[env.name] = env.value; } } } @@ -451,9 +398,63 @@ class PythonSDKInject extends SDKInject { protected get containerPath(): string { return '/otel-auto-instrumentation-python'; } + + protected overrideAdditionalEnvironments(envsToOverride: { [key: string]: string }, envsFromTaskDef: { [key: string]: string }): void { + if (envsFromTaskDef[constants.PythonInstrumentation.PYTHONPATH]) { + const pythonPath = envsFromTaskDef[constants.PythonInstrumentation.PYTHONPATH]; + envsToOverride[constants.PythonInstrumentation.PYTHONPATH] = `/otel-auto-instrumentation-python/opentelemetry/instrumentation/auto_instrumentation:${pythonPath}:/otel-auto-instrumentation-python`; + } + } +} + +abstract class DotNetSDKInject extends SDKInject { + protected static readonly DOTNET_COMMON_ENVS = [ + { + name: constants.DotnetInstrumentation.OTEL_DOTNET_DISTRO, + value: constants.DotnetInstrumentation.OTEL_DOTNET_DISTRO_AWS_DISTRO, + }, + { + name: constants.DotnetInstrumentation.OTEL_DOTNET_CONFIGURATOR, + value: constants.DotnetInstrumentation.OTEL_DOTNET_CONFIGURATOR_AWS_CONFIGURATOR, + }, + { + name: constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_PLUGINS, + value: constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_PLUGINS_ADOT, + }, + ]; } +class DotNetSDKOnLinuxInject extends DotNetSDKInject { + private static readonly DOTNET_LINUX_ENVS = [ + { + name: constants.DotnetInstrumentation.CORECLR_ENABLE_PROFILING, + value: constants.DotnetInstrumentation.CORECLR_ENABLE_PROFILING_ENABLED, + }, + { + name: constants.DotnetInstrumentation.CORECLR_PROFILER, + value: constants.DotnetInstrumentation.CORECLR_PROFILER_OTEL, + }, + { + name: constants.DotnetInstrumentation.CORECLR_PROFILER_PATH, + value: constants.DotnetInstrumentation.CORECLR_PROFILER_PATH_LINUX_X64, + }, + { + name: constants.DotnetInstrumentation.DOTNET_STARTUP_HOOKS, + value: constants.DotnetInstrumentation.DOTNET_STARTUP_HOOKS_LINUX_ADOT, + }, + { + name: constants.DotnetInstrumentation.DOTNET_ADDITIONAL_DEPS, + value: constants.DotnetInstrumentation.DOTNET_ADDITIONAL_DEPS_LINUX_ADOT, + }, + { + name: constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_HOME, + value: constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_HOME_LINUX_ADOT, + }, + { + name: constants.DotnetInstrumentation.DOTNET_SHARED_STORE, + value: constants.DotnetInstrumentation.DOTNET_SHARED_STORE_LINUX_ADOT, + }, + ]; -class DotNetSDKOnLinuxInject extends SDKInject { private cpuArch: ecs.CpuArchitecture; constructor( @@ -474,39 +475,69 @@ class DotNetSDKOnLinuxInject extends SDKInject { return 128; } - public applyAdditionalEnvironments(container: ecs.ContainerDefinition): void { - const environments = (container as any).environment; + public injectAdditionalEnvironments(envsToInject: { [key: string]: string }, envsFromTaskDef: { [key: string]: string }): void { let libPath = 'linux-x64'; if (this.cpuArch == ecs.CpuArchitecture.ARM64) { libPath = 'linux-arm64'; } - for (const env of [...DOTNET_COMMON_ENVS, { + for (const env of [...DotNetSDKInject.DOTNET_COMMON_ENVS, { name: 'CORECLR_PROFILER_PATH', value: `/otel-auto-instrumentation-dotnet/${libPath}/OpenTelemetry.AutoInstrumentation.Native.so`, }]) { - if (!environments[env.name]) { - container.addEnvironment(env.name, env.value); - } + envsToInject[env.name] = env.value; } - if (environments.OTEL_DOTNET_AUTO_HOME) { + if (envsFromTaskDef[constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_HOME]) { // If OTEL_DOTNET_AUTO_HOME env var is already set, we will assume that .NET Auto-instrumentation is already configured. return; } - for (const env of DOTNET_LINUX_ENVS) { - if (!environments[env.name]) { - container.addEnvironment(env.name, env.value); - } + for (const env of DotNetSDKOnLinuxInject.DOTNET_LINUX_ENVS) { + envsToInject[env.name] = env.value; } } protected get containerPath(): string { return '/otel-auto-instrumentation-dotnet'; } + + protected overrideAdditionalEnvironments(_envsToOverride: { [key: string]: string }, _envsFromTaskDef: { [key: string]: string }): void { + // No additional overrides needed for .NET on Linux + } } -class DotNetSDKOnWindowsInject extends SDKInject { +class DotNetSDKOnWindowsInject extends DotNetSDKInject { + private static readonly DOTNET_WINDOWS_ENVS = [ + { + name: constants.DotnetInstrumentation.CORECLR_ENABLE_PROFILING, + value: constants.DotnetInstrumentation.CORECLR_ENABLE_PROFILING_ENABLED, + }, + { + name: constants.DotnetInstrumentation.CORECLR_PROFILER, + value: constants.DotnetInstrumentation.CORECLR_PROFILER_OTEL, + }, + { + name: constants.DotnetInstrumentation.CORECLR_PROFILER_PATH, + value: constants.DotnetInstrumentation.CORECLR_PROFILER_PATH_WINDOWS_X64, + }, + { + name: constants.DotnetInstrumentation.DOTNET_STARTUP_HOOKS, + value: constants.DotnetInstrumentation.DOTNET_STARTUP_HOOKS_WINDOWS_ADOT, + }, + { + name: constants.DotnetInstrumentation.DOTNET_ADDITIONAL_DEPS, + value: constants.DotnetInstrumentation.DOTNET_ADDITIONAL_DEPS_WINDOWS_ADOT, + }, + { + name: constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_HOME, + value: constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_HOME_WINDOWS_ADOT, + }, + { + name: constants.DotnetInstrumentation.DOTNET_SHARED_STORE, + value: constants.DotnetInstrumentation.DOTNET_SHARED_STORE_WINDOWS_ADOT, + }, + ]; + get command(): string[] { return ['CMD', '/c', @@ -526,27 +557,26 @@ class DotNetSDKOnWindowsInject extends SDKInject { return 128; } - public applyAdditionalEnvironments(container: ecs.ContainerDefinition): void { - const environments = (container as any).environment; - for (const env of DOTNET_COMMON_ENVS) { - if (!environments[env.name]) { - container.addEnvironment(env.name, env.value); - } + public injectAdditionalEnvironments(envsToInject: { [key: string]: string }, envsFromTaskDef: { [key: string]: string }): void { + for (const env of DotNetSDKInject.DOTNET_COMMON_ENVS) { + envsToInject[env.name] = env.value; } - if (environments.OTEL_DOTNET_AUTO_HOME) { + if (envsFromTaskDef[constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_HOME]) { // If OTEL_DOTNET_AUTO_HOME env var is already set, we will assume that .NET Auto-instrumentation is already configured. return; } - for (const env of DOTNET_WINDOWS_ENVS) { - if (!environments[env.name]) { - container.addEnvironment(env.name, env.value); - } + for (const env of DotNetSDKOnWindowsInject.DOTNET_WINDOWS_ENVS) { + envsToInject[env.name] = env.value; } } protected get containerPath(): string { return 'C:\\otel-auto-instrumentation-dotnet'; } + + protected overrideAdditionalEnvironments(_envsToOverride: { [key: string]: string }, _envsFromTaskDef: { [key: string]: string }): void { + // No additional overrides needed for .NET on Windows + } } class NodeSDKInject extends SDKInject { @@ -558,21 +588,26 @@ class NodeSDKInject extends SDKInject { return 128; } - public applyAdditionalEnvironments(container: ecs.ContainerDefinition): void { - const environments = (container as any).environment; - const originalNodeOptions = environments.NODE_OPTIONS ?? ''; - let renderedNodeOptions = `${originalNodeOptions} --require /otel-auto-instrumentation-nodejs/autoinstrumentation.js`; - container.addEnvironment('NODE_OPTIONS', renderedNodeOptions); + public injectAdditionalEnvironments(envsToInject: { [key: string]: string }, _envsFromTaskDef: { [key: string]: string }): void { + envsToInject[constants.NodeInstrumentation.NODE_OPTIONS] = ' --require /otel-auto-instrumentation-nodejs/autoinstrumentation.js'; } protected get containerPath(): string { return '/otel-auto-instrumentation-nodejs'; } + + protected overrideAdditionalEnvironments(envsToOverride: { [key: string]: string }, envsFromTaskDef: { [key: string]: string }): void { + if (envsFromTaskDef[constants.NodeInstrumentation.NODE_OPTIONS]) { + const originalNodeOptions = envsFromTaskDef[constants.NodeInstrumentation.NODE_OPTIONS] ?? ''; + let renderedNodeOptions = `${originalNodeOptions} --require /otel-auto-instrumentation-nodejs/autoinstrumentation.js`; + envsToOverride[constants.NodeInstrumentation.NODE_OPTIONS] = renderedNodeOptions; + } + } } const CLOUDWATCH_AGENT_IMAGE = 'amazon/cloudwatch-agent:latest'; const CLOUDWATCH_AGENT_IMAGE_WIN2019 = 'public.ecr.aws/cloudwatch-agent/cloudwatch-agent:latest-windowsservercore2019'; -const CLOUDWATCH_AGENT_IMAGE_WIN2022 ='public.ecr.aws/cloudwatch-agent/cloudwatch-agent:latest-windowsservercore2022'; +const CLOUDWATCH_AGENT_IMAGE_WIN2022 = 'public.ecr.aws/cloudwatch-agent/cloudwatch-agent:latest-windowsservercore2022'; const CW_CONFIG_CONTENT = { logs: { metrics_collected: { @@ -616,6 +651,7 @@ export class ApplicationSignalsIntegration extends Construct { let cloudWatchAgentImage = CLOUDWATCH_AGENT_IMAGE; let cpuArch = ecs.CpuArchitecture.X86_64; let isWindows = false; + if (runtimePlatformObj) { const runtimePlatform = runtimePlatformObj as ecs.RuntimePlatform; if (runtimePlatform.operatingSystemFamily) { @@ -637,7 +673,7 @@ export class ApplicationSignalsIntegration extends Construct { } } - const cloudWatchAgentConfig = props.cloudWatchAgent ?? { enableSidecar: true }; + const cloudWatchAgentConfig = props.cloudWatchAgent ?? { enableSidecar: true, containerName: DEFAULT_CONTAINER_NAME }; if (props.taskDefinition.compatibility === ecs.Compatibility.FARGATE && !cloudWatchAgentConfig.enableSidecar) { throw new Error('Fargate tasks must deploy CloudWatch Agent as a sidecar container'); @@ -647,60 +683,56 @@ export class ApplicationSignalsIntegration extends Construct { } overrideEnvironments.push(...props.overrideEnvironments ?? []); - switch (props.instrumentation.language) { - case InstrumentationLanguage.JAVA: - this.sdkInject = new JavaSDKInject( + if (props.instrumentation.sdkVersion instanceof JavaInstrumentationVersion) { + this.sdkInject = new JavaSDKInject( + props.taskDefinition, + this.mountVolumeName, + props.instrumentation.sdkVersion.imageURI(), + overrideEnvironments, + ); + } else if (props.instrumentation.sdkVersion instanceof PythonInstrumentationVersion) { + this.sdkInject = new PythonSDKInject( + props.taskDefinition, + this.mountVolumeName, + props.instrumentation.sdkVersion.imageURI(), + overrideEnvironments, + ); + } else if (props.instrumentation.sdkVersion instanceof DotnetInstrumentationVersion) { + if (isWindows) { + this.sdkInject = new DotNetSDKOnWindowsInject( props.taskDefinition, this.mountVolumeName, props.instrumentation.sdkVersion.imageURI(), overrideEnvironments, ); - break; - case InstrumentationLanguage.PYTHON: - this.sdkInject = new PythonSDKInject( + } else { + this.sdkInject = new DotNetSDKOnLinuxInject( props.taskDefinition, this.mountVolumeName, props.instrumentation.sdkVersion.imageURI(), + cpuArch, overrideEnvironments, ); - break; - case InstrumentationLanguage.DOTNET: - if (isWindows) { - this.sdkInject = new DotNetSDKOnWindowsInject( - props.taskDefinition, - this.mountVolumeName, - props.instrumentation.sdkVersion.imageURI(), - overrideEnvironments, - ); - } else { - this.sdkInject = new DotNetSDKOnLinuxInject( - props.taskDefinition, - this.mountVolumeName, - props.instrumentation.sdkVersion.imageURI(), - cpuArch, - overrideEnvironments, - ); - } - break; - case InstrumentationLanguage.NODEJS: - this.sdkInject = new NodeSDKInject( - props.taskDefinition, - this.mountVolumeName, - props.instrumentation.sdkVersion.imageURI(), - overrideEnvironments, - ); - break; + } + } else if (props.instrumentation.sdkVersion instanceof NodeInstrumentationVersion) { + this.sdkInject = new NodeSDKInject( + props.taskDefinition, + this.mountVolumeName, + props.instrumentation.sdkVersion.imageURI(), + overrideEnvironments, + ); } let cwaContainer: ecs.ContainerDefinitionOptions | undefined; + let cwaName = cloudWatchAgentConfig.containerName ?? DEFAULT_CONTAINER_NAME; if (cloudWatchAgentConfig.enableSidecar) { - cwaContainer = cloudWatchAgentConfig.container ?? this.getCloudWatchAgentContainer(cloudWatchAgentImage); + cwaContainer = cloudWatchAgentConfig.container ?? this.getCloudWatchAgentContainer(cwaName, cloudWatchAgentImage); } - this.mutateTaskDefinition(props.taskDefinition, cwaContainer); + this.mutateTaskDefinition(props.taskDefinition, cwaName, cwaContainer); } - private mutateTaskDefinition(taskDefinition: ecs.TaskDefinition, cwaContainer?: ecs.ContainerDefinitionOptions) { + private mutateTaskDefinition(taskDefinition: ecs.TaskDefinition, name: string, cwaContainer?: ecs.ContainerDefinitionOptions) { taskDefinition.addVolume({ name: this.mountVolumeName, }); @@ -716,7 +748,7 @@ export class ApplicationSignalsIntegration extends Construct { } if (cwaContainer) { - let cwagentContainer = taskDefinition.addContainer('cloudwatch-agent', cwaContainer); + let cwagentContainer = taskDefinition.addContainer(name, cwaContainer); defaultContainer.addContainerDependencies({ container: cwagentContainer, condition: ecs.ContainerDependencyCondition.START, @@ -724,13 +756,13 @@ export class ApplicationSignalsIntegration extends Construct { } } - private getCloudWatchAgentContainer(image: string): ecs.ContainerDefinitionOptions { + private getCloudWatchAgentContainer(name: string, image: string): ecs.ContainerDefinitionOptions { return { image: ecs.ContainerImage.fromRegistry(image), environment: { CW_CONFIG_CONTENT: JSON.stringify(CW_CONFIG_CONTENT), }, - logging: new ecs.AwsLogDriver({ streamPrefix: 'cloudwatch-agent' }), + logging: new ecs.AwsLogDriver({ streamPrefix: name }), user: '0:1338', memoryReservationMiB: 50, portMappings: [ diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/package.json b/packages/@aws-cdk/aws-applicationsignals-alpha/package.json index 9056b0c49426b..bc4bd6f67b90f 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/package.json +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/package.json @@ -87,7 +87,6 @@ "@aws-cdk/integ-runner": "0.0.0", "@aws-cdk/integ-tests-alpha": "0.0.0", "@aws-cdk/pkglint": "0.0.0", - "@aws-cdk/aws-ecs": "^1.204.0", "@types/jest": "^29.5.14", "aws-cdk-lib": "0.0.0", "constructs": "^10.0.0" @@ -109,9 +108,6 @@ "tag": "latest" }, "pkglint": { - "exclude": [ - "naming/package-matches-directory", - "assert/assert-dependency" - ] + "exclude": [] } } diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/ecs-enablement.test.ts b/packages/@aws-cdk/aws-applicationsignals-alpha/test/ecs-enablement.test.ts index 8a4f3f4c4af6d..51f218cdbd5c2 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/test/ecs-enablement.test.ts +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/ecs-enablement.test.ts @@ -2,7 +2,7 @@ import { Stack } from 'aws-cdk-lib'; import { Template } from 'aws-cdk-lib/assertions'; import * as ecs from 'aws-cdk-lib/aws-ecs'; -import { ApplicationSignalsIntegration, InstrumentationLanguage, DotnetInstrumentationVersion, PythonInstrumentationVersion, JavaInstrumentationVersion, NodeInstrumentationVersion } from '../lib'; +import { ApplicationSignalsIntegration, DotnetInstrumentationVersion, PythonInstrumentationVersion, JavaInstrumentationVersion, NodeInstrumentationVersion } from '../lib'; describe('application signals integration', () => { test('should create basic application signals configurations with java', () => { @@ -20,7 +20,6 @@ describe('application signals integration', () => { new ApplicationSignalsIntegration(stack, 'TestIntegration', { taskDefinition: fargateTaskDefinition, instrumentation: { - language: InstrumentationLanguage.JAVA, sdkVersion: JavaInstrumentationVersion.V1_32_6, }, }); @@ -197,7 +196,6 @@ describe('application signals integration', () => { new ApplicationSignalsIntegration(stack, 'TestFailure', { taskDefinition: fargateTaskDefinition, instrumentation: { - language: InstrumentationLanguage.JAVA, sdkVersion: JavaInstrumentationVersion.V1_32_6, }, serviceName: 'demo', @@ -226,7 +224,6 @@ describe('application signals integration', () => { new ApplicationSignalsIntegration(stack, 'TestIntegration', { taskDefinition: ec2TaskDefinition, instrumentation: { - language: InstrumentationLanguage.PYTHON, sdkVersion: PythonInstrumentationVersion.V0_8_0, }, serviceName: 'demo', @@ -385,7 +382,6 @@ describe('application signals integration', () => { new ApplicationSignalsIntegration(stack, 'TestIntegration', { taskDefinition: ec2TaskDefinition, instrumentation: { - language: InstrumentationLanguage.DOTNET, sdkVersion: DotnetInstrumentationVersion.V1_6_0, }, serviceName: 'demo', @@ -539,7 +535,7 @@ describe('application signals integration', () => { }); }); - test('should create application signals configurations with dotnet on windows', () => { + test('should create application signals configurations with dotnet on windows2019', () => { // GIVEN const stack = new Stack(); @@ -556,7 +552,6 @@ describe('application signals integration', () => { new ApplicationSignalsIntegration(stack, 'TestIntegration', { taskDefinition: ec2TaskDefinition, instrumentation: { - language: InstrumentationLanguage.DOTNET, sdkVersion: DotnetInstrumentationVersion.V1_6_0_WINDOWS2019, runtimePlatform: { operatingSystemFamily: ecs.OperatingSystemFamily.WINDOWS_SERVER_2019_CORE, @@ -721,6 +716,187 @@ describe('application signals integration', () => { }); }); + test('should create application signals configurations with dotnet on windows2022', () => { + // GIVEN + const stack = new Stack(); + + // WHEN + const ec2TaskDefinition = new ecs.Ec2TaskDefinition(stack, 'TestTaskDefinition', { + networkMode: ecs.NetworkMode.HOST, + }); + ec2TaskDefinition.addContainer('app', { + image: ecs.ContainerImage.fromRegistry('nathanpeck/name'), + cpu: 0, + memoryLimitMiB: 512, + }); + + new ApplicationSignalsIntegration(stack, 'TestIntegration', { + taskDefinition: ec2TaskDefinition, + instrumentation: { + sdkVersion: DotnetInstrumentationVersion.V1_6_0_WINDOWS2022, + runtimePlatform: { + operatingSystemFamily: ecs.OperatingSystemFamily.WINDOWS_SERVER_2022_CORE, + }, + }, + serviceName: 'demo', + cloudWatchAgent: { + enableSidecar: false, + }, + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { + ContainerDefinitions: [ + { + Environment: [ + { + Name: 'OTEL_LOGS_EXPORTER', + Value: 'none', + }, + { + Name: 'OTEL_METRICS_EXPORTER', + Value: 'none', + }, + { + Name: 'OTEL_EXPORTER_OTLP_PROTOCOL', + Value: 'http/protobuf', + }, + { + Name: 'OTEL_AWS_APPLICATION_SIGNALS_ENABLED', + Value: 'true', + }, + { + Name: 'OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT', + Value: 'http://localhost:4316/v1/metrics', + }, + { + Name: 'OTEL_EXPORTER_OTLP_TRACES_ENDPOINT', + Value: 'http://localhost:4316/v1/traces', + }, + { + Name: 'OTEL_TRACES_SAMPLER', + Value: 'xray', + }, + { + Name: 'OTEL_TRACES_SAMPLER_ARG', + Value: 'endpoint=http://localhost:2000', + }, + { + Name: 'OTEL_PROPAGATORS', + Value: 'tracecontext,baggage,b3,xray', + }, + { + Name: 'OTEL_DOTNET_DISTRO', + Value: 'aws_distro', + }, + { + Name: 'OTEL_DOTNET_CONFIGURATOR', + Value: 'aws_configurator', + }, + { + Name: 'OTEL_DOTNET_AUTO_PLUGINS', + Value: 'AWS.Distro.OpenTelemetry.AutoInstrumentation.Plugin, AWS.Distro.OpenTelemetry.AutoInstrumentation', + }, + { + Name: 'CORECLR_ENABLE_PROFILING', + Value: '1', + }, + { + Name: 'CORECLR_PROFILER', + Value: '{918728DD-259F-4A6A-AC2B-B85E1B658318}', + }, + { + Name: 'CORECLR_PROFILER_PATH', + Value: 'C:\\otel-auto-instrumentation-dotnet\\win-x64\\OpenTelemetry.AutoInstrumentation.Native.dll', + }, + { + Name: 'DOTNET_STARTUP_HOOKS', + Value: 'C:\\otel-auto-instrumentation-dotnet\\net\\OpenTelemetry.AutoInstrumentation.StartupHook.dll', + }, + { + Name: 'DOTNET_ADDITIONAL_DEPS', + Value: 'C:\\otel-auto-instrumentation-dotnet\\AdditionalDeps', + }, + { + Name: 'OTEL_DOTNET_AUTO_HOME', + Value: 'C:\\otel-auto-instrumentation-dotnet', + }, + { + Name: 'DOTNET_SHARED_STORE', + Value: 'C:\\otel-auto-instrumentation-dotnet\\store', + }, + { + Name: 'OTEL_RESOURCE_ATTRIBUTES', + Value: 'service.name=demo', + }, + ], + Essential: true, + Image: 'nathanpeck/name', + MountPoints: [ + { + ContainerPath: 'C:\\otel-auto-instrumentation-dotnet', + ReadOnly: false, + SourceVolume: 'opentelemetry-auto-instrumentation', + }, + ], + Cpu: 0, + Memory: 512, + Name: 'app', + DependsOn: [ + { + Condition: 'SUCCESS', + ContainerName: 'adot-init', + }, + ], + }, + { + Command: [ + 'CMD', + '/c', + 'xcopy', + '/e', + 'C:\\autoinstrumentation\\*', + 'C:\\otel-auto-instrumentation-dotnet', + '&&', + 'icacls', + 'C:\\otel-auto-instrumentation-dotnet', + '/grant', + '*S-1-1-0:R', + '/T', + ], + Essential: false, + Image: 'public.ecr.aws/aws-observability/adot-autoinstrumentation-dotnet:v1.6.0-windows2022', + MountPoints: [ + { + ContainerPath: 'C:\\otel-auto-instrumentation-dotnet', + ReadOnly: false, + SourceVolume: 'opentelemetry-auto-instrumentation', + }, + ], + Name: 'adot-init', + Cpu: 0, + Memory: 128, + }, + ], + Family: 'TestTaskDefinition', + NetworkMode: 'host', + RequiresCompatibilities: [ + 'EC2', + ], + TaskRoleArn: { + 'Fn::GetAtt': [ + 'TestTaskDefinitionTaskRole38EA0D26', + 'Arn', + ], + }, + Volumes: [ + { + Name: 'opentelemetry-auto-instrumentation', + }, + ], + }); + }); + test('should create application signals configurations with node', () => { // GIVEN const stack = new Stack(); @@ -738,7 +914,6 @@ describe('application signals integration', () => { new ApplicationSignalsIntegration(stack, 'TestIntegration', { taskDefinition: ec2TaskDefinition, instrumentation: { - language: InstrumentationLanguage.NODEJS, sdkVersion: NodeInstrumentationVersion.V0_5_0, }, @@ -857,4 +1032,142 @@ describe('application signals integration', () => { }); }); + test('should create application signals configurations with custom node options', () => { + // GIVEN + const stack = new Stack(); + + // WHEN + const ec2TaskDefinition = new ecs.Ec2TaskDefinition(stack, 'TestTaskDefinition', { + networkMode: ecs.NetworkMode.HOST, + }); + ec2TaskDefinition.addContainer('app', { + image: ecs.ContainerImage.fromRegistry('nathanpeck/name'), + cpu: 0, + memoryLimitMiB: 512, + environment: { + NODE_OPTIONS: '--max-old-space-size=4096', + }, + }); + + new ApplicationSignalsIntegration(stack, 'TestIntegration', { + taskDefinition: ec2TaskDefinition, + instrumentation: { + sdkVersion: NodeInstrumentationVersion.V0_5_0, + + }, + serviceName: 'demo', + cloudWatchAgent: { + enableSidecar: false, + }, + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { + ContainerDefinitions: [ + { + Environment: [ + { + Name: 'NODE_OPTIONS', + Value: '--max-old-space-size=4096 --require /otel-auto-instrumentation-nodejs/autoinstrumentation.js', + }, + { + Name: 'OTEL_LOGS_EXPORTER', + Value: 'none', + }, + { + Name: 'OTEL_METRICS_EXPORTER', + Value: 'none', + }, + { + Name: 'OTEL_EXPORTER_OTLP_PROTOCOL', + Value: 'http/protobuf', + }, + { + Name: 'OTEL_AWS_APPLICATION_SIGNALS_ENABLED', + Value: 'true', + }, + { + Name: 'OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT', + Value: 'http://localhost:4316/v1/metrics', + }, + { + Name: 'OTEL_EXPORTER_OTLP_TRACES_ENDPOINT', + Value: 'http://localhost:4316/v1/traces', + }, + { + Name: 'OTEL_TRACES_SAMPLER', + Value: 'xray', + }, + { + Name: 'OTEL_TRACES_SAMPLER_ARG', + Value: 'endpoint=http://localhost:2000', + }, + { + Name: 'OTEL_PROPAGATORS', + Value: 'tracecontext,baggage,b3,xray', + }, + { + Name: 'OTEL_RESOURCE_ATTRIBUTES', + Value: 'service.name=demo', + }, + ], + Essential: true, + Image: 'nathanpeck/name', + MountPoints: [ + { + ContainerPath: '/otel-auto-instrumentation-nodejs', + ReadOnly: false, + SourceVolume: 'opentelemetry-auto-instrumentation', + }, + ], + Cpu: 0, + Memory: 512, + Name: 'app', + DependsOn: [ + { + Condition: 'SUCCESS', + ContainerName: 'adot-init', + }, + ], + }, + { + Command: [ + 'cp', + '-a', + '/autoinstrumentation/.', + '/otel-auto-instrumentation-nodejs', + ], + Essential: false, + Image: 'public.ecr.aws/aws-observability/adot-autoinstrumentation-node:v0.5.0', + MountPoints: [ + { + ContainerPath: '/otel-auto-instrumentation-nodejs', + ReadOnly: false, + SourceVolume: 'opentelemetry-auto-instrumentation', + }, + ], + Name: 'adot-init', + Cpu: 0, + Memory: 128, + }, + ], + Family: 'TestTaskDefinition', + NetworkMode: 'host', + RequiresCompatibilities: [ + 'EC2', + ], + TaskRoleArn: { + 'Fn::GetAtt': [ + 'TestTaskDefinitionTaskRole38EA0D26', + 'Arn', + ], + }, + Volumes: [ + { + Name: 'opentelemetry-auto-instrumentation', + }, + ], + }); + }); + }); diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.ts b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.ts index a61e5132b4094..82f5d904b9c6e 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.ts +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.ts @@ -1,7 +1,7 @@ +import * as integ from '@aws-cdk/integ-tests-alpha'; import * as cdk from 'aws-cdk-lib'; import * as ecs from 'aws-cdk-lib/aws-ecs'; -import * as integ from '@aws-cdk/integ-tests-alpha'; import * as appsignals from '../lib'; const app = new cdk.App(); @@ -11,6 +11,7 @@ const stack = new cdk.Stack(app, 'ecs-enablement-integration'); const ec2TaskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDefinition', { networkMode: ecs.NetworkMode.HOST, }); + ec2TaskDefinition.addContainer('app', { image: ecs.ContainerImage.fromRegistry('nathanpeck/name'), cpu: 0, @@ -20,7 +21,6 @@ ec2TaskDefinition.addContainer('app', { new appsignals.ApplicationSignalsIntegration(stack, 'TestEc2TaskDefinitionIntegration', { taskDefinition: ec2TaskDefinition, instrumentation: { - language: appsignals.InstrumentationLanguage.PYTHON, sdkVersion: appsignals.PythonInstrumentationVersion.V0_8_0, }, serviceName: 'demo', diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ecs-enablement-integration.assets.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ecs-enablement-integration.assets.json index a95c7bd409712..99bd22b6626ac 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ecs-enablement-integration.assets.json +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ecs-enablement-integration.assets.json @@ -1,7 +1,7 @@ { "version": "39.0.0", "files": { - "5c65e2c03af1ab7b150357b60fef1da93e0a8f604070524542fc31d7765edaec": { + "5acf6c0acb64eaedc9d71ce5b2ace633828b5b5cb4f275a04d31ad815c63fc1f": { "source": { "path": "ecs-enablement-integration.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "5c65e2c03af1ab7b150357b60fef1da93e0a8f604070524542fc31d7765edaec.json", + "objectKey": "5acf6c0acb64eaedc9d71ce5b2ace633828b5b5cb4f275a04d31ad815c63fc1f.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ecs-enablement-integration.template.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ecs-enablement-integration.template.json index ceb9df82e8d17..f22ee4ac853d1 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ecs-enablement-integration.template.json +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ecs-enablement-integration.template.json @@ -1,6 +1,6 @@ { "Resources": { - "FargateTaskDefinitionTaskRoleE3C2BCAA": { + "TestRole6C9272DF": { "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { @@ -14,7 +14,22 @@ } ], "Version": "2012-10-17" - } + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/CloudWatchAgentServerPolicy" + ] + ] + } + ], + "RoleName": "TestRole" } }, "FargateTaskDefinition8E3B365E": { @@ -171,7 +186,7 @@ }, "TaskRoleArn": { "Fn::GetAtt": [ - "FargateTaskDefinitionTaskRoleE3C2BCAA", + "TestRole6C9272DF", "Arn" ] }, diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/manifest.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/manifest.json index 0ebbdc7e8bbd1..5014c0aeca2ff 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/manifest.json +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/manifest.json @@ -18,7 +18,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/5c65e2c03af1ab7b150357b60fef1da93e0a8f604070524542fc31d7765edaec.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/5acf6c0acb64eaedc9d71ce5b2ace633828b5b5cb4f275a04d31ad815c63fc1f.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -34,10 +34,10 @@ "ecs-enablement-integration.assets" ], "metadata": { - "/ecs-enablement-integration/FargateTaskDefinition/TaskRole/Resource": [ + "/ecs-enablement-integration/TestRole/Resource": [ { "type": "aws:cdk:logicalId", - "data": "FargateTaskDefinitionTaskRoleE3C2BCAA" + "data": "TestRole6C9272DF" } ], "/ecs-enablement-integration/FargateTaskDefinition/Resource": [ diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/tree.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/tree.json index 05d0a597e0461..2f396bc86afe2 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/tree.json +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/tree.json @@ -8,53 +8,68 @@ "id": "ecs-enablement-integration", "path": "ecs-enablement-integration", "children": { - "FargateTaskDefinition": { - "id": "FargateTaskDefinition", - "path": "ecs-enablement-integration/FargateTaskDefinition", + "TestRole": { + "id": "TestRole", + "path": "ecs-enablement-integration/TestRole", "children": { - "TaskRole": { - "id": "TaskRole", - "path": "ecs-enablement-integration/FargateTaskDefinition/TaskRole", - "children": { - "ImportTaskRole": { - "id": "ImportTaskRole", - "path": "ecs-enablement-integration/FargateTaskDefinition/TaskRole/ImportTaskRole", - "constructInfo": { - "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" - } - }, - "Resource": { - "id": "Resource", - "path": "ecs-enablement-integration/FargateTaskDefinition/TaskRole/Resource", - "attributes": { - "aws:cdk:cloudformation:type": "AWS::IAM::Role", - "aws:cdk:cloudformation:props": { - "assumeRolePolicyDocument": { - "Statement": [ - { - "Action": "sts:AssumeRole", - "Effect": "Allow", - "Principal": { - "Service": "ecs-tasks.amazonaws.com" - } - } - ], - "Version": "2012-10-17" + "ImportTestRole": { + "id": "ImportTestRole", + "path": "ecs-enablement-integration/TestRole/ImportTestRole", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "ecs-enablement-integration/TestRole/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "assumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "ecs-tasks.amazonaws.com" + } } - } + ], + "Version": "2012-10-17" }, - "constructInfo": { - "fqn": "aws-cdk-lib.aws_iam.CfnRole", - "version": "0.0.0" - } + "managedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/CloudWatchAgentServerPolicy" + ] + ] + } + ], + "roleName": "TestRole" } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_iam.Role", + "fqn": "aws-cdk-lib.aws_iam.CfnRole", "version": "0.0.0" } - }, + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Role", + "version": "0.0.0" + } + }, + "FargateTaskDefinition": { + "id": "FargateTaskDefinition", + "path": "ecs-enablement-integration/FargateTaskDefinition", + "children": { "Resource": { "id": "Resource", "path": "ecs-enablement-integration/FargateTaskDefinition/Resource", @@ -212,7 +227,7 @@ }, "taskRoleArn": { "Fn::GetAtt": [ - "FargateTaskDefinitionTaskRoleE3C2BCAA", + "TestRole6C9272DF", "Arn" ] }, diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.ts b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.ts index 40248a8d90a59..bb8b1dfa3fa06 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.ts +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.ts @@ -1,13 +1,14 @@ +import * as integ from '@aws-cdk/integ-tests-alpha'; import * as cdk from 'aws-cdk-lib'; import * as ecs from 'aws-cdk-lib/aws-ecs'; -import * as integ from '@aws-cdk/integ-tests-alpha'; -import { ApplicationSignalsIntegration, InstrumentationLanguage, DotnetInstrumentationVersion } from '../lib'; import { Role, ManagedPolicy, ServicePrincipal } from 'aws-cdk-lib/aws-iam'; -const app = new cdk.App(); +import { ApplicationSignalsIntegration, DotnetInstrumentationVersion } from '../lib'; +const app = new cdk.App(); const stack = new cdk.Stack(app, 'ecs-enablement-integration'); -const taskRole = new Role(app, 'TestRole', { + +const taskRole = new Role(stack, 'TestRole', { roleName: 'TestRole', assumedBy: new ServicePrincipal('ecs-tasks.amazonaws.com'), managedPolicies: [ @@ -30,7 +31,6 @@ fargateTaskDefinition.addContainer('app', { new ApplicationSignalsIntegration(stack, 'TestFargateSidecarIntegration', { taskDefinition: fargateTaskDefinition, instrumentation: { - language: InstrumentationLanguage.DOTNET, sdkVersion: DotnetInstrumentationVersion.V1_6_0_WINDOWS2019, }, serviceName: 'demo', From 521a7bd8c6726353d04b9367b3175eae07be4d99 Mon Sep 17 00:00:00 2001 From: Zhou Date: Tue, 21 Jan 2025 23:32:43 -0800 Subject: [PATCH 3/4] Update daemon test --- .../lib/enablement/ecs.ts | 5 +- .../__entrypoint__.js | 155 +++ .../index.js | 1 + .../ecs-enablement-integration.assets.json | 17 +- .../ecs-enablement-integration.template.json | 842 ++++++++++++- .../manifest.json | 229 +++- .../tree.json | 1070 ++++++++++++++++- .../test/integ.ecs-enablement-daemon.ts | 66 +- 8 files changed, 2367 insertions(+), 18 deletions(-) create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/asset.a1acfc2b5f4f6b183fd2bb9863f486bc5edef6a357b355a070d9a0e502df418c/__entrypoint__.js create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/asset.a1acfc2b5f4f6b183fd2bb9863f486bc5edef6a357b355a070d9a0e502df418c/index.js diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/ecs.ts b/packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/ecs.ts index ba4409450efca..a6e82cc9eb1db 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/ecs.ts +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/ecs.ts @@ -655,18 +655,19 @@ export class ApplicationSignalsIntegration extends Construct { if (runtimePlatformObj) { const runtimePlatform = runtimePlatformObj as ecs.RuntimePlatform; if (runtimePlatform.operatingSystemFamily) { + isWindows = runtimePlatform.operatingSystemFamily.isWindows(); + switch (runtimePlatform.operatingSystemFamily) { case ecs.OperatingSystemFamily.WINDOWS_SERVER_2019_CORE: case ecs.OperatingSystemFamily.WINDOWS_SERVER_2019_FULL: cloudWatchAgentImage = CLOUDWATCH_AGENT_IMAGE_WIN2019; - isWindows = true; break; case ecs.OperatingSystemFamily.WINDOWS_SERVER_2022_CORE: case ecs.OperatingSystemFamily.WINDOWS_SERVER_2022_FULL: cloudWatchAgentImage = CLOUDWATCH_AGENT_IMAGE_WIN2022; - isWindows = true; break; } + if (runtimePlatform.cpuArchitecture) { cpuArch = runtimePlatform.cpuArchitecture; } diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/asset.a1acfc2b5f4f6b183fd2bb9863f486bc5edef6a357b355a070d9a0e502df418c/__entrypoint__.js b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/asset.a1acfc2b5f4f6b183fd2bb9863f486bc5edef6a357b355a070d9a0e502df418c/__entrypoint__.js new file mode 100644 index 0000000000000..ff3a517fba12d --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/asset.a1acfc2b5f4f6b183fd2bb9863f486bc5edef6a357b355a070d9a0e502df418c/__entrypoint__.js @@ -0,0 +1,155 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.external = void 0; +exports.handler = handler; +exports.withRetries = withRetries; +const https = require("https"); +const url = require("url"); +// for unit tests +exports.external = { + sendHttpRequest: defaultSendHttpRequest, + log: defaultLog, + includeStackTraces: true, + userHandlerIndex: './index', +}; +const CREATE_FAILED_PHYSICAL_ID_MARKER = 'AWSCDK::CustomResourceProviderFramework::CREATE_FAILED'; +const MISSING_PHYSICAL_ID_MARKER = 'AWSCDK::CustomResourceProviderFramework::MISSING_PHYSICAL_ID'; +async function handler(event, context) { + const sanitizedEvent = { ...event, ResponseURL: '...' }; + exports.external.log(JSON.stringify(sanitizedEvent, undefined, 2)); + // ignore DELETE event when the physical resource ID is the marker that + // indicates that this DELETE is a subsequent DELETE to a failed CREATE + // operation. + if (event.RequestType === 'Delete' && event.PhysicalResourceId === CREATE_FAILED_PHYSICAL_ID_MARKER) { + exports.external.log('ignoring DELETE event caused by a failed CREATE event'); + await submitResponse('SUCCESS', event); + return; + } + try { + // invoke the user handler. this is intentionally inside the try-catch to + // ensure that if there is an error it's reported as a failure to + // cloudformation (otherwise cfn waits). + // eslint-disable-next-line @typescript-eslint/no-require-imports + const userHandler = require(exports.external.userHandlerIndex).handler; + const result = await userHandler(sanitizedEvent, context); + // validate user response and create the combined event + const responseEvent = renderResponse(event, result); + // submit to cfn as success + await submitResponse('SUCCESS', responseEvent); + } + catch (e) { + const resp = { + ...event, + Reason: exports.external.includeStackTraces ? e.stack : e.message, + }; + if (!resp.PhysicalResourceId) { + // special case: if CREATE fails, which usually implies, we usually don't + // have a physical resource id. in this case, the subsequent DELETE + // operation does not have any meaning, and will likely fail as well. to + // address this, we use a marker so the provider framework can simply + // ignore the subsequent DELETE. + if (event.RequestType === 'Create') { + exports.external.log('CREATE failed, responding with a marker physical resource id so that the subsequent DELETE will be ignored'); + resp.PhysicalResourceId = CREATE_FAILED_PHYSICAL_ID_MARKER; + } + else { + // otherwise, if PhysicalResourceId is not specified, something is + // terribly wrong because all other events should have an ID. + exports.external.log(`ERROR: Malformed event. "PhysicalResourceId" is required: ${JSON.stringify(event)}`); + } + } + // this is an actual error, fail the activity altogether and exist. + await submitResponse('FAILED', resp); + } +} +function renderResponse(cfnRequest, handlerResponse = {}) { + // if physical ID is not returned, we have some defaults for you based + // on the request type. + const physicalResourceId = handlerResponse.PhysicalResourceId ?? cfnRequest.PhysicalResourceId ?? cfnRequest.RequestId; + // if we are in DELETE and physical ID was changed, it's an error. + if (cfnRequest.RequestType === 'Delete' && physicalResourceId !== cfnRequest.PhysicalResourceId) { + throw new Error(`DELETE: cannot change the physical resource ID from "${cfnRequest.PhysicalResourceId}" to "${handlerResponse.PhysicalResourceId}" during deletion`); + } + // merge request event and result event (result prevails). + return { + ...cfnRequest, + ...handlerResponse, + PhysicalResourceId: physicalResourceId, + }; +} +async function submitResponse(status, event) { + const json = { + Status: status, + Reason: event.Reason ?? status, + StackId: event.StackId, + RequestId: event.RequestId, + PhysicalResourceId: event.PhysicalResourceId || MISSING_PHYSICAL_ID_MARKER, + LogicalResourceId: event.LogicalResourceId, + NoEcho: event.NoEcho, + Data: event.Data, + }; + const parsedUrl = url.parse(event.ResponseURL); + const loggingSafeUrl = `${parsedUrl.protocol}//${parsedUrl.hostname}/${parsedUrl.pathname}?***`; + exports.external.log('submit response to cloudformation', loggingSafeUrl, json); + const responseBody = JSON.stringify(json); + const req = { + hostname: parsedUrl.hostname, + path: parsedUrl.path, + method: 'PUT', + headers: { + 'content-type': '', + 'content-length': Buffer.byteLength(responseBody, 'utf8'), + }, + }; + const retryOptions = { + attempts: 5, + sleep: 1000, + }; + await withRetries(retryOptions, exports.external.sendHttpRequest)(req, responseBody); +} +async function defaultSendHttpRequest(options, requestBody) { + return new Promise((resolve, reject) => { + try { + const request = https.request(options, (response) => { + response.resume(); // Consume the response but don't care about it + if (!response.statusCode || response.statusCode >= 400) { + reject(new Error(`Unsuccessful HTTP response: ${response.statusCode}`)); + } + else { + resolve(); + } + }); + request.on('error', reject); + request.write(requestBody); + request.end(); + } + catch (e) { + reject(e); + } + }); +} +function defaultLog(fmt, ...params) { + // eslint-disable-next-line no-console + console.log(fmt, ...params); +} +function withRetries(options, fn) { + return async (...xs) => { + let attempts = options.attempts; + let ms = options.sleep; + while (true) { + try { + return await fn(...xs); + } + catch (e) { + if (attempts-- <= 0) { + throw e; + } + await sleep(Math.floor(Math.random() * ms)); + ms *= 2; + } + } + }; +} +async function sleep(ms) { + return new Promise((ok) => setTimeout(ok, ms)); +} diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/asset.a1acfc2b5f4f6b183fd2bb9863f486bc5edef6a357b355a070d9a0e502df418c/index.js b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/asset.a1acfc2b5f4f6b183fd2bb9863f486bc5edef6a357b355a070d9a0e502df418c/index.js new file mode 100644 index 0000000000000..013bcaffd8fe5 --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/asset.a1acfc2b5f4f6b183fd2bb9863f486bc5edef6a357b355a070d9a0e502df418c/index.js @@ -0,0 +1 @@ +"use strict";var I=Object.create;var t=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty;var G=(r,e)=>{for(var o in e)t(r,o,{get:e[o],enumerable:!0})},n=(r,e,o,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of P(e))!l.call(r,s)&&s!==o&&t(r,s,{get:()=>e[s],enumerable:!(i=y(e,s))||i.enumerable});return r};var R=(r,e,o)=>(o=r!=null?I(g(r)):{},n(e||!r||!r.__esModule?t(o,"default",{value:r,enumerable:!0}):o,r)),S=r=>n(t({},"__esModule",{value:!0}),r);var k={};G(k,{handler:()=>f});module.exports=S(k);var a=R(require("@aws-sdk/client-ec2")),u=new a.EC2({});function c(r,e){return{GroupId:r,IpPermissions:[{UserIdGroupPairs:[{GroupId:r,UserId:e}],IpProtocol:"-1"}]}}function d(r){return{GroupId:r,IpPermissions:[{IpRanges:[{CidrIp:"0.0.0.0/0"}],IpProtocol:"-1"}]}}async function f(r){let e=r.ResourceProperties.DefaultSecurityGroupId,o=r.ResourceProperties.Account;switch(r.RequestType){case"Create":return p(e,o);case"Update":return h(r);case"Delete":return m(e,o)}}async function h(r){let e=r.OldResourceProperties.DefaultSecurityGroupId,o=r.ResourceProperties.DefaultSecurityGroupId;e!==o&&(await m(e,r.ResourceProperties.Account),await p(o,r.ResourceProperties.Account))}async function p(r,e){try{await u.revokeSecurityGroupEgress(d(r))}catch(o){if(o.name!=="InvalidPermission.NotFound")throw o}try{await u.revokeSecurityGroupIngress(c(r,e))}catch(o){if(o.name!=="InvalidPermission.NotFound")throw o}}async function m(r,e){await u.authorizeSecurityGroupIngress(c(r,e)),await u.authorizeSecurityGroupEgress(d(r))}0&&(module.exports={handler}); diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ecs-enablement-integration.assets.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ecs-enablement-integration.assets.json index 0aefe5b5f33cf..a35d6857d3481 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ecs-enablement-integration.assets.json +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ecs-enablement-integration.assets.json @@ -1,7 +1,20 @@ { "version": "39.0.0", "files": { - "76ae201d6ac397b6a3ba171c80e8d2e82bb0be5818af316bc2d5816068334084": { + "a1acfc2b5f4f6b183fd2bb9863f486bc5edef6a357b355a070d9a0e502df418c": { + "source": { + "path": "asset.a1acfc2b5f4f6b183fd2bb9863f486bc5edef6a357b355a070d9a0e502df418c", + "packaging": "zip" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "a1acfc2b5f4f6b183fd2bb9863f486bc5edef6a357b355a070d9a0e502df418c.zip", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + }, + "dcac3df399e5ea2ad6e83532fc55e1a6e67edc5542e26ee9116810cfe3207a9d": { "source": { "path": "ecs-enablement-integration.template.json", "packaging": "file" @@ -9,7 +22,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "76ae201d6ac397b6a3ba171c80e8d2e82bb0be5818af316bc2d5816068334084.json", + "objectKey": "dcac3df399e5ea2ad6e83532fc55e1a6e67edc5542e26ee9116810cfe3207a9d.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ecs-enablement-integration.template.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ecs-enablement-integration.template.json index 617d823c916fa..d28d40b0b7b36 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ecs-enablement-integration.template.json +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ecs-enablement-integration.template.json @@ -1,5 +1,717 @@ { "Resources": { + "TestVpcE77CE678": { + "Type": "AWS::EC2::VPC", + "Properties": { + "CidrBlock": "10.0.0.0/16", + "EnableDnsHostnames": true, + "EnableDnsSupport": true, + "InstanceTenancy": "default", + "Tags": [ + { + "Key": "Name", + "Value": "ecs-enablement-integration/TestVpc" + } + ] + } + }, + "TestVpcPublicSubnet1SubnetA7DB1EDF": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "AvailabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": "" + } + ] + }, + "CidrBlock": "10.0.0.0/18", + "MapPublicIpOnLaunch": true, + "Tags": [ + { + "Key": "aws-cdk:subnet-name", + "Value": "Public" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Public" + }, + { + "Key": "Name", + "Value": "ecs-enablement-integration/TestVpc/PublicSubnet1" + } + ], + "VpcId": { + "Ref": "TestVpcE77CE678" + } + } + }, + "TestVpcPublicSubnet1RouteTable4CBFF871": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "ecs-enablement-integration/TestVpc/PublicSubnet1" + } + ], + "VpcId": { + "Ref": "TestVpcE77CE678" + } + } + }, + "TestVpcPublicSubnet1RouteTableAssociation7D1DECD9": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "TestVpcPublicSubnet1RouteTable4CBFF871" + }, + "SubnetId": { + "Ref": "TestVpcPublicSubnet1SubnetA7DB1EDF" + } + } + }, + "TestVpcPublicSubnet1DefaultRoute6C0F0315": { + "Type": "AWS::EC2::Route", + "Properties": { + "DestinationCidrBlock": "0.0.0.0/0", + "GatewayId": { + "Ref": "TestVpcIGW9DD53F70" + }, + "RouteTableId": { + "Ref": "TestVpcPublicSubnet1RouteTable4CBFF871" + } + }, + "DependsOn": [ + "TestVpcVPCGWF1827B84" + ] + }, + "TestVpcPublicSubnet1EIP4884338C": { + "Type": "AWS::EC2::EIP", + "Properties": { + "Domain": "vpc", + "Tags": [ + { + "Key": "Name", + "Value": "ecs-enablement-integration/TestVpc/PublicSubnet1" + } + ] + } + }, + "TestVpcPublicSubnet1NATGatewayA323E3EC": { + "Type": "AWS::EC2::NatGateway", + "Properties": { + "AllocationId": { + "Fn::GetAtt": [ + "TestVpcPublicSubnet1EIP4884338C", + "AllocationId" + ] + }, + "SubnetId": { + "Ref": "TestVpcPublicSubnet1SubnetA7DB1EDF" + }, + "Tags": [ + { + "Key": "Name", + "Value": "ecs-enablement-integration/TestVpc/PublicSubnet1" + } + ] + }, + "DependsOn": [ + "TestVpcPublicSubnet1DefaultRoute6C0F0315", + "TestVpcPublicSubnet1RouteTableAssociation7D1DECD9" + ] + }, + "TestVpcPublicSubnet2Subnet80A14523": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "AvailabilityZone": { + "Fn::Select": [ + 1, + { + "Fn::GetAZs": "" + } + ] + }, + "CidrBlock": "10.0.64.0/18", + "MapPublicIpOnLaunch": true, + "Tags": [ + { + "Key": "aws-cdk:subnet-name", + "Value": "Public" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Public" + }, + { + "Key": "Name", + "Value": "ecs-enablement-integration/TestVpc/PublicSubnet2" + } + ], + "VpcId": { + "Ref": "TestVpcE77CE678" + } + } + }, + "TestVpcPublicSubnet2RouteTable75B88314": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "ecs-enablement-integration/TestVpc/PublicSubnet2" + } + ], + "VpcId": { + "Ref": "TestVpcE77CE678" + } + } + }, + "TestVpcPublicSubnet2RouteTableAssociationB386A819": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "TestVpcPublicSubnet2RouteTable75B88314" + }, + "SubnetId": { + "Ref": "TestVpcPublicSubnet2Subnet80A14523" + } + } + }, + "TestVpcPublicSubnet2DefaultRoute054DAE0A": { + "Type": "AWS::EC2::Route", + "Properties": { + "DestinationCidrBlock": "0.0.0.0/0", + "GatewayId": { + "Ref": "TestVpcIGW9DD53F70" + }, + "RouteTableId": { + "Ref": "TestVpcPublicSubnet2RouteTable75B88314" + } + }, + "DependsOn": [ + "TestVpcVPCGWF1827B84" + ] + }, + "TestVpcPublicSubnet2EIP83F7944C": { + "Type": "AWS::EC2::EIP", + "Properties": { + "Domain": "vpc", + "Tags": [ + { + "Key": "Name", + "Value": "ecs-enablement-integration/TestVpc/PublicSubnet2" + } + ] + } + }, + "TestVpcPublicSubnet2NATGatewayA9858C31": { + "Type": "AWS::EC2::NatGateway", + "Properties": { + "AllocationId": { + "Fn::GetAtt": [ + "TestVpcPublicSubnet2EIP83F7944C", + "AllocationId" + ] + }, + "SubnetId": { + "Ref": "TestVpcPublicSubnet2Subnet80A14523" + }, + "Tags": [ + { + "Key": "Name", + "Value": "ecs-enablement-integration/TestVpc/PublicSubnet2" + } + ] + }, + "DependsOn": [ + "TestVpcPublicSubnet2DefaultRoute054DAE0A", + "TestVpcPublicSubnet2RouteTableAssociationB386A819" + ] + }, + "TestVpcPrivateSubnet1SubnetCC65D771": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "AvailabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": "" + } + ] + }, + "CidrBlock": "10.0.128.0/18", + "MapPublicIpOnLaunch": false, + "Tags": [ + { + "Key": "aws-cdk:subnet-name", + "Value": "Private" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Private" + }, + { + "Key": "Name", + "Value": "ecs-enablement-integration/TestVpc/PrivateSubnet1" + } + ], + "VpcId": { + "Ref": "TestVpcE77CE678" + } + } + }, + "TestVpcPrivateSubnet1RouteTable469B0105": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "ecs-enablement-integration/TestVpc/PrivateSubnet1" + } + ], + "VpcId": { + "Ref": "TestVpcE77CE678" + } + } + }, + "TestVpcPrivateSubnet1RouteTableAssociationFFD4DFF7": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "TestVpcPrivateSubnet1RouteTable469B0105" + }, + "SubnetId": { + "Ref": "TestVpcPrivateSubnet1SubnetCC65D771" + } + } + }, + "TestVpcPrivateSubnet1DefaultRoute32E7B814": { + "Type": "AWS::EC2::Route", + "Properties": { + "DestinationCidrBlock": "0.0.0.0/0", + "NatGatewayId": { + "Ref": "TestVpcPublicSubnet1NATGatewayA323E3EC" + }, + "RouteTableId": { + "Ref": "TestVpcPrivateSubnet1RouteTable469B0105" + } + } + }, + "TestVpcPrivateSubnet2SubnetDE0C64A2": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "AvailabilityZone": { + "Fn::Select": [ + 1, + { + "Fn::GetAZs": "" + } + ] + }, + "CidrBlock": "10.0.192.0/18", + "MapPublicIpOnLaunch": false, + "Tags": [ + { + "Key": "aws-cdk:subnet-name", + "Value": "Private" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Private" + }, + { + "Key": "Name", + "Value": "ecs-enablement-integration/TestVpc/PrivateSubnet2" + } + ], + "VpcId": { + "Ref": "TestVpcE77CE678" + } + } + }, + "TestVpcPrivateSubnet2RouteTableCEF29F7C": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "ecs-enablement-integration/TestVpc/PrivateSubnet2" + } + ], + "VpcId": { + "Ref": "TestVpcE77CE678" + } + } + }, + "TestVpcPrivateSubnet2RouteTableAssociation18250AB4": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "TestVpcPrivateSubnet2RouteTableCEF29F7C" + }, + "SubnetId": { + "Ref": "TestVpcPrivateSubnet2SubnetDE0C64A2" + } + } + }, + "TestVpcPrivateSubnet2DefaultRouteA7EB6930": { + "Type": "AWS::EC2::Route", + "Properties": { + "DestinationCidrBlock": "0.0.0.0/0", + "NatGatewayId": { + "Ref": "TestVpcPublicSubnet2NATGatewayA9858C31" + }, + "RouteTableId": { + "Ref": "TestVpcPrivateSubnet2RouteTableCEF29F7C" + } + } + }, + "TestVpcIGW9DD53F70": { + "Type": "AWS::EC2::InternetGateway", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "ecs-enablement-integration/TestVpc" + } + ] + } + }, + "TestVpcVPCGWF1827B84": { + "Type": "AWS::EC2::VPCGatewayAttachment", + "Properties": { + "InternetGatewayId": { + "Ref": "TestVpcIGW9DD53F70" + }, + "VpcId": { + "Ref": "TestVpcE77CE678" + } + } + }, + "TestVpcRestrictDefaultSecurityGroupCustomResourceB02B826A": { + "Type": "Custom::VpcRestrictDefaultSG", + "Properties": { + "ServiceToken": { + "Fn::GetAtt": [ + "CustomVpcRestrictDefaultSGCustomResourceProviderHandlerDC833E5E", + "Arn" + ] + }, + "DefaultSecurityGroupId": { + "Fn::GetAtt": [ + "TestVpcE77CE678", + "DefaultSecurityGroup" + ] + }, + "Account": { + "Ref": "AWS::AccountId" + } + }, + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + }, + "CustomVpcRestrictDefaultSGCustomResourceProviderRole26592FE0": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ] + }, + "ManagedPolicyArns": [ + { + "Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + } + ], + "Policies": [ + { + "PolicyName": "Inline", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "ec2:AuthorizeSecurityGroupIngress", + "ec2:AuthorizeSecurityGroupEgress", + "ec2:RevokeSecurityGroupIngress", + "ec2:RevokeSecurityGroupEgress" + ], + "Resource": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":ec2:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":security-group/", + { + "Fn::GetAtt": [ + "TestVpcE77CE678", + "DefaultSecurityGroup" + ] + } + ] + ] + } + ] + } + ] + } + } + ] + } + }, + "CustomVpcRestrictDefaultSGCustomResourceProviderHandlerDC833E5E": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": { + "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" + }, + "S3Key": "a1acfc2b5f4f6b183fd2bb9863f486bc5edef6a357b355a070d9a0e502df418c.zip" + }, + "Timeout": 900, + "MemorySize": 128, + "Handler": "__entrypoint__.handler", + "Role": { + "Fn::GetAtt": [ + "CustomVpcRestrictDefaultSGCustomResourceProviderRole26592FE0", + "Arn" + ] + }, + "Runtime": { + "Fn::FindInMap": [ + "LatestNodeRuntimeMap", + { + "Ref": "AWS::Region" + }, + "value" + ] + }, + "Description": "Lambda function for removing all inbound/outbound rules from the VPC default security group" + }, + "DependsOn": [ + "CustomVpcRestrictDefaultSGCustomResourceProviderRole26592FE0" + ] + }, + "TestClusterE0095054": { + "Type": "AWS::ECS::Cluster" + }, + "Namespace9B63B8C8": { + "Type": "AWS::ServiceDiscovery::PrivateDnsNamespace", + "Properties": { + "Name": "local", + "Vpc": { + "Ref": "TestVpcE77CE678" + } + } + }, + "CwAgentDaemonTaskDefTaskRoleB630618E": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "ecs-tasks.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "CwAgentDaemonTaskDefD42721B8": { + "Type": "AWS::ECS::TaskDefinition", + "Properties": { + "ContainerDefinitions": [ + { + "Cpu": 128, + "Environment": [ + { + "Name": "CW_CONFIG_CONTENT", + "Value": "{\"agent\": {\"debug\": true}, \"traces\": {\"traces_collected\": {\"application_signals\": {\"enabled\": true}}}, \"logs\": {\"metrics_collected\": {\"application_signals\": {\"enabled\": true}}}}" + } + ], + "Essential": true, + "Image": "public.ecr.aws/cloudwatch-agent/cloudwatch-agent:latest", + "LogConfiguration": { + "LogDriver": "awslogs", + "Options": { + "awslogs-group": { + "Ref": "CwAgentLogGroupBF702CD8" + }, + "awslogs-stream-prefix": "ecs", + "awslogs-region": { + "Ref": "AWS::Region" + } + } + }, + "Memory": 64, + "Name": "ecs-cwagent", + "PortMappings": [ + { + "ContainerPort": 4316, + "HostPort": 4316, + "Name": "cwagent-4316", + "Protocol": "tcp" + }, + { + "ContainerPort": 2000, + "HostPort": 2000, + "Name": "cwagent-2000", + "Protocol": "tcp" + } + ] + } + ], + "ExecutionRoleArn": { + "Fn::GetAtt": [ + "CwAgentDaemonTaskDefExecutionRoleDB11FC2A", + "Arn" + ] + }, + "Family": "ecsenablementintegrationCwAgentDaemonTaskDefB3E3B54C", + "NetworkMode": "bridge", + "RequiresCompatibilities": [ + "EC2" + ], + "TaskRoleArn": { + "Fn::GetAtt": [ + "CwAgentDaemonTaskDefTaskRoleB630618E", + "Arn" + ] + } + } + }, + "CwAgentDaemonTaskDefExecutionRoleDB11FC2A": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "ecs-tasks.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "CwAgentDaemonTaskDefExecutionRoleDefaultPolicy765BB856": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "logs:CreateLogStream", + "logs:PutLogEvents" + ], + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "CwAgentLogGroupBF702CD8", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "CwAgentDaemonTaskDefExecutionRoleDefaultPolicy765BB856", + "Roles": [ + { + "Ref": "CwAgentDaemonTaskDefExecutionRoleDB11FC2A" + } + ] + } + }, + "CwAgentLogGroupBF702CD8": { + "Type": "AWS::Logs::LogGroup", + "Properties": { + "LogGroupName": "/ecs/ecs-cwagent-cdk-daemon", + "RetentionInDays": 731 + }, + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + }, + "CwAgentDaemonServiceA063D544": { + "Type": "AWS::ECS::Service", + "Properties": { + "Cluster": { + "Ref": "TestClusterE0095054" + }, + "DeploymentConfiguration": { + "MaximumPercent": 100, + "MinimumHealthyPercent": 0 + }, + "EnableECSManagedTags": false, + "LaunchType": "EC2", + "SchedulingStrategy": "DAEMON", + "ServiceConnectConfiguration": { + "Enabled": true, + "Namespace": { + "Fn::GetAtt": [ + "Namespace9B63B8C8", + "Arn" + ] + }, + "Services": [ + { + "ClientAliases": [ + { + "DnsName": "cwagent-4316-http", + "Port": 4316 + } + ], + "PortName": "cwagent-4316" + }, + { + "ClientAliases": [ + { + "DnsName": "cwagent-2000-http", + "Port": 2000 + } + ], + "PortName": "cwagent-2000" + } + ] + }, + "TaskDefinition": { + "Ref": "CwAgentDaemonTaskDefD42721B8" + } + }, + "DependsOn": [ + "CwAgentDaemonTaskDefTaskRoleB630618E" + ] + }, "Ec2TaskDefinitionTaskRole0B78BC85": { "Type": "AWS::IAM::Role", "Properties": { @@ -48,11 +760,11 @@ }, { "Name": "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", - "Value": "http://cwagent.local:4316/v1/metrics" + "Value": "http://cwagent-4316-http:4316/v1/metrics" }, { "Name": "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", - "Value": "http://cwagent.local:4316/v1/traces" + "Value": "hhttp://cwagent-4316-http:4316/v1/traces" }, { "Name": "OTEL_TRACES_SAMPLER", @@ -60,7 +772,7 @@ }, { "Name": "OTEL_TRACES_SAMPLER_ARG", - "Value": "endpoint=http://ccwagent.local:2000" + "Value": "endpoint=http://cwagent-2000-http:2000" }, { "Name": "OTEL_PROPAGATORS", @@ -135,6 +847,130 @@ } } }, + "Mappings": { + "LatestNodeRuntimeMap": { + "af-south-1": { + "value": "nodejs20.x" + }, + "ap-east-1": { + "value": "nodejs20.x" + }, + "ap-northeast-1": { + "value": "nodejs20.x" + }, + "ap-northeast-2": { + "value": "nodejs20.x" + }, + "ap-northeast-3": { + "value": "nodejs20.x" + }, + "ap-south-1": { + "value": "nodejs20.x" + }, + "ap-south-2": { + "value": "nodejs20.x" + }, + "ap-southeast-1": { + "value": "nodejs20.x" + }, + "ap-southeast-2": { + "value": "nodejs20.x" + }, + "ap-southeast-3": { + "value": "nodejs20.x" + }, + "ap-southeast-4": { + "value": "nodejs20.x" + }, + "ap-southeast-5": { + "value": "nodejs20.x" + }, + "ap-southeast-7": { + "value": "nodejs20.x" + }, + "ca-central-1": { + "value": "nodejs20.x" + }, + "ca-west-1": { + "value": "nodejs20.x" + }, + "cn-north-1": { + "value": "nodejs18.x" + }, + "cn-northwest-1": { + "value": "nodejs18.x" + }, + "eu-central-1": { + "value": "nodejs20.x" + }, + "eu-central-2": { + "value": "nodejs20.x" + }, + "eu-isoe-west-1": { + "value": "nodejs18.x" + }, + "eu-north-1": { + "value": "nodejs20.x" + }, + "eu-south-1": { + "value": "nodejs20.x" + }, + "eu-south-2": { + "value": "nodejs20.x" + }, + "eu-west-1": { + "value": "nodejs20.x" + }, + "eu-west-2": { + "value": "nodejs20.x" + }, + "eu-west-3": { + "value": "nodejs20.x" + }, + "il-central-1": { + "value": "nodejs20.x" + }, + "me-central-1": { + "value": "nodejs20.x" + }, + "me-south-1": { + "value": "nodejs20.x" + }, + "mx-central-1": { + "value": "nodejs20.x" + }, + "sa-east-1": { + "value": "nodejs20.x" + }, + "us-east-1": { + "value": "nodejs20.x" + }, + "us-east-2": { + "value": "nodejs20.x" + }, + "us-gov-east-1": { + "value": "nodejs18.x" + }, + "us-gov-west-1": { + "value": "nodejs18.x" + }, + "us-iso-east-1": { + "value": "nodejs18.x" + }, + "us-iso-west-1": { + "value": "nodejs18.x" + }, + "us-isob-east-1": { + "value": "nodejs18.x" + }, + "us-west-1": { + "value": "nodejs20.x" + }, + "us-west-2": { + "value": "nodejs20.x" + } + } + }, "Parameters": { "BootstrapVersion": { "Type": "AWS::SSM::Parameter::Value", diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/manifest.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/manifest.json index 463906efcbd07..856bf1c27968e 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/manifest.json +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/manifest.json @@ -18,7 +18,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/76ae201d6ac397b6a3ba171c80e8d2e82bb0be5818af316bc2d5816068334084.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/dcac3df399e5ea2ad6e83532fc55e1a6e67edc5542e26ee9116810cfe3207a9d.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -34,6 +34,228 @@ "ecs-enablement-integration.assets" ], "metadata": { + "/ecs-enablement-integration/TestVpc/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "TestVpcE77CE678" + } + ], + "/ecs-enablement-integration/TestVpc/PublicSubnet1/Subnet": [ + { + "type": "aws:cdk:logicalId", + "data": "TestVpcPublicSubnet1SubnetA7DB1EDF" + } + ], + "/ecs-enablement-integration/TestVpc/PublicSubnet1/RouteTable": [ + { + "type": "aws:cdk:logicalId", + "data": "TestVpcPublicSubnet1RouteTable4CBFF871" + } + ], + "/ecs-enablement-integration/TestVpc/PublicSubnet1/RouteTableAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "TestVpcPublicSubnet1RouteTableAssociation7D1DECD9" + } + ], + "/ecs-enablement-integration/TestVpc/PublicSubnet1/DefaultRoute": [ + { + "type": "aws:cdk:logicalId", + "data": "TestVpcPublicSubnet1DefaultRoute6C0F0315" + } + ], + "/ecs-enablement-integration/TestVpc/PublicSubnet1/EIP": [ + { + "type": "aws:cdk:logicalId", + "data": "TestVpcPublicSubnet1EIP4884338C" + } + ], + "/ecs-enablement-integration/TestVpc/PublicSubnet1/NATGateway": [ + { + "type": "aws:cdk:logicalId", + "data": "TestVpcPublicSubnet1NATGatewayA323E3EC" + } + ], + "/ecs-enablement-integration/TestVpc/PublicSubnet2/Subnet": [ + { + "type": "aws:cdk:logicalId", + "data": "TestVpcPublicSubnet2Subnet80A14523" + } + ], + "/ecs-enablement-integration/TestVpc/PublicSubnet2/RouteTable": [ + { + "type": "aws:cdk:logicalId", + "data": "TestVpcPublicSubnet2RouteTable75B88314" + } + ], + "/ecs-enablement-integration/TestVpc/PublicSubnet2/RouteTableAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "TestVpcPublicSubnet2RouteTableAssociationB386A819" + } + ], + "/ecs-enablement-integration/TestVpc/PublicSubnet2/DefaultRoute": [ + { + "type": "aws:cdk:logicalId", + "data": "TestVpcPublicSubnet2DefaultRoute054DAE0A" + } + ], + "/ecs-enablement-integration/TestVpc/PublicSubnet2/EIP": [ + { + "type": "aws:cdk:logicalId", + "data": "TestVpcPublicSubnet2EIP83F7944C" + } + ], + "/ecs-enablement-integration/TestVpc/PublicSubnet2/NATGateway": [ + { + "type": "aws:cdk:logicalId", + "data": "TestVpcPublicSubnet2NATGatewayA9858C31" + } + ], + "/ecs-enablement-integration/TestVpc/PrivateSubnet1/Subnet": [ + { + "type": "aws:cdk:logicalId", + "data": "TestVpcPrivateSubnet1SubnetCC65D771" + } + ], + "/ecs-enablement-integration/TestVpc/PrivateSubnet1/RouteTable": [ + { + "type": "aws:cdk:logicalId", + "data": "TestVpcPrivateSubnet1RouteTable469B0105" + } + ], + "/ecs-enablement-integration/TestVpc/PrivateSubnet1/RouteTableAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "TestVpcPrivateSubnet1RouteTableAssociationFFD4DFF7" + } + ], + "/ecs-enablement-integration/TestVpc/PrivateSubnet1/DefaultRoute": [ + { + "type": "aws:cdk:logicalId", + "data": "TestVpcPrivateSubnet1DefaultRoute32E7B814" + } + ], + "/ecs-enablement-integration/TestVpc/PrivateSubnet2/Subnet": [ + { + "type": "aws:cdk:logicalId", + "data": "TestVpcPrivateSubnet2SubnetDE0C64A2" + } + ], + "/ecs-enablement-integration/TestVpc/PrivateSubnet2/RouteTable": [ + { + "type": "aws:cdk:logicalId", + "data": "TestVpcPrivateSubnet2RouteTableCEF29F7C" + } + ], + "/ecs-enablement-integration/TestVpc/PrivateSubnet2/RouteTableAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "TestVpcPrivateSubnet2RouteTableAssociation18250AB4" + } + ], + "/ecs-enablement-integration/TestVpc/PrivateSubnet2/DefaultRoute": [ + { + "type": "aws:cdk:logicalId", + "data": "TestVpcPrivateSubnet2DefaultRouteA7EB6930" + } + ], + "/ecs-enablement-integration/TestVpc/IGW": [ + { + "type": "aws:cdk:logicalId", + "data": "TestVpcIGW9DD53F70" + } + ], + "/ecs-enablement-integration/TestVpc/VPCGW": [ + { + "type": "aws:cdk:logicalId", + "data": "TestVpcVPCGWF1827B84" + } + ], + "/ecs-enablement-integration/TestVpc/RestrictDefaultSecurityGroupCustomResource/Default": [ + { + "type": "aws:cdk:logicalId", + "data": "TestVpcRestrictDefaultSecurityGroupCustomResourceB02B826A" + } + ], + "/ecs-enablement-integration/LatestNodeRuntimeMap": [ + { + "type": "aws:cdk:logicalId", + "data": "LatestNodeRuntimeMap" + } + ], + "/ecs-enablement-integration/Custom::VpcRestrictDefaultSGCustomResourceProvider": [ + { + "type": "aws:cdk:is-custom-resource-handler-customResourceProvider", + "data": true + } + ], + "/ecs-enablement-integration/Custom::VpcRestrictDefaultSGCustomResourceProvider/Role": [ + { + "type": "aws:cdk:logicalId", + "data": "CustomVpcRestrictDefaultSGCustomResourceProviderRole26592FE0" + } + ], + "/ecs-enablement-integration/Custom::VpcRestrictDefaultSGCustomResourceProvider/Handler": [ + { + "type": "aws:cdk:logicalId", + "data": "CustomVpcRestrictDefaultSGCustomResourceProviderHandlerDC833E5E" + } + ], + "/ecs-enablement-integration/TestCluster/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "TestClusterE0095054" + } + ], + "/ecs-enablement-integration/Namespace/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "Namespace9B63B8C8" + } + ], + "/ecs-enablement-integration/CwAgentDaemonTaskDef/TaskRole/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "CwAgentDaemonTaskDefTaskRoleB630618E" + } + ], + "/ecs-enablement-integration/CwAgentDaemonTaskDef/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "CwAgentDaemonTaskDefD42721B8" + } + ], + "/ecs-enablement-integration/CwAgentDaemonTaskDef/ExecutionRole/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "CwAgentDaemonTaskDefExecutionRoleDB11FC2A" + } + ], + "/ecs-enablement-integration/CwAgentDaemonTaskDef/ExecutionRole/DefaultPolicy/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "CwAgentDaemonTaskDefExecutionRoleDefaultPolicy765BB856" + } + ], + "/ecs-enablement-integration/CwAgentLogGroup/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "CwAgentLogGroupBF702CD8" + } + ], + "/ecs-enablement-integration/CwAgentDaemonService": [ + { + "type": "aws:cdk:warning", + "data": "minHealthyPercent has not been configured so the default value of 0% for a daemon service is used. See https://github.com/aws/aws-cdk/issues/31705 [ack: @aws-cdk/aws-ecs:minHealthyPercentDaemon]" + } + ], + "/ecs-enablement-integration/CwAgentDaemonService/Service": [ + { + "type": "aws:cdk:logicalId", + "data": "CwAgentDaemonServiceA063D544" + } + ], "/ecs-enablement-integration/Ec2TaskDefinition/TaskRole/Resource": [ { "type": "aws:cdk:logicalId", @@ -43,10 +265,7 @@ "/ecs-enablement-integration/Ec2TaskDefinition/Resource": [ { "type": "aws:cdk:logicalId", - "data": "Ec2TaskDefinitionB25030BE", - "trace": [ - "!!DESTRUCTIVE_CHANGES: WILL_REPLACE" - ] + "data": "Ec2TaskDefinitionB25030BE" } ], "/ecs-enablement-integration/BootstrapVersion": [ diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/tree.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/tree.json index a624d6107394e..27650f5003a02 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/tree.json +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/tree.json @@ -8,6 +8,1070 @@ "id": "ecs-enablement-integration", "path": "ecs-enablement-integration", "children": { + "TestVpc": { + "id": "TestVpc", + "path": "ecs-enablement-integration/TestVpc", + "children": { + "Resource": { + "id": "Resource", + "path": "ecs-enablement-integration/TestVpc/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::VPC", + "aws:cdk:cloudformation:props": { + "cidrBlock": "10.0.0.0/16", + "enableDnsHostnames": true, + "enableDnsSupport": true, + "instanceTenancy": "default", + "tags": [ + { + "key": "Name", + "value": "ecs-enablement-integration/TestVpc" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnVPC", + "version": "0.0.0" + } + }, + "PublicSubnet1": { + "id": "PublicSubnet1", + "path": "ecs-enablement-integration/TestVpc/PublicSubnet1", + "children": { + "Subnet": { + "id": "Subnet", + "path": "ecs-enablement-integration/TestVpc/PublicSubnet1/Subnet", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", + "aws:cdk:cloudformation:props": { + "availabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": "" + } + ] + }, + "cidrBlock": "10.0.0.0/18", + "mapPublicIpOnLaunch": true, + "tags": [ + { + "key": "aws-cdk:subnet-name", + "value": "Public" + }, + { + "key": "aws-cdk:subnet-type", + "value": "Public" + }, + { + "key": "Name", + "value": "ecs-enablement-integration/TestVpc/PublicSubnet1" + } + ], + "vpcId": { + "Ref": "TestVpcE77CE678" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", + "version": "0.0.0" + } + }, + "Acl": { + "id": "Acl", + "path": "ecs-enablement-integration/TestVpc/PublicSubnet1/Acl", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "RouteTable": { + "id": "RouteTable", + "path": "ecs-enablement-integration/TestVpc/PublicSubnet1/RouteTable", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", + "aws:cdk:cloudformation:props": { + "tags": [ + { + "key": "Name", + "value": "ecs-enablement-integration/TestVpc/PublicSubnet1" + } + ], + "vpcId": { + "Ref": "TestVpcE77CE678" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", + "version": "0.0.0" + } + }, + "RouteTableAssociation": { + "id": "RouteTableAssociation", + "path": "ecs-enablement-integration/TestVpc/PublicSubnet1/RouteTableAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "TestVpcPublicSubnet1RouteTable4CBFF871" + }, + "subnetId": { + "Ref": "TestVpcPublicSubnet1SubnetA7DB1EDF" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", + "version": "0.0.0" + } + }, + "DefaultRoute": { + "id": "DefaultRoute", + "path": "ecs-enablement-integration/TestVpc/PublicSubnet1/DefaultRoute", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Route", + "aws:cdk:cloudformation:props": { + "destinationCidrBlock": "0.0.0.0/0", + "gatewayId": { + "Ref": "TestVpcIGW9DD53F70" + }, + "routeTableId": { + "Ref": "TestVpcPublicSubnet1RouteTable4CBFF871" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRoute", + "version": "0.0.0" + } + }, + "EIP": { + "id": "EIP", + "path": "ecs-enablement-integration/TestVpc/PublicSubnet1/EIP", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::EIP", + "aws:cdk:cloudformation:props": { + "domain": "vpc", + "tags": [ + { + "key": "Name", + "value": "ecs-enablement-integration/TestVpc/PublicSubnet1" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnEIP", + "version": "0.0.0" + } + }, + "NATGateway": { + "id": "NATGateway", + "path": "ecs-enablement-integration/TestVpc/PublicSubnet1/NATGateway", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::NatGateway", + "aws:cdk:cloudformation:props": { + "allocationId": { + "Fn::GetAtt": [ + "TestVpcPublicSubnet1EIP4884338C", + "AllocationId" + ] + }, + "subnetId": { + "Ref": "TestVpcPublicSubnet1SubnetA7DB1EDF" + }, + "tags": [ + { + "key": "Name", + "value": "ecs-enablement-integration/TestVpc/PublicSubnet1" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnNatGateway", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.PublicSubnet", + "version": "0.0.0" + } + }, + "PublicSubnet2": { + "id": "PublicSubnet2", + "path": "ecs-enablement-integration/TestVpc/PublicSubnet2", + "children": { + "Subnet": { + "id": "Subnet", + "path": "ecs-enablement-integration/TestVpc/PublicSubnet2/Subnet", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", + "aws:cdk:cloudformation:props": { + "availabilityZone": { + "Fn::Select": [ + 1, + { + "Fn::GetAZs": "" + } + ] + }, + "cidrBlock": "10.0.64.0/18", + "mapPublicIpOnLaunch": true, + "tags": [ + { + "key": "aws-cdk:subnet-name", + "value": "Public" + }, + { + "key": "aws-cdk:subnet-type", + "value": "Public" + }, + { + "key": "Name", + "value": "ecs-enablement-integration/TestVpc/PublicSubnet2" + } + ], + "vpcId": { + "Ref": "TestVpcE77CE678" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", + "version": "0.0.0" + } + }, + "Acl": { + "id": "Acl", + "path": "ecs-enablement-integration/TestVpc/PublicSubnet2/Acl", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "RouteTable": { + "id": "RouteTable", + "path": "ecs-enablement-integration/TestVpc/PublicSubnet2/RouteTable", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", + "aws:cdk:cloudformation:props": { + "tags": [ + { + "key": "Name", + "value": "ecs-enablement-integration/TestVpc/PublicSubnet2" + } + ], + "vpcId": { + "Ref": "TestVpcE77CE678" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", + "version": "0.0.0" + } + }, + "RouteTableAssociation": { + "id": "RouteTableAssociation", + "path": "ecs-enablement-integration/TestVpc/PublicSubnet2/RouteTableAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "TestVpcPublicSubnet2RouteTable75B88314" + }, + "subnetId": { + "Ref": "TestVpcPublicSubnet2Subnet80A14523" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", + "version": "0.0.0" + } + }, + "DefaultRoute": { + "id": "DefaultRoute", + "path": "ecs-enablement-integration/TestVpc/PublicSubnet2/DefaultRoute", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Route", + "aws:cdk:cloudformation:props": { + "destinationCidrBlock": "0.0.0.0/0", + "gatewayId": { + "Ref": "TestVpcIGW9DD53F70" + }, + "routeTableId": { + "Ref": "TestVpcPublicSubnet2RouteTable75B88314" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRoute", + "version": "0.0.0" + } + }, + "EIP": { + "id": "EIP", + "path": "ecs-enablement-integration/TestVpc/PublicSubnet2/EIP", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::EIP", + "aws:cdk:cloudformation:props": { + "domain": "vpc", + "tags": [ + { + "key": "Name", + "value": "ecs-enablement-integration/TestVpc/PublicSubnet2" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnEIP", + "version": "0.0.0" + } + }, + "NATGateway": { + "id": "NATGateway", + "path": "ecs-enablement-integration/TestVpc/PublicSubnet2/NATGateway", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::NatGateway", + "aws:cdk:cloudformation:props": { + "allocationId": { + "Fn::GetAtt": [ + "TestVpcPublicSubnet2EIP83F7944C", + "AllocationId" + ] + }, + "subnetId": { + "Ref": "TestVpcPublicSubnet2Subnet80A14523" + }, + "tags": [ + { + "key": "Name", + "value": "ecs-enablement-integration/TestVpc/PublicSubnet2" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnNatGateway", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.PublicSubnet", + "version": "0.0.0" + } + }, + "PrivateSubnet1": { + "id": "PrivateSubnet1", + "path": "ecs-enablement-integration/TestVpc/PrivateSubnet1", + "children": { + "Subnet": { + "id": "Subnet", + "path": "ecs-enablement-integration/TestVpc/PrivateSubnet1/Subnet", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", + "aws:cdk:cloudformation:props": { + "availabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": "" + } + ] + }, + "cidrBlock": "10.0.128.0/18", + "mapPublicIpOnLaunch": false, + "tags": [ + { + "key": "aws-cdk:subnet-name", + "value": "Private" + }, + { + "key": "aws-cdk:subnet-type", + "value": "Private" + }, + { + "key": "Name", + "value": "ecs-enablement-integration/TestVpc/PrivateSubnet1" + } + ], + "vpcId": { + "Ref": "TestVpcE77CE678" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", + "version": "0.0.0" + } + }, + "Acl": { + "id": "Acl", + "path": "ecs-enablement-integration/TestVpc/PrivateSubnet1/Acl", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "RouteTable": { + "id": "RouteTable", + "path": "ecs-enablement-integration/TestVpc/PrivateSubnet1/RouteTable", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", + "aws:cdk:cloudformation:props": { + "tags": [ + { + "key": "Name", + "value": "ecs-enablement-integration/TestVpc/PrivateSubnet1" + } + ], + "vpcId": { + "Ref": "TestVpcE77CE678" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", + "version": "0.0.0" + } + }, + "RouteTableAssociation": { + "id": "RouteTableAssociation", + "path": "ecs-enablement-integration/TestVpc/PrivateSubnet1/RouteTableAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "TestVpcPrivateSubnet1RouteTable469B0105" + }, + "subnetId": { + "Ref": "TestVpcPrivateSubnet1SubnetCC65D771" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", + "version": "0.0.0" + } + }, + "DefaultRoute": { + "id": "DefaultRoute", + "path": "ecs-enablement-integration/TestVpc/PrivateSubnet1/DefaultRoute", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Route", + "aws:cdk:cloudformation:props": { + "destinationCidrBlock": "0.0.0.0/0", + "natGatewayId": { + "Ref": "TestVpcPublicSubnet1NATGatewayA323E3EC" + }, + "routeTableId": { + "Ref": "TestVpcPrivateSubnet1RouteTable469B0105" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRoute", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.PrivateSubnet", + "version": "0.0.0" + } + }, + "PrivateSubnet2": { + "id": "PrivateSubnet2", + "path": "ecs-enablement-integration/TestVpc/PrivateSubnet2", + "children": { + "Subnet": { + "id": "Subnet", + "path": "ecs-enablement-integration/TestVpc/PrivateSubnet2/Subnet", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", + "aws:cdk:cloudformation:props": { + "availabilityZone": { + "Fn::Select": [ + 1, + { + "Fn::GetAZs": "" + } + ] + }, + "cidrBlock": "10.0.192.0/18", + "mapPublicIpOnLaunch": false, + "tags": [ + { + "key": "aws-cdk:subnet-name", + "value": "Private" + }, + { + "key": "aws-cdk:subnet-type", + "value": "Private" + }, + { + "key": "Name", + "value": "ecs-enablement-integration/TestVpc/PrivateSubnet2" + } + ], + "vpcId": { + "Ref": "TestVpcE77CE678" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", + "version": "0.0.0" + } + }, + "Acl": { + "id": "Acl", + "path": "ecs-enablement-integration/TestVpc/PrivateSubnet2/Acl", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "RouteTable": { + "id": "RouteTable", + "path": "ecs-enablement-integration/TestVpc/PrivateSubnet2/RouteTable", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", + "aws:cdk:cloudformation:props": { + "tags": [ + { + "key": "Name", + "value": "ecs-enablement-integration/TestVpc/PrivateSubnet2" + } + ], + "vpcId": { + "Ref": "TestVpcE77CE678" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", + "version": "0.0.0" + } + }, + "RouteTableAssociation": { + "id": "RouteTableAssociation", + "path": "ecs-enablement-integration/TestVpc/PrivateSubnet2/RouteTableAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "TestVpcPrivateSubnet2RouteTableCEF29F7C" + }, + "subnetId": { + "Ref": "TestVpcPrivateSubnet2SubnetDE0C64A2" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", + "version": "0.0.0" + } + }, + "DefaultRoute": { + "id": "DefaultRoute", + "path": "ecs-enablement-integration/TestVpc/PrivateSubnet2/DefaultRoute", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Route", + "aws:cdk:cloudformation:props": { + "destinationCidrBlock": "0.0.0.0/0", + "natGatewayId": { + "Ref": "TestVpcPublicSubnet2NATGatewayA9858C31" + }, + "routeTableId": { + "Ref": "TestVpcPrivateSubnet2RouteTableCEF29F7C" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRoute", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.PrivateSubnet", + "version": "0.0.0" + } + }, + "IGW": { + "id": "IGW", + "path": "ecs-enablement-integration/TestVpc/IGW", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::InternetGateway", + "aws:cdk:cloudformation:props": { + "tags": [ + { + "key": "Name", + "value": "ecs-enablement-integration/TestVpc" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnInternetGateway", + "version": "0.0.0" + } + }, + "VPCGW": { + "id": "VPCGW", + "path": "ecs-enablement-integration/TestVpc/VPCGW", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::VPCGatewayAttachment", + "aws:cdk:cloudformation:props": { + "internetGatewayId": { + "Ref": "TestVpcIGW9DD53F70" + }, + "vpcId": { + "Ref": "TestVpcE77CE678" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnVPCGatewayAttachment", + "version": "0.0.0" + } + }, + "RestrictDefaultSecurityGroupCustomResource": { + "id": "RestrictDefaultSecurityGroupCustomResource", + "path": "ecs-enablement-integration/TestVpc/RestrictDefaultSecurityGroupCustomResource", + "children": { + "Default": { + "id": "Default", + "path": "ecs-enablement-integration/TestVpc/RestrictDefaultSecurityGroupCustomResource/Default", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnResource", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.CustomResource", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.Vpc", + "version": "0.0.0" + } + }, + "LatestNodeRuntimeMap": { + "id": "LatestNodeRuntimeMap", + "path": "ecs-enablement-integration/LatestNodeRuntimeMap", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnMapping", + "version": "0.0.0" + } + }, + "Custom::VpcRestrictDefaultSGCustomResourceProvider": { + "id": "Custom::VpcRestrictDefaultSGCustomResourceProvider", + "path": "ecs-enablement-integration/Custom::VpcRestrictDefaultSGCustomResourceProvider", + "children": { + "Staging": { + "id": "Staging", + "path": "ecs-enablement-integration/Custom::VpcRestrictDefaultSGCustomResourceProvider/Staging", + "constructInfo": { + "fqn": "aws-cdk-lib.AssetStaging", + "version": "0.0.0" + } + }, + "Role": { + "id": "Role", + "path": "ecs-enablement-integration/Custom::VpcRestrictDefaultSGCustomResourceProvider/Role", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnResource", + "version": "0.0.0" + } + }, + "Handler": { + "id": "Handler", + "path": "ecs-enablement-integration/Custom::VpcRestrictDefaultSGCustomResourceProvider/Handler", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnResource", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.CustomResourceProviderBase", + "version": "0.0.0" + } + }, + "TestCluster": { + "id": "TestCluster", + "path": "ecs-enablement-integration/TestCluster", + "children": { + "Resource": { + "id": "Resource", + "path": "ecs-enablement-integration/TestCluster/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ECS::Cluster", + "aws:cdk:cloudformation:props": {} + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ecs.CfnCluster", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ecs.Cluster", + "version": "0.0.0" + } + }, + "Namespace": { + "id": "Namespace", + "path": "ecs-enablement-integration/Namespace", + "children": { + "Resource": { + "id": "Resource", + "path": "ecs-enablement-integration/Namespace/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ServiceDiscovery::PrivateDnsNamespace", + "aws:cdk:cloudformation:props": { + "name": "local", + "vpc": { + "Ref": "TestVpcE77CE678" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_servicediscovery.CfnPrivateDnsNamespace", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_servicediscovery.PrivateDnsNamespace", + "version": "0.0.0" + } + }, + "CwAgentDaemonTaskDef": { + "id": "CwAgentDaemonTaskDef", + "path": "ecs-enablement-integration/CwAgentDaemonTaskDef", + "children": { + "TaskRole": { + "id": "TaskRole", + "path": "ecs-enablement-integration/CwAgentDaemonTaskDef/TaskRole", + "children": { + "ImportTaskRole": { + "id": "ImportTaskRole", + "path": "ecs-enablement-integration/CwAgentDaemonTaskDef/TaskRole/ImportTaskRole", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "ecs-enablement-integration/CwAgentDaemonTaskDef/TaskRole/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "assumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "ecs-tasks.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnRole", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Role", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "ecs-enablement-integration/CwAgentDaemonTaskDef/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ECS::TaskDefinition", + "aws:cdk:cloudformation:props": { + "containerDefinitions": [ + { + "cpu": 128, + "essential": true, + "image": "public.ecr.aws/cloudwatch-agent/cloudwatch-agent:latest", + "memory": 64, + "name": "ecs-cwagent", + "portMappings": [ + { + "containerPort": 4316, + "hostPort": 4316, + "protocol": "tcp", + "name": "cwagent-4316" + }, + { + "containerPort": 2000, + "hostPort": 2000, + "protocol": "tcp", + "name": "cwagent-2000" + } + ], + "logConfiguration": { + "logDriver": "awslogs", + "options": { + "awslogs-group": { + "Ref": "CwAgentLogGroupBF702CD8" + }, + "awslogs-stream-prefix": "ecs", + "awslogs-region": { + "Ref": "AWS::Region" + } + } + }, + "environment": [ + { + "name": "CW_CONFIG_CONTENT", + "value": "{\"agent\": {\"debug\": true}, \"traces\": {\"traces_collected\": {\"application_signals\": {\"enabled\": true}}}, \"logs\": {\"metrics_collected\": {\"application_signals\": {\"enabled\": true}}}}" + } + ] + } + ], + "executionRoleArn": { + "Fn::GetAtt": [ + "CwAgentDaemonTaskDefExecutionRoleDB11FC2A", + "Arn" + ] + }, + "family": "ecsenablementintegrationCwAgentDaemonTaskDefB3E3B54C", + "networkMode": "bridge", + "requiresCompatibilities": [ + "EC2" + ], + "taskRoleArn": { + "Fn::GetAtt": [ + "CwAgentDaemonTaskDefTaskRoleB630618E", + "Arn" + ] + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ecs.CfnTaskDefinition", + "version": "0.0.0" + } + }, + "ecs-cwagent": { + "id": "ecs-cwagent", + "path": "ecs-enablement-integration/CwAgentDaemonTaskDef/ecs-cwagent", + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ecs.ContainerDefinition", + "version": "0.0.0" + } + }, + "ExecutionRole": { + "id": "ExecutionRole", + "path": "ecs-enablement-integration/CwAgentDaemonTaskDef/ExecutionRole", + "children": { + "ImportExecutionRole": { + "id": "ImportExecutionRole", + "path": "ecs-enablement-integration/CwAgentDaemonTaskDef/ExecutionRole/ImportExecutionRole", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "ecs-enablement-integration/CwAgentDaemonTaskDef/ExecutionRole/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "assumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "ecs-tasks.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnRole", + "version": "0.0.0" + } + }, + "DefaultPolicy": { + "id": "DefaultPolicy", + "path": "ecs-enablement-integration/CwAgentDaemonTaskDef/ExecutionRole/DefaultPolicy", + "children": { + "Resource": { + "id": "Resource", + "path": "ecs-enablement-integration/CwAgentDaemonTaskDef/ExecutionRole/DefaultPolicy/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Policy", + "aws:cdk:cloudformation:props": { + "policyDocument": { + "Statement": [ + { + "Action": [ + "logs:CreateLogStream", + "logs:PutLogEvents" + ], + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "CwAgentLogGroupBF702CD8", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "policyName": "CwAgentDaemonTaskDefExecutionRoleDefaultPolicy765BB856", + "roles": [ + { + "Ref": "CwAgentDaemonTaskDefExecutionRoleDB11FC2A" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnPolicy", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Policy", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Role", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ecs.Ec2TaskDefinition", + "version": "0.0.0" + } + }, + "CwAgentLogGroup": { + "id": "CwAgentLogGroup", + "path": "ecs-enablement-integration/CwAgentLogGroup", + "children": { + "Resource": { + "id": "Resource", + "path": "ecs-enablement-integration/CwAgentLogGroup/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Logs::LogGroup", + "aws:cdk:cloudformation:props": { + "logGroupName": "/ecs/ecs-cwagent-cdk-daemon", + "retentionInDays": 731 + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_logs.CfnLogGroup", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_logs.LogGroup", + "version": "0.0.0" + } + }, + "CwAgentDaemonService": { + "id": "CwAgentDaemonService", + "path": "ecs-enablement-integration/CwAgentDaemonService", + "children": { + "Service": { + "id": "Service", + "path": "ecs-enablement-integration/CwAgentDaemonService/Service", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ECS::Service", + "aws:cdk:cloudformation:props": { + "cluster": { + "Ref": "TestClusterE0095054" + }, + "deploymentConfiguration": { + "maximumPercent": 100, + "minimumHealthyPercent": 0 + }, + "enableEcsManagedTags": false, + "launchType": "EC2", + "schedulingStrategy": "DAEMON", + "serviceConnectConfiguration": { + "enabled": true, + "namespace": { + "Fn::GetAtt": [ + "Namespace9B63B8C8", + "Arn" + ] + }, + "services": [ + { + "portName": "cwagent-4316", + "clientAliases": [ + { + "port": 4316, + "dnsName": "cwagent-4316-http" + } + ] + }, + { + "portName": "cwagent-2000", + "clientAliases": [ + { + "port": 2000, + "dnsName": "cwagent-2000-http" + } + ] + } + ] + }, + "taskDefinition": { + "Ref": "CwAgentDaemonTaskDefD42721B8" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ecs.CfnService", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ecs.Ec2Service", + "version": "0.0.0" + } + }, "Ec2TaskDefinition": { "id": "Ec2TaskDefinition", "path": "ecs-enablement-integration/Ec2TaskDefinition", @@ -100,11 +1164,11 @@ }, { "name": "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", - "value": "http://cwagent.local:4316/v1/metrics" + "value": "http://cwagent-4316-http:4316/v1/metrics" }, { "name": "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", - "value": "http://cwagent.local:4316/v1/traces" + "value": "hhttp://cwagent-4316-http:4316/v1/traces" }, { "name": "OTEL_TRACES_SAMPLER", @@ -112,7 +1176,7 @@ }, { "name": "OTEL_TRACES_SAMPLER_ARG", - "value": "endpoint=http://ccwagent.local:2000" + "value": "endpoint=http://cwagent-2000-http:2000" }, { "name": "OTEL_PROPAGATORS", diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.ts b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.ts index 82f5d904b9c6e..46ff6065c4948 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.ts +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.ts @@ -1,13 +1,73 @@ import * as integ from '@aws-cdk/integ-tests-alpha'; import * as cdk from 'aws-cdk-lib'; +import * as ec2 from 'aws-cdk-lib/aws-ec2'; import * as ecs from 'aws-cdk-lib/aws-ecs'; +import { LogGroup } from 'aws-cdk-lib/aws-logs'; +import { PrivateDnsNamespace } from 'aws-cdk-lib/aws-servicediscovery'; import * as appsignals from '../lib'; const app = new cdk.App(); const stack = new cdk.Stack(app, 'ecs-enablement-integration'); +const vpc = new ec2.Vpc(stack, 'TestVpc', {}); +const cluster = new ecs.Cluster(stack, 'TestCluster', { vpc }); +const namespace = new PrivateDnsNamespace(stack, 'Namespace', { + vpc, + name: 'local', +}); + +// Define Task Definition for CloudWatch agent (Daemon) +const cwAgentTaskDefinition = new ecs.Ec2TaskDefinition(stack, 'CwAgentDaemonTaskDef'); + +// Add the CloudWatch agent container +cwAgentTaskDefinition.addContainer('ecs-cwagent', { + image: ecs.ContainerImage.fromRegistry('public.ecr.aws/cloudwatch-agent/cloudwatch-agent:latest'), + cpu: 128, + memoryLimitMiB: 64, + portMappings: [ + { + name: 'cwagent-4316', + containerPort: 4316, + hostPort: 4316, + }, + { + name: 'cwagent-2000', + containerPort: 2000, + hostPort: 2000, + }, + ], + logging: new ecs.AwsLogDriver({ + streamPrefix: 'ecs', + logGroup: new LogGroup(stack, 'CwAgentLogGroup', { + logGroupName: '/ecs/ecs-cwagent-cdk-daemon', + removalPolicy: cdk.RemovalPolicy.DESTROY, + }), + }), + environment: { + CW_CONFIG_CONTENT: '{"agent": {"debug": true}, "traces": {"traces_collected": {"application_signals": {"enabled": true}}}, "logs": {"metrics_collected": {"application_signals": {"enabled": true}}}}', + }, +}); + +new ecs.Ec2Service(stack, 'CwAgentDaemonService', { + cluster, + taskDefinition: cwAgentTaskDefinition, + daemon: true, // Runs one container per EC2 instance + serviceConnectConfiguration: { + namespace: namespace.namespaceArn, + services: [{ + portMappingName: 'cwagent-4316', + dnsName: 'cwagent-4316-http', + port: 4316, + }, { + portMappingName: 'cwagent-2000', + dnsName: 'cwagent-2000-http', + port: 2000, + }], + }, +}); + const ec2TaskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDefinition', { networkMode: ecs.NetworkMode.HOST, }); @@ -27,13 +87,13 @@ new appsignals.ApplicationSignalsIntegration(stack, 'TestEc2TaskDefinitionIntegr overrideEnvironments: [ { name: appsignals.CommonExporting.OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT, - value: 'http://cwagent.local:4316/v1/metrics', + value: 'http://cwagent-4316-http:4316/v1/metrics', }, { name: appsignals.TraceExporting.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, - value: 'http://cwagent.local:4316/v1/traces', + value: 'hhttp://cwagent-4316-http:4316/v1/traces', }, { name: appsignals.TraceExporting.OTEL_TRACES_SAMPLER_ARG, - value: 'endpoint=http://ccwagent.local:2000', + value: 'endpoint=http://cwagent-2000-http:2000', }, ], cloudWatchAgent: { From d261b3e02396b7d558e669283e4c3ef6bc7bef4d Mon Sep 17 00:00:00 2001 From: Zhou Date: Tue, 21 Jan 2025 23:43:51 -0800 Subject: [PATCH 4/4] Address additional comments --- .../aws-applicationsignals-alpha/README.md | 290 ++++---- .../lib/enablement/ecs-cloudwatch-agent.ts | 163 +++++ .../lib/enablement/ecs-sdk-instrumentation.ts | 429 +++++++++++ .../lib/enablement/ecs.ts | 691 ++---------------- .../enablement/instrumentation-versions.ts | 123 ++++ .../aws-applicationsignals-alpha/lib/index.ts | 3 + .../test/ecs-enablement.test.ts | 40 +- ...efaultTestDeployAssert0A2A622F.assets.json | 2 +- .../cdk.out | 2 +- .../ecs-enablement-integration.assets.json | 6 +- .../ecs-enablement-integration.template.json | 99 ++- .../integ.json | 2 +- .../manifest.json | 382 +++++++++- .../tree.json | 390 ++++++++-- .../test/integ.ecs-enablement-daemon.ts | 58 +- ...efaultTestDeployAssert7F3E5290.assets.json | 2 +- .../cdk.out | 2 +- .../ecs-enablement-integration.assets.json | 6 +- .../ecs-enablement-integration.template.json | 15 +- .../integ.json | 2 +- .../manifest.json | 68 +- .../tree.json | 63 +- .../test/integ.ecs-enablement-sidecar.ts | 10 +- 23 files changed, 1860 insertions(+), 988 deletions(-) create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/ecs-cloudwatch-agent.ts create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/ecs-sdk-instrumentation.ts create mode 100644 packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/instrumentation-versions.ts diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/README.md b/packages/@aws-cdk/aws-applicationsignals-alpha/README.md index a33bd95a290ba..bcb8063bfa69f 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/README.md +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/README.md @@ -15,196 +15,164 @@ - - ---- - -![cdk-constructs: Experimental](https://img.shields.io/badge/cdk--constructs-experimental-important.svg?style=for-the-badge) - -> The APIs of higher level constructs in this module are experimental and under active development. -> They are subject to non-backward compatible changes or removal in any future version. These are -> not subject to the [Semantic Versioning](https://semver.org/) model and breaking changes will be -> announced in the release notes. This means that while you may use them, you may need to update -> your source code when upgrading to a newer version of this package. - ---- - -## Application Signals - CloudWatch Application Signals is an auto-instrumentation solution built on OpenTelemetry that enables zero-code collection of monitoring data, such -as traces and metrics, from applications running across multiple platforms. It also supports topology auto-discovery based on collected monitoring -data and includes a new feature for managing service-level objectives (SLOs). +as traces and metrics, from applications running across multiple platforms. It also supports topology auto-discovery based on collected monitoring data +and includes a new feature for managing service-level objectives (SLOs). It supports Java, Python, .NET, and Node.js on platforms including EKS (and native Kubernetes), Lambda, ECS, and EC2. For more details, visit [Application Signals](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Application-Monitoring-Sections.html) on the AWS public website. -## Application Signals L2 CDK for enablement +## Application Signals Enablement L2 Constructs -This module is a collection of L2 constructs which leverages native L1 CFN resources, simplifying the enablement steps and the creation of Application +A collection of L2 constructs which leverages native L1 CFN resources, simplifying the enablement steps and the creation of Application Signals resources. -This module is part of the [AWS Cloud Development Kit](https://github.com/aws/aws-cdk) project. - -```ts nofixture -import * as appsignals from '@aws-cdk/aws-applicationsignals-alpha'; -``` - ### ApplicationSignalsIntegration `ApplicationSignalsIntegration` aims to address key challenges in the current CDK enablement process, which requires complex manual configurations for ECS customers. Application Signals is designed to be flexible and is supported for other platforms as well. However, the initial focus is on supporting ECS, with plans to potentially extend support to other platforms in the future. -#### 1. Enable Application Signals on ECS with sidecar mode - -##### 1.1. Create a TaskDefinition for application - -```ts -import * as ecs from 'aws-cdk-lib/aws-ecs'; - -const fargateTaskDefinition = new ecs.FargateTaskDefinition(stack, 'FargateTaskDefinition', { - taskRole: taskRole, - cpu: 2048, - memoryLimitMiB: 4096 -}); - -fargateTaskDefinition.addContainer('app', { - image: ..., - ... -}); -``` - -##### 1.2. Configure ApplicationSignalsIntegration - -Key steps: +#### Enable Application Signals on ECS with sidecar mode 1. Configure `instrumentation` to instrument the application with the ADOT Java Agent. 2. Setting `enableSidecar` to true to add the CloudWatch Agent as a sidecar container. ```ts -new appsignals.ApplicationSignalsIntegration(this, 'ApplicationSignalsIntegration', { - taskDefinition, - instrumentation: { - language: appsignals.InstrumentationLanguage.JAVA, - sdkVersion: appsignals.JavaInstrumentationVersion.V1_32_6 - }, - serviceName: 'sample-app', - cloudWatchAgent: { - enableSidecar: true, - } -}); -``` - -#### 2. Enable Application Signals on ECS with daemon mode - -Note: Since the daemon deployment strategy is not supported on ECS Fargate, this mode is only supported on ECS on EC2. - -##### 2.1. Run CloudWatch Agent as a daemon service - -```ts +import { Construct } from 'constructs'; +import * as appsignals from '@aws-cdk/aws-applicationsignals-alpha'; +import * as cdk from 'aws-cdk-lib'; import * as ecs from 'aws-cdk-lib/aws-ecs'; -import * as logs from 'aws-cdk-lib/aws-logs'; -// Create a task definition for CloudWatch agent -const cwAgentTaskDefinition = new ecs.Ec2TaskDefinition(this, 'CloudWatchAgentTaskDefinition'); - -// Add CloudWatch agent container -const cwAgentContainer = cwAgentTaskDefinition.addContainer('ecs-cwagent', { - image: ecs.ContainerImage.fromRegistry("public.ecr.aws/cloudwatch-agent/cloudwatch-agent:latest"), - cpu: 128, - memoryLimitMiB: 64, - portMappings: [ - { - name: 'cwagent-4316', - containerPort: 4316, - hostPort: 4316, - }, - { - name: 'cwagent-2000', - containerPort: 2000, - hostPort: 2000, - }, - ], - logging: new ecs.AwsLogDriver({ - streamPrefix: 'ecs', - logGroup: new logs.LogGroup(this, 'CwAgentLogGroup', { - logGroupName: '/ecs/ecs-cwagent-cdk-daemon', - removalPolicy: cdk.RemovalPolicy.DESTROY, - }), - }), - environment: { - CW_CONFIG_CONTENT: '{"traces": {"traces_collected": {"application_signals": {}}}, "logs": {"metrics_collected":{"application_signals": {}}}}' +class MyStack extends cdk.Stack { + public constructor(scope?: Construct, id?: string, props: cdk.StackProps = {}) { + super(); + const fargateTaskDefinition = new ecs.FargateTaskDefinition(this, 'FargateTaskDefinition', { + cpu: 2048, + memoryLimitMiB: 4096 + }); + + fargateTaskDefinition.addContainer('app', { + image: ecs.ContainerImage.fromRegistry('test/sample-app'), + }); + + new appsignals.ApplicationSignalsIntegration(this, 'ApplicationSignalsIntegration', { + taskDefinition: fargateTaskDefinition, + instrumentation: { + sdkVersion: appsignals.JavaInstrumentationVersion.V1_32_6 + }, + serviceName: 'sample-app', + cloudWatchAgentSidecar: { + containerName: 'cloudwatch-agent', + cpu: 256, + memoryLimitMiB: 512 + } + }); } -}); - -// Create the CloudWatch agent daemon service -new ecs.Ec2Service(this, 'CloudWatchAgentDaemon', { - cluster, - taskDefinition: cwAgentTaskDefinition, - daemon: true, // Runs one container per EC2 instance - serviceConnectConfiguration: { // Create service connect - namespace: namespace.namespaceArn, - services: [{ - portMappingName: 'cwagent-4316', - dnsName: 'cwagent-4316-http', - port: 4316 - }, { - portMappingName: 'cwagent-2000', - dnsName: 'cwagent-2000-http', - port: 2000 - }] - } -}); +} ``` -##### 2.2. Create a TaskDefinition for application +#### Enable Application Signals on ECS with daemon mode -```ts -import * as ecs from 'aws-cdk-lib/aws-ecs'; - -const ec2TaskDefinition = new ecs.Ec2TaskDefinition(this, 'EC2TaskDefinition', { - taskRole: taskRole, - ... -}); - -ec2TaskDefinition.addContainer('app', { - image: ..., - ... -}); -``` - -##### 2.3. Configure ApplicationSignalsIntegration - -Key steps: +Note: Since the daemon deployment strategy is not supported on ECS Fargate, this mode is only supported on ECS on EC2. +1. Run CloudWatch Agent as a daemon service with service connect. 1. Configure `instrumentation` to instrument the application with the ADOT Python Agent. -2. Set `enableSidecar` to false to disable running CloudWatch agent as a sidecar. -3. Override environment variables by configuring `overrideEnvironments` to use Service Connect to communicate to the CloudWatch agent server +1. Set `enableSidecar` to false to disable running CloudWatch agent as a sidecar. +1. Override environment variables by configuring `overrideEnvironments` to use service connect endpoints to communicate to the CloudWatch agent server ```ts -new appsignals.ApplicationSignalsIntegration(this, 'ApplicationSignalsIntegration', ec2TaskDefinition, { - instrumentation: { - language: appsignals.InstrumentationLanguage.PYTHON, - sdkVersion: appsignals.PythonInstrumentationVersion.V0_8_0 - }, - overrideEnvironments: [{ - name: appsignals.CommonExporting.OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT, - // overwrite the endpoint to point to the created Service Connect - value: "http://cwagent-4316-http:4316/v1/metrics" - }, { - name: appsignals.TraceExporting.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, - // overwrite the endpoint to point to the created Service Connect - value: "http://cwagent-4316-http:4316/v1/traces" - }, { - name: appsignals.TraceExporting.OTEL_TRACES_SAMPLER_ARG, - // overwrite the endpoint to point to the created Service Connect - value: "endpoint=http://cwagent-2000-http:2000" - }], - serviceName: 'sample-app', - cloudWatchAgent: { - // disable sidecar mode - enableSidecar: false, +import { Construct } from 'constructs'; +import * as appsignals from '@aws-cdk/aws-applicationsignals-alpha'; +import * as cdk from 'aws-cdk-lib'; +import * as ec2 from 'aws-cdk-lib/aws-ec2'; +import * as ecs from 'aws-cdk-lib/aws-ecs'; +import * as logs from 'aws-cdk-lib/aws-logs'; + +class MyStack extends cdk.Stack { + public constructor(scope?: Construct, id?: string, props: cdk.StackProps = {}) { + super(scope, id, props); + + const vpc = new ec2.Vpc(this, 'TestVpc', {}); + const cluster = new ecs.Cluster(this, 'TestCluster', { vpc }); + // Create a task definition for CloudWatch agent + const cwAgentTaskDefinition = new ecs.Ec2TaskDefinition(this, 'CloudWatchAgentTaskDefinition'); + + new appsignals.CloudWatchAgentIntegration(this, 'CloudWatchAgent', + { + taskDefinition: cwAgentTaskDefinition, + containerName: 'ecs-cwagent', + enableLogging: true, + cpu: 128, + memoryLimitMiB: 64, + portMappings: [ + { + name: 'cwagent-4316', + containerPort: 4316, + hostPort: 4316, + }, + { + name: 'cwagent-2000', + containerPort: 2000, + hostPort: 2000, + }, + ], + } + ) + + // Create the CloudWatch agent daemon service + new ecs.Ec2Service(this, 'CloudWatchAgentDaemon', { + cluster, + taskDefinition: cwAgentTaskDefinition, + daemon: true, // Runs one container per EC2 instance + serviceConnectConfiguration: { + namespace: 'namespace-arn', + services: [ + { + portMappingName: 'cwagent-4316', + dnsName: 'cwagent-4316-http', + port: 4316 + }, + { + portMappingName: 'cwagent-2000', + dnsName: 'cwagent-2000-http', + port: 2000 + } + ] + } + }); + + const ec2TaskDefinition = new ecs.Ec2TaskDefinition(this, 'Ec2TaskDefinition', { + networkMode: ecs.NetworkMode.HOST, + }); + + ec2TaskDefinition.addContainer('app', { + image: ecs.ContainerImage.fromRegistry('test/sample-app'), + cpu: 0, + memoryLimitMiB: 512, + }); + + new appsignals.ApplicationSignalsIntegration(this, 'ApplicationSignalsIntegration', { + taskDefinition: ec2TaskDefinition, + instrumentation: { + sdkVersion: appsignals.PythonInstrumentationVersion.V0_8_0 + }, + overrideEnvironments: [{ + name: appsignals.CommonExporting.OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT, + // overwrite the endpoint to point to the created Service Connect + value: "http://cwagent-4316-http:4316/v1/metrics" + }, { + name: appsignals.TraceExporting.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, + // overwrite the endpoint to point to the created Service Connect + value: "http://cwagent-4316-http:4316/v1/traces" + }, { + name: appsignals.TraceExporting.OTEL_TRACES_SAMPLER_ARG, + // overwrite the endpoint to point to the created Service Connect + value: "endpoint=http://cwagent-2000-http:2000" + }], + serviceName: 'sample-app' + }); } -}); +} ``` diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/ecs-cloudwatch-agent.ts b/packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/ecs-cloudwatch-agent.ts new file mode 100644 index 0000000000000..ed10036882c20 --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/ecs-cloudwatch-agent.ts @@ -0,0 +1,163 @@ +import * as ecs from 'aws-cdk-lib/aws-ecs'; +import { Construct } from 'constructs'; + +/** + * Provides version information and image selection for CloudWatch Agent. + */ +export class CloudWatchAgentVersion { + /** + * Default CloudWatch Agent image for Linux. + */ + public static readonly CLOUDWATCH_AGENT_IMAGE = 'amazon/cloudwatch-agent:latest'; + + /** + * CloudWatch Agent image for Windows Server 2019. + */ + public static readonly CLOUDWATCH_AGENT_IMAGE_WIN2019 = 'public.ecr.aws/cloudwatch-agent/cloudwatch-agent:latest-windowsservercore2019'; + + /** + * CloudWatch Agent image for Windows Server 2022. + */ + public static readonly CLOUDWATCH_AGENT_IMAGE_WIN2022 = 'public.ecr.aws/cloudwatch-agent/cloudwatch-agent:latest-windowsservercore2022'; + + /** + * Gets the appropriate CloudWatch Agent image based on the operating system. + * @param operatingSystemFamily - The ECS operating system family + * @returns The CloudWatch Agent image URI + */ + public static getCloudWatchAgentImage(operatingSystemFamily?: ecs.OperatingSystemFamily): string { + let cloudWatchAgentImage = CloudWatchAgentVersion.CLOUDWATCH_AGENT_IMAGE; + if (operatingSystemFamily) { + switch (operatingSystemFamily) { + case ecs.OperatingSystemFamily.WINDOWS_SERVER_2019_CORE: + case ecs.OperatingSystemFamily.WINDOWS_SERVER_2019_FULL: + cloudWatchAgentImage = CloudWatchAgentVersion.CLOUDWATCH_AGENT_IMAGE_WIN2019; + break; + case ecs.OperatingSystemFamily.WINDOWS_SERVER_2022_CORE: + case ecs.OperatingSystemFamily.WINDOWS_SERVER_2022_FULL: + cloudWatchAgentImage = CloudWatchAgentVersion.CLOUDWATCH_AGENT_IMAGE_WIN2022; + break; + } + } + return cloudWatchAgentImage; + } +} + +/** + * Configuration options for the CloudWatch Agent container. + */ +export interface CloudWatchAgentOptions { + /** + * Name of the CloudWatch Agent container. + */ + readonly containerName: string; + + /** + * Custom agent configuration in JSON format. + * @default - Uses default configuration for Application Signals + */ + readonly agentConfig?: string; + + /** + * Whether to enable logging for the CloudWatch Agent. + * @default - false + */ + readonly enableLogging?: boolean; + + /** + * The minimum number of CPU units to reserve for the container. + * @default - No minimum CPU units reserved. + */ + readonly cpu?: number; + + /** + * The amount (in MiB) of memory to present to the container. + * @default - No memory limit. + */ + readonly memoryLimitMiB?: number; + + /** + * The soft limit (in MiB) of memory to reserve for the container. + * @default - No memory reserved. + */ + readonly memoryReservationMiB?: number; + + /** + * Operating system family for the CloudWatch Agent. + * @default - Linux + */ + readonly operatingSystemFamily?: ecs.OperatingSystemFamily; + + /** + * The port mappings to add to the container definition. + * @default - No ports are mapped. + */ + readonly portMappings?: ecs.PortMapping[]; +} + +/** + * Properties for integrating CloudWatch Agent into an ECS task definition. + */ +export interface CloudWatchAgentIntegrationProps extends CloudWatchAgentOptions { + /** + * The task definition to integrate CloudWatch agent into. + * + * [disable-awslint:ref-via-interface] + */ + readonly taskDefinition: ecs.TaskDefinition; +} + +/** + * A construct that adds CloudWatch Agent as a container to an ECS task definition. + */ +export class CloudWatchAgentIntegration extends Construct { + private static readonly DEFAULT_CONFIG = { + logs: { + metrics_collected: { + application_signals: { + enabled: true, + }, + }, + }, + traces: { + traces_collected: { + application_signals: { + enabled: true, + }, + }, + }, + }; + + /** + * The CloudWatch Agent container definition. + */ + readonly agentContainer: ecs.ContainerDefinition; + + /** + * Creates a new CloudWatch Agent integration. + * @param scope - The construct scope + * @param id - The construct ID + * @param props - Configuration properties + */ + constructor(scope: Construct, + id: string, + props: CloudWatchAgentIntegrationProps, + ) { + super(scope, id); + + this.agentContainer = props.taskDefinition.addContainer(props.containerName, { + image: ecs.ContainerImage.fromRegistry(CloudWatchAgentVersion.getCloudWatchAgentImage(props.operatingSystemFamily)), + cpu: props.cpu, + memoryLimitMiB: props.memoryLimitMiB, + memoryReservationMiB: props.memoryReservationMiB, + logging: props.enableLogging? new ecs.AwsLogDriver({ + streamPrefix: props.containerName, + }): undefined, + user: '0:1338', + portMappings: props.portMappings, + environment: { + CW_CONFIG_CONTENT: props.agentConfig ? props.agentConfig: JSON.stringify(CloudWatchAgentIntegration.DEFAULT_CONFIG), + }, + }); + } +} diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/ecs-sdk-instrumentation.ts b/packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/ecs-sdk-instrumentation.ts new file mode 100644 index 0000000000000..94d460cb5210a --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/ecs-sdk-instrumentation.ts @@ -0,0 +1,429 @@ +import * as ecs from 'aws-cdk-lib/aws-ecs'; +import * as constants from './constants'; +import * as inst from './instrumentation-versions'; + +/** + * Interface for environment extensions. + */ +export interface EnvironmentExtension { + /** + * The name of the environment variable. + */ + readonly name: string; + /** + * The value of the environment variable. + */ + readonly value: string; +} + +/** + * Injector is a base class for all SDK injects to mutate the task definition + * to inject the ADOT init container and configure the application container with + * the necessary environment variables. + */ +export abstract class Injector { + private static readonly DEFAULT_ENVS: EnvironmentExtension[] = [ + { + name: constants.LogsExporting.OTEL_LOGS_EXPORTER, + value: constants.LogsExporting.OTEL_LOGS_EXPORTER_NONE, + }, + { + name: constants.MetricsExporting.OTEL_METRICS_EXPORTER, + value: constants.MetricsExporting.OTEL_METRICS_EXPORTER_NONE, + }, + { + name: constants.CommonExporting.OTEL_EXPORTER_OTLP_PROTOCOL, + value: constants.CommonExporting.OTEL_EXPORTER_OTLP_PROTOCOL_HTTP_PROTOBUF, + }, + { + name: constants.CommonExporting.OTEL_AWS_APPLICATION_SIGNALS, + value: constants.CommonExporting.OTEL_AWS_APPLICATION_SIGNALS_ENABLED, + }, + { + name: constants.CommonExporting.OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT, + value: constants.CommonExporting.OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT_LOCAL_CWA, + }, + { + name: constants.TraceExporting.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, + value: constants.TraceExporting.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT_LOCAL_CWA, + }, + { + name: constants.TraceExporting.OTEL_TRACES_SAMPLER, + value: constants.TraceExporting.OTEL_TRACES_SAMPLER_XRAY, + }, + { + name: constants.TraceExporting.OTEL_TRACES_SAMPLER_ARG, + value: constants.TraceExporting.OTEL_TRACES_SAMPLER_ARG_LOCAL_CWA, + }, + { + name: constants.TraceExporting.OTEL_PROPAGATORS, + value: constants.TraceExporting.OTEL_PROPAGATORS_APPLICATION_SIGNALS, + }, + ]; + + protected taskDefinition: ecs.TaskDefinition; + protected sharedVolumeName: string; + protected instrumentationVersion: inst.InstrumentationVersion; + private overrideEnvironments?: EnvironmentExtension[]; + + public constructor( + taskDefinition: ecs.TaskDefinition, + sharedVolumeName: string, + instrumentationVersion: inst.InstrumentationVersion, + overrideEnvironments?: EnvironmentExtension[]) { + this.taskDefinition = taskDefinition; + this.sharedVolumeName = sharedVolumeName; + this.instrumentationVersion = instrumentationVersion; + this.overrideEnvironments = overrideEnvironments; + } + + /** + * The command to run the init container. + */ + abstract get command(): string[]; + /** + * The path to ADOT SDK agent in the init container. + */ + protected abstract get containerPath(): string; + /** + * Inject additional environment variables to the application container other than the DEFAULT_ENVS. + */ + protected abstract injectAdditionalEnvironments(envsToInject: { [key: string]: string }, envsFromTaskDef: { [key: string]: string }): void; + /** + * Override environment variables in the application container. + */ + protected abstract overrideAdditionalEnvironments(envsToOverride: { [key: string]: string }, envsFromTaskDef: { [key: string]: string }): void; + + /** + * Inject ADOT SDK agent init container. + * @returns The created ContainerDefinition + */ + public injectInitContainer(): ecs.ContainerDefinition { + const initContainer = this.taskDefinition.addContainer('adot-init', { + image: ecs.ContainerImage.fromRegistry(this.instrumentationVersion.imageURI()), + essential: false, + command: this.command, + cpu: 0, + memoryLimitMiB: this.instrumentationVersion.memoryLimitMiB(), + }); + initContainer.addMountPoints({ + sourceVolume: this.sharedVolumeName, + containerPath: this.containerPath, + // double check + readOnly: false, + }); + return initContainer; + } + + /** + * Render the application container for SDK instrumentation. + * @param container The application container + */ + public renderDefaultContainer(container: ecs.ContainerDefinition): void { + const envsToInject: { [key: string]: string } = {}; + const envsFromTaskDef = (container as any).environment; + + for (const env of Injector.DEFAULT_ENVS) { + envsToInject[env.name] = env.value; + } + this.injectAdditionalEnvironments(envsToInject, envsFromTaskDef); + + const envsToOverride: { [key: string]: string } = {}; + this.overrideAdditionalEnvironments(envsToOverride, envsFromTaskDef); + + for (const [key, value] of Object.entries(envsToInject)) { + if (!envsFromTaskDef[key]) { + container.addEnvironment(key, value); + } + } + + for (const [key, value] of Object.entries(envsToOverride)) { + container.addEnvironment(key, value); + } + for (const env of this.overrideEnvironments ?? []) { + container.addEnvironment(env.name, env.value); + } + + container.addMountPoints({ + sourceVolume: this.sharedVolumeName, + containerPath: this.containerPath, + // double check + readOnly: false, + }); + } +} + +/** + * Java-specific implementation of the SDK injector. + * Handles Java agent configuration and environment setup. + */ +export class JavaInjector extends Injector { + private static readonly JAVA_ENVS = [ + { + name: constants.JavaInstrumentation.JAVA_TOOL_OPTIONS, + value: constants.JavaInstrumentation.JAVA_TOOL_OPTIONS_ADOT, + }, + ]; + + get command(): string[] { + return ['cp', '/javaagent.jar', `${this.containerPath}/javaagent.jar`]; + } + + protected get containerPath(): string { + return '/otel-auto-instrumentation'; + } + + protected injectAdditionalEnvironments(envsToInject: { [key: string]: string }, _envsFromTaskDef: { [key: string]: string }): void { + for (const env of JavaInjector.JAVA_ENVS) { + envsToInject[env.name] = env.value; + } + } + + protected overrideAdditionalEnvironments(_envsToOverride: { [key: string]: string }, _overrideEnvironments: { [key: string]: string }): void { + // No additional overrides needed for Java + } +} + +/** + * Python-specific implementation of the SDK injector. + * Handles Python auto-instrumentation setup and PYTHONPATH configuration. + */ +export class PythonInjector extends Injector { + private static readonly PYTHON_ENVS = [ + { + name: constants.PythonInstrumentation.OTEL_PYTHON_DISTRO, + value: constants.PythonInstrumentation.OTEL_PYTHON_DISTRO_AWS_DISTRO, + }, + { + name: constants.PythonInstrumentation.OTEL_PYTHON_CONFIGURATOR, + value: constants.PythonInstrumentation.OTEL_PYTHON_CONFIGURATOR_AWS_CONFIGURATOR, + }, + { + name: constants.PythonInstrumentation.PYTHONPATH, + value: constants.PythonInstrumentation.PYTHONPATH_ADOT, + }, + ]; + get command(): string[] { + return ['cp', '-a', '/autoinstrumentation/.', this.containerPath]; + } + + protected injectAdditionalEnvironments(envsToInject: { [key: string]: string }, _envsFromTaskDef: { [key: string]: string }): void { + for (const env of PythonInjector.PYTHON_ENVS) { + envsToInject[env.name] = env.value; + } + } + + protected get containerPath(): string { + return '/otel-auto-instrumentation-python'; + } + + protected overrideAdditionalEnvironments(envsToOverride: { [key: string]: string }, envsFromTaskDef: { [key: string]: string }): void { + if (envsFromTaskDef[constants.PythonInstrumentation.PYTHONPATH]) { + const pythonPath = envsFromTaskDef[constants.PythonInstrumentation.PYTHONPATH]; + envsToOverride[constants.PythonInstrumentation.PYTHONPATH] = `${this.containerPath}/opentelemetry/instrumentation/auto_instrumentation:${pythonPath}:${this.containerPath}`; + } + } +} + +/** + * Base class for .NET SDK injectors. + * Contains common .NET configuration settings used by both Windows and Linux implementations. + */ +export abstract class DotNetInjector extends Injector { + protected static readonly DOTNET_COMMON_ENVS: EnvironmentExtension[] = [ + { + name: constants.DotnetInstrumentation.OTEL_DOTNET_DISTRO, + value: constants.DotnetInstrumentation.OTEL_DOTNET_DISTRO_AWS_DISTRO, + }, + { + name: constants.DotnetInstrumentation.OTEL_DOTNET_CONFIGURATOR, + value: constants.DotnetInstrumentation.OTEL_DOTNET_CONFIGURATOR_AWS_CONFIGURATOR, + }, + { + name: constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_PLUGINS, + value: constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_PLUGINS_ADOT, + }, + ]; +} + +/** + * Linux-specific implementation of the .NET SDK injector. + * Handles CoreCLR profiler setup and paths for Linux environments. + */ +export class DotNetLinuxInjector extends DotNetInjector { + private static readonly DOTNET_LINUX_ENVS = [ + { + name: constants.DotnetInstrumentation.CORECLR_ENABLE_PROFILING, + value: constants.DotnetInstrumentation.CORECLR_ENABLE_PROFILING_ENABLED, + }, + { + name: constants.DotnetInstrumentation.CORECLR_PROFILER, + value: constants.DotnetInstrumentation.CORECLR_PROFILER_OTEL, + }, + { + name: constants.DotnetInstrumentation.CORECLR_PROFILER_PATH, + value: constants.DotnetInstrumentation.CORECLR_PROFILER_PATH_LINUX_X64, + }, + { + name: constants.DotnetInstrumentation.DOTNET_STARTUP_HOOKS, + value: constants.DotnetInstrumentation.DOTNET_STARTUP_HOOKS_LINUX_ADOT, + }, + { + name: constants.DotnetInstrumentation.DOTNET_ADDITIONAL_DEPS, + value: constants.DotnetInstrumentation.DOTNET_ADDITIONAL_DEPS_LINUX_ADOT, + }, + { + name: constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_HOME, + value: constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_HOME_LINUX_ADOT, + }, + { + name: constants.DotnetInstrumentation.DOTNET_SHARED_STORE, + value: constants.DotnetInstrumentation.DOTNET_SHARED_STORE_LINUX_ADOT, + }, + ]; + + private cpuArch: ecs.CpuArchitecture; + + constructor( + taskDefinition: ecs.TaskDefinition, + sharedVolumeName: string, + instrumentationVersion: inst.InstrumentationVersion, + cpuArch: ecs.CpuArchitecture, + overrideEnvironments?: EnvironmentExtension[]) { + super(taskDefinition, sharedVolumeName, instrumentationVersion, overrideEnvironments); + this.cpuArch = cpuArch; + } + + get command(): string[] { + return ['cp', '-a', '/autoinstrumentation/.', this.containerPath]; + } + + protected injectAdditionalEnvironments(envsToInject: { [key: string]: string }, envsFromTaskDef: { [key: string]: string }): void { + let libPath = 'linux-x64'; + if (this.cpuArch == ecs.CpuArchitecture.ARM64) { + libPath = 'linux-arm64'; + } + for (const env of [...DotNetInjector.DOTNET_COMMON_ENVS, { + name: 'CORECLR_PROFILER_PATH', + value: `${this.containerPath}/${libPath}/OpenTelemetry.AutoInstrumentation.Native.so`, + }]) { + envsToInject[env.name] = env.value; + } + + if (envsFromTaskDef[constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_HOME]) { + // If OTEL_DOTNET_AUTO_HOME env var is already set, we will assume that .NET Auto-instrumentation is already configured. + return; + } + + for (const env of DotNetLinuxInjector.DOTNET_LINUX_ENVS) { + envsToInject[env.name] = env.value; + } + } + + protected get containerPath(): string { + return '/otel-auto-instrumentation-dotnet'; + } + + protected overrideAdditionalEnvironments(_envsToOverride: { [key: string]: string }, _envsFromTaskDef: { [key: string]: string }): void { + // No additional overrides needed for .NET on Linux + } +} + +/** + * Windows-specific implementation of the .NET SDK injector. + * Handles CoreCLR profiler setup and paths for Windows environments. + */ +export class DotNetWindowsInjector extends DotNetInjector { + private static readonly DOTNET_WINDOWS_ENVS = [ + { + name: constants.DotnetInstrumentation.CORECLR_ENABLE_PROFILING, + value: constants.DotnetInstrumentation.CORECLR_ENABLE_PROFILING_ENABLED, + }, + { + name: constants.DotnetInstrumentation.CORECLR_PROFILER, + value: constants.DotnetInstrumentation.CORECLR_PROFILER_OTEL, + }, + { + name: constants.DotnetInstrumentation.CORECLR_PROFILER_PATH, + value: constants.DotnetInstrumentation.CORECLR_PROFILER_PATH_WINDOWS_X64, + }, + { + name: constants.DotnetInstrumentation.DOTNET_STARTUP_HOOKS, + value: constants.DotnetInstrumentation.DOTNET_STARTUP_HOOKS_WINDOWS_ADOT, + }, + { + name: constants.DotnetInstrumentation.DOTNET_ADDITIONAL_DEPS, + value: constants.DotnetInstrumentation.DOTNET_ADDITIONAL_DEPS_WINDOWS_ADOT, + }, + { + name: constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_HOME, + value: constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_HOME_WINDOWS_ADOT, + }, + { + name: constants.DotnetInstrumentation.DOTNET_SHARED_STORE, + value: constants.DotnetInstrumentation.DOTNET_SHARED_STORE_WINDOWS_ADOT, + }, + ]; + + get command(): string[] { + return ['CMD', + '/c', + 'xcopy', + '/e', + 'C:\\autoinstrumentation\\*', + 'C:\\otel-auto-instrumentation-dotnet', + '&&', + 'icacls', + 'C:\\otel-auto-instrumentation-dotnet', + '/grant', + '*S-1-1-0:R', + '/T']; + } + + protected injectAdditionalEnvironments(envsToInject: { [key: string]: string }, envsFromTaskDef: { [key: string]: string }): void { + for (const env of DotNetInjector.DOTNET_COMMON_ENVS) { + envsToInject[env.name] = env.value; + } + if (envsFromTaskDef[constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_HOME]) { + // If OTEL_DOTNET_AUTO_HOME env var is already set, we will assume that .NET Auto-instrumentation is already configured. + return; + } + for (const env of DotNetWindowsInjector.DOTNET_WINDOWS_ENVS) { + envsToInject[env.name] = env.value; + } + } + + protected get containerPath(): string { + return 'C:\\otel-auto-instrumentation-dotnet'; + } + + protected overrideAdditionalEnvironments(_envsToOverride: { [key: string]: string }, _envsFromTaskDef: { [key: string]: string }): void { + // No additional overrides needed for .NET on Windows + } +} + +/** + * Node.js-specific implementation of the SDK injector. + * Handles Node.js auto-instrumentation setup and NODE_OPTIONS configuration. + */ +export class NodeInjector extends Injector { + get command(): string[] { + return ['cp', '-a', '/autoinstrumentation/.', this.containerPath]; + } + + protected injectAdditionalEnvironments(envsToInject: { [key: string]: string }, _envsFromTaskDef: { [key: string]: string }): void { + envsToInject[constants.NodeInstrumentation.NODE_OPTIONS] = ` --require ${this.containerPath}/autoinstrumentation.js`; + } + + protected get containerPath(): string { + return '/otel-auto-instrumentation-nodejs'; + } + + protected overrideAdditionalEnvironments(envsToOverride: { [key: string]: string }, envsFromTaskDef: { [key: string]: string }): void { + if (envsFromTaskDef[constants.NodeInstrumentation.NODE_OPTIONS]) { + const originalNodeOptions = envsFromTaskDef[constants.NodeInstrumentation.NODE_OPTIONS] ?? ''; + let renderedNodeOptions = `${originalNodeOptions} --require ${this.containerPath}/autoinstrumentation.js`; + envsToOverride[constants.NodeInstrumentation.NODE_OPTIONS] = renderedNodeOptions; + } + } +} diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/ecs.ts b/packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/ecs.ts index a6e82cc9eb1db..7bd44c42d0c87 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/ecs.ts +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/ecs.ts @@ -2,115 +2,9 @@ import * as ecs from 'aws-cdk-lib/aws-ecs'; import { ManagedPolicy } from 'aws-cdk-lib/aws-iam'; import { Construct } from 'constructs'; import * as constants from './constants'; - -/** - * Base class for instrumentation versions. - * Provides functionality to generate image URIs for different instrumentation types. - */ -export abstract class InstrumentationVersion { - public constructor(protected readonly imageRepo: string, protected readonly version: string) { } - - /** - * Get the image URI for the instrumentation version. - * @returns The image URI. - */ - public imageURI(): string { - return `${this.imageRepo}:${this.version}`; - } -} - -/** - * Available versions for Java instrumentation. - */ -export class JavaInstrumentationVersion extends InstrumentationVersion { - /** - * The image repository for Java instrumentation. - */ - public static readonly IMAGE_REPO = 'public.ecr.aws/aws-observability/adot-autoinstrumentation-java'; - /** - * ADOT Java Instrumentation version 1.33.0 - */ - public static readonly V1_33_0 = new JavaInstrumentationVersion(JavaInstrumentationVersion.IMAGE_REPO, 'v1.33.0'); - /** - * ADOT Java Instrumentation version 1.32.6 - */ - public static readonly V1_32_6 = new JavaInstrumentationVersion(JavaInstrumentationVersion.IMAGE_REPO, 'v1.32.6'); -} - -/** - * Available versions for .NET instrumentation. - */ -/** - * Available versions for Python instrumentation. - */ -export class PythonInstrumentationVersion extends InstrumentationVersion { - /** - * The image repository for Python instrumentation. - */ - public static readonly IMAGE_REPO = 'public.ecr.aws/aws-observability/adot-autoinstrumentation-python'; - /** - * ADOT Python Instrumentation version 0.8.0 - */ - public static readonly V0_8_0 = new PythonInstrumentationVersion(PythonInstrumentationVersion.IMAGE_REPO, 'v0.8.0'); -} - -/** - * Available versions for .NET instrumentation. - */ -export class DotnetInstrumentationVersion extends InstrumentationVersion { - /** - * The image repository for .NET instrumentation. - */ - public static readonly IMAGE_REPO = 'public.ecr.aws/aws-observability/adot-autoinstrumentation-dotnet'; - /** - * ADOT .NET Instrumentation version 1.6.0 - */ - public static readonly V1_6_0 = new DotnetInstrumentationVersion(DotnetInstrumentationVersion.IMAGE_REPO, 'v1.6.0'); - /** - * ADOT .NET Instrumentation version 1.6.0 for ARM64 - */ - public static readonly V1_6_0_ARM64 = new DotnetInstrumentationVersion(DotnetInstrumentationVersion.IMAGE_REPO, 'v1.6.0-arm64'); - /** - * ADOT .NET Instrumentation version 1.6.0 for AMD64 - */ - public static readonly V1_6_0_AMD64 = new DotnetInstrumentationVersion(DotnetInstrumentationVersion.IMAGE_REPO, 'v1.6.0-amd64'); - /** - * ADOT .NET Instrumentation version 1.6.0 for Windows 2022 - */ - public static readonly V1_6_0_WINDOWS2022 = new DotnetInstrumentationVersion(DotnetInstrumentationVersion.IMAGE_REPO, 'v1.6.0-windows2022'); - /** - * ADOT .NET Instrumentation version 1.6.0 for Windows 2019 - */ - public static readonly V1_6_0_WINDOWS2019 = new DotnetInstrumentationVersion(DotnetInstrumentationVersion.IMAGE_REPO, 'v1.6.0-windows2019'); -} - -/** - * Available versions for Node.js instrumentation. - */ -export class NodeInstrumentationVersion extends InstrumentationVersion { - /** - * The image repository for Node.js instrumentation. - */ - public static readonly IMAGE_REPO = 'public.ecr.aws/aws-observability/adot-autoinstrumentation-node'; - /** - * ADOT Node.js Instrumentation version 0.5.0 - */ - public static readonly V0_5_0 = new NodeInstrumentationVersion(NodeInstrumentationVersion.IMAGE_REPO, 'v0.5.0'); -} - -/** - * Interface for environment extensions. - */ -export interface EnvironmentExtension { - /** - * The name of the environment variable. - */ - readonly name: string; - /** - * The value of the environment variable. - */ - readonly value: string; -} +import * as agent from './ecs-cloudwatch-agent'; +import * as sdk from './ecs-sdk-instrumentation'; +import * as inst from './instrumentation-versions'; /** * Interface for instrumentation properties. @@ -119,7 +13,7 @@ export interface InstrumentationProps { /** * The version of the instrumentation. */ - readonly sdkVersion: InstrumentationVersion; + readonly sdkVersion: inst.InstrumentationVersion; /** * The runtime platform of the instrumentation. * @@ -157,480 +51,23 @@ export interface ApplicationSignalsIntegrationProps { * * @default - no environment variables to override. */ - readonly overrideEnvironments?: EnvironmentExtension[]; + readonly overrideEnvironments?: sdk.EnvironmentExtension[]; /** * The CloudWatch Agent properties. * * @default - a basic agent sidecar container with latest public image */ - readonly cloudWatchAgent?: CloudWatchAgentProps; -} - -/** - * Interface for CloudWatch Agent properties. - */ -export interface CloudWatchAgentProps { - - /** - * The name of the CloudWatch Agent container. - * - * @default - cloudwatch-agent - */ - readonly containerName?: string; - - /** - * Whether to enable the CloudWatch Agent sidecar. - * - * @default - true - */ - readonly enableSidecar: boolean; - - /** - * The container definition options for the CloudWatch Agent. - * - * @default - a basic CloudWatch Agent container with latest public image. - */ - readonly container?: ecs.ContainerDefinitionOptions; + readonly cloudWatchAgentSidecar?: agent.CloudWatchAgentOptions; } -const DEFAULT_CONTAINER_NAME = 'cloudwatch-agent'; - -/** - * SDKInject is a base class for all SDK injects to mutate the task definition - * to inject the ADOT init container and configure the application container with - * the necessary environment variables. - */ -abstract class SDKInject { - - private static readonly DEFAULT_ENVS = [ - { - name: constants.LogsExporting.OTEL_LOGS_EXPORTER, - value: constants.LogsExporting.OTEL_LOGS_EXPORTER_NONE, - }, - { - name: constants.MetricsExporting.OTEL_METRICS_EXPORTER, - value: constants.MetricsExporting.OTEL_METRICS_EXPORTER_NONE, - }, - { - name: constants.CommonExporting.OTEL_EXPORTER_OTLP_PROTOCOL, - value: constants.CommonExporting.OTEL_EXPORTER_OTLP_PROTOCOL_HTTP_PROTOBUF, - }, - { - name: constants.CommonExporting.OTEL_AWS_APPLICATION_SIGNALS, - value: constants.CommonExporting.OTEL_AWS_APPLICATION_SIGNALS_ENABLED, - }, - { - name: constants.CommonExporting.OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT, - value: constants.CommonExporting.OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT_LOCAL_CWA, - }, - { - name: constants.TraceExporting.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, - value: constants.TraceExporting.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT_LOCAL_CWA, - }, - { - name: constants.TraceExporting.OTEL_TRACES_SAMPLER, - value: constants.TraceExporting.OTEL_TRACES_SAMPLER_XRAY, - }, - { - name: constants.TraceExporting.OTEL_TRACES_SAMPLER_ARG, - value: constants.TraceExporting.OTEL_TRACES_SAMPLER_ARG_LOCAL_CWA, - }, - { - name: constants.TraceExporting.OTEL_PROPAGATORS, - value: constants.TraceExporting.OTEL_PROPAGATORS_APPLICATION_SIGNALS, - }, - ]; - - protected taskDefinition: ecs.TaskDefinition; - protected sharedVolumeName: string; - protected adotImage: string; - private overrideEnvironments?: EnvironmentExtension[]; - - constructor( - taskDefinition: ecs.TaskDefinition, - sharedVolumeName: string, - adotImage: string, - overrideEnvironments?: EnvironmentExtension[]) { - this.taskDefinition = taskDefinition; - this.sharedVolumeName = sharedVolumeName; - this.adotImage = adotImage; - this.overrideEnvironments = overrideEnvironments; - } - - /** - * The command to run the init container. - */ - abstract get command(): string[]; - /** - * The memory limit for the init container. - */ - abstract get memoryLimitMiB(): number; - /** - * The path to ADOT SDK agent in the init container. - */ - protected abstract get containerPath(): string; - /** - * Inject additional environment variables to the application container - * other than the DEFAULT_ENVS. - */ - protected abstract injectAdditionalEnvironments(envsToInject: { [key: string]: string }, envsFromTaskDef: { [key: string]: string }): void; - /** - * Override additional environment variables to the application container - * other than the DEFAULT_ENVS. - */ - protected abstract overrideAdditionalEnvironments(envsToOverride: { [key: string]: string }, envsFromTaskDef: { [key: string]: string }): void; - - public injectInitContainer(): ecs.ContainerDefinition { - const initContainer = this.taskDefinition.addContainer('adot-init', { - image: ecs.ContainerImage.fromRegistry(this.adotImage), - essential: false, - command: this.command, - cpu: 0, - memoryLimitMiB: this.memoryLimitMiB, - }); - initContainer.addMountPoints({ - sourceVolume: this.sharedVolumeName, - containerPath: this.containerPath, - // double check - readOnly: false, - }); - return initContainer; - } - - public renderDefaultContainer(container: ecs.ContainerDefinition) { - const envsToInject: { [key: string]: string } = {}; - const envsFromTaskDef = (container as any).environment; - - for (const env of SDKInject.DEFAULT_ENVS) { - envsToInject[env.name] = env.value; - } - this.injectAdditionalEnvironments(envsToInject, envsFromTaskDef); - - const envsToOverride: { [key: string]: string } = {}; - this.overrideAdditionalEnvironments(envsToOverride, envsFromTaskDef); - - for (const [key, value] of Object.entries(envsToInject)) { - if (!envsFromTaskDef[key]) { - container.addEnvironment(key, value); - } - } - - for (const [key, value] of Object.entries(envsToOverride)) { - container.addEnvironment(key, value); - } - for (const env of this.overrideEnvironments ?? []) { - container.addEnvironment(env.name, env.value); - } - - container.addMountPoints({ - sourceVolume: this.sharedVolumeName, - containerPath: this.containerPath, - // double check - readOnly: false, - }); - } -} - -class JavaSDKInject extends SDKInject { - private static readonly JAVA_ENVS = [ - { - name: constants.JavaInstrumentation.JAVA_TOOL_OPTIONS, - value: constants.JavaInstrumentation.JAVA_TOOL_OPTIONS_ADOT, - }, - ]; - - get command(): string[] { - return ['cp', '/javaagent.jar', '/otel-auto-instrumentation/javaagent.jar']; - } - - get memoryLimitMiB(): number { - return 64; - } - - protected get containerPath(): string { - return '/otel-auto-instrumentation'; - } - - protected injectAdditionalEnvironments(envs: { [key: string]: string }) { - for (const env of JavaSDKInject.JAVA_ENVS) { - envs[env.name] = env.value; - } - } - - protected overrideAdditionalEnvironments(_envsToOverride: { [key: string]: string }, _overrideEnvironments: { [key: string]: string }): void { - // No additional overrides needed for Java - } -} - -class PythonSDKInject extends SDKInject { - private static readonly PYTHON_ENVS = [ - { - name: constants.PythonInstrumentation.OTEL_PYTHON_DISTRO, - value: constants.PythonInstrumentation.OTEL_PYTHON_DISTRO_AWS_DISTRO, - }, - { - name: constants.PythonInstrumentation.OTEL_PYTHON_CONFIGURATOR, - value: constants.PythonInstrumentation.OTEL_PYTHON_CONFIGURATOR_AWS_CONFIGURATOR, - }, - { - name: constants.PythonInstrumentation.PYTHONPATH, - value: constants.PythonInstrumentation.PYTHONPATH_ADOT, - }, - ]; - get command(): string[] { - return ['cp', '-a', '/autoinstrumentation/.', '/otel-auto-instrumentation-python']; - } - - get memoryLimitMiB(): number { - return 32; - } - - public injectAdditionalEnvironments(envsToInject: { [key: string]: string }, envsFromTaskDef: { [key: string]: string }): void { - for (const env of PythonSDKInject.PYTHON_ENVS) { - envsToInject[env.name] = env.value; - if (!envsFromTaskDef[env.name]) { - envsToInject[env.name] = env.value; - } - } - } - - protected get containerPath(): string { - return '/otel-auto-instrumentation-python'; - } - - protected overrideAdditionalEnvironments(envsToOverride: { [key: string]: string }, envsFromTaskDef: { [key: string]: string }): void { - if (envsFromTaskDef[constants.PythonInstrumentation.PYTHONPATH]) { - const pythonPath = envsFromTaskDef[constants.PythonInstrumentation.PYTHONPATH]; - envsToOverride[constants.PythonInstrumentation.PYTHONPATH] = `/otel-auto-instrumentation-python/opentelemetry/instrumentation/auto_instrumentation:${pythonPath}:/otel-auto-instrumentation-python`; - } - } -} - -abstract class DotNetSDKInject extends SDKInject { - protected static readonly DOTNET_COMMON_ENVS = [ - { - name: constants.DotnetInstrumentation.OTEL_DOTNET_DISTRO, - value: constants.DotnetInstrumentation.OTEL_DOTNET_DISTRO_AWS_DISTRO, - }, - { - name: constants.DotnetInstrumentation.OTEL_DOTNET_CONFIGURATOR, - value: constants.DotnetInstrumentation.OTEL_DOTNET_CONFIGURATOR_AWS_CONFIGURATOR, - }, - { - name: constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_PLUGINS, - value: constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_PLUGINS_ADOT, - }, - ]; -} -class DotNetSDKOnLinuxInject extends DotNetSDKInject { - private static readonly DOTNET_LINUX_ENVS = [ - { - name: constants.DotnetInstrumentation.CORECLR_ENABLE_PROFILING, - value: constants.DotnetInstrumentation.CORECLR_ENABLE_PROFILING_ENABLED, - }, - { - name: constants.DotnetInstrumentation.CORECLR_PROFILER, - value: constants.DotnetInstrumentation.CORECLR_PROFILER_OTEL, - }, - { - name: constants.DotnetInstrumentation.CORECLR_PROFILER_PATH, - value: constants.DotnetInstrumentation.CORECLR_PROFILER_PATH_LINUX_X64, - }, - { - name: constants.DotnetInstrumentation.DOTNET_STARTUP_HOOKS, - value: constants.DotnetInstrumentation.DOTNET_STARTUP_HOOKS_LINUX_ADOT, - }, - { - name: constants.DotnetInstrumentation.DOTNET_ADDITIONAL_DEPS, - value: constants.DotnetInstrumentation.DOTNET_ADDITIONAL_DEPS_LINUX_ADOT, - }, - { - name: constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_HOME, - value: constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_HOME_LINUX_ADOT, - }, - { - name: constants.DotnetInstrumentation.DOTNET_SHARED_STORE, - value: constants.DotnetInstrumentation.DOTNET_SHARED_STORE_LINUX_ADOT, - }, - ]; - - private cpuArch: ecs.CpuArchitecture; - - constructor( - taskDefinition: ecs.TaskDefinition, - sharedVolumeName: string, - adotImage: string, - cpuArch: ecs.CpuArchitecture, - overrideEnvironments?: EnvironmentExtension[]) { - super(taskDefinition, sharedVolumeName, adotImage, overrideEnvironments); - this.cpuArch = cpuArch; - } - - get command(): string[] { - return ['cp', '-a', '/autoinstrumentation/.', '/otel-auto-instrumentation-dotnet']; - } - - get memoryLimitMiB(): number { - return 128; - } - - public injectAdditionalEnvironments(envsToInject: { [key: string]: string }, envsFromTaskDef: { [key: string]: string }): void { - let libPath = 'linux-x64'; - if (this.cpuArch == ecs.CpuArchitecture.ARM64) { - libPath = 'linux-arm64'; - } - for (const env of [...DotNetSDKInject.DOTNET_COMMON_ENVS, { - name: 'CORECLR_PROFILER_PATH', - value: `/otel-auto-instrumentation-dotnet/${libPath}/OpenTelemetry.AutoInstrumentation.Native.so`, - }]) { - envsToInject[env.name] = env.value; - } - - if (envsFromTaskDef[constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_HOME]) { - // If OTEL_DOTNET_AUTO_HOME env var is already set, we will assume that .NET Auto-instrumentation is already configured. - return; - } - - for (const env of DotNetSDKOnLinuxInject.DOTNET_LINUX_ENVS) { - envsToInject[env.name] = env.value; - } - } - - protected get containerPath(): string { - return '/otel-auto-instrumentation-dotnet'; - } - - protected overrideAdditionalEnvironments(_envsToOverride: { [key: string]: string }, _envsFromTaskDef: { [key: string]: string }): void { - // No additional overrides needed for .NET on Linux - } -} - -class DotNetSDKOnWindowsInject extends DotNetSDKInject { - private static readonly DOTNET_WINDOWS_ENVS = [ - { - name: constants.DotnetInstrumentation.CORECLR_ENABLE_PROFILING, - value: constants.DotnetInstrumentation.CORECLR_ENABLE_PROFILING_ENABLED, - }, - { - name: constants.DotnetInstrumentation.CORECLR_PROFILER, - value: constants.DotnetInstrumentation.CORECLR_PROFILER_OTEL, - }, - { - name: constants.DotnetInstrumentation.CORECLR_PROFILER_PATH, - value: constants.DotnetInstrumentation.CORECLR_PROFILER_PATH_WINDOWS_X64, - }, - { - name: constants.DotnetInstrumentation.DOTNET_STARTUP_HOOKS, - value: constants.DotnetInstrumentation.DOTNET_STARTUP_HOOKS_WINDOWS_ADOT, - }, - { - name: constants.DotnetInstrumentation.DOTNET_ADDITIONAL_DEPS, - value: constants.DotnetInstrumentation.DOTNET_ADDITIONAL_DEPS_WINDOWS_ADOT, - }, - { - name: constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_HOME, - value: constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_HOME_WINDOWS_ADOT, - }, - { - name: constants.DotnetInstrumentation.DOTNET_SHARED_STORE, - value: constants.DotnetInstrumentation.DOTNET_SHARED_STORE_WINDOWS_ADOT, - }, - ]; - - get command(): string[] { - return ['CMD', - '/c', - 'xcopy', - '/e', - 'C:\\autoinstrumentation\\*', - 'C:\\otel-auto-instrumentation-dotnet', - '&&', - 'icacls', - 'C:\\otel-auto-instrumentation-dotnet', - '/grant', - '*S-1-1-0:R', - '/T']; - } - - get memoryLimitMiB(): number { - return 128; - } - - public injectAdditionalEnvironments(envsToInject: { [key: string]: string }, envsFromTaskDef: { [key: string]: string }): void { - for (const env of DotNetSDKInject.DOTNET_COMMON_ENVS) { - envsToInject[env.name] = env.value; - } - if (envsFromTaskDef[constants.DotnetInstrumentation.OTEL_DOTNET_AUTO_HOME]) { - // If OTEL_DOTNET_AUTO_HOME env var is already set, we will assume that .NET Auto-instrumentation is already configured. - return; - } - for (const env of DotNetSDKOnWindowsInject.DOTNET_WINDOWS_ENVS) { - envsToInject[env.name] = env.value; - } - } - - protected get containerPath(): string { - return 'C:\\otel-auto-instrumentation-dotnet'; - } - - protected overrideAdditionalEnvironments(_envsToOverride: { [key: string]: string }, _envsFromTaskDef: { [key: string]: string }): void { - // No additional overrides needed for .NET on Windows - } -} - -class NodeSDKInject extends SDKInject { - get command(): string[] { - return ['cp', '-a', '/autoinstrumentation/.', '/otel-auto-instrumentation-nodejs']; - } - - get memoryLimitMiB(): number { - return 128; - } - - public injectAdditionalEnvironments(envsToInject: { [key: string]: string }, _envsFromTaskDef: { [key: string]: string }): void { - envsToInject[constants.NodeInstrumentation.NODE_OPTIONS] = ' --require /otel-auto-instrumentation-nodejs/autoinstrumentation.js'; - } - - protected get containerPath(): string { - return '/otel-auto-instrumentation-nodejs'; - } - - protected overrideAdditionalEnvironments(envsToOverride: { [key: string]: string }, envsFromTaskDef: { [key: string]: string }): void { - if (envsFromTaskDef[constants.NodeInstrumentation.NODE_OPTIONS]) { - const originalNodeOptions = envsFromTaskDef[constants.NodeInstrumentation.NODE_OPTIONS] ?? ''; - let renderedNodeOptions = `${originalNodeOptions} --require /otel-auto-instrumentation-nodejs/autoinstrumentation.js`; - envsToOverride[constants.NodeInstrumentation.NODE_OPTIONS] = renderedNodeOptions; - } - } -} - -const CLOUDWATCH_AGENT_IMAGE = 'amazon/cloudwatch-agent:latest'; -const CLOUDWATCH_AGENT_IMAGE_WIN2019 = 'public.ecr.aws/cloudwatch-agent/cloudwatch-agent:latest-windowsservercore2019'; -const CLOUDWATCH_AGENT_IMAGE_WIN2022 = 'public.ecr.aws/cloudwatch-agent/cloudwatch-agent:latest-windowsservercore2022'; -const CW_CONFIG_CONTENT = { - logs: { - metrics_collected: { - application_signals: { - enabled: true, - }, - }, - }, - traces: { - traces_collected: { - application_signals: { - enabled: true, - }, - }, - }, -}; - /** * Class for integrating Application Signals into an ECS task definition. */ export class ApplicationSignalsIntegration extends Construct { - private sdkInject?: SDKInject; + private sdkInjector?: sdk.Injector; private mountVolumeName: string = 'opentelemetry-auto-instrumentation'; + private cloudWatchAgentSidecar?: agent.CloudWatchAgentOptions; constructor( scope: Construct, @@ -642,13 +79,12 @@ export class ApplicationSignalsIntegration extends Construct { serviceName = props.taskDefinition.family; } - let overrideEnvironments: EnvironmentExtension[] = [{ - name: constants.CommonExporting.OTEL_RESOURCE_ATTRIBUTES, - value: `service.name=${serviceName}`, - }]; + if (props.taskDefinition.compatibility === ecs.Compatibility.FARGATE && !props.cloudWatchAgentSidecar) { + throw new Error('Fargate tasks must deploy CloudWatch Agent as a sidecar container'); + } + this.cloudWatchAgentSidecar = props.cloudWatchAgentSidecar; let runtimePlatformObj = props.instrumentation.runtimePlatform ?? (props.taskDefinition as any).runtimePlatform; - let cloudWatchAgentImage = CLOUDWATCH_AGENT_IMAGE; let cpuArch = ecs.CpuArchitecture.X86_64; let isWindows = false; @@ -656,126 +92,87 @@ export class ApplicationSignalsIntegration extends Construct { const runtimePlatform = runtimePlatformObj as ecs.RuntimePlatform; if (runtimePlatform.operatingSystemFamily) { isWindows = runtimePlatform.operatingSystemFamily.isWindows(); - - switch (runtimePlatform.operatingSystemFamily) { - case ecs.OperatingSystemFamily.WINDOWS_SERVER_2019_CORE: - case ecs.OperatingSystemFamily.WINDOWS_SERVER_2019_FULL: - cloudWatchAgentImage = CLOUDWATCH_AGENT_IMAGE_WIN2019; - break; - case ecs.OperatingSystemFamily.WINDOWS_SERVER_2022_CORE: - case ecs.OperatingSystemFamily.WINDOWS_SERVER_2022_FULL: - cloudWatchAgentImage = CLOUDWATCH_AGENT_IMAGE_WIN2022; - break; - } - if (runtimePlatform.cpuArchitecture) { cpuArch = runtimePlatform.cpuArchitecture; } } } - const cloudWatchAgentConfig = props.cloudWatchAgent ?? { enableSidecar: true, containerName: DEFAULT_CONTAINER_NAME }; - - if (props.taskDefinition.compatibility === ecs.Compatibility.FARGATE && !cloudWatchAgentConfig.enableSidecar) { - throw new Error('Fargate tasks must deploy CloudWatch Agent as a sidecar container'); - } - if (cloudWatchAgentConfig.enableSidecar) { - props.taskDefinition.taskRole.addManagedPolicy(ManagedPolicy.fromAwsManagedPolicyName('CloudWatchAgentServerPolicy')); - } - + let overrideEnvironments: sdk.EnvironmentExtension[] = [{ + name: constants.CommonExporting.OTEL_RESOURCE_ATTRIBUTES, + value: `service.name=${serviceName}`, + }]; overrideEnvironments.push(...props.overrideEnvironments ?? []); - if (props.instrumentation.sdkVersion instanceof JavaInstrumentationVersion) { - this.sdkInject = new JavaSDKInject( + if (props.instrumentation.sdkVersion instanceof inst.JavaInstrumentationVersion) { + this.sdkInjector = new sdk.JavaInjector( props.taskDefinition, this.mountVolumeName, - props.instrumentation.sdkVersion.imageURI(), + props.instrumentation.sdkVersion, overrideEnvironments, ); - } else if (props.instrumentation.sdkVersion instanceof PythonInstrumentationVersion) { - this.sdkInject = new PythonSDKInject( + } else if (props.instrumentation.sdkVersion instanceof inst.PythonInstrumentationVersion) { + this.sdkInjector = new sdk.PythonInjector( props.taskDefinition, this.mountVolumeName, - props.instrumentation.sdkVersion.imageURI(), + props.instrumentation.sdkVersion, overrideEnvironments, ); - } else if (props.instrumentation.sdkVersion instanceof DotnetInstrumentationVersion) { + } else if (props.instrumentation.sdkVersion instanceof inst.DotnetInstrumentationVersion) { if (isWindows) { - this.sdkInject = new DotNetSDKOnWindowsInject( + this.sdkInjector = new sdk.DotNetWindowsInjector( props.taskDefinition, this.mountVolumeName, - props.instrumentation.sdkVersion.imageURI(), + props.instrumentation.sdkVersion, overrideEnvironments, ); } else { - this.sdkInject = new DotNetSDKOnLinuxInject( + this.sdkInjector = new sdk.DotNetLinuxInjector( props.taskDefinition, this.mountVolumeName, - props.instrumentation.sdkVersion.imageURI(), + props.instrumentation.sdkVersion, cpuArch, overrideEnvironments, ); } - } else if (props.instrumentation.sdkVersion instanceof NodeInstrumentationVersion) { - this.sdkInject = new NodeSDKInject( + } else if (props.instrumentation.sdkVersion instanceof inst.NodeInstrumentationVersion) { + this.sdkInjector = new sdk.NodeInjector( props.taskDefinition, this.mountVolumeName, - props.instrumentation.sdkVersion.imageURI(), + props.instrumentation.sdkVersion, overrideEnvironments, ); } - let cwaContainer: ecs.ContainerDefinitionOptions | undefined; - let cwaName = cloudWatchAgentConfig.containerName ?? DEFAULT_CONTAINER_NAME; - if (cloudWatchAgentConfig.enableSidecar) { - cwaContainer = cloudWatchAgentConfig.container ?? this.getCloudWatchAgentContainer(cwaName, cloudWatchAgentImage); - } - - this.mutateTaskDefinition(props.taskDefinition, cwaName, cwaContainer); + this.mutateTaskDefinition(props.taskDefinition); } - private mutateTaskDefinition(taskDefinition: ecs.TaskDefinition, name: string, cwaContainer?: ecs.ContainerDefinitionOptions) { + private mutateTaskDefinition(taskDefinition: ecs.TaskDefinition) { taskDefinition.addVolume({ name: this.mountVolumeName, }); let defaultContainer = taskDefinition.defaultContainer!; - if (this.sdkInject) { - this.sdkInject.renderDefaultContainer(defaultContainer); - let initContainer = this.sdkInject.injectInitContainer(); + if (this.sdkInjector) { + this.sdkInjector.renderDefaultContainer(defaultContainer); + let initContainer = this.sdkInjector.injectInitContainer(); defaultContainer.addContainerDependencies({ container: initContainer, condition: ecs.ContainerDependencyCondition.SUCCESS, }); } - if (cwaContainer) { - let cwagentContainer = taskDefinition.addContainer(name, cwaContainer); + if (this.cloudWatchAgentSidecar) { + taskDefinition.taskRole.addManagedPolicy(ManagedPolicy.fromAwsManagedPolicyName('CloudWatchAgentServerPolicy')); + const cloudWatchAgent = new agent.CloudWatchAgentIntegration(this, 'CloudWatchAgentSidecar', + { + taskDefinition: taskDefinition, + ...this.cloudWatchAgentSidecar, + }, + ); defaultContainer.addContainerDependencies({ - container: cwagentContainer, + container: cloudWatchAgent.agentContainer, condition: ecs.ContainerDependencyCondition.START, }); } } - - private getCloudWatchAgentContainer(name: string, image: string): ecs.ContainerDefinitionOptions { - return { - image: ecs.ContainerImage.fromRegistry(image), - environment: { - CW_CONFIG_CONTENT: JSON.stringify(CW_CONFIG_CONTENT), - }, - logging: new ecs.AwsLogDriver({ streamPrefix: name }), - user: '0:1338', - memoryReservationMiB: 50, - portMappings: [ - { - containerPort: 4316, - hostPort: 4316, - }, - { - containerPort: 2000, - hostPort: 2000, - }, - ], - }; - } } diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/instrumentation-versions.ts b/packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/instrumentation-versions.ts new file mode 100644 index 0000000000000..86e741810f3fc --- /dev/null +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/instrumentation-versions.ts @@ -0,0 +1,123 @@ +/** + * Base class for instrumentation versions. + * Provides functionality to generate image URIs for different instrumentation types. + */ +export abstract class InstrumentationVersion { + public constructor(protected readonly imageRepo: string, protected readonly version: string, protected readonly memoryLimit: number) { } + + /** + * Get the image URI for the instrumentation version. + * @returns The image URI. + */ + public imageURI(): string { + return `${this.imageRepo}:${this.version}`; + } + + /** + * Get the memory limit in MiB for the instrumentation version. + * @returns The memory limit + */ + public memoryLimitMiB(): number { + return this.memoryLimit; + } +} + +/** + * Available versions for Java instrumentation. + */ +export class JavaInstrumentationVersion extends InstrumentationVersion { + /** + * The image repository for Java instrumentation. + */ + public static readonly IMAGE_REPO = 'public.ecr.aws/aws-observability/adot-autoinstrumentation-java'; + + /** + * The default memory limit of the Java instrumentation. + */ + public static readonly DEFAULT_MEMORY_LIMIT_MIB = 64; + /** + * ADOT Java Instrumentation version 1.33.0 + */ + public static readonly V1_33_0 = new JavaInstrumentationVersion(JavaInstrumentationVersion.IMAGE_REPO, 'v1.33.0', JavaInstrumentationVersion.DEFAULT_MEMORY_LIMIT_MIB); + /** + * ADOT Java Instrumentation version 1.32.6 + */ + public static readonly V1_32_6 = new JavaInstrumentationVersion(JavaInstrumentationVersion.IMAGE_REPO, 'v1.32.6', JavaInstrumentationVersion.DEFAULT_MEMORY_LIMIT_MIB); +} + +/** + * Available versions for .NET instrumentation. + */ +/** + * Available versions for Python instrumentation. + */ +export class PythonInstrumentationVersion extends InstrumentationVersion { + /** + * The image repository for Python instrumentation. + */ + public static readonly IMAGE_REPO = 'public.ecr.aws/aws-observability/adot-autoinstrumentation-python'; + + /** + * The default memory limit of the Python instrumentation. + */ + public static readonly DEFAULT_MEMORY_LIMIT_MIB = 32; + + /** + * ADOT Python Instrumentation version 0.8.0 + */ + public static readonly V0_8_0 = new PythonInstrumentationVersion(PythonInstrumentationVersion.IMAGE_REPO, 'v0.8.0', PythonInstrumentationVersion.DEFAULT_MEMORY_LIMIT_MIB); +} + +/** + * Available versions for .NET instrumentation. + */ +export class DotnetInstrumentationVersion extends InstrumentationVersion { + /** + * The image repository for .NET instrumentation. + */ + public static readonly IMAGE_REPO = 'public.ecr.aws/aws-observability/adot-autoinstrumentation-dotnet'; + + /** + * The default memory limit of the .NET instrumentation. + */ + public static readonly DEFAULT_MEMORY_LIMIT_MIB = 128; + /** + * ADOT .NET Instrumentation version 1.6.0 + */ + public static readonly V1_6_0 = new DotnetInstrumentationVersion(DotnetInstrumentationVersion.IMAGE_REPO, 'v1.6.0', DotnetInstrumentationVersion.DEFAULT_MEMORY_LIMIT_MIB); + /** + * ADOT .NET Instrumentation version 1.6.0 for ARM64 + */ + public static readonly V1_6_0_ARM64 = new DotnetInstrumentationVersion(DotnetInstrumentationVersion.IMAGE_REPO, 'v1.6.0-arm64', DotnetInstrumentationVersion.DEFAULT_MEMORY_LIMIT_MIB); + /** + * ADOT .NET Instrumentation version 1.6.0 for AMD64 + */ + public static readonly V1_6_0_AMD64 = new DotnetInstrumentationVersion(DotnetInstrumentationVersion.IMAGE_REPO, 'v1.6.0-amd64', DotnetInstrumentationVersion.DEFAULT_MEMORY_LIMIT_MIB); + /** + * ADOT .NET Instrumentation version 1.6.0 for Windows 2022 + */ + public static readonly V1_6_0_WINDOWS2022 = new DotnetInstrumentationVersion(DotnetInstrumentationVersion.IMAGE_REPO, 'v1.6.0-windows2022', DotnetInstrumentationVersion.DEFAULT_MEMORY_LIMIT_MIB); + /** + * ADOT .NET Instrumentation version 1.6.0 for Windows 2019 + */ + public static readonly V1_6_0_WINDOWS2019 = new DotnetInstrumentationVersion(DotnetInstrumentationVersion.IMAGE_REPO, 'v1.6.0-windows2019', DotnetInstrumentationVersion.DEFAULT_MEMORY_LIMIT_MIB); +} + +/** + * Available versions for Node.js instrumentation. + */ +export class NodeInstrumentationVersion extends InstrumentationVersion { + /** + * The image repository for Node.js instrumentation. + */ + public static readonly IMAGE_REPO = 'public.ecr.aws/aws-observability/adot-autoinstrumentation-node'; + + /** + * The default memory limit of the Node.js instrumentation. + */ + public static readonly DEFAULT_MEMORY_LIMIT_MIB = 128; + /** + * ADOT Node.js Instrumentation version 0.5.0 + */ + public static readonly V0_5_0 = new NodeInstrumentationVersion(NodeInstrumentationVersion.IMAGE_REPO, 'v0.5.0', NodeInstrumentationVersion.DEFAULT_MEMORY_LIMIT_MIB); +} diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/lib/index.ts b/packages/@aws-cdk/aws-applicationsignals-alpha/lib/index.ts index 5851f9f70949c..a1a19a160235e 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/lib/index.ts +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/lib/index.ts @@ -1,3 +1,6 @@ // AWS::ApplicationSignals Cloudformation Resources export * from './enablement/ecs'; export * from './enablement/constants'; +export * from './enablement/instrumentation-versions'; +export * from './enablement/ecs-cloudwatch-agent'; +export * from './enablement/ecs-sdk-instrumentation'; diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/ecs-enablement.test.ts b/packages/@aws-cdk/aws-applicationsignals-alpha/test/ecs-enablement.test.ts index 51f218cdbd5c2..836fe686b8085 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/test/ecs-enablement.test.ts +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/ecs-enablement.test.ts @@ -22,6 +22,11 @@ describe('application signals integration', () => { instrumentation: { sdkVersion: JavaInstrumentationVersion.V1_32_6, }, + cloudWatchAgentSidecar: { + containerName: 'cloudwatch-agent', + enableLogging: true, + memoryReservationMiB: 50, + }, }); // THEN @@ -137,18 +142,6 @@ describe('application signals integration', () => { }, MemoryReservation: 50, Name: 'cloudwatch-agent', - PortMappings: [ - { - ContainerPort: 4316, - HostPort: 4316, - Protocol: 'tcp', - }, - { - ContainerPort: 2000, - HostPort: 2000, - Protocol: 'tcp', - }, - ], User: '0:1338', }, ], @@ -180,7 +173,6 @@ describe('application signals integration', () => { }); test('should fail if fargate task definition does not have a sidecar', () => { - expect(() => { // GIVEN const stack = new Stack(); @@ -199,9 +191,6 @@ describe('application signals integration', () => { sdkVersion: JavaInstrumentationVersion.V1_32_6, }, serviceName: 'demo', - cloudWatchAgent: { - enableSidecar: false, - }, }); }).toThrow(/Fargate tasks must deploy CloudWatch Agent as a sidecar container/); }); @@ -243,9 +232,6 @@ describe('application signals integration', () => { value: 'endpoint=http://cwagent.local:2000', }, ], - cloudWatchAgent: { - enableSidecar: false, - }, }); // THEN @@ -385,9 +371,6 @@ describe('application signals integration', () => { sdkVersion: DotnetInstrumentationVersion.V1_6_0, }, serviceName: 'demo', - cloudWatchAgent: { - enableSidecar: false, - }, }); // THEN @@ -558,9 +541,6 @@ describe('application signals integration', () => { }, }, serviceName: 'demo', - cloudWatchAgent: { - enableSidecar: false, - }, }); // THEN @@ -739,9 +719,6 @@ describe('application signals integration', () => { }, }, serviceName: 'demo', - cloudWatchAgent: { - enableSidecar: false, - }, }); // THEN @@ -918,9 +895,6 @@ describe('application signals integration', () => { }, serviceName: 'demo', - cloudWatchAgent: { - enableSidecar: false, - }, }); // THEN @@ -1056,9 +1030,6 @@ describe('application signals integration', () => { }, serviceName: 'demo', - cloudWatchAgent: { - enableSidecar: false, - }, }); // THEN @@ -1169,5 +1140,4 @@ describe('application signals integration', () => { ], }); }); - }); diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ApplicationSignalsIntegrationECSDaemonDefaultTestDeployAssert0A2A622F.assets.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ApplicationSignalsIntegrationECSDaemonDefaultTestDeployAssert0A2A622F.assets.json index a2984d23111d5..339f2fa3a2a79 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ApplicationSignalsIntegrationECSDaemonDefaultTestDeployAssert0A2A622F.assets.json +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ApplicationSignalsIntegrationECSDaemonDefaultTestDeployAssert0A2A622F.assets.json @@ -1,5 +1,5 @@ { - "version": "39.0.0", + "version": "40.0.0", "files": { "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { "source": { diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/cdk.out b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/cdk.out index 91e1a8b9901d5..1e02a2deb191b 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/cdk.out +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/cdk.out @@ -1 +1 @@ -{"version":"39.0.0"} \ No newline at end of file +{"version":"40.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ecs-enablement-integration.assets.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ecs-enablement-integration.assets.json index a35d6857d3481..df04dbf028cc8 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ecs-enablement-integration.assets.json +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ecs-enablement-integration.assets.json @@ -1,5 +1,5 @@ { - "version": "39.0.0", + "version": "40.0.0", "files": { "a1acfc2b5f4f6b183fd2bb9863f486bc5edef6a357b355a070d9a0e502df418c": { "source": { @@ -14,7 +14,7 @@ } } }, - "dcac3df399e5ea2ad6e83532fc55e1a6e67edc5542e26ee9116810cfe3207a9d": { + "e99e497fe431aa6e238d9ff1cbb2456e20363821f82e30da6063551d6b96eb05": { "source": { "path": "ecs-enablement-integration.template.json", "packaging": "file" @@ -22,7 +22,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "dcac3df399e5ea2ad6e83532fc55e1a6e67edc5542e26ee9116810cfe3207a9d.json", + "objectKey": "e99e497fe431aa6e238d9ff1cbb2456e20363821f82e30da6063551d6b96eb05.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ecs-enablement-integration.template.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ecs-enablement-integration.template.json index d28d40b0b7b36..6b3ff2ece66a3 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ecs-enablement-integration.template.json +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/ecs-enablement-integration.template.json @@ -553,18 +553,24 @@ "Environment": [ { "Name": "CW_CONFIG_CONTENT", - "Value": "{\"agent\": {\"debug\": true}, \"traces\": {\"traces_collected\": {\"application_signals\": {\"enabled\": true}}}, \"logs\": {\"metrics_collected\": {\"application_signals\": {\"enabled\": true}}}}" + "Value": "{\"logs\":{\"metrics_collected\":{\"application_signals\":{\"enabled\":true}}},\"traces\":{\"traces_collected\":{\"application_signals\":{\"enabled\":true}}}}" + }, + { + "Name": "AWS_REGION", + "Value": { + "Ref": "AWS::Region" + } } ], "Essential": true, - "Image": "public.ecr.aws/cloudwatch-agent/cloudwatch-agent:latest", + "Image": "amazon/cloudwatch-agent:latest", "LogConfiguration": { "LogDriver": "awslogs", "Options": { "awslogs-group": { - "Ref": "CwAgentLogGroupBF702CD8" + "Ref": "CwAgentDaemonTaskDefecscwagentLogGroupEE66E5BB" }, - "awslogs-stream-prefix": "ecs", + "awslogs-stream-prefix": "ecs-cwagent", "awslogs-region": { "Ref": "AWS::Region" } @@ -585,7 +591,8 @@ "Name": "cwagent-2000", "Protocol": "tcp" } - ] + ], + "User": "0:1338" } ], "ExecutionRoleArn": { @@ -595,7 +602,7 @@ ] }, "Family": "ecsenablementintegrationCwAgentDaemonTaskDefB3E3B54C", - "NetworkMode": "bridge", + "NetworkMode": "awsvpc", "RequiresCompatibilities": [ "EC2" ], @@ -607,6 +614,11 @@ } } }, + "CwAgentDaemonTaskDefecscwagentLogGroupEE66E5BB": { + "Type": "AWS::Logs::LogGroup", + "UpdateReplacePolicy": "Retain", + "DeletionPolicy": "Retain" + }, "CwAgentDaemonTaskDefExecutionRoleDB11FC2A": { "Type": "AWS::IAM::Role", "Properties": { @@ -637,7 +649,7 @@ "Effect": "Allow", "Resource": { "Fn::GetAtt": [ - "CwAgentLogGroupBF702CD8", + "CwAgentDaemonTaskDefecscwagentLogGroupEE66E5BB", "Arn" ] } @@ -653,15 +665,6 @@ ] } }, - "CwAgentLogGroupBF702CD8": { - "Type": "AWS::Logs::LogGroup", - "Properties": { - "LogGroupName": "/ecs/ecs-cwagent-cdk-daemon", - "RetentionInDays": 731 - }, - "UpdateReplacePolicy": "Delete", - "DeletionPolicy": "Delete" - }, "CwAgentDaemonServiceA063D544": { "Type": "AWS::ECS::Service", "Properties": { @@ -674,6 +677,27 @@ }, "EnableECSManagedTags": false, "LaunchType": "EC2", + "NetworkConfiguration": { + "AwsvpcConfiguration": { + "AssignPublicIp": "DISABLED", + "SecurityGroups": [ + { + "Fn::GetAtt": [ + "CwAgentDaemonServiceSecurityGroup4155633D", + "GroupId" + ] + } + ], + "Subnets": [ + { + "Ref": "TestVpcPrivateSubnet1SubnetCC65D771" + }, + { + "Ref": "TestVpcPrivateSubnet2SubnetDE0C64A2" + } + ] + } + }, "SchedulingStrategy": "DAEMON", "ServiceConnectConfiguration": { "Enabled": true, @@ -712,6 +736,25 @@ "CwAgentDaemonTaskDefTaskRoleB630618E" ] }, + "CwAgentDaemonServiceSecurityGroup4155633D": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "ecs-enablement-integration/CwAgentDaemonService/SecurityGroup", + "SecurityGroupEgress": [ + { + "CidrIp": "0.0.0.0/0", + "Description": "Allow all outbound traffic by default", + "IpProtocol": "-1" + } + ], + "VpcId": { + "Ref": "TestVpcE77CE678" + } + }, + "DependsOn": [ + "CwAgentDaemonTaskDefTaskRoleB630618E" + ] + }, "Ec2TaskDefinitionTaskRole0B78BC85": { "Type": "AWS::IAM::Role", "Properties": { @@ -742,6 +785,12 @@ } ], "Environment": [ + { + "Name": "AWS_REGION", + "Value": { + "Ref": "AWS::Region" + } + }, { "Name": "OTEL_LOGS_EXPORTER", "Value": "none" @@ -815,6 +864,14 @@ "/otel-auto-instrumentation-python" ], "Cpu": 0, + "Environment": [ + { + "Name": "AWS_REGION", + "Value": { + "Ref": "AWS::Region" + } + } + ], "Essential": false, "Image": "public.ecr.aws/aws-observability/adot-autoinstrumentation-python:v0.8.0", "Memory": 32, @@ -829,7 +886,7 @@ } ], "Family": "ecsenablementintegrationEc2TaskDefinition9DAAE5F5", - "NetworkMode": "host", + "NetworkMode": "awsvpc", "RequiresCompatibilities": [ "EC2" ], @@ -895,10 +952,10 @@ "value": "nodejs20.x" }, "cn-north-1": { - "value": "nodejs18.x" + "value": "nodejs20.x" }, "cn-northwest-1": { - "value": "nodejs18.x" + "value": "nodejs20.x" }, "eu-central-1": { "value": "nodejs20.x" @@ -949,10 +1006,10 @@ "value": "nodejs20.x" }, "us-gov-east-1": { - "value": "nodejs18.x" + "value": "nodejs20.x" }, "us-gov-west-1": { - "value": "nodejs18.x" + "value": "nodejs20.x" }, "us-iso-east-1": { "value": "nodejs18.x" diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/integ.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/integ.json index 157fde561b72e..347d592e8a502 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/integ.json +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/integ.json @@ -1,5 +1,5 @@ { - "version": "39.0.0", + "version": "40.0.0", "testCases": { "ApplicationSignalsIntegrationECSDaemon/DefaultTest": { "stacks": [ diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/manifest.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/manifest.json index 856bf1c27968e..ad641de365e62 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/manifest.json +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/manifest.json @@ -1,5 +1,5 @@ { - "version": "39.0.0", + "version": "40.0.0", "artifacts": { "ecs-enablement-integration.assets": { "type": "cdk:asset-manifest", @@ -18,7 +18,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/dcac3df399e5ea2ad6e83532fc55e1a6e67edc5542e26ee9116810cfe3207a9d.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/e99e497fe431aa6e238d9ff1cbb2456e20363821f82e30da6063551d6b96eb05.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -34,12 +34,54 @@ "ecs-enablement-integration.assets" ], "metadata": { + "/ecs-enablement-integration/TestVpc": [ + { + "type": "aws:cdk:analytics:construct", + "data": "*" + } + ], "/ecs-enablement-integration/TestVpc/Resource": [ { "type": "aws:cdk:logicalId", "data": "TestVpcE77CE678" } ], + "/ecs-enablement-integration/TestVpc/PublicSubnet1": [ + { + "type": "aws:cdk:analytics:construct", + "data": { + "availabilityZone": "*", + "vpcId": "*", + "cidrBlock": "*", + "mapPublicIpOnLaunch": true, + "ipv6CidrBlock": "*", + "assignIpv6AddressOnCreation": "*" + } + }, + { + "type": "aws:cdk:analytics:construct", + "data": { + "availabilityZone": "*", + "vpcId": "*", + "cidrBlock": "*", + "mapPublicIpOnLaunch": true, + "ipv6CidrBlock": "*", + "assignIpv6AddressOnCreation": "*" + } + }, + { + "type": "aws:cdk:analytics:method", + "data": {} + }, + { + "type": "aws:cdk:analytics:method", + "data": { + "addNatGateway": [ + "*" + ] + } + } + ], "/ecs-enablement-integration/TestVpc/PublicSubnet1/Subnet": [ { "type": "aws:cdk:logicalId", @@ -76,6 +118,42 @@ "data": "TestVpcPublicSubnet1NATGatewayA323E3EC" } ], + "/ecs-enablement-integration/TestVpc/PublicSubnet2": [ + { + "type": "aws:cdk:analytics:construct", + "data": { + "availabilityZone": "*", + "vpcId": "*", + "cidrBlock": "*", + "mapPublicIpOnLaunch": true, + "ipv6CidrBlock": "*", + "assignIpv6AddressOnCreation": "*" + } + }, + { + "type": "aws:cdk:analytics:construct", + "data": { + "availabilityZone": "*", + "vpcId": "*", + "cidrBlock": "*", + "mapPublicIpOnLaunch": true, + "ipv6CidrBlock": "*", + "assignIpv6AddressOnCreation": "*" + } + }, + { + "type": "aws:cdk:analytics:method", + "data": {} + }, + { + "type": "aws:cdk:analytics:method", + "data": { + "addNatGateway": [ + "*" + ] + } + } + ], "/ecs-enablement-integration/TestVpc/PublicSubnet2/Subnet": [ { "type": "aws:cdk:logicalId", @@ -112,6 +190,34 @@ "data": "TestVpcPublicSubnet2NATGatewayA9858C31" } ], + "/ecs-enablement-integration/TestVpc/PrivateSubnet1": [ + { + "type": "aws:cdk:analytics:construct", + "data": { + "availabilityZone": "*", + "vpcId": "*", + "cidrBlock": "*", + "mapPublicIpOnLaunch": false, + "ipv6CidrBlock": "*", + "assignIpv6AddressOnCreation": "*" + } + }, + { + "type": "aws:cdk:analytics:construct", + "data": { + "availabilityZone": "*", + "vpcId": "*", + "cidrBlock": "*", + "mapPublicIpOnLaunch": false, + "ipv6CidrBlock": "*", + "assignIpv6AddressOnCreation": "*" + } + }, + { + "type": "aws:cdk:analytics:method", + "data": {} + } + ], "/ecs-enablement-integration/TestVpc/PrivateSubnet1/Subnet": [ { "type": "aws:cdk:logicalId", @@ -136,6 +242,34 @@ "data": "TestVpcPrivateSubnet1DefaultRoute32E7B814" } ], + "/ecs-enablement-integration/TestVpc/PrivateSubnet2": [ + { + "type": "aws:cdk:analytics:construct", + "data": { + "availabilityZone": "*", + "vpcId": "*", + "cidrBlock": "*", + "mapPublicIpOnLaunch": false, + "ipv6CidrBlock": "*", + "assignIpv6AddressOnCreation": "*" + } + }, + { + "type": "aws:cdk:analytics:construct", + "data": { + "availabilityZone": "*", + "vpcId": "*", + "cidrBlock": "*", + "mapPublicIpOnLaunch": false, + "ipv6CidrBlock": "*", + "assignIpv6AddressOnCreation": "*" + } + }, + { + "type": "aws:cdk:analytics:method", + "data": {} + } + ], "/ecs-enablement-integration/TestVpc/PrivateSubnet2/Subnet": [ { "type": "aws:cdk:logicalId", @@ -172,6 +306,12 @@ "data": "TestVpcVPCGWF1827B84" } ], + "/ecs-enablement-integration/TestVpc/RestrictDefaultSecurityGroupCustomResource": [ + { + "type": "aws:cdk:analytics:construct", + "data": "*" + } + ], "/ecs-enablement-integration/TestVpc/RestrictDefaultSecurityGroupCustomResource/Default": [ { "type": "aws:cdk:logicalId", @@ -202,18 +342,86 @@ "data": "CustomVpcRestrictDefaultSGCustomResourceProviderHandlerDC833E5E" } ], + "/ecs-enablement-integration/TestCluster": [ + { + "type": "aws:cdk:analytics:construct", + "data": { + "vpc": "*" + } + } + ], "/ecs-enablement-integration/TestCluster/Resource": [ { "type": "aws:cdk:logicalId", "data": "TestClusterE0095054" } ], + "/ecs-enablement-integration/Namespace": [ + { + "type": "aws:cdk:analytics:construct", + "data": { + "vpc": "*", + "name": "*" + } + } + ], "/ecs-enablement-integration/Namespace/Resource": [ { "type": "aws:cdk:logicalId", "data": "Namespace9B63B8C8" } ], + "/ecs-enablement-integration/CwAgentDaemonTaskDef": [ + { + "type": "aws:cdk:analytics:construct", + "data": "*" + }, + { + "type": "aws:cdk:analytics:construct", + "data": "*" + }, + { + "type": "aws:cdk:analytics:method", + "data": "*" + }, + { + "type": "aws:cdk:analytics:method", + "data": "*" + }, + { + "type": "aws:cdk:analytics:method", + "data": "*" + }, + { + "type": "aws:cdk:analytics:method", + "data": "*" + }, + { + "type": "aws:cdk:analytics:method", + "data": "*" + }, + { + "type": "aws:cdk:analytics:method", + "data": "*" + } + ], + "/ecs-enablement-integration/CwAgentDaemonTaskDef/TaskRole": [ + { + "type": "aws:cdk:analytics:construct", + "data": { + "assumedBy": { + "principalAccount": "*", + "assumeRoleAction": "*" + } + } + } + ], + "/ecs-enablement-integration/CwAgentDaemonTaskDef/TaskRole/ImportTaskRole": [ + { + "type": "aws:cdk:analytics:construct", + "data": "*" + } + ], "/ecs-enablement-integration/CwAgentDaemonTaskDef/TaskRole/Resource": [ { "type": "aws:cdk:logicalId", @@ -223,7 +431,66 @@ "/ecs-enablement-integration/CwAgentDaemonTaskDef/Resource": [ { "type": "aws:cdk:logicalId", - "data": "CwAgentDaemonTaskDefD42721B8" + "data": "CwAgentDaemonTaskDefD42721B8", + "trace": [ + "!!DESTRUCTIVE_CHANGES: WILL_REPLACE" + ] + } + ], + "/ecs-enablement-integration/CwAgentDaemonTaskDef/ecs-cwagent/LogGroup": [ + { + "type": "aws:cdk:analytics:construct", + "data": { + "retention": "*" + } + } + ], + "/ecs-enablement-integration/CwAgentDaemonTaskDef/ecs-cwagent/LogGroup/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "CwAgentDaemonTaskDefecscwagentLogGroupEE66E5BB" + } + ], + "/ecs-enablement-integration/CwAgentDaemonTaskDef/ExecutionRole": [ + { + "type": "aws:cdk:analytics:construct", + "data": { + "assumedBy": { + "principalAccount": "*", + "assumeRoleAction": "*" + }, + "roleName": "*" + } + }, + { + "type": "aws:cdk:analytics:method", + "data": { + "addToPrincipalPolicy": [ + {} + ] + } + }, + { + "type": "aws:cdk:analytics:method", + "data": { + "attachInlinePolicy": [ + "*" + ] + } + }, + { + "type": "aws:cdk:analytics:method", + "data": { + "attachInlinePolicy": [ + "*" + ] + } + } + ], + "/ecs-enablement-integration/CwAgentDaemonTaskDef/ExecutionRole/ImportExecutionRole": [ + { + "type": "aws:cdk:analytics:construct", + "data": "*" } ], "/ecs-enablement-integration/CwAgentDaemonTaskDef/ExecutionRole/Resource": [ @@ -232,19 +499,51 @@ "data": "CwAgentDaemonTaskDefExecutionRoleDB11FC2A" } ], - "/ecs-enablement-integration/CwAgentDaemonTaskDef/ExecutionRole/DefaultPolicy/Resource": [ + "/ecs-enablement-integration/CwAgentDaemonTaskDef/ExecutionRole/DefaultPolicy": [ { - "type": "aws:cdk:logicalId", - "data": "CwAgentDaemonTaskDefExecutionRoleDefaultPolicy765BB856" + "type": "aws:cdk:analytics:construct", + "data": "*" + }, + { + "type": "aws:cdk:analytics:method", + "data": { + "attachToRole": [ + "*" + ] + } + }, + { + "type": "aws:cdk:analytics:method", + "data": { + "attachToRole": [ + "*" + ] + } + }, + { + "type": "aws:cdk:analytics:method", + "data": { + "addStatements": [ + {} + ] + } } ], - "/ecs-enablement-integration/CwAgentLogGroup/Resource": [ + "/ecs-enablement-integration/CwAgentDaemonTaskDef/ExecutionRole/DefaultPolicy/Resource": [ { "type": "aws:cdk:logicalId", - "data": "CwAgentLogGroupBF702CD8" + "data": "CwAgentDaemonTaskDefExecutionRoleDefaultPolicy765BB856" } ], "/ecs-enablement-integration/CwAgentDaemonService": [ + { + "type": "aws:cdk:analytics:construct", + "data": "*" + }, + { + "type": "aws:cdk:analytics:method", + "data": "*" + }, { "type": "aws:cdk:warning", "data": "minHealthyPercent has not been configured so the default value of 0% for a daemon service is used. See https://github.com/aws/aws-cdk/issues/31705 [ack: @aws-cdk/aws-ecs:minHealthyPercentDaemon]" @@ -256,6 +555,59 @@ "data": "CwAgentDaemonServiceA063D544" } ], + "/ecs-enablement-integration/CwAgentDaemonService/SecurityGroup": [ + { + "type": "aws:cdk:analytics:construct", + "data": { + "vpc": "*" + } + } + ], + "/ecs-enablement-integration/CwAgentDaemonService/SecurityGroup/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "CwAgentDaemonServiceSecurityGroup4155633D" + } + ], + "/ecs-enablement-integration/Ec2TaskDefinition": [ + { + "type": "aws:cdk:analytics:construct", + "data": "*" + }, + { + "type": "aws:cdk:analytics:construct", + "data": "*" + }, + { + "type": "aws:cdk:analytics:method", + "data": "*" + }, + { + "type": "aws:cdk:analytics:method", + "data": "*" + }, + { + "type": "aws:cdk:analytics:method", + "data": "*" + } + ], + "/ecs-enablement-integration/Ec2TaskDefinition/TaskRole": [ + { + "type": "aws:cdk:analytics:construct", + "data": { + "assumedBy": { + "principalAccount": "*", + "assumeRoleAction": "*" + } + } + } + ], + "/ecs-enablement-integration/Ec2TaskDefinition/TaskRole/ImportTaskRole": [ + { + "type": "aws:cdk:analytics:construct", + "data": "*" + } + ], "/ecs-enablement-integration/Ec2TaskDefinition/TaskRole/Resource": [ { "type": "aws:cdk:logicalId", @@ -265,7 +617,10 @@ "/ecs-enablement-integration/Ec2TaskDefinition/Resource": [ { "type": "aws:cdk:logicalId", - "data": "Ec2TaskDefinitionB25030BE" + "data": "Ec2TaskDefinitionB25030BE", + "trace": [ + "!!DESTRUCTIVE_CHANGES: WILL_REPLACE" + ] } ], "/ecs-enablement-integration/BootstrapVersion": [ @@ -279,6 +634,15 @@ "type": "aws:cdk:logicalId", "data": "CheckBootstrapVersion" } + ], + "CwAgentLogGroupBF702CD8": [ + { + "type": "aws:cdk:logicalId", + "data": "CwAgentLogGroupBF702CD8", + "trace": [ + "!!DESTRUCTIVE_CHANGES: WILL_DESTROY" + ] + } ] }, "displayName": "ecs-enablement-integration" diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/tree.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/tree.json index 27650f5003a02..5c30316d75713 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/tree.json +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.js.snapshot/tree.json @@ -84,7 +84,8 @@ "path": "ecs-enablement-integration/TestVpc/PublicSubnet1/Acl", "constructInfo": { "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [] } }, "RouteTable": { @@ -199,7 +200,31 @@ }, "constructInfo": { "fqn": "aws-cdk-lib.aws_ec2.PublicSubnet", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + { + "availabilityZone": "*", + "vpcId": "*", + "cidrBlock": "*", + "mapPublicIpOnLaunch": true, + "ipv6CidrBlock": "*", + "assignIpv6AddressOnCreation": "*" + }, + { + "availabilityZone": "*", + "vpcId": "*", + "cidrBlock": "*", + "mapPublicIpOnLaunch": true, + "ipv6CidrBlock": "*", + "assignIpv6AddressOnCreation": "*" + }, + {}, + { + "addNatGateway": [ + "*" + ] + } + ] } }, "PublicSubnet2": { @@ -251,7 +276,8 @@ "path": "ecs-enablement-integration/TestVpc/PublicSubnet2/Acl", "constructInfo": { "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [] } }, "RouteTable": { @@ -366,7 +392,31 @@ }, "constructInfo": { "fqn": "aws-cdk-lib.aws_ec2.PublicSubnet", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + { + "availabilityZone": "*", + "vpcId": "*", + "cidrBlock": "*", + "mapPublicIpOnLaunch": true, + "ipv6CidrBlock": "*", + "assignIpv6AddressOnCreation": "*" + }, + { + "availabilityZone": "*", + "vpcId": "*", + "cidrBlock": "*", + "mapPublicIpOnLaunch": true, + "ipv6CidrBlock": "*", + "assignIpv6AddressOnCreation": "*" + }, + {}, + { + "addNatGateway": [ + "*" + ] + } + ] } }, "PrivateSubnet1": { @@ -418,7 +468,8 @@ "path": "ecs-enablement-integration/TestVpc/PrivateSubnet1/Acl", "constructInfo": { "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [] } }, "RouteTable": { @@ -485,7 +536,26 @@ }, "constructInfo": { "fqn": "aws-cdk-lib.aws_ec2.PrivateSubnet", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + { + "availabilityZone": "*", + "vpcId": "*", + "cidrBlock": "*", + "mapPublicIpOnLaunch": false, + "ipv6CidrBlock": "*", + "assignIpv6AddressOnCreation": "*" + }, + { + "availabilityZone": "*", + "vpcId": "*", + "cidrBlock": "*", + "mapPublicIpOnLaunch": false, + "ipv6CidrBlock": "*", + "assignIpv6AddressOnCreation": "*" + }, + {} + ] } }, "PrivateSubnet2": { @@ -537,7 +607,8 @@ "path": "ecs-enablement-integration/TestVpc/PrivateSubnet2/Acl", "constructInfo": { "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [] } }, "RouteTable": { @@ -604,7 +675,26 @@ }, "constructInfo": { "fqn": "aws-cdk-lib.aws_ec2.PrivateSubnet", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + { + "availabilityZone": "*", + "vpcId": "*", + "cidrBlock": "*", + "mapPublicIpOnLaunch": false, + "ipv6CidrBlock": "*", + "assignIpv6AddressOnCreation": "*" + }, + { + "availabilityZone": "*", + "vpcId": "*", + "cidrBlock": "*", + "mapPublicIpOnLaunch": false, + "ipv6CidrBlock": "*", + "assignIpv6AddressOnCreation": "*" + }, + {} + ] } }, "IGW": { @@ -660,13 +750,19 @@ }, "constructInfo": { "fqn": "aws-cdk-lib.CustomResource", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + "*" + ] } } }, "constructInfo": { "fqn": "aws-cdk-lib.aws_ec2.Vpc", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + "*" + ] } }, "LatestNodeRuntimeMap": { @@ -730,7 +826,12 @@ }, "constructInfo": { "fqn": "aws-cdk-lib.aws_ecs.Cluster", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + { + "vpc": "*" + } + ] } }, "Namespace": { @@ -757,7 +858,13 @@ }, "constructInfo": { "fqn": "aws-cdk-lib.aws_servicediscovery.PrivateDnsNamespace", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + { + "vpc": "*", + "name": "*" + } + ] } }, "CwAgentDaemonTaskDef": { @@ -773,7 +880,10 @@ "path": "ecs-enablement-integration/CwAgentDaemonTaskDef/TaskRole/ImportTaskRole", "constructInfo": { "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + "*" + ] } }, "Resource": { @@ -804,7 +914,15 @@ }, "constructInfo": { "fqn": "aws-cdk-lib.aws_iam.Role", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + { + "assumedBy": { + "principalAccount": "*", + "assumeRoleAction": "*" + } + } + ] } }, "Resource": { @@ -817,7 +935,7 @@ { "cpu": 128, "essential": true, - "image": "public.ecr.aws/cloudwatch-agent/cloudwatch-agent:latest", + "image": "amazon/cloudwatch-agent:latest", "memory": 64, "name": "ecs-cwagent", "portMappings": [ @@ -834,13 +952,14 @@ "name": "cwagent-2000" } ], + "user": "0:1338", "logConfiguration": { "logDriver": "awslogs", "options": { "awslogs-group": { - "Ref": "CwAgentLogGroupBF702CD8" + "Ref": "CwAgentDaemonTaskDefecscwagentLogGroupEE66E5BB" }, - "awslogs-stream-prefix": "ecs", + "awslogs-stream-prefix": "ecs-cwagent", "awslogs-region": { "Ref": "AWS::Region" } @@ -849,7 +968,13 @@ "environment": [ { "name": "CW_CONFIG_CONTENT", - "value": "{\"agent\": {\"debug\": true}, \"traces\": {\"traces_collected\": {\"application_signals\": {\"enabled\": true}}}, \"logs\": {\"metrics_collected\": {\"application_signals\": {\"enabled\": true}}}}" + "value": "{\"logs\":{\"metrics_collected\":{\"application_signals\":{\"enabled\":true}}},\"traces\":{\"traces_collected\":{\"application_signals\":{\"enabled\":true}}}}" + }, + { + "name": "AWS_REGION", + "value": { + "Ref": "AWS::Region" + } } ] } @@ -861,7 +986,7 @@ ] }, "family": "ecsenablementintegrationCwAgentDaemonTaskDefB3E3B54C", - "networkMode": "bridge", + "networkMode": "awsvpc", "requiresCompatibilities": [ "EC2" ], @@ -881,6 +1006,35 @@ "ecs-cwagent": { "id": "ecs-cwagent", "path": "ecs-enablement-integration/CwAgentDaemonTaskDef/ecs-cwagent", + "children": { + "LogGroup": { + "id": "LogGroup", + "path": "ecs-enablement-integration/CwAgentDaemonTaskDef/ecs-cwagent/LogGroup", + "children": { + "Resource": { + "id": "Resource", + "path": "ecs-enablement-integration/CwAgentDaemonTaskDef/ecs-cwagent/LogGroup/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Logs::LogGroup", + "aws:cdk:cloudformation:props": {} + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_logs.CfnLogGroup", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_logs.LogGroup", + "version": "0.0.0", + "metadata": [ + { + "retention": "*" + } + ] + } + } + }, "constructInfo": { "fqn": "aws-cdk-lib.aws_ecs.ContainerDefinition", "version": "0.0.0" @@ -895,7 +1049,10 @@ "path": "ecs-enablement-integration/CwAgentDaemonTaskDef/ExecutionRole/ImportExecutionRole", "constructInfo": { "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + "*" + ] } }, "Resource": { @@ -943,7 +1100,7 @@ "Effect": "Allow", "Resource": { "Fn::GetAtt": [ - "CwAgentLogGroupBF702CD8", + "CwAgentDaemonTaskDefecscwagentLogGroupEE66E5BB", "Arn" ] } @@ -967,43 +1124,78 @@ }, "constructInfo": { "fqn": "aws-cdk-lib.aws_iam.Policy", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + "*", + { + "attachToRole": [ + "*" + ] + }, + { + "attachToRole": [ + "*" + ] + }, + { + "addStatements": [ + {} + ] + } + ] } } }, "constructInfo": { "fqn": "aws-cdk-lib.aws_iam.Role", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + { + "assumedBy": { + "principalAccount": "*", + "assumeRoleAction": "*" + }, + "roleName": "*" + }, + { + "addToPrincipalPolicy": [ + {} + ] + }, + { + "attachInlinePolicy": [ + "*" + ] + }, + { + "attachInlinePolicy": [ + "*" + ] + } + ] } } }, "constructInfo": { "fqn": "aws-cdk-lib.aws_ecs.Ec2TaskDefinition", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + "*", + "*", + "*", + "*", + "*", + "*", + "*", + "*" + ] } }, - "CwAgentLogGroup": { - "id": "CwAgentLogGroup", - "path": "ecs-enablement-integration/CwAgentLogGroup", - "children": { - "Resource": { - "id": "Resource", - "path": "ecs-enablement-integration/CwAgentLogGroup/Resource", - "attributes": { - "aws:cdk:cloudformation:type": "AWS::Logs::LogGroup", - "aws:cdk:cloudformation:props": { - "logGroupName": "/ecs/ecs-cwagent-cdk-daemon", - "retentionInDays": 731 - } - }, - "constructInfo": { - "fqn": "aws-cdk-lib.aws_logs.CfnLogGroup", - "version": "0.0.0" - } - } - }, + "CloudWatchAgent": { + "id": "CloudWatchAgent", + "path": "ecs-enablement-integration/CloudWatchAgent", "constructInfo": { - "fqn": "aws-cdk-lib.aws_logs.LogGroup", + "fqn": "@aws-cdk/aws-applicationsignals-alpha.CloudWatchAgentIntegration", "version": "0.0.0" } }, @@ -1026,6 +1218,27 @@ }, "enableEcsManagedTags": false, "launchType": "EC2", + "networkConfiguration": { + "awsvpcConfiguration": { + "assignPublicIp": "DISABLED", + "subnets": [ + { + "Ref": "TestVpcPrivateSubnet1SubnetCC65D771" + }, + { + "Ref": "TestVpcPrivateSubnet2SubnetDE0C64A2" + } + ], + "securityGroups": [ + { + "Fn::GetAtt": [ + "CwAgentDaemonServiceSecurityGroup4155633D", + "GroupId" + ] + } + ] + } + }, "schedulingStrategy": "DAEMON", "serviceConnectConfiguration": { "enabled": true, @@ -1065,11 +1278,54 @@ "fqn": "aws-cdk-lib.aws_ecs.CfnService", "version": "0.0.0" } + }, + "SecurityGroup": { + "id": "SecurityGroup", + "path": "ecs-enablement-integration/CwAgentDaemonService/SecurityGroup", + "children": { + "Resource": { + "id": "Resource", + "path": "ecs-enablement-integration/CwAgentDaemonService/SecurityGroup/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SecurityGroup", + "aws:cdk:cloudformation:props": { + "groupDescription": "ecs-enablement-integration/CwAgentDaemonService/SecurityGroup", + "securityGroupEgress": [ + { + "cidrIp": "0.0.0.0/0", + "description": "Allow all outbound traffic by default", + "ipProtocol": "-1" + } + ], + "vpcId": { + "Ref": "TestVpcE77CE678" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSecurityGroup", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.SecurityGroup", + "version": "0.0.0", + "metadata": [ + { + "vpc": "*" + } + ] + } } }, "constructInfo": { "fqn": "aws-cdk-lib.aws_ecs.Ec2Service", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + "*", + "*" + ] } }, "Ec2TaskDefinition": { @@ -1085,7 +1341,10 @@ "path": "ecs-enablement-integration/Ec2TaskDefinition/TaskRole/ImportTaskRole", "constructInfo": { "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + "*" + ] } }, "Resource": { @@ -1116,7 +1375,15 @@ }, "constructInfo": { "fqn": "aws-cdk-lib.aws_iam.Role", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + { + "assumedBy": { + "principalAccount": "*", + "assumeRoleAction": "*" + } + } + ] } }, "Resource": { @@ -1146,6 +1413,12 @@ ], "name": "app", "environment": [ + { + "name": "AWS_REGION", + "value": { + "Ref": "AWS::Region" + } + }, { "name": "OTEL_LOGS_EXPORTER", "value": "none" @@ -1218,11 +1491,19 @@ "sourceVolume": "opentelemetry-auto-instrumentation" } ], - "name": "adot-init" + "name": "adot-init", + "environment": [ + { + "name": "AWS_REGION", + "value": { + "Ref": "AWS::Region" + } + } + ] } ], "family": "ecsenablementintegrationEc2TaskDefinition9DAAE5F5", - "networkMode": "host", + "networkMode": "awsvpc", "requiresCompatibilities": [ "EC2" ], @@ -1263,7 +1544,14 @@ }, "constructInfo": { "fqn": "aws-cdk-lib.aws_ecs.Ec2TaskDefinition", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + "*", + "*", + "*", + "*", + "*" + ] } }, "TestEc2TaskDefinitionIntegration": { diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.ts b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.ts index 46ff6065c4948..ea806f4e26308 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.ts +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-daemon.ts @@ -3,7 +3,6 @@ import * as integ from '@aws-cdk/integ-tests-alpha'; import * as cdk from 'aws-cdk-lib'; import * as ec2 from 'aws-cdk-lib/aws-ec2'; import * as ecs from 'aws-cdk-lib/aws-ecs'; -import { LogGroup } from 'aws-cdk-lib/aws-logs'; import { PrivateDnsNamespace } from 'aws-cdk-lib/aws-servicediscovery'; import * as appsignals from '../lib'; @@ -19,36 +18,30 @@ const namespace = new PrivateDnsNamespace(stack, 'Namespace', { }); // Define Task Definition for CloudWatch agent (Daemon) -const cwAgentTaskDefinition = new ecs.Ec2TaskDefinition(stack, 'CwAgentDaemonTaskDef'); - -// Add the CloudWatch agent container -cwAgentTaskDefinition.addContainer('ecs-cwagent', { - image: ecs.ContainerImage.fromRegistry('public.ecr.aws/cloudwatch-agent/cloudwatch-agent:latest'), - cpu: 128, - memoryLimitMiB: 64, - portMappings: [ - { - name: 'cwagent-4316', - containerPort: 4316, - hostPort: 4316, - }, - { - name: 'cwagent-2000', - containerPort: 2000, - hostPort: 2000, - }, - ], - logging: new ecs.AwsLogDriver({ - streamPrefix: 'ecs', - logGroup: new LogGroup(stack, 'CwAgentLogGroup', { - logGroupName: '/ecs/ecs-cwagent-cdk-daemon', - removalPolicy: cdk.RemovalPolicy.DESTROY, - }), - }), - environment: { - CW_CONFIG_CONTENT: '{"agent": {"debug": true}, "traces": {"traces_collected": {"application_signals": {"enabled": true}}}, "logs": {"metrics_collected": {"application_signals": {"enabled": true}}}}', - }, +const cwAgentTaskDefinition = new ecs.Ec2TaskDefinition(stack, 'CwAgentDaemonTaskDef', { + networkMode: ecs.NetworkMode.AWS_VPC, }); +new appsignals.CloudWatchAgentIntegration(stack, 'CloudWatchAgent', + { + taskDefinition: cwAgentTaskDefinition, + containerName: 'ecs-cwagent', + enableLogging: true, + cpu: 128, + memoryLimitMiB: 64, + portMappings: [ + { + name: 'cwagent-4316', + containerPort: 4316, + hostPort: 4316, + }, + { + name: 'cwagent-2000', + containerPort: 2000, + hostPort: 2000, + }, + ], + }, +); new ecs.Ec2Service(stack, 'CwAgentDaemonService', { cluster, @@ -69,7 +62,7 @@ new ecs.Ec2Service(stack, 'CwAgentDaemonService', { }); const ec2TaskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDefinition', { - networkMode: ecs.NetworkMode.HOST, + networkMode: ecs.NetworkMode.AWS_VPC, }); ec2TaskDefinition.addContainer('app', { @@ -96,9 +89,6 @@ new appsignals.ApplicationSignalsIntegration(stack, 'TestEc2TaskDefinitionIntegr value: 'endpoint=http://cwagent-2000-http:2000', }, ], - cloudWatchAgent: { - enableSidecar: false, - }, }); new integ.IntegTest(app, 'ApplicationSignalsIntegrationECSDaemon', { diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ApplicationSignalsIntegrationECSSidecarDefaultTestDeployAssert7F3E5290.assets.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ApplicationSignalsIntegrationECSSidecarDefaultTestDeployAssert7F3E5290.assets.json index 42598b49363da..9a0cc49abc15f 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ApplicationSignalsIntegrationECSSidecarDefaultTestDeployAssert7F3E5290.assets.json +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ApplicationSignalsIntegrationECSSidecarDefaultTestDeployAssert7F3E5290.assets.json @@ -1,5 +1,5 @@ { - "version": "39.0.0", + "version": "40.0.0", "files": { "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { "source": { diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/cdk.out b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/cdk.out index 91e1a8b9901d5..1e02a2deb191b 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/cdk.out +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/cdk.out @@ -1 +1 @@ -{"version":"39.0.0"} \ No newline at end of file +{"version":"40.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ecs-enablement-integration.assets.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ecs-enablement-integration.assets.json index 99bd22b6626ac..b06d465d80370 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ecs-enablement-integration.assets.json +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ecs-enablement-integration.assets.json @@ -1,7 +1,7 @@ { - "version": "39.0.0", + "version": "40.0.0", "files": { - "5acf6c0acb64eaedc9d71ce5b2ace633828b5b5cb4f275a04d31ad815c63fc1f": { + "85e45147ef01023326d4476fe3c452af17130eb92f15477dedbd6ecf76d671e0": { "source": { "path": "ecs-enablement-integration.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "5acf6c0acb64eaedc9d71ce5b2ace633828b5b5cb4f275a04d31ad815c63fc1f.json", + "objectKey": "85e45147ef01023326d4476fe3c452af17130eb92f15477dedbd6ecf76d671e0.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ecs-enablement-integration.template.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ecs-enablement-integration.template.json index f22ee4ac853d1..8eb5dcbc9af7b 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ecs-enablement-integration.template.json +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/ecs-enablement-integration.template.json @@ -44,7 +44,7 @@ }, { "Condition": "START", - "ContainerName": "cwagent" + "ContainerName": "cloudwatch-agent" } ], "Environment": [ @@ -169,9 +169,18 @@ "Name": "adot-init" }, { + "Cpu": 256, + "Environment": [ + { + "Name": "CW_CONFIG_CONTENT", + "Value": "{\"logs\":{\"metrics_collected\":{\"application_signals\":{\"enabled\":true}}},\"traces\":{\"traces_collected\":{\"application_signals\":{\"enabled\":true}}}}" + } + ], "Essential": true, - "Image": "public.ecr.aws/cloudwatch-agent/cloudwatch-agent:1.300051.0b992-windowsservercore2019", - "Name": "cwagent" + "Image": "amazon/cloudwatch-agent:latest", + "Memory": 512, + "Name": "cloudwatch-agent", + "User": "0:1338" } ], "Cpu": "2048", diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/integ.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/integ.json index 787cf0357c4c1..6e494e7789eb5 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/integ.json +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/integ.json @@ -1,5 +1,5 @@ { - "version": "39.0.0", + "version": "40.0.0", "testCases": { "ApplicationSignalsIntegrationECSSidecar/DefaultTest": { "stacks": [ diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/manifest.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/manifest.json index 5014c0aeca2ff..bf5f3250d0e2b 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/manifest.json +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/manifest.json @@ -1,5 +1,5 @@ { - "version": "39.0.0", + "version": "40.0.0", "artifacts": { "ecs-enablement-integration.assets": { "type": "cdk:asset-manifest", @@ -18,7 +18,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/5acf6c0acb64eaedc9d71ce5b2ace633828b5b5cb4f275a04d31ad815c63fc1f.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/85e45147ef01023326d4476fe3c452af17130eb92f15477dedbd6ecf76d671e0.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -34,16 +34,78 @@ "ecs-enablement-integration.assets" ], "metadata": { + "/ecs-enablement-integration/TestRole": [ + { + "type": "aws:cdk:analytics:construct", + "data": { + "roleName": "*", + "assumedBy": { + "principalAccount": "*", + "assumeRoleAction": "*" + }, + "managedPolicies": [ + { + "managedPolicyArn": "*" + } + ] + } + }, + { + "type": "aws:cdk:analytics:method", + "data": { + "addManagedPolicy": [ + { + "managedPolicyArn": "*" + } + ] + } + } + ], + "/ecs-enablement-integration/TestRole/ImportTestRole": [ + { + "type": "aws:cdk:analytics:construct", + "data": "*" + } + ], "/ecs-enablement-integration/TestRole/Resource": [ { "type": "aws:cdk:logicalId", "data": "TestRole6C9272DF" } ], + "/ecs-enablement-integration/FargateTaskDefinition": [ + { + "type": "aws:cdk:analytics:construct", + "data": "*" + }, + { + "type": "aws:cdk:analytics:construct", + "data": "*" + }, + { + "type": "aws:cdk:analytics:method", + "data": "*" + }, + { + "type": "aws:cdk:analytics:method", + "data": "*" + }, + { + "type": "aws:cdk:analytics:method", + "data": "*" + }, + { + "type": "aws:cdk:analytics:method", + "data": "*" + } + ], "/ecs-enablement-integration/FargateTaskDefinition/Resource": [ { "type": "aws:cdk:logicalId", - "data": "FargateTaskDefinition8E3B365E" + "data": "FargateTaskDefinition8E3B365E", + "trace": [ + "!!DESTRUCTIVE_CHANGES: WILL_REPLACE" + ] } ], "/ecs-enablement-integration/BootstrapVersion": [ diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/tree.json b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/tree.json index 2f396bc86afe2..4a8cacde6ca30 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/tree.json +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.js.snapshot/tree.json @@ -17,7 +17,10 @@ "path": "ecs-enablement-integration/TestRole/ImportTestRole", "constructInfo": { "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + "*" + ] } }, "Resource": { @@ -63,7 +66,28 @@ }, "constructInfo": { "fqn": "aws-cdk-lib.aws_iam.Role", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + { + "roleName": "*", + "assumedBy": { + "principalAccount": "*", + "assumeRoleAction": "*" + }, + "managedPolicies": [ + { + "managedPolicyArn": "*" + } + ] + }, + { + "addManagedPolicy": [ + { + "managedPolicyArn": "*" + } + ] + } + ] } }, "FargateTaskDefinition": { @@ -84,7 +108,7 @@ "condition": "SUCCESS" }, { - "containerName": "cwagent", + "containerName": "cloudwatch-agent", "condition": "START" } ], @@ -210,9 +234,18 @@ "name": "adot-init" }, { + "cpu": 256, "essential": true, - "image": "public.ecr.aws/cloudwatch-agent/cloudwatch-agent:1.300051.0b992-windowsservercore2019", - "name": "cwagent" + "image": "amazon/cloudwatch-agent:latest", + "memory": 512, + "name": "cloudwatch-agent", + "user": "0:1338", + "environment": [ + { + "name": "CW_CONFIG_CONTENT", + "value": "{\"logs\":{\"metrics_collected\":{\"application_signals\":{\"enabled\":true}}},\"traces\":{\"traces_collected\":{\"application_signals\":{\"enabled\":true}}}}" + } + ] } ], "cpu": "2048", @@ -270,12 +303,30 @@ }, "constructInfo": { "fqn": "aws-cdk-lib.aws_ecs.FargateTaskDefinition", - "version": "0.0.0" + "version": "0.0.0", + "metadata": [ + "*", + "*", + "*", + "*", + "*", + "*" + ] } }, "TestFargateSidecarIntegration": { "id": "TestFargateSidecarIntegration", "path": "ecs-enablement-integration/TestFargateSidecarIntegration", + "children": { + "CloudWatchAgentSidecar": { + "id": "CloudWatchAgentSidecar", + "path": "ecs-enablement-integration/TestFargateSidecarIntegration/CloudWatchAgentSidecar", + "constructInfo": { + "fqn": "@aws-cdk/aws-applicationsignals-alpha.CloudWatchAgentIntegration", + "version": "0.0.0" + } + } + }, "constructInfo": { "fqn": "@aws-cdk/aws-applicationsignals-alpha.ApplicationSignalsIntegration", "version": "0.0.0" diff --git a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.ts b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.ts index bb8b1dfa3fa06..b384ec05a26c4 100644 --- a/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.ts +++ b/packages/@aws-cdk/aws-applicationsignals-alpha/test/integ.ecs-enablement-sidecar.ts @@ -34,12 +34,10 @@ new ApplicationSignalsIntegration(stack, 'TestFargateSidecarIntegration', { sdkVersion: DotnetInstrumentationVersion.V1_6_0_WINDOWS2019, }, serviceName: 'demo', - cloudWatchAgent: { - enableSidecar: true, - container: { - containerName: 'cwagent', - image: ecs.ContainerImage.fromRegistry('public.ecr.aws/cloudwatch-agent/cloudwatch-agent:1.300051.0b992-windowsservercore2019'), - }, + cloudWatchAgentSidecar: { + containerName: 'cloudwatch-agent', + cpu: 256, + memoryLimitMiB: 512, }, });