elastic / elastic-agent

Elastic Agent - single, unified way to add monitoring for logs, metrics, and other types of data to a host.
Other
126 stars 135 forks source link

Docker image running Elastic Agent in Otel mode #5246

Closed michalpristas closed 1 month ago

michalpristas commented 2 months ago

Currently agent start in normal mode by default. Only way how to change that is overriding command that's executed. This approach is not always viable.

For this reason we should create and additional image where agent starts in otel mode.

@cmacknz while we're at it it would be nice to consider making this image slim and get rid of all the agent boilerplate that is not needed when running otel (as this will be explicitly named elastic-agent-otel). What i have in mind is symlink to binary and all beats/endpoint...

strawgate commented 1 month ago

it it would be nice to consider making this image slim

Ideally we should keep all components in the image for now and minimize the differences between this and the existing image until we have a better idea of how long this will be around for and what the use-cases will be.

For this reason we should create and additional image where agent starts in otel mode.

I wish I knew more about the build process but I would have thought that we could have just built from the existing image:

FROM .../elastic-agent:current_tag...

CMD ["--config", "otel.yml"]

And saved ourselves from adding a whole new image pipeline? Or just put the otel CMD part in a conditional and otherwise have the two images be identical?

cmacknz commented 1 month ago

It might actually be simpler if we just implement this as an environment variable like ELASTIC_AGENT_OTEL=true to save us the work of creating a new container.

Thinking more, one day we probably want to obsolete the elastic-agent-otel container because it will be the same as elastic-agent so we can just save ourselves the trouble.

rogercoll commented 1 month ago

@michalpristas Is this change already included in 8.15.1-SNAPSHOT version? How could I test it?

The following command seems not to be launching the otel binary yet (or ELASTIC_AGENT_OTEL="true"):

 $ docker run -e ELASTIC_AGENT_OTEL=true docker.elastic.co/beats/elastic-agent:8.15.1-SNAPSHOT
{"log.level":"info","@timestamp":"2024-08-21T15:16:29.728Z","log.origin":{"function":"github.com/elastic/elastic-agent/internal/pkg/agent/cmd.runElasticAgent","file.name":"cmd/run.go","file.line":195},"message":"Elastic Agent started","log":{"source":"elastic-agent"},"process.pid":7,"agent.version":"8.15.1","agent.unprivileged":true,"ecs.version":"1.6.0"}
blakerouse commented 1 month ago

@rogercoll This is not in 8.15.1-SNAPSHOT. It will only be present on 8.16.0-SNAPSHOT, once a new snapshot is built. Possible that one has not been built yet.

rogercoll commented 1 month ago

I can confirm that 8.16.0-SNAPSHOT has been build and fixes the issue. Thanks team!

herrBez commented 3 weeks ago

If someone needs to make it work with version 8.15.x, please note that we need to overwrite the command and also the entrypoint. Sharing a sample docker-compose.yml in the hope it can be helpful:

services:
  elastic-agent:
    image: docker.elastic.co/beats/elastic-agent:8.15.1 
    container_name: elastic-agent # instead of 
    restart: no
    entrypoint: "elastic-agent"
    command: ["otel", "-c", "/etc/elastic-agent/otel.yaml"]
    volumes:
      - type: bind
        source: ./otel.yaml
        target: /etc/elastic-agent/otel.yaml