Skip to content

Make examples start and manage dockerized Prometheus if Prometheus is missing #157

Open
@gagbo

Description

Oh I see, so the point of this PR is to automatically start Prometheus in a Docker container if it's missing, instead of having to have Prometheus installed on the computer.

The title of the PR made me think the goal was to connect to something that has been running for months on the machine already, with configured targets, that's why I was confused.

If that's the case, then a simple solution would be to write an extra /util/prometheus.docker.internal.yml config file, that configures scraping targets to point to host.docker.internal instead of localhost, and tell MacOS/Windows users to use this file instead of the current one (I haven't tested it yet, but I'm fairly confident it would work)

A (more complicated) solution could be to:

  • catch when the prometheus binary is missing,
  • if that's the case, directly use std::process::Command to spawn the container with the command,
  • use the Drop implementation of the ChildGuard to kill the spawned command (which will kill the Prometheus container)

The more complex solution still needs the simple version as a stepping stone to work, i.e. using a if cfg! statement to choose whether to use util/prometheus.yml or util/prometheus.docker.yml as the volume mount input argument basically. But if we're able to pull that off, it would keep the examples self contained (so no need to read the docs and find and copy/paste the docker run command), while also working on all major OSes even if you don't have Prometheus installed. What do you think?

If you don't want to commit more time to this though it's fine, we can put in the docs that it'll only work on Linux, and I'll patch the missing bits for different OSes.

(I also noticed that the util/prometheus.yml file also references the autometrics recording and alerting rules files, which allows to see how the instrumented code generates alerts (or not); but this file doesn't exist in this repo anymore so we'll tackle this in another issue)

Originally posted by @gagbo in #114 (comment)

This also means we need to figure out the ports for the example apps, and fix the autometrics rules file

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions