/
config.yml
154 lines (154 loc) · 5.32 KB
/
config.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
version: 2
workflows:
version: 2
build-docker-image:
jobs:
- build
- dockerfile:
requires:
- build
# nightly:
# triggers:
# - schedule:
# cron: "15 0 * * 1-5"
# filters:
# branches:
# only:
# - master
# jobs:
# - loadtest
jobs:
build:
docker:
- image: circleci/golang:1.10
- image: neo4j:3.2.7-enterprise
environment:
NEO4J_AUTH: none
NEO4J_HEAP_MEMORY: 256
NEO4J_CACHE_MEMORY: 256M
working_directory: /go/src/github.com/Financial-Times/public-people-api
environment:
NEO4J_TEST_URL: "http://localhost:7474/db/data/"
CIRCLE_TEST_REPORTS: /tmp/test-results
CIRCLE_COVERAGE_REPORT: /tmp/coverage-results
steps:
- checkout
- run:
name: Make /go owned by circleci
command: sudo chown -R circleci:circleci /go
- run:
name: Create test folder
command: |
mkdir -p ${CIRCLE_TEST_REPORTS}/golang
mkdir -p ${CIRCLE_COVERAGE_REPORT}
- run:
name: Download dependencies
command: |
go get -u github.com/jstemmer/go-junit-report
go get -u github.com/mattn/goveralls
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
- run:
name: Import libraries
command: dep ensure -v -vendor-only
- run:
name: Wait for Neo to be available
command: wget --retry-connrefused --no-check-certificate -T 60 $NEO4J_TEST_URL; curl $NEO4J_TEST_URL
- run:
name: Run tests and coverage
command: |
go test ./... -race -cover -coverprofile=$CIRCLE_COVERAGE_REPORT/coverage.out | go-junit-report > $CIRCLE_TEST_REPORTS/golang/junit.xml
- run:
name: Upload Coverage
command: /go/bin/goveralls -coverprofile=$CIRCLE_COVERAGE_REPORT/coverage.out -service=circle-ci -repotoken=$COVERALLS_TOKEN
- store_test_results:
path: /tmp/test-results
dockerfile:
working_directory: /public-people-api
docker:
- image: docker:18.03
steps:
- checkout
- setup_docker_engine
- run:
name: Build Dockerfile
command: docker build .
loadtest:
working_directory: /go/src/github.com/Financial-Times/public-people-api
docker:
- image: golang:1.10
environment:
GOPATH: /go
steps:
- checkout
- run:
name: External Dependencies
command: go get -u github.com/tsenart/vegeta
- run:
name: Install jq
command: |
wget https://github.com/stedolan/jq/releases/download/jq-1.5/jq-1.5.tar.gz
tar -xzf jq-1.5.tar.gz
cd jq-1.5
./configure
make
make install
- run:
name: Install vegeta
command: |
cd /go/src/github.com/tsenart/vegeta
go install
cd /go/bin
- run:
name: Run load test
command: vegeta attack -workers=2 -duration=300s -targets=./people.req > results.bin
- run:
name: Get hist and result
command: |
vegeta report -inputs=results.bin -reporter='hist[0,50ms,100ms,250ms,500ms,1s,2s,5s]'
echo "------------------------------------------------------"
vegeta report -inputs=results.bin -reporter=text
- run:
name: Store load test result
command: echo "nothing for now"
- run:
name: Send result to Slack when test fails
command: |
TEST_RESULT=`vegeta report -inputs=results.bin -reporter=text`
TIMESTAMP=$(date "+%s")
SUCCEEDED_MESSAGE=$(cat <<EOF
{
"attachments": [
{
"text": "Load testing succeeded - $CIRCLE_PROJECT_REPONAME/$CIRCLE_BRANCH",
"color": "good",
}
]
}
EOF
)
FAILED_MESSAGE=$(cat <<EOF
{
"attachments": [
{
"author_name": "$CIRCLE_PR_USERNAME",
"title": "Load testing failed - $CIRCLE_PROJECT_REPONAME/$CIRCLE_BRANCH <$CIRCLE_BUILD_URL|#$CIRCLE_BUILD_NUM>",
"color": "danger",
"text": "95th latency is over 500ms. \n \`\`\`$TEST_RESULT\`\`\`",
"footer": "$CIRCLE_PROJECT_REPONAME/$CIRCLE_BRANCH",
"ts": $TIMESTAMP,
"mrkdwn_in": ["text"]
}
]
}
EOF
)
# Latency values from report are nano second.
# The threshold is over 500ms (95 percentile latency)
LATENCY_MS=`vegeta report -inputs=results.bin -reporter=json | jq -e '.latencies."95th" / (1000 * 1000) | floor'`
if [ $LATENCY_MS -lt 500 ] ; then
curl "${SLACK_WEBHOOK_URL}" -X "POST" -H "content-type: application/json" -d "${SUCCEEDED_MESSAGE}"
exit 0
else
curl "${SLACK_WEBHOOK_URL}" -X "POST" -H "content-type: application/json" -d "${FAILED_MESSAGE}"
exit 1
fi