Skip to content

Feature Request: Add cURL to the Container Images #477

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

Open
SeamusGrafana opened this issue Mar 6, 2023 · 7 comments · May be fixed by grafana/agent#6297
Open

Feature Request: Add cURL to the Container Images #477

SeamusGrafana opened this issue Mar 6, 2023 · 7 comments · May be fixed by grafana/agent#6297
Labels
enhancement New feature or request

Comments

@SeamusGrafana
Copy link

Hello,

Would it be possible to add cURL to the Container Images by default?

This helps with troubleshooting connectivity from the Agent Container to an Endpoint and I often find myself having to install it manually when testing/troubleshooting issues and it aids me in resolving them.

Additionally, it also allows you to define a custom Healthcheck in a Docker Compose file to use the health endpoint.

Thanks

@tpaschalis tpaschalis added the enhancement New feature or request label Mar 8, 2023
@PaniniHode PaniniHode linked a pull request Feb 5, 2024 that will close this issue
4 tasks
@tpaschalis
Copy link
Member

Is this enabling any use case other than a shortcut for apt update && apt-install -y curl?

If it isn't, then I'd be a little wary of introducing a new dependency just for the sake of it.

@SeamusGrafana
Copy link
Author

Personally, I would use it as a Health Check for the Docker Container when running Docker Compose, against the Ready or Health Endpoint

@andeki92
Copy link

andeki92 commented Apr 5, 2024

I support the idea of incorporating curl to facilitate easier health checks. Our setup uses Podman, where health checks are performed within the container. Consequently, accessing the /-/ready endpoint directly is challenging.

For those encountering this issue, an alternative is to employ exec health checks. The following command can serve as a workaround:

/bin/bash -c 'echo -e "GET /-/ready HTTP/1.1\nHost: localhost\nConnection: close\n\n"> /dev/tcp/localhost/<application-port>'

This uses the /dev/tcp system utility to report the endpoint status!

@rfratto rfratto transferred this issue from grafana/agent Apr 11, 2024
@brpaz
Copy link

brpaz commented Apr 30, 2024

@tpaschalis I stumbled on this when trying to install Grafana Alloy for the first time, on my cluster.

I understand the reason, for not introducing a new dependency, but curl or wget are pretty standard to have and pretty much the common way to do health checks in containers.

Having the health endpoint is kind useless if I can´t call it :)

@lehuyv
Copy link

lehuyv commented Aug 7, 2024

A health endpoint would also be useful in a non-containerized situation. For example, when Grafana Alloy is installed directly on Windows or Linux, it is used to receive traces, and there is a requirement for some sort of redundancy. Would be nice to take into consideration this use case when establishing the solution.

@adamsthws
Copy link

I support the idea of incorporating curl to facilitate easier health checks. Our setup uses Podman, where health checks are performed within the container. Consequently, accessing the /-/ready endpoint directly is challenging.

For those encountering this issue, an alternative is to employ exec health checks. The following command can serve as a workaround:

/bin/bash -c 'echo -e "GET /-/ready HTTP/1.1\nHost: localhost\nConnection: close\n\n"> /dev/tcp/localhost/'

This uses the /dev/tcp system utility to report the endpoint status!

Thankyou for this kind stranger!

@ssukienn
Copy link

Method with piping to TCP descriptor (this is bash based btw!) will not take into account layer 7 HTTP request/response at all. So any endpoint would work as long as the TCP connection is established.

This already is super hacky and ugly and probably better to just extend the image for curl/wget, but we could pipe the response back by using a descriptor of our choice (i.e 42 but whatever >2 should do):

root@2d2b65251d23:/# exec 42<>/dev/tcp/localhost/12345
root@2d2b65251d23:/# echo -e "GET /-/ready HTTP/1.1\nHost: localhost\nConnection: close\n\n" >&42
root@2d2b65251d23:/# cat <&42
HTTP/1.1 200 OK
Date: Mon, 21 Apr 2025 17:21:36 GMT
Content-Length: 16
Content-Type: text/plain; charset=utf-8
Connection: close

Alloy is ready.

and then we can parse actual HTTP response and test for something like 200 status code. Whole thing;

    healthcheck:
      test: 
        - CMD-SHELL
        - |
          bash -c '
          exec 42<>/dev/tcp/localhost/12345;
          echo -e "GET /-/ready HTTP/1.1\nHost: localhost\nConnection: close\n\n" >&42;
          head -1 <&42 | cut -d" " -f2 | grep -q "^200$" || exit 1;
          exec 42<&-;
          exec 42>&-'

Seems to work, but if HC could race each other, this has some potential for side effects

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

7 participants