Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions internal/stack/_static/docker-compose-stack.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,12 @@ services:
interval: 60s
timeout: 50s
retries: 5
# logstash expects the key in pkcs8 format. Hence converting the key.pem to pkcs8 format using openssl.
# Also logstash-filter-elastic_integration plugin is installed by default to run ingest pipelines in logstash.
# elastic-package#1637 made improvements to enable logstash stats through port 9600.
command: bash -c 'openssl pkcs8 -inform PEM -in /usr/share/logstash/config/certs/key.pem -topk8 -nocrypt -outform PEM -out /tmp/logstash.pkcs8.key && chmod +x /tmp/logstash.pkcs8.key && if [[ ! $(bin/logstash-plugin list) == *"logstash-filter-elastic_integration"* ]]; then echo "Missing plugin logstash-filter-elastic_integration, installing now" && bin/logstash-plugin install logstash-filter-elastic_integration; fi && bin/logstash -f /usr/share/logstash/pipeline/logstash.conf'
command: bash /usr/share/logstash/startup.sh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 thanks!

volumes:
- "../certs/logstash/key.pem:/usr/share/logstash/config/certs/key.pem"
- "../certs/logstash/cert.pem:/usr/share/logstash/config/certs/cert.pem"
- "../certs/logstash/ca-cert.pem:/usr/share/logstash/config/certs/ca-cert.pem"
- "../certs/elasticsearch/cert.pem:/usr/share/logstash/config/certs/elasticsearch.pem"
- "./logstash.conf:/usr/share/logstash/pipeline/logstash.conf:ro"
- "../certs/logstash:/usr/share/logstash/config/certs"
- "../certs/elasticsearch/cert.pem:/usr/share/logstash/config/certs/elasticsearch.pem:ro"
- "./logstash.conf:/usr/share/logstash/pipeline/generated_logstash.conf:ro"
- "./logstash_startup.sh:/usr/share/logstash/startup.sh"
ports:
- "127.0.0.1:5044:5044"
- "127.0.0.1:9600:9600"
Expand Down
38 changes: 38 additions & 0 deletions internal/stack/_static/logstash_startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

set -euo pipefail

LOGSTASH_HOME="/usr/share/logstash/"

# logstash expects the key in pkcs8 format.
# Hence converting the key.pem to pkcs8 format using openssl.
create_cert() {
ls_cert_path="$LOGSTASH_HOME/config/certs"
openssl pkcs8 -inform PEM -in "$ls_cert_path/key.pem" -topk8 -nocrypt -outform PEM -out "/tmp/logstash.pkcs8.key"
chmod 777 "/tmp/logstash.pkcs8.key"
Comment on lines +11 to +12
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit. It doesn't use to be a good practice to write a key in /tmp or with 777. But this is a testing scenario, so as you prefer if we don't have another way to do it now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! Let me follow up Nits with separate PR because this is somehow blocking my another task: elastic/logstash-filter-elastic_integration#122 (comment)

}

# config copy is intentional that mounted volumes will be busy and cannot be overwritten
overwrite_pipeline_config() {
ls_pipeline_config_path="$LOGSTASH_HOME/pipeline/"
cat "$ls_pipeline_config_path/generated_logstash.conf" > "$ls_pipeline_config_path/logstash.conf"
}

# installs the given plugin if it is not installed
install_plugin_if_missing() {
plugin_name=$1
if [[ ! $(bin/logstash-plugin list) == *"$plugin_name"* ]]; then
echo "Missing plugin $plugin_name, installing now"
bin/logstash-plugin install "$plugin_name"
fi
}

# runs Logstash
run() {
bin/logstash -f "$LOGSTASH_HOME/pipeline/logstash.conf" --config.reload.automatic
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit. Could we use exec to replace the process?

Suggested change
bin/logstash -f "$LOGSTASH_HOME/pipeline/logstash.conf" --config.reload.automatic
exec bin/logstash -f "$LOGSTASH_HOME/pipeline/logstash.conf" --config.reload.automatic

}

create_cert
overwrite_pipeline_config
install_plugin_if_missing "logstash-filter-elastic_integration"
run
8 changes: 3 additions & 5 deletions internal/stack/_static/serverless-docker-compose.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ services:
interval: 60s
timeout: 50s
retries: 5
# logstash expects the key in pkcs8 format. Hence converting the key.pem to pkcs8 format using openssl.
# Also logstash-filter-elastic_integration plugin is installed by default to run ingest pipelines in logstash.
# elastic-package#1637 made improvements to enable logstash stats through port 9600.
command: bash -c 'openssl pkcs8 -inform PEM -in /usr/share/logstash/config/certs/key.pem -topk8 -nocrypt -outform PEM -out /usr/share/logstash/config/certs/logstash.pkcs8.key && chmod 777 /usr/share/logstash/config/certs/logstash.pkcs8.key && if [[ ! $(bin/logstash-plugin list) == *"logstash-filter-elastic_integration"* ]]; then echo "Missing plugin logstash-filter-elastic_integration, installing now" && bin/logstash-plugin install logstash-filter-elastic_integration; fi && bin/logstash -f /usr/share/logstash/pipeline/logstash.conf'
command: bash /usr/share/logstash/startup.sh
volumes:
- "../certs/logstash:/usr/share/logstash/config/certs"
- "./logstash.conf:/usr/share/logstash/pipeline/logstash.conf:ro"
- "./logstash.conf:/usr/share/logstash/pipeline/generated_logstash.conf:ro"
- "./logstash_startup.sh:/usr/share/logstash/startup.sh"
ports:
- "127.0.0.1:5044:5044"
- "127.0.0.1:9600:9600"
Expand Down
6 changes: 6 additions & 0 deletions internal/stack/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ var (
Path: ElasticAgentEnvFile,
Content: staticSource.Template("_static/elastic-agent.env.tmpl"),
},
&resource.File{
Path: "logstash_startup.sh",
CreateParent: true,
Content: staticSource.Template("_static/logstash_startup.sh"),
Mode: resource.FileMode(0755),
},
}
)

Expand Down
6 changes: 6 additions & 0 deletions internal/stack/serverlessresources.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ var (
Path: LogstashConfigFile,
Content: staticSource.Template("_static/serverless-logstash.conf.tmpl"),
},
&resource.File{
Path: "logstash_startup.sh",
CreateParent: true,
Content: staticSource.Template("_static/logstash_startup.sh"),
Mode: resource.FileMode(0755),
},
}
)

Expand Down