diff --git a/.github/e2e.sh b/.github/e2e.sh index 87b82fbe..3bcadbda 100755 --- a/.github/e2e.sh +++ b/.github/e2e.sh @@ -102,6 +102,14 @@ EOF nix run nixpkgs#hurl -- --test --error-format=long .github/e2e.hurl } echo ::endgroup:: + + # Docker Compose + echo ::group::Docker healthcheck test + docker compose ps --format json \ + | jq 'map(select(.State != "running" or .Health == "unhealthy")) | map({Service, State, Status, Health})' + docker compose ps --format json \ + | jq -e 'map(select(.State != "running" or .Health == "unhealthy")) | length == 0' + echo ::endgroup:: ;; coverage) diff --git a/cmd/healthcheck.go b/cmd/healthcheck.go index 4d768130..1b7f7b4e 100644 --- a/cmd/healthcheck.go +++ b/cmd/healthcheck.go @@ -4,13 +4,27 @@ package cmd import ( + "fmt" "net/http" "github.com/spf13/cobra" ) +type healthcheckOptions struct { + Host string + Port uint16 +} + +// HealthcheckOptions stores the command-line option values for the healthcheck +// command. +var HealthcheckOptions healthcheckOptions + func init() { RootCmd.AddCommand(healthcheckCmd) + healthcheckCmd.Flags().Uint16VarP(&HealthcheckOptions.Port, "port", "p", 8080, + "HTTP port for health check") + healthcheckCmd.Flags().StringVarP(&HealthcheckOptions.Host, "host", "h", "localhost", + "HTTP host for health check") } var healthcheckCmd = &cobra.Command{ @@ -18,7 +32,9 @@ var healthcheckCmd = &cobra.Command{ Short: "Check healthness", Long: `Check if Akvorado is alive using the builtin HTTP endpoint.`, RunE: func(cmd *cobra.Command, _ []string) error { - resp, err := http.Get("http://localhost:8080/api/v0/healthcheck") + resp, err := http.Get(fmt.Sprintf("http://%s:%d/api/v0/healthcheck", + HealthcheckOptions.Host, + HealthcheckOptions.Port)) if err != nil { return err } diff --git a/console/data/docs/99-changelog.md b/console/data/docs/99-changelog.md index 37484462..89e3e131 100644 --- a/console/data/docs/99-changelog.md +++ b/console/data/docs/99-changelog.md @@ -14,6 +14,7 @@ identified with a specific icon: - 🩹 *docker*: restart geoip container on boot - 🌱 *orchestrator*: add `kafka`→`manage-topic` flag to enable or disable topic management +- 🌱 *cmd*: add `--host` and `--port` flags to `akvorado healthcheck` ## 2.0.3 - 2025-11-19