Skip to content

Commit 6cf3be6

Browse files
Run apm-server standalone as part of e2e tests (#3728)
Adds an integration test to ensure that server/agent.go propagates config from proto.APMConfig correctly. Adds the apm-server as a stand-alone binary in our e2e test suite, and specifies tests so we can test if fleet-server properly loads and sends trace information.
1 parent a46c709 commit 6cf3be6

17 files changed

+656
-26
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ go.work.sum
2828

2929
.service_token*
3030
.kibana_service_token
31-
31+
.apm_server_api_key
3232

3333
# direnv
3434
.envrc*

Makefile

+6-4
Original file line numberDiff line numberDiff line change
@@ -357,13 +357,15 @@ e2e-certs: ## - Use openssl to create a CA, encrypted private key, and signed fl
357357

358358
.PHONY: e2e-docker-start
359359
e2e-docker-start: int-docker-start ## - Start a testing instance of Elasticsearch and Kibana in docker containers
360-
@KIBANA_TOKEN=$(shell ./dev-tools/e2e/get-kibana-servicetoken.sh ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}@${TEST_ELASTICSEARCH_HOSTS}) docker compose -f ./dev-tools/e2e/docker-compose.yml --env-file ./dev-tools/integration/.env up -d --remove-orphans kibana
361-
@./dev-tools/e2e/wait-for-kibana.sh ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}@localhost:5601
360+
@KIBANA_TOKEN=$(shell ./dev-tools/e2e/get-kibana-servicetoken.sh ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}@${TEST_ELASTICSEARCH_HOSTS}) \
361+
APM_KEY=$(shell ./dev-tools/e2e/get-apm-server-api-key.sh ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}@${TEST_ELASTICSEARCH_HOSTS}) \
362+
docker compose -f ./dev-tools/e2e/docker-compose.yml --env-file ./dev-tools/integration/.env up -d --remove-orphans kibana --remove-orphans apm-server --wait
363+
@./dev-tools/e2e/wait-for-apm.sh localhost:8200
362364

363365
.PHONY: e2e-docker-stop
364366
e2e-docker-stop: ## - Tear down testing Elasticsearch and Kibana instances
365-
@KIBANA_TOKEN="supress-warning" docker compose -f ./dev-tools/e2e/docker-compose.yml --env-file ./dev-tools/integration/.env down
366-
rm -f .kibana_service_token
367+
@KIBANA_TOKEN="supress-warning" APM_KEY="supress-warning" docker compose -f ./dev-tools/e2e/docker-compose.yml --env-file ./dev-tools/integration/.env down
368+
rm -f .kibana_service_token .apm_server_api_key
367369
@$(MAKE) int-docker-stop
368370

369371
.PHONY: test-e2e

dev-tools/e2e/apm-server.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
######################### APM Server Configuration #########################
2+
3+
################################ APM Server ################################
4+
5+
apm-server:
6+
host: "0.0.0.0:8200"
7+
8+
# Agent authorization configuration. If no methods are defined, all requests will be allowed.
9+
auth:
10+
api_key:
11+
enabled: false
12+
secret_token: "b!gS3cret"
13+
14+
logging.level: debug
15+
logging.to_stderr: true
16+
17+
output.elasticsearch:
18+
hosts: ["elasticsearch:9200"]
19+
api_key: "${API_KEY}"

dev-tools/e2e/docker-compose.yml

+23
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ services:
33
kibana:
44
image: "docker.elastic.co/kibana/kibana:${ELASTICSEARCH_VERSION}-amd64"
55
container_name: kibana
6+
healthcheck:
7+
test: ["CMD", "curl", "-f", "${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}@localhost:5601/api/status"]
8+
start_period: 20s
9+
interval: 10s
10+
timeout: 10s
11+
retries: 3
612
environment:
713
- KIBANA_TOKEN=${KIBANA_TOKEN}
814
volumes:
@@ -11,6 +17,23 @@ services:
1117
- 127.0.0.1:5601:5601
1218
networks:
1319
- integration
20+
apm-server:
21+
image: "docker.elastic.co/apm/apm-server:${ELASTICSEARCH_VERSION}-amd64"
22+
container_name: apm-server
23+
# curl is not in the apm-server image
24+
#healthcheck:
25+
# test: ["CMD", "curl", "-f", "localhost:8200"]
26+
# interval: 10s
27+
# timeout: 10s
28+
# retries: 3
29+
environment:
30+
- API_KEY=${APM_KEY}
31+
volumes:
32+
- ./apm-server.yml:/usr/share/apm-server/apm-server.yml
33+
ports:
34+
- 127.0.0.1:8200:8200
35+
networks:
36+
- integration
1437
# Attach to the integration test network
1538
networks:
1639
integration:
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
3+
host="$1"
4+
5+
jsonBody=$(curl -sSL -XPOST "$host/_security/api_key" -H 'Content-Type: application/json' -d'
6+
{
7+
"name": "apm-server-key",
8+
"role_descriptors": {
9+
"apm_writer": {
10+
"indices": [{
11+
"names": ["apm-*"],
12+
"privileges": ["create_index", "create_doc"]
13+
}, {
14+
"names": [".apm-source-map"],
15+
"privileges": ["read"]
16+
}, {
17+
"names": [".apm-agent-configuration"],
18+
"privileges": ["read"],
19+
"allow_restricted_indices": true
20+
}, {
21+
"names": ["traces-apm*", "logs-apm*", "metrics-apm*"],
22+
"privileges": ["auto_configure", "create_doc"]
23+
}],
24+
"cluster": ["monitor"]
25+
},
26+
"apm_monitoring_writer": {
27+
"indices": [{
28+
"names": [".monitoring-beats-*"],
29+
"privileges": ["create_index", "create_doc"]
30+
}]
31+
},
32+
"apm_api_key": {
33+
"cluster": ["manage_own_api_key"],
34+
"applications": [{
35+
"application": "apm",
36+
"privileges": ["event:write"],
37+
"resources": ["*"]
38+
}]
39+
}
40+
}
41+
}
42+
')
43+
44+
# use grep and sed to get the encoded api key as we may not have jq or a similar tool on the instance
45+
apiKey=$(echo ${jsonBody} | grep -Eo '"encoded"[^}]*' | grep -Eo ':.*' | sed -r "s/://" | sed -r 's/"//g' | base64 --decode)
46+
47+
# cache ApiKey for testing
48+
if [ -z "$apiKey" ]
49+
then
50+
apiKey=`cat .apm_server_api_key`
51+
else
52+
echo "$apiKey" > .apm_server_api_key
53+
fi
54+
55+
echo "$apiKey"

dev-tools/e2e/kibana.yml

+22
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ xpack.fleet.packages:
1313
version: latest
1414
- name: fleet_server
1515
version: latest
16+
- name: apm
17+
version: latest
1618
xpack.fleet.agentPolicies:
1719
- name: dummy-policy
1820
id: dummy-policy
@@ -35,6 +37,26 @@ xpack.fleet.agentPolicies:
3537
id: default-fleet-server
3638
package:
3739
name: fleet_server
40+
- name: apm-policy
41+
id: apm-policy
42+
namespace: default
43+
monitoring_enabled: []
44+
package_policies:
45+
- name: apm-1
46+
id: default-apm
47+
package:
48+
name: apm
49+
- name: fleet-server-apm
50+
id: fleet-server-apm
51+
monitoring_enabled: []
52+
is_default_fleet_server: false
53+
is_managed: false
54+
namespace: default
55+
package_policies:
56+
- name: fleet_server-2
57+
id: default-fleet-server
58+
package:
59+
name: fleet_server
3860
xpack.fleet.outputs:
3961
- id: fleet-default-output
4062
name: default

dev-tools/e2e/wait-for-kibana.sh dev-tools/e2e/wait-for-apm.sh

+7-9
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,24 @@ cmd="$@"
88

99
REPO_ROOT=$(cd $(dirname $(readlink -f "$0"))/../.. && pwd)
1010

11-
12-
13-
until $(curl --output /dev/null --silent --head --fail "${host}/api/status"); do
14-
if [[ ! $(docker compose -f $REPO_ROOT/dev-tools/e2e/docker-compose.yml --env-file $REPO_ROOT/dev-tools/integration/.env ps --filter status=running -q kibana 2>/dev/null) ]]; then
15-
echo "Kibana container is not running"
16-
docker-compose -f $REPO_ROOT/dev-tools/e2e/docker-compose.yml --env-file $REPO_ROOT/dev-tools/integration/.env logs kibana
11+
until $(curl --output /dev/null --silent --fail "${host}"); do
12+
if [[ ! $(docker compose -f $REPO_ROOT/dev-tools/e2e/docker-compose.yml --env-file $REPO_ROOT/dev-tools/integration/.env ps --filter status=running -q apm-server 2>/dev/null) ]]; then
13+
echo "apm-server container is not running"
14+
docker-compose -f $REPO_ROOT/dev-tools/e2e/docker-compose.yml --env-file $REPO_ROOT/dev-tools/integration/.env logs apm-server
1715
exit 1
1816
fi
1917
printf '.'
2018
sleep 1
2119
done
2220

23-
# First wait for ES to start...
21+
# First wait for apm-server to start...
2422
response=$(curl $host)
2523

2624
until [ "$response" = "200" ]; do
27-
response=$(curl --write-out %{http_code} --silent --output /dev/null "${host}/api/status")
25+
response=$(curl --write-out %{http_code} --silent --output /dev/null "${host}")
2826
echo '.'
2927
sleep 1
3028
done
3129

32-
>&2 echo "Kibana is up"
30+
>&2 echo "apm-server is up"
3331
exec $cmd

dev-tools/integration/elasticsearch.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ network.host: 0.0.0.0
33

44
xpack.security.enabled: true
55
xpack.security.authc.api_key.enabled: true
6+
xpack.security.authc.token.enabled: true
67
xpack.license.self_generated.type: trial
7-
discovery.type: single-node
8+
discovery.type: single-node

0 commit comments

Comments
 (0)