cmd/healthcheck: add --host and --port flags

But really, this could be autodiscovered through an abstract Unix socket
instead.
This commit is contained in:
Vincent Bernat
2025-11-24 05:36:37 +01:00
parent 61dd6bd7d7
commit e0c6b878fa
3 changed files with 26 additions and 1 deletions

8
.github/e2e.sh vendored
View File

@@ -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)

View File

@@ -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
}

View File

@@ -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