Skip to content

Commit bd55cfa

Browse files
committed
feat(fleet): collect Docker logs and metrics
Mirrors the behaviour of the Metricsbeat and Filebeat extensions through Elastic Agent, using the Docker integration.
1 parent 51f5978 commit bd55cfa

File tree

4 files changed

+58
-8
lines changed

4 files changed

+58
-8
lines changed

.github/workflows/scripts/run-tests-fleet.sh

+42-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ endgroup
3535
# AND event.dataset:"system.cpu"
3636
# AND metricset.name:"cpu"
3737
#
38-
log 'Searching a document generated by Fleet Server'
38+
log 'Searching a system document generated by Fleet Server'
3939

4040
declare response
4141
declare -i count
@@ -70,3 +70,44 @@ if (( count == 0 )); then
7070
echo 'Expected at least 1 document'
7171
exit 1
7272
fi
73+
74+
# We expect to find log entries for the 'elasticsearch' Compose service using
75+
# the following query:
76+
#
77+
# agent.name:"fleet-server"
78+
# AND agent.type:"filebeat"
79+
# AND container.name:"docker-elk-elasticsearch-1"
80+
#
81+
log 'Searching a container document generated by Fleet Server'
82+
83+
response=
84+
count=0
85+
86+
was_retried=0
87+
88+
# retry for max 60s (30*2s)
89+
for _ in $(seq 1 30); do
90+
response="$(curl "http://${ip_es}:9200/logs-docker.container_logs-default/_search?q=agent.name:%22fleet-server%22%20AND%20agent.type:%22filebeat%22%20AND%20container.name:%22docker-elk-elasticsearch-1%22&pretty" -s -u elastic:testpasswd)"
91+
92+
set +u # prevent "unbound variable" if assigned value is not an integer
93+
count="$(jq -rn --argjson data "${response}" '$data.hits.total.value')"
94+
set -u
95+
96+
if (( count > 0 )); then
97+
break
98+
fi
99+
100+
was_retried=1
101+
echo -n 'x' >&2
102+
sleep 2
103+
done
104+
if ((was_retried)); then
105+
# flush stderr, important in non-interactive environments (CI)
106+
echo >&2
107+
fi
108+
109+
echo "$response"
110+
if (( count == 0 )); then
111+
echo 'Expected at least 1 document'
112+
exit 1
113+
fi

extensions/fleet/README.md

-7
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ management UI: [Fleet UI Settings][fleet-cfg].
3737

3838
## Known Issues
3939

40-
- Logs and metrics are only collected within the Fleet Server's container. Ultimately, we want to emulate the behaviour
41-
of the existing Metricsbeat and Filebeat extensions, and collect logs and metrics from all ELK containers
42-
out-of-the-box. Unfortunately, this kind of use-case isn't (yet) well supported by Fleet, and most advanced
43-
configurations currently require running Elastic Agents in [standalone mode][fleet-standalone].
44-
(Relevant resource: [Migrate from Beats to Elastic Agent][fleet-beats])
4540
- The Elastic Agent auto-enrolls using the `elastic` super-user. With this approach, you do not need to generate a
4641
service token — either using the Fleet management UI or [CLI utility][es-svc-token] — prior to starting this
4742
extension. However convenient that is, this approach _does not follow security best practices_, and we recommend
@@ -64,6 +59,4 @@ management UI: [Fleet UI Settings][fleet-cfg].
6459

6560
[config-kbn]: ../../kibana/config/kibana.yml
6661

67-
[fleet-standalone]: https://www.elastic.co/guide/en/fleet/current/elastic-agent-configuration.html
68-
[fleet-beats]: https://www.elastic.co/guide/en/fleet/current/migrate-beats-to-agent.html
6962
[es-svc-token]: https://www.elastic.co/guide/en/elasticsearch/reference/current/service-tokens-command.html

extensions/fleet/fleet-compose.yml

+11
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,19 @@ services:
66
context: extensions/fleet/
77
args:
88
ELASTIC_VERSION: ${ELASTIC_VERSION}
9+
# Run as 'root' instead of 'elastic-agent' (uid 1000) to allow reading
10+
# 'docker.sock' and the host's filesystem.
11+
user: root
912
volumes:
1013
- fleet-server:/usr/share/elastic-agent/state:Z
14+
- type: bind
15+
source: /var/lib/docker/containers
16+
target: /var/lib/docker/containers
17+
read_only: true
18+
- type: bind
19+
source: /var/run/docker.sock
20+
target: /var/run/docker.sock
21+
read_only: true
1122
environment:
1223
FLEET_SERVER_ENABLE: '1'
1324
FLEET_SERVER_INSECURE_HTTP: '1'

kibana/config/kibana.yml

+5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ xpack.fleet.packages:
4747
version: latest
4848
- name: elastic_agent
4949
version: latest
50+
- name: docker
51+
version: latest
5052
- name: apm
5153
version: latest
5254

@@ -67,6 +69,9 @@ xpack.fleet.agentPolicies:
6769
- name: elastic_agent-1
6870
package:
6971
name: elastic_agent
72+
- name: docker-1
73+
package:
74+
name: docker
7075
- name: Agent Policy APM Server
7176
id: agent-policy-apm-server
7277
description: Static agent policy for the APM Server integration

0 commit comments

Comments
 (0)