Skip to content
This repository was archived by the owner on Sep 28, 2022. It is now read-only.

Commit bbeb76e

Browse files
committed
Added sample test that indexes documents in elasticsearch
1 parent 5e40bc7 commit bbeb76e

File tree

4 files changed

+186
-11
lines changed

4 files changed

+186
-11
lines changed
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
4+
# software and associated documentation files (the "Software"), to deal in the Software
5+
# without restriction, including without limitation the rights to use, copy, modify,
6+
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
7+
# permit persons to whom the Software is furnished to do so.
8+
#
9+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
10+
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
11+
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
12+
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
13+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
14+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15+
AWSTemplateFormatVersion: 2010-09-09
16+
Description: Distributed load testing (DLT) using AWS Fargate
17+
18+
Parameters:
19+
FargateClusterName:
20+
Type: String
21+
Default: "dlt-fargate"
22+
DockerImage:
23+
Type: String
24+
DockerTaskMemory:
25+
Type: Number
26+
Default: 2048
27+
AllowedValues:
28+
- 512
29+
- 1024
30+
- 2048
31+
- 3072
32+
- 4096
33+
- 5120
34+
- 6144
35+
- 7168
36+
- 8192
37+
- 16384
38+
DockerTaskCpu:
39+
Type: Number
40+
Default: 512
41+
AllowedValues:
42+
- 256
43+
- 512
44+
- 1024
45+
- 2048
46+
- 4096
47+
Vpc:
48+
Type: AWS::EC2::VPC::Id
49+
Description: VPC where the Fargate cluster will be placed
50+
SubnetA:
51+
Type: AWS::EC2::Subnet::Id
52+
Description: Subnet A of the VPC
53+
SubnetB:
54+
Type: AWS::EC2::Subnet::Id
55+
Description: Subnet B of the VPC
56+
SubnetC:
57+
Type: AWS::EC2::Subnet::Id
58+
Description: Subnet C of the VPC
59+
60+
Metadata:
61+
AWS::CloudFormation::Interface:
62+
ParameterGroups:
63+
-
64+
Label:
65+
default: "Network Configuration"
66+
Parameters:
67+
- Vpc
68+
- SubnetA
69+
- SubnetB
70+
- SubnetC
71+
-
72+
Label:
73+
default: "Fargate and Docker Configuration"
74+
Parameters:
75+
- FargateClusterName
76+
- DockerImage
77+
- DockerTaskMemory
78+
- DockerTaskCpu
79+
80+
Outputs:
81+
SubnetA:
82+
Value: !Ref SubnetA
83+
SubnetB:
84+
Value: !Ref SubnetB
85+
SubnetC:
86+
Value: !Ref SubnetC
87+
FargateClusterName:
88+
Value: !Ref FargateCluster
89+
TaskSecurityGroup:
90+
Value: !Ref FargateTaskSecurityGroup
91+
TaskDefinitionArn:
92+
Value: !Ref FargateTaskDefinition
93+
TaskIAMRole:
94+
Value: !Ref FargateTaskExecutionRole
95+
96+
Resources:
97+
FargateTaskSecurityGroup:
98+
Type: AWS::EC2::SecurityGroup
99+
Properties:
100+
GroupDescription: 'DLT Fargate tasks security group'
101+
VpcId: !Ref Vpc
102+
SecurityGroupEgress:
103+
IpProtocol: '-1'
104+
CidrIp: 0.0.0.0/0
105+
106+
FargateCluster:
107+
Type: AWS::ECS::Cluster
108+
Properties:
109+
ClusterName: !Ref FargateClusterName
110+
111+
FargateTaskExecutionRole:
112+
Type: AWS::IAM::Role
113+
Properties:
114+
AssumeRolePolicyDocument:
115+
Version: "2012-10-17"
116+
Statement:
117+
-
118+
Effect: Allow
119+
Action: "sts:AssumeRole"
120+
Principal:
121+
Service: "ecs-tasks.amazonaws.com"
122+
ManagedPolicyArns:
123+
- "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
124+
125+
FargateTaskCloudWatchLogGroup:
126+
Type: AWS::Logs::LogGroup
127+
Properties:
128+
RetentionInDays: 365
129+
130+
TaurusLogFilterAvgResponseTime:
131+
Type: AWS::Logs::MetricFilter
132+
Properties:
133+
FilterPattern: "[time, logType=INFO*, logTitle=Current*, numVu, vu, numSucc, succ, numFail, fail, avgRt, x]"
134+
LogGroupName: !Ref FargateTaskCloudWatchLogGroup
135+
MetricTransformations:
136+
-
137+
MetricValue: "$avgRt"
138+
MetricNamespace: "dlt-fargate/taurus"
139+
MetricName: "avgResponseTime"
140+
141+
FargateTaskDefinition:
142+
Type: AWS::ECS::TaskDefinition
143+
Properties:
144+
Cpu: !Ref DockerTaskCpu
145+
ExecutionRoleArn: !GetAtt FargateTaskExecutionRole.Arn
146+
Family: 'dlt-fargate-task'
147+
Memory: !Ref DockerTaskMemory
148+
NetworkMode: awsvpc
149+
RequiresCompatibilities:
150+
- FARGATE
151+
TaskRoleArn: !GetAtt FargateTaskExecutionRole.Arn
152+
ContainerDefinitions:
153+
-
154+
Name: "dlt-fargate-task"
155+
Essential: true
156+
Image: !Ref DockerImage
157+
Memory: !Ref DockerTaskMemory
158+
LogConfiguration:
159+
LogDriver: awslogs
160+
Options:
161+
awslogs-group: !Ref FargateTaskCloudWatchLogGroup
162+
awslogs-region: !Ref "AWS::Region"
163+
awslogs-stream-prefix: "dlt-fargate"
164+
Command:
165+
- "taurus.yml"

examples/elasticsearch/index.test.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,29 @@
22
// SPDX-License-Identifier: MIT-0
33
const elasticsearch = require('elasticsearch');
44
const awsElasticSearch = require('http-aws-es');
5+
const ChanceJs = require('chance');
6+
const chance = new ChanceJs();
57

6-
describe('Elasticsearch GameDay', function() {
8+
describe('Elasticsearch GameDay', () => {
79

810
const elasticSearchUrl = 'https://banana.us-west-2.es.amazonaws.com';
11+
const index = 'performance-testing';
912
const client = new elasticsearch.Client({
1013
hosts: [elasticSearchUrl],
1114
connectionClass: awsElasticSearch,
1215
apiVersion: "6.3",
1316
});
1417

15-
it('check health of cluster', function (done) {
16-
return client.cluster.health()
17-
.then(data => {
18-
console.log('Health=', data);
19-
done();
20-
})
21-
.catch(err => {
22-
console.log('Error=', err);
23-
done();
24-
});
18+
it('stores a JSON document', () => {
19+
return client.index({
20+
index: index,
21+
type: 'dummyType',
22+
id: chance.hash(),
23+
body: {
24+
name: chance.first(),
25+
created: new Date().getTime(),
26+
description: chance.paragraph(),
27+
},
28+
});
2529
});
2630
});

examples/elasticsearch/package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/elasticsearch/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"main": "index.test.js",
66
"dependencies": {
77
"aws-sdk": "^2.348.0",
8+
"chance": "^1.0.16",
89
"elasticsearch": "^15.2.0",
910
"http-aws-es": "^6.0.0",
1011
"mocha": "^3.0.2"

0 commit comments

Comments
 (0)