Skip to content
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

add check to access agent-metrics endpoint #151

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 29 additions & 10 deletions internal/locald/rootmanager/tp_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rootmanager

import (
"fmt"
"net/http"
"time"

"log/slog"
Expand Down Expand Up @@ -128,16 +129,34 @@ func (mon *tpMonitor) checkTunnelProxyAccess(ctx context.Context) bool {
restartSvcs = true
}
}
if !restartSvcs {
// the grpc check for connecting to the tunnel proxy does not suffice
// because it has built-in retries and may re-use a connection while
// we are unable to establish a new connection. So, we also check
// the controller manager health endpoint
cli := &http.Client{
Transport: &http.Transport{},
Timeout: 10 * time.Second,
}
resp, err := cli.Get("http://agent-metrics.signadot.svc:9090/metrics")
if err != nil {
mon.log.Error("unable to reach agent-metrics, restarting services", "error", err)
restartSvcs = true
} else {
resp.Body.Close()
}
}
if !restartSvcs {
mon.starting = false
return true
}

if restartSvcs {
// Restart localnet
mon.root.stopLocalnetService()
mon.root.runLocalnetService(ctx, mon.tpLocalAddr, mon.ipMap)
// Restart localnet
mon.root.stopLocalnetService()
mon.root.runLocalnetService(ctx, mon.tpLocalAddr, mon.ipMap)

// Restart etc hosts
mon.root.stopEtcHostsService()
mon.root.runEtcHostsService(ctx, mon.tpLocalAddr, mon.ipMap)
}
mon.starting = false
return true
// Restart etc hosts
mon.root.stopEtcHostsService()
mon.root.runEtcHostsService(ctx, mon.tpLocalAddr, mon.ipMap)
return false
}
2 changes: 1 addition & 1 deletion internal/locald/sandboxmanager/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

var (
ErrSandboxManagerUnavailable = errors.New(
"sandboxmanager is not running, start it with \"signadot local connect\"")
`sandboxmanager is not running, start it with "signadot local connect"`)
)

func GetStatus() (*sbmapi.StatusResponse, error) {
Expand Down