Skip to content

Commit 6f41cf8

Browse files
mat-rumianpmalek
authored andcommitted
AWS OTel Collector templates (#788)
* Add AWS OTel Collector config templates
1 parent ebf2f63 commit 6f41cf8

File tree

5 files changed

+565
-1
lines changed

5 files changed

+565
-1
lines changed

examples/README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,29 @@ the configuration also includes cascading filter config,
4242
which is described in more detail in [trace filtering documentation](https://help.sumologic.com/Traces/Getting_Started_with_Transaction_Tracing/What_if_I_don't_want_to_send_all_the_tracing_data_to_Sumo_Logic%3F).
4343

4444
Please refer to [relevant documentation](https://help.sumologic.com/Traces/Getting_Started_with_Transaction_Tracing/Set_up_traces_collection_for_other_environments)
45-
for more details.
45+
for more details.
46+
47+
### AWS OTel Collector configuration file
48+
[non-kubernetes/aws-otel-config.yaml](non-kubernetes/aws-otel-config.yaml) contains
49+
an AWS OpenTelemetry Collector distrubtion YAML file which includes configuration
50+
for OpenTelemetry Collector. Should be deployed on the AWS environments.
51+
52+
### AWS OTel Collector for ECS in EC2 mode template
53+
[non-kubernetes/aws-otel-ecs-ec2-deployment.yaml](non-kubernetes/aws-otel-ecs-ec2-deployment.yaml) contains
54+
an AWS OpenTelemetry Collector distribution YAML file which includes
55+
CloudFormation template. It should be deployed on the AWS ECS EC2
56+
environment.
57+
58+
### AWS OTel Collector for ECS in Fargate mode template
59+
[non-kubernetes/aws-otel-ecs-fargate-deployment.yaml](non-kubernetes/aws-otel-ecs-fargate-deployment.yaml) contains
60+
an AWS OpenTelemetry Collector distribution YAML file which includes
61+
CloudFormation template. It should be deployed on the AWS ECS Fargate
62+
environment.
63+
64+
### AWS OTel Collector for EC2 deployment template
65+
[non-kubernetes/aws-otel-ec2-deployment.yaml](non-kubernetes/aws-otel-ec2-deployment.yaml) contains
66+
an AWS OpenTelemetry Collector distribution YAML file which includes
67+
CloudFormation template. It should be deployed on the AWS EC2.
68+
=======
69+
for more details.
70+
>>>>>>> main
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
extensions:
2+
health_check:
3+
receivers:
4+
otlp:
5+
protocols:
6+
grpc:
7+
endpoint: 0.0.0.0:4317
8+
http:
9+
endpoint: 0.0.0.0:55681
10+
awsxray:
11+
endpoint: 0.0.0.0:2000
12+
transport: udp
13+
processors:
14+
batch/traces:
15+
timeout: 1s
16+
send_batch_size: 50
17+
batch/metrics:
18+
timeout: 60s
19+
exporters:
20+
otlphttp:
21+
endpoint: $SUMO_HTTP_TRACES_URL
22+
service:
23+
extensions: [health_check]
24+
pipelines:
25+
traces:
26+
receivers: [otlp,awsxray]
27+
processors: [batch/traces]
28+
exporters: [otlphttp]
29+
metrics:
30+
receivers: [otlp]
31+
processors: [batch/metrics]
32+
exporters: [otlphttp]
Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
---
2+
AWSTemplateFormatVersion: '2010-09-09'
3+
Description: 'Template to install AWS OTel Collector on EC2 - Amazon Linux.'
4+
Parameters:
5+
SSHKeyName:
6+
Description: Name of an existing EC2 KeyPair to enable SSH access to the instance
7+
Type: AWS::EC2::KeyPair::KeyName
8+
ConstraintDescription: must be the name of an existing EC2 KeyPair.
9+
InstanceType:
10+
Description: EC2 instance type
11+
Type: String
12+
Default: m4.2xlarge
13+
ConstraintDescription: must be a valid EC2 instance type.
14+
InstanceAMI:
15+
Description: Managed AMI ID for EC2 Instance
16+
Type : String
17+
IAMRole:
18+
Description: EC2 attached IAM role
19+
Type: String
20+
Default: SumologicAWSOTelColRoleEC2
21+
ConstraintDescription: must be an existing IAM role which will be attached to EC2 instance.
22+
IAMPolicy:
23+
Description: IAM Role attached IAM Managed Policy
24+
Type: String
25+
Default: SumologicAWSOTelColPolicyEC2
26+
ConstraintDescription: Must be an existing IAM Managed Policy which will be attached to IAM Role.
27+
IAMInstanceProfileName:
28+
Description: IAM Role attached IAM Instance Profile
29+
Type: String
30+
Default: SumologicAWSOTelColRoleEC2
31+
ConstraintDescription: Must be an existing IAM Instance Profile which will be attached to IAM Role.
32+
SumoHttpTracesURL:
33+
Type: String
34+
Description: Enther the Sumologic HTTP Traces Endpoint URL
35+
Resources:
36+
EC2Instance:
37+
Type: AWS::EC2::Instance
38+
Metadata:
39+
AWS::CloudFormation::Init:
40+
configSets:
41+
default:
42+
- 01_setupCfnHup
43+
- 02_config-aws-otel-collector
44+
- 03_restart-aws-otel-collector
45+
UpdateEnvironment:
46+
- 02_config-aws-otel-collector
47+
- 03_restart-aws-otel-collector
48+
# Definition of YAML configuration of aws-otel-collector, you can change the configuration below.
49+
02_config-aws-otel-collector:
50+
files:
51+
'/opt/aws/aws-otel-collector/etc/config.yaml':
52+
content: !Sub
53+
- |
54+
extensions:
55+
health_check:
56+
receivers:
57+
otlp:
58+
protocols:
59+
grpc:
60+
endpoint: 0.0.0.0:4317
61+
http:
62+
endpoint: 0.0.0.0:55681
63+
awsxray:
64+
endpoint: 0.0.0.0:2000
65+
transport: udp
66+
processors:
67+
batch/traces:
68+
timeout: 1s
69+
send_batch_size: 50
70+
batch/metrics:
71+
timeout: 60s
72+
exporters:
73+
otlphttp:
74+
endpoint: ${sumo_http_traces_url}
75+
service:
76+
extensions: [health_check]
77+
pipelines:
78+
traces:
79+
receivers: [otlp,awsxray]
80+
processors: [batch/traces]
81+
exporters: [otlphttp]
82+
metrics:
83+
receivers: [otlp]
84+
processors: [batch/metrics]
85+
exporters: [otlphttp]
86+
- sumo_http_traces_url: !Ref SumoHttpTracesURL
87+
# Invoke aws-otel-collector-ctl to restart aws-otel-collector.
88+
03_restart-aws-otel-collector:
89+
commands:
90+
01_stop_service:
91+
command: sudo /opt/aws/aws-otel-collector/bin/aws-otel-collector-ctl -a stop
92+
02_start_service:
93+
command: sudo /opt/aws/aws-otel-collector/bin/aws-otel-collector-ctl -a start
94+
# Cfn-hup setting, it is to monitor the change of metadata.
95+
# When there is change in the contents of json file in the metadata section, cfn-hup will call cfn-init to restart aws-otel-collector.
96+
01_setupCfnHup:
97+
files:
98+
'/etc/cfn/cfn-hup.conf':
99+
content: !Sub |
100+
[main]
101+
stack=${AWS::StackId}
102+
region=${AWS::Region}
103+
interval=1
104+
mode: '000400'
105+
owner: root
106+
group: root
107+
'/etc/cfn/hooks.d/aws-otel-collector-auto-reloader.conf':
108+
content: !Sub |
109+
[cfn-auto-reloader-hook]
110+
triggers=post.update
111+
path=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init.02_config-aws-otel-collector
112+
action=/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets UpdateEnvironment
113+
runas=root
114+
mode: '000400'
115+
owner: root
116+
group: root
117+
"/lib/systemd/system/cfn-hup.service":
118+
content: !Sub |
119+
[Unit]
120+
Description=cfn-hup daemon
121+
[Service]
122+
Type=simple
123+
ExecStart=/opt/aws/bin/cfn-hup
124+
Restart=always
125+
[Install]
126+
WantedBy=multi-user.target
127+
commands:
128+
01enable_cfn_hup:
129+
command: !Sub |
130+
systemctl enable cfn-hup.service
131+
02start_cfn_hup:
132+
command: !Sub |
133+
systemctl start cfn-hup.service
134+
135+
Properties:
136+
InstanceType:
137+
Ref: InstanceType
138+
IamInstanceProfile:
139+
Ref: IAMRole
140+
KeyName:
141+
Ref: SSHKeyName
142+
ImageId:
143+
Ref: InstanceAMI
144+
SecurityGroups:
145+
- Ref: InstanceSecurityGroup
146+
Tags:
147+
- Key: Name
148+
Value: sumologic-aws-otel-col-ec2
149+
UserData:
150+
# This script below is to install aws-otel-collector, restart aws-otel-collector and tell the result to cloudformation.
151+
Fn::Base64: !Sub
152+
- |
153+
#!/bin/bash
154+
155+
# Download AWS OTel Collector RPM
156+
sudo rpm -Uvh https://aws-otel-collector.s3.amazonaws.com/amazon_linux/amd64/latest/aws-otel-collector.rpm
157+
158+
# Setup Sumologic HTTP Traces URL ENV
159+
echo "export SUMO_HTTP_TRACES_URL=${sumo_http_traces_url}" > /etc/profile.d/setSumoVar.sh
160+
161+
/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets default
162+
/opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region}
163+
- sumo_http_traces_url: !Ref SumoHttpTracesURL
164+
DependsOn:
165+
- EC2Role
166+
- IAMInstanceProfile
167+
- InstanceSecurityGroup
168+
169+
IAMInstanceProfile:
170+
Type: 'AWS::IAM::InstanceProfile'
171+
Properties:
172+
InstanceProfileName: !Ref IAMInstanceProfileName
173+
Path: /
174+
Roles:
175+
- !Ref IAMRole
176+
DependsOn: EC2Role
177+
178+
EC2Role:
179+
Type: 'AWS::IAM::Role'
180+
Properties:
181+
Description: Allows EC2 to call AWS services on your behalf.
182+
AssumeRolePolicyDocument:
183+
Version: 2012-10-17
184+
Statement:
185+
- Effect: Allow
186+
Principal:
187+
Service: ec2.amazonaws.com
188+
Action: 'sts:AssumeRole'
189+
ManagedPolicyArns:
190+
- !Sub 'arn:aws:iam::${AWS::AccountId}:policy/${IAMPolicy}'
191+
RoleName: !Ref IAMRole
192+
DependsOn: EC2Policy
193+
194+
EC2Policy:
195+
Type: 'AWS::IAM::ManagedPolicy'
196+
Properties:
197+
Description: Allows EC2 to call AWS services on your behalf.
198+
Path: /
199+
ManagedPolicyName: !Ref IAMPolicy
200+
PolicyDocument:
201+
Version: "2012-10-17"
202+
Statement:
203+
- Effect: Allow
204+
Action:
205+
- logs:PutLogEvents
206+
- logs:CreateLogGroup
207+
- logs:CreateLogStream
208+
- logs:DescribeLogStreams
209+
- logs:DescribeLogGroups
210+
- xray:PutTraceSegments
211+
- xray:PutTelemetryRecords
212+
- xray:GetSamplingRules
213+
- xray:GetSamplingTargets
214+
- xray:GetSamplingStatisticSummaries
215+
- ssm:GetParameters
216+
Resource: '*'
217+
218+
InstanceSecurityGroup:
219+
Type: AWS::EC2::SecurityGroup
220+
Properties:
221+
GroupDescription: Enable SSH access via port 22
222+
SecurityGroupIngress:
223+
- IpProtocol: tcp
224+
FromPort: 22
225+
ToPort: 22
226+
CidrIp: 0.0.0.0/0
227+
- IpProtocol: tcp
228+
FromPort: 4317
229+
ToPort: 4317
230+
CidrIp: 0.0.0.0/0
231+
- IpProtocol: tcp
232+
FromPort: 55680
233+
ToPort: 55680
234+
CidrIp: 0.0.0.0/0
235+
- IpProtocol: tcp
236+
FromPort: 55681
237+
ToPort: 55681
238+
CidrIp: 0.0.0.0/0
239+
- IpProtocol: udp
240+
FromPort: 2000
241+
ToPort: 2000
242+
CidrIp: 0.0.0.0/0

0 commit comments

Comments
 (0)