-
Notifications
You must be signed in to change notification settings - Fork 427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add system tests to kibana package #4444
Merged
crespocarlos
merged 10 commits into
elastic:main
from
crespocarlos:4008-kibana-package-system-tests
Nov 1, 2022
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a618b8c
Add system tests for kibana package
crespocarlos e224f97
Fix mapping and README.md
crespocarlos 9f9ffce
Fix stats and status tests
crespocarlos 2615158
Fix log ingest pipeline
crespocarlos 3b56c0f
Set default env var value
crespocarlos 0aca5a7
Fix docker-compose.yml
crespocarlos 8196c20
Fix docker-compose setup and use Hostname env var on test config
crespocarlos 0376cf5
Remove mime_type field when null
crespocarlos f4eb2d1
Fix log generation
crespocarlos 1fe63da
Replace .env with variants.yml
crespocarlos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,62 @@ | ||
version: "2.3" | ||
services: | ||
elasticsearch: | ||
image: "docker.elastic.co/elasticsearch/elasticsearch:${ELASTIC_VERSION}" | ||
image: "docker.elastic.co/elasticsearch/elasticsearch:${ELASTIC_VERSION:-8.5.0-SNAPSHOT}" | ||
environment: | ||
- "ES_JAVA_OPTS=-Xms1g -Xmx1g" | ||
- ELASTIC_PASSWORD | ||
- "ELASTIC_PASSWORD=changeme" | ||
ports: | ||
- "127.0.0.1:9201:9200" | ||
volumes: | ||
- "./config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml" | ||
healthcheck: | ||
test: curl -sfo /dev/null -u elastic:${ELASTIC_PASSWORD} localhost:9200 || exit 1 | ||
test: curl -sfo /dev/null -u elastic:changeme http://localhost:9200 || exit 1 | ||
retries: 300 | ||
interval: 1s | ||
setup: | ||
image: "alpine/curl:latest" | ||
user: root | ||
environment: | ||
- "ES_SERVICE_HOST=http://elasticsearch:9200" | ||
- ELASTIC_PASSWORD | ||
- KIBANA_PASSWORD | ||
- "ELASTIC_PASSWORD=changeme" | ||
- "KIBANA_PASSWORD=changeme" | ||
command: ["/bin/sh", "./setup.sh"] | ||
volumes: | ||
- ./scripts/setup.sh:/setup.sh | ||
- "./scripts/setup.sh:/setup.sh" | ||
kibana: | ||
image: "docker.elastic.co/kibana/kibana:${ELASTIC_VERSION}" | ||
image: "docker.elastic.co/kibana/kibana:${ELASTIC_VERSION:-8.5.0-SNAPSHOT}" | ||
user: "1001:0" | ||
group_add: | ||
- "0" | ||
depends_on: | ||
elasticsearch: | ||
condition: service_healthy | ||
volumes: | ||
- ./config/kibana.yml:/usr/share/kibana/config/kibana.yml | ||
- ${SERVICE_LOGS_DIR}:/usr/share/kibana/logs | ||
- "./config/kibana.yml:/usr/share/kibana/config/kibana.yml" | ||
- "kbn_logs:/usr/share/kibana/logs" | ||
ports: | ||
- "127.0.0.1:5602:5601" | ||
healthcheck: | ||
test: curl -sfo /dev/null localhost:5601 || exit 1 | ||
test: curl -sfo /dev/null http://localhost:5601 || exit 1 | ||
retries: 600 | ||
interval: 1s | ||
log_generation: | ||
image: "alpine/curl:latest" | ||
user: root | ||
depends_on: | ||
kibana: | ||
condition: service_healthy | ||
environment: | ||
- "KIBANA_SERVICE_HOST=http://kibana:5601" | ||
- ELASTIC_PASSWORD | ||
- KIBANA_PASSWORD | ||
command: ["/bin/sh", "./generate-audit-logs.sh"] | ||
- "ELASTIC_PASSWORD=changeme" | ||
- "KIBANA_PASSWORD=changeme" | ||
command: ["/bin/sh", "./generate-logs.sh"] | ||
volumes: | ||
- ./scripts/generate-audit-logs.sh:/generate-audit-logs.sh | ||
- "./scripts/generate-logs.sh:/generate-logs.sh" | ||
- "${SERVICE_LOGS_DIR}:/var/log" | ||
- "kbn_logs:/kbn_logs" | ||
volumes: | ||
kbn_logs: | ||
driver_opts: | ||
type: tmpfs | ||
device: tmpfs |
24 changes: 0 additions & 24 deletions
24
packages/kibana/_dev/deploy/docker/scripts/generate-audit-logs.sh
This file was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
packages/kibana/_dev/deploy/docker/scripts/generate-logs.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/bin/sh | ||
|
||
# Makes requests to kibana API so that audit logs can be generated | ||
set -e | ||
|
||
# Copy the log files content from this container to /var/log/ which is a bind mounted to ${SERVICE_LOGS_DIR} | ||
# This sh must be executed by a root user in order to have permission to write in the ${SERVICE_LOGS_DIR} folder | ||
copy_log_files () { | ||
for f in /kbn_logs/*; | ||
do | ||
echo "Copy ${f##*/} file..." | ||
|
||
if [[ ! -e /var/log/${f##*/} ]]; then | ||
touch /var/log/${f##*/} | ||
fi | ||
|
||
## appends only new lines | ||
comm -23 "$f" /var/log/${f##*/} >> /var/log/${f##*/} | ||
done | ||
} | ||
|
||
attempt_counter=0 | ||
max_attempts=6 | ||
|
||
until curl -s --request GET \ | ||
--url $KIBANA_SERVICE_HOST/login \ | ||
--user "elastic:$KIBANA_PASSWORD" \ | ||
--header 'Content-Type: application/json' | ||
do | ||
|
||
if [ ${attempt_counter} -eq ${max_attempts} ];then | ||
echo "Max attempts reached" | ||
exit 1 | ||
fi | ||
|
||
printf '.' | ||
attempt_counter=$(($attempt_counter+1)) | ||
sleep 10 | ||
done | ||
|
||
while true | ||
do | ||
curl -s --request GET \ | ||
--url $KIBANA_SERVICE_HOST/api/features \ | ||
--user "elastic:$KIBANA_PASSWORD" \ | ||
--header 'Content-Type: application/json' | ||
|
||
echo "Audit log created" | ||
|
||
copy_log_files | ||
|
||
sleep 10 | ||
done |
24 changes: 17 additions & 7 deletions
24
packages/kibana/_dev/deploy/docker/scripts/setup.sh
100644 → 100755
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,22 @@ | ||
#!/bin/sh | ||
|
||
#Sets a password for kibana_system user | ||
attempt_counter=0 | ||
max_attempts=6 | ||
|
||
set -e | ||
|
||
until curl --request POST $ES_SERVICE_HOST/_security/user/kibana_system/_password \ | ||
--user elastic:$ELASTIC_PASSWORD \ | ||
until curl -s --request POST $ES_SERVICE_HOST/_security/user/kibana_system/_password \ | ||
--user "elastic:$ELASTIC_PASSWORD" \ | ||
--header 'Content-Type: application/json' \ | ||
--data "{\"password\":\"$KIBANA_PASSWORD\"}" | ||
do sleep 10; | ||
done; | ||
--data "{\"password\":\"$KIBANA_PASSWORD\"}" | ||
do | ||
if [ ${attempt_counter} -eq ${max_attempts} ];then | ||
echo "Max attempts reached" | ||
exit 1 | ||
fi | ||
|
||
printf '.' | ||
attempt_counter=$(($attempt_counter+1)) | ||
sleep 10 | ||
done | ||
|
||
echo "Setup complete" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
variants: | ||
kibana_8.5.0: | ||
ELASTIC_VERSION: 8.5.0-SNAPSHOT | ||
default: kibana_8.5.0 |
5 changes: 5 additions & 0 deletions
5
packages/kibana/data_stream/audit/_dev/test/system/test-default-config.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
input: logfile | ||
data_stream: | ||
vars: | ||
paths: | ||
- "{{SERVICE_LOGS_DIR}}/audit.log" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since Kibana container is not started with
root
user, we use a in memory mount. With this mount,log_generation
container, which is logged in withroot
, is able to get the files generated by kibana and copy them to${SERVICE_LOGS_DIR}