-
Notifications
You must be signed in to change notification settings - Fork 119
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
Allow to define custom scripts in independent Elastic Agents #1822
Conversation
Update agent code to use go-resources to deploy the required files.
if [[ "$independent_agent" == "false" && "$package_name" == "oracle" ]]; then | ||
echoerr "Package \"${package_name}\" skipped: not supported with Elastic Agent running in the stack (missing required software)." | ||
continue | ||
fi |
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.
Required exception, since CI tests this package with both:
- Generic Elastic stack started with
elastic-package stack up
- Independent Elastic Agents (setting env. variable)
Elastic Agent from the stack does not have the required libraries for this package.
@@ -13,6 +13,27 @@ const ( | |||
elasticAgentTagsEnv = "ELASTIC_AGENT_TAGS" | |||
) | |||
|
|||
type AgentSettings struct { |
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.
Moved to an independent struct in order to be used as embbeded struct here and in the test config. That makes possible to copy all fields at one in https://github.com/elastic/elastic-package/pull/1822/files#diff-de89bc59d9fa58f6220a67bda14afddc8f04ef1b816e81c2ca851711625f5834R339
pre_start_script: | | ||
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/opt/oracle/instantclient_21_4" | ||
export PATH="${PATH}:/opt/oracle/instantclient_21_4" | ||
cd /opt/oracle/instantclient_21_4 |
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.
Tested locally without this pre-start script and it also worked. However, I'd prefer to keep it since it was set in the Dockerfile too here:
Lines 13 to 16 in e53417a
RUN export LD_LIBRARY_PATH=/opt/oracle/instantclient_21_4:$LD_LIBRARY_PATH && export PATH=/opt/oracle/instantclient_21_7:$PATH | |
ENV LD_LIBRARY_PATH "${LD_LIBRARY_PATH}:/opt/oracle/instantclient_21_4" | |
ENV PATH "${PATH}:/opt/oracle/instantclient_21_4" | |
WORKDIR /opt/oracle/instantclient_21_4 |
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.
Maybe we can use a simpler package for testing. It could even maybe enough to have a script that writes a file, and a config that reads this file with a log input.
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.
Added a new test package under test/packages/other
with a minimal configuration to use these scripts.
About the test package oracle
, do you think it should be kept under parallel
as an example for the migration ?
vars: | ||
hosts: | ||
- "oracle://sys:Oradoc_db1@elastic-package-service-oracle-1:1521/ORCLCDB.localdomain?sysdba=1" | ||
agent: |
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.
According to the tests in this PR, to update the oracle
package in the integrations repository it should be needed:
- add this key
agent
to each of the test system configuration files - update the hosts value to set as host
elastic-package-service-oracle-1
. - remove
_dev/deploy/agent
folders - replace agent folders with
_dev/deploy/docker
folder (something similar to this PR) with just the service definition (oracle
).
@@ -0,0 +1,16 @@ | |||
vars: | |||
hosts: | |||
- "oracle://sys:Oradoc_db1@elastic-package-service-oracle-1:1521/ORCLCDB.localdomain?sysdba=1" |
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.
This is required to be changed since the container name changes from oracle
to elastic-package-service-oracle-1
.
- - "oracle://sys:Oradoc_db1@oracle:1521/ORCLCDB.localdomain?sysdba=1"
+ - "oracle://sys:Oradoc_db1@elastic-package-service-oracle-1:1521/ORCLCDB.localdomain?sysdba=1"
services: | ||
elastic-agent: | ||
hostname: ${AGENT_HOSTNAME} | ||
{{ if ne $custom_script "" }} | ||
image: "${ELASTIC_AGENT_IMAGE_REF}-custom" |
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.
Should we use some other suffix to avoid conflicts? The image tag will be used if it exists, and it could be an unexpected one. Maybe we can use a checksum of the scripts.
image: "${ELASTIC_AGENT_IMAGE_REF}-custom" | |
image: "${ELASTIC_AGENT_IMAGE_REF}-{{ $some_id }}" |
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.
Added as a suffix the MD5 sum of the Dockerfile created.
image: "elastic-package-test-elastic-agent-complete:{{ $stack_version }}-{{ $dockerfile_hash }}"
The result is images like this:
elastic-package-test-elastic-agent-complete:8.13.2-861d45f9a2042f22c52105b4b3d1708a
- "oracle://sys:Oradoc_db1@elastic-package-service-oracle-1:1521/ORCLCDB.localdomain?sysdba=1" | ||
agent: | ||
runtime: docker | ||
custom_script: | |
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.
Should we make this an object?
custom_script: | | |
custom_script: | |
content: | |
This could be useful to support referencing scripts in the future, or even other interpreters:
custom_script:
language: bash
source: ./custom.sh
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.
Added for custom_script
(now it's named provisioning_script
) and also for pre_start_script
.
For pre_start_script
, it is just allowed language sh
, since it is injected directly those commands into the start script (entrypoint.sh).
test/packages/parallel/oracle/data_stream/memory/_dev/test/system/test-memory-config.yml
Outdated
Show resolved
Hide resolved
pre_start_script: | | ||
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/opt/oracle/instantclient_21_4" | ||
export PATH="${PATH}:/opt/oracle/instantclient_21_4" | ||
cd /opt/oracle/instantclient_21_4 |
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.
Maybe we can use a simpler package for testing. It could even maybe enough to have a script that writes a file, and a config that reads this file with a log input.
internal/agentdeployer/agent.go
Outdated
"kibana_host": "https://kibana:5601", | ||
"fleet_url": "https://fleet-server:8220", |
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.
Umm, would that work with the serverless provider?
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.
I took as a basis the docker-custom base template, and according to that I'd say custom agents would not work with the serverless provider.
elastic-package/internal/servicedeployer/_static/docker-custom-agent-base.yml
Lines 11 to 15 in 901661e
environment: | |
- FLEET_ENROLL=1 | |
- FLEET_URL=https://fleet-server:8220 | |
- KIBANA_HOST=https://kibana:5601 | |
- FLEET_TOKEN_POLICY_NAME=${FLEET_TOKEN_POLICY_NAME} |
I'll try to give it a chance to make it work.
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.
Well, we can leave this for a different change.
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.
Yes, it would be better. It would require a few more changes. Afterwards, I'll create a PR to add Serverless support for independent Elastic Agents.
/test |
💚 Build Succeeded
History
cc @mrodm |
@@ -0,0 +1,40 @@ | |||
format_version: 1.0.0 | |||
name: oracle |
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.
Maybe it's interesting to keep this for reference until oracle
package is updated in integrations. WDYT ?
- json: | ||
field: message | ||
target_field: target | ||
- set: | ||
field: error.message | ||
value: not present target | ||
if: ctx?.target == null | ||
on_failure: | ||
- set: | ||
field: error.message | ||
value: '{{ _ingest.on_failure_message }}' |
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.
If message is not a JSON (written by the entrypoint script) , system tests are going to fail.
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.
👍
Part of #787
This PR allows to define custom scripts for independent Elastic Agents. This custom scripts can be used to install required software to run the required tests successfully. For instance some libraries as it happens with
oracle
package.Example of the new keys added into the configuration file:
Now the files required to spin a new independent Elastic Agent using containers has been migrated to
go-resources
. Files generated can be checked within the profile folder:$ ls -l ~/.elastic-package/profiles/default/deployer/docker-agent-oracle-memory-61511/ total 12 -rw-r--r-- 1 user user 1046 may 8 16:15 docker-agent-base.yml -rw-r--r-- 1 user user 203 may 8 16:15 Dockerfile -rwxr-xr-x 1 user user 764 may 8 16:15 script.sh
If custom scripts are required,
elastic-package
builds a new Docker image adding the suffix-custom
to the tag. Example:$ docker images |grep custom docker.elastic.co/elastic-agent/elastic-agent-complete 8.13.2-custom ee55b4ece29b 22 hours ago 3.95GB
Testing
Added a new test package
test/packages/parallel/oracle
based on the one fromtest/packages/with-custom-agent/oracle
but with some changes:oracle
service in_dev/deploy/docker
.This package does not work when tested with the Elastic stack running from the stack since it is missing some required libraries/dependencies the container.