Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add adot instrumentation #926

Closed
wants to merge 46 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
7bd449e
[DOP-4033]: Add adot instrumentation
branberry Oct 12, 2023
6787d74
Use module.exports
branberry Oct 12, 2023
bcb2b66
Use proxy handler
branberry Oct 13, 2023
4810dbd
Use regular handler
branberry Oct 13, 2023
3ad5304
Update exports
branberry Oct 13, 2023
a406a2b
Use module.exports
branberry Oct 13, 2023
20d85d6
Update cdk version and use latest adot
branberry Oct 13, 2023
59b120e
Remove ADOT
branberry Oct 13, 2023
82edf6c
add provisioned concurrency
branberry Oct 13, 2023
1d44889
[DOP-4033]: Comment out adot
branberry Oct 16, 2023
e63cd00
Remove adot
branberry Oct 16, 2023
5f8a318
Add adot back in
branberry Oct 16, 2023
2308c88
Merge branch 'master' into tracing-poc
branberry Oct 26, 2023
ae46c5c
Add autoinstrumentation
branberry Oct 26, 2023
0d96010
add back in manual instrumentation
branberry Oct 27, 2023
de43e5c
add back in manual instrumentation
branberry Oct 27, 2023
f81bfff
Update manual instrumentation
branberry Oct 30, 2023
e64d217
Update manual instrumentation
branberry Oct 30, 2023
fd6d86f
Add path
branberry Oct 30, 2023
7a265bb
Add x-ray tracing policy
branberry Oct 30, 2023
397658a
Add sidecar
branberry Oct 30, 2023
82f29fa
Use default otel config
branberry Oct 30, 2023
8768f3b
Enable x-ray tracing
branberry Oct 30, 2023
4a70bfd
Use simple span processor
branberry Oct 30, 2023
fec6c44
Manually add OTel layer
branberry Oct 30, 2023
1a99354
Add collector and instrumentation layers
branberry Oct 30, 2023
c0ce76e
Add region
branberry Oct 31, 2023
e292a6a
Add config.yml
branberry Oct 31, 2023
c1925bb
Update path
branberry Oct 31, 2023
5c79368
Use collector.yaml
branberry Oct 31, 2023
517aa80
Add collectors and confi.yaml
branberry Oct 31, 2023
b62aef8
Rename
branberry Oct 31, 2023
6209fb8
use valid exporter for metrics
branberry Oct 31, 2023
cd30f3b
Add env variable
branberry Oct 31, 2023
fffe41b
remvoe otel env vars
branberry Oct 31, 2023
5fc9909
revert
branberry Oct 31, 2023
8b9dbc0
Use latest version
branberry Oct 31, 2023
0e508d3
Don\t suppress aws
branberry Oct 31, 2023
69c8d55
log queue message
branberry Oct 31, 2023
3f97b9e
use config
branberry Oct 31, 2023
0fe870b
Add dependency
branberry Oct 31, 2023
c01ad0e
Add tracing
branberry Nov 6, 2023
68627ed
Change condition
branberry Nov 6, 2023
6fee2ee
Update tracing
branberry Nov 7, 2023
d14c889
add logging
branberry Nov 7, 2023
402aad6
Merge branch 'master' into tracing-poc
branberry Nov 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile.enhanced
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ ENV OAS_MODULE_PATH=${WORK_DIRECTORY}/modules/oas-page-builder/index.js

RUN mkdir repos && chmod 755 repos
EXPOSE 3000
CMD ["node", "enhanced/enhancedApp.js"]
CMD ["node", "--require", "./otel/index.js" , "enhanced/enhancedApp.js"]
4 changes: 2 additions & 2 deletions api/controllers/v2/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async function prepGithubPushPayload(
const branch_info = await repoBranchesRepository.getRepoBranchAliases(
githubEvent.repository.name,
branch_name,
repoInfo.project
repoInfo?.project
);
const urlSlug = branch_info.aliasObject?.urlSlug ?? branch_name;
const project = repoInfo?.project ?? githubEvent.repository.name;
Expand Down Expand Up @@ -58,7 +58,7 @@ async function prepGithubPushPayload(
};
}

export const TriggerBuild = async (event: APIGatewayEvent): Promise<APIGatewayProxyResult> => {
module.exports.TriggerBuild = async (event: APIGatewayEvent): Promise<APIGatewayProxyResult> => {
const client = new mongodb.MongoClient(c.get('dbUrl'));
await client.connect();
const db = client.db(c.get('dbName'));
Expand Down
20 changes: 19 additions & 1 deletion cdk-infra/lib/constructs/api/webhook-api-construct.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { Duration } from 'aws-cdk-lib';
import { Cors, CorsOptions, LambdaIntegration, LambdaRestApi } from 'aws-cdk-lib/aws-apigateway';
import { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda';
import {
AdotLambdaExecWrapper,
AdotLambdaLayerJavaScriptSdkVersion,
AdotLayerVersion,
Code,
Function,
Runtime,
Tracing,
} from 'aws-cdk-lib/aws-lambda';
import { SqsEventSource } from 'aws-cdk-lib/aws-lambda-event-sources';
import { BundlingOptions, NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';
import { IQueue } from 'aws-cdk-lib/aws-sqs';
Expand Down Expand Up @@ -71,7 +79,16 @@ export class WebhookApiConstruct extends Construct {
handler: 'TriggerBuild',
bundling,
environment,
memorySize: 1024,
timeout,
tracing: Tracing.ACTIVE,
currentVersionOptions: {
provisionedConcurrentExecutions: 5,
},
adotInstrumentation: {
execWrapper: AdotLambdaExecWrapper.REGULAR_HANDLER,
layerVersion: AdotLayerVersion.fromJavaScriptSdkLayerVersion(AdotLambdaLayerJavaScriptSdkVersion.LATEST),
},
});

const githubDeleteArtifactsLambda = new NodejsFunction(this, 'githubDeleteArtifactsLambda', {
Expand Down Expand Up @@ -123,6 +140,7 @@ export class WebhookApiConstruct extends Construct {
const restApi = new LambdaRestApi(this, apiName, {
handler: rootEndpointLambda,
proxy: false,
cloudWatchRole: true,
});

const webhookEndpoint = restApi.root.addResource('webhook');
Expand Down
19 changes: 19 additions & 0 deletions cdk-infra/lib/constructs/otel/otel-construct.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { IVpc } from 'aws-cdk-lib/aws-ec2';
import { Cluster } from 'aws-cdk-lib/aws-ecs';
import { Construct } from 'constructs';

interface Props {
vpc: IVpc;
}

export class OtelCollectorConstruct extends Construct {
constructor(scope: Construct, id: string, { vpc }: Props) {
super(scope, id);

const cluster = new Cluster(this, 'otel-cluster', {
vpc,
enableFargateCapacityProviders: true,
containerInsights: true,
});
}
}
55 changes: 48 additions & 7 deletions cdk-infra/lib/constructs/worker/worker-construct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { IVpc } from 'aws-cdk-lib/aws-ec2';
import {
AssetImageProps,
Cluster,
ContainerDependencyCondition,
ContainerImage,
FargateService,
FargateTaskDefinition,
LogDrivers,
Protocol,
} from 'aws-cdk-lib/aws-ecs';
import { Effect, IRole, PolicyStatement, Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam';
import { LogGroup } from 'aws-cdk-lib/aws-logs';
Expand Down Expand Up @@ -80,6 +82,17 @@ export class WorkerConstruct extends Construct {
executionRole,
});

const xrayTracingPolicy = new PolicyStatement({
effect: Effect.ALLOW,
actions: [
'xray:PutTraceSegments',
'xray:PutTelemetryRecords',
'xray:GetSamplingRules',
'xray:GetSamplingTargets',
'xray:GetSamplingStatisticSummaries',
],
resources: ['*'],
});
const updateTaskProtectionPolicy = new PolicyStatement({
effect: Effect.ALLOW,
actions: ['ecs:UpdateTaskProtection'],
Expand All @@ -91,17 +104,45 @@ export class WorkerConstruct extends Construct {
resources: ['*'],
});

taskRole.addToPolicy(xrayTracingPolicy);
taskRole.addToPolicy(updateTaskProtectionPolicy);

taskDefinition.addContainer('workerImage', {
image: ContainerImage.fromAsset(path.join(__dirname, '../../../../'), containerProps),
environment: dockerEnvironment,
logging: LogDrivers.awsLogs({
streamPrefix: 'autobuilderworker',
logGroup: taskDefLogGroup,
}),
const sideCar = taskDefinition.addContainer('otelSidecar', {
image: ContainerImage.fromRegistry('amazon/aws-otel-collector'),
command: ['--config=/etc/ecs/ecs-default-config.yaml'],
portMappings: [
{
hostPort: 2000,
protocol: Protocol.UDP,
containerPort: 2000,
},
{
hostPort: 4317,
protocol: Protocol.TCP,
containerPort: 4317,
},
{
hostPort: 8125,
protocol: Protocol.UDP,
containerPort: 8125,
},
],
});

taskDefinition
.addContainer('workerImage', {
image: ContainerImage.fromAsset(path.join(__dirname, '../../../../'), containerProps),
environment: dockerEnvironment,
logging: LogDrivers.awsLogs({
streamPrefix: 'autobuilderworker',
logGroup: taskDefLogGroup,
}),
})
.addContainerDependencies({
container: sideCar,
condition: ContainerDependencyCondition.START,
});

const env = getEnv();

new FargateService(this, 'fargateService', {
Expand Down
64 changes: 27 additions & 37 deletions cdk-infra/package-lock.json

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

4 changes: 2 additions & 2 deletions cdk-infra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@swc/helpers": "^0.5.1",
"@types/jest": "^29.4.0",
"@types/node": "18.14.6",
"aws-cdk": "2.73.0",
"aws-cdk": "2.100.0",
"esbuild": "^0.18.3",
"jest": "^29.5.0",
"regenerator-runtime": "^0.13.11",
Expand All @@ -31,7 +31,7 @@
},
"dependencies": {
"@aws-sdk/client-ssm": "^3.342.0",
"aws-cdk-lib": "2.73.0",
"aws-cdk-lib": "2.103.1",
"constructs": "^10.0.0",
"source-map-support": "^0.5.21"
}
Expand Down
27 changes: 27 additions & 0 deletions cdk-infra/static/api/config/collector.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#collector.yaml in the root directory
#Set an environment variable 'OPENTELEMETRY_COLLECTOR_CONFIG_FILE' to '/var/task/collector.yaml'

receivers:
otlp:
protocols:
grpc:
endpoint: 'localhost:4317'
http:
endpoint: 'localhost:4318'

exporters:
# NOTE: Prior to v0.86.0 use `logging` instead of `debug`.
debug:
awsxray:

service:
pipelines:
traces:
receivers: [otlp]
exporters: [awsxray]
metrics:
receivers: [otlp]
exporters: [prometheusremotewrite]
telemetry:
metrics:
address: localhost:8888
24 changes: 24 additions & 0 deletions cdk-infra/static/api/config/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
receivers:
otlp:
protocols:
grpc:
endpoint: 'localhost:4317'
http:
endpoint: 'localhost:4318'

exporters:
# NOTE: Prior to v0.86.0 use `logging` instead of `debug`.
debug:
verbosity: detailed

service:
pipelines:
traces:
receivers: [otlp]
exporters: [debug]
metrics:
receivers: [otlp]
exporters: [debug]
telemetry:
metrics:
address: localhost:8888
Loading
Loading